<commit_before>package JpAws;

import api.Cluster;
import api.MachineGroup;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.*;
import datameer.awstasks.aws.ec2.InstanceGroupImpl;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import system.ClientToMaster;
import system.ReservationServiceImpl;
import system.Worker;

/**
 *
 * @author charlesmunger
 */
public class Ec2ReservationService extends ReservationServiceImpl
{

    /**
     * This is the AMI-ID for the machine to initialize as masters and workers.
     * Currently, it uses the standard Amazon Linux image.
     */
    public static final String AMIID = "ami-e565ba8c";
    /**
     * This is the AMI-ID for Cluster Compute instances - they need an HVM image.
     */
    public static final String HVM_AMIID = "ami-0da96764";
    /**
     * This is the name of the security group for EC2 instances to use.
     */
    public static final String SECURITY_GROUP = "jpregelgroup";
    private final AmazonEC2 ec2 = new AmazonEC2Client(PregelAuthenticator.get());
    private final Map<String, String> heapSizeMap = new HashMap<String, String>();

    public Ec2ReservationService()
    {
        heapSizeMap.put("m1.small", "-Xmx1600m -Xms1600m  ");
        heapSizeMap.put("m1.medium", "-Xmx3600m -Xms3600m ");
        heapSizeMap.put("cc2.8xlarge","-Xmx58000m ");
        heapSizeMap.put("m1.large","-Xmx7100m -Xms7100m");
        DescribeSecurityGroupsResult describeSecurityGroups = null;
        final DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withGroupNames(SECURITY_GROUP);
        try
        {
            describeSecurityGroups = ec2.describeSecurityGroups(req);
        } catch (AmazonServiceException e)
        {
            ec2.createSecurityGroup(new CreateSecurityGroupRequest(SECURITY_GROUP, "Created programatically by jpregel-aws"));
            describeSecurityGroups = ec2.describeSecurityGroups(req);
        }
        List<IpPermission> ipPermissions = describeSecurityGroups.getSecurityGroups().get(0).getIpPermissions();
        IpPermission p = new IpPermission();
        p.setIpProtocol("tcp");
        p.setFromPort(0);
        p.setToPort(65535);
        p.setIpRanges(Collections.singleton("0.0.0.0/0"));
        if (!ipPermissions.contains(p))
        {
            ec2.authorizeSecurityGroupIngress(new AuthorizeSecurityGroupIngressRequest(SECURITY_GROUP, Collections.singletonList(p)));
        }
    }

    public static Cluster  newSmallCluster(int numWorkers) throws Exception
    {
        Ec2ReservationService rs = new Ec2ReservationService();
        return new Cluster(rs,"m1.small","m1,small",numWorkers);
    }

    public static Cluster newMassiveCluster(int numWorkers) throws Exception {
        Ec2ReservationService rs = new Ec2ReservationService();<commit_msg>Fixed comma that was bugging out worker small instance reservation.<commit_after>package JpAws;

import api.Cluster;
import api.MachineGroup;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.ec2.AmazonEC2;
import com.amazonaws.services.ec2.AmazonEC2Client;
import com.amazonaws.services.ec2.model.*;
import datameer.awstasks.aws.ec2.InstanceGroupImpl;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import system.ClientToMaster;
import system.ReservationServiceImpl;
import system.Worker;

/**
 *
 * @author charlesmunger
 */
public class Ec2ReservationService extends ReservationServiceImpl
{

    /**
     * This is the AMI-ID for the machine to initialize as masters and workers.
     * Currently, it uses the standard Amazon Linux image.
     */
    public static final String AMIID = "ami-e565ba8c";
    /**
     * This is the AMI-ID for Cluster Compute instances - they need an HVM image.
     */
    public static final String HVM_AMIID = "ami-0da96764";
    /**
     * This is the name of the security group for EC2 instances to use.
     */
    public static final String SECURITY_GROUP = "jpregelgroup";
    private final AmazonEC2 ec2 = new AmazonEC2Client(PregelAuthenticator.get());
    private final Map<String, String> heapSizeMap = new HashMap<String, String>();

    public Ec2ReservationService()
    {
        heapSizeMap.put("m1.small", "-Xmx1600m -Xms1600m  ");
        heapSizeMap.put("m1.medium", "-Xmx3600m -Xms3600m ");
        heapSizeMap.put("cc2.8xlarge","-Xmx58000m ");
        heapSizeMap.put("m1.large","-Xmx7100m -Xms7100m");
        DescribeSecurityGroupsResult describeSecurityGroups = null;
        final DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withGroupNames(SECURITY_GROUP);
        try
        {
            describeSecurityGroups = ec2.describeSecurityGroups(req);
        } catch (AmazonServiceException e)
        {
            ec2.createSecurityGroup(new CreateSecurityGroupRequest(SECURITY_GROUP, "Created programatically by jpregel-aws"));
            describeSecurityGroups = ec2.describeSecurityGroups(req);
        }
        List<IpPermission> ipPermissions = describeSecurityGroups.getSecurityGroups().get(0).getIpPermissions();
        IpPermission p = new IpPermission();
        p.setIpProtocol("tcp");
        p.setFromPort(0);
        p.setToPort(65535);
        p.setIpRanges(Collections.singleton("0.0.0.0/0"));
        if (!ipPermissions.contains(p))
        {
            ec2.authorizeSecurityGroupIngress(new AuthorizeSecurityGroupIngressRequest(SECURITY_GROUP, Collections.singletonList(p)));
        }
    }

    public static Cluster  newSmallCluster(int numWorkers) throws Exception
    {
        Ec2ReservationService rs = new Ec2ReservationService();
        return new Cluster(rs,"m1.small","m1.small",numWorkers);
    }

    public static Cluster newMassiveCluster(int numWorkers) throws Exception {
        Ec2ReservationService rs = new Ec2ReservationService();
{'fraction_non_alphanumeric': 0.09747706422018348, 'fraction_numerical': 0.025557011795543906, 'mean_word_length': 3.576461769115442, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '232245', 'n_tokens_mistral': 1835, 'n_tokens_neox': 1766, 'n_words': 392}