Example usage for com.amazonaws.services.ec2.model BlockDeviceMapping setVirtualName

List of usage examples for com.amazonaws.services.ec2.model BlockDeviceMapping setVirtualName

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model BlockDeviceMapping setVirtualName.

Prototype


public void setVirtualName(String virtualName) 

Source Link

Document

The virtual device name (ephemeralN).

Usage

From source file:de.unibi.cebitec.bibigrid.meta.aws.CreateClusterAWS.java

@Override
public CreateClusterAWS configureClusterMasterInstance() {
    // done for master. More volume description later when master is running

    ////////////////////////////////////////////////////////////////////////
    /////////////// preparing blockdevicemappings for master////////////////
    Map<String, String> masterSnapshotToMountPointMap = this.config.getMasterMounts();
    int ephemerals = config.getMasterInstanceType().getSpec().ephemerals;
    DeviceMapper masterDeviceMapper = new DeviceMapper(config.getMode(), masterSnapshotToMountPointMap,
            ephemerals);/*from w w w  .  ja va  2 s  . co  m*/
    masterDeviceMappings = new ArrayList<>();
    // create Volumes first
    if (!this.config.getMasterMounts().isEmpty()) {
        log.info(V, "Defining master volumes");
        masterDeviceMappings = createBlockDeviceMappings(masterDeviceMapper);
    }

    List<BlockDeviceMapping> ephemeralList = new ArrayList<>();
    for (int i = 0; i < this.config.getMasterInstanceType().getSpec().ephemerals; ++i) {
        BlockDeviceMapping temp = new BlockDeviceMapping();
        String virtualName = "ephemeral" + i;
        String deviceName = "/dev/sd" + ephemeral(i);
        temp.setVirtualName(virtualName);
        temp.setDeviceName(deviceName);
        ephemeralList.add(temp);
    }

    masterDeviceMappings.addAll(ephemeralList);

    base64MasterUserData = UserDataCreator.masterUserData(masterDeviceMapper, this.config,
            environment.getKeypair());

    log.info(V, "Master UserData:\n {}", new String(Base64.decodeBase64(base64MasterUserData)));
    //////////////////////////////////////////////////////////////////////////
    /////// create Placementgroup ////////////////////

    if (this.config.getMasterInstanceType().getSpec().clusterInstance) {
        if (config.isUseSpotInstances()) {
            spotInstancePlacement = new SpotPlacement(config.getAvailabilityZone());
            spotInstancePlacement.setGroupName(environment.getPlacementGroup());
        } else {
            instancePlacement = new Placement(this.config.getAvailabilityZone());
            instancePlacement.setGroupName(environment.getPlacementGroup());
        }
    }

    //////////////////////////////////////////////////////////////////////////
    /////// create NetworkInterfaceSpecification for MASTER instance with FIXED internal IP and public ip
    masterNetworkInterfaces = new ArrayList<>();

    inis = new InstanceNetworkInterfaceSpecification();
    inis.withPrivateIpAddress(environment.getMASTERIP()).withGroups(environment.getSecReqResult().getGroupId())
            .withAssociatePublicIpAddress(true).withSubnetId(environment.getSubnet().getSubnetId())
            .withDeviceIndex(0);

    masterNetworkInterfaces.add(inis); // add eth0

    slaveNetworkInterfaces = new ArrayList<>();
    inis = new InstanceNetworkInterfaceSpecification();
    inis.withGroups(environment.getSecReqResult().getGroupId())
            .withSubnetId(environment.getSubnet().getSubnetId())
            .withAssociatePublicIpAddress(config.isPublicSlaveIps()).withDeviceIndex(0);

    slaveNetworkInterfaces.add(inis);

    return this;
}

From source file:de.unibi.cebitec.bibigrid.meta.aws.CreateClusterAWS.java

@Override
public CreateClusterAWS configureClusterSlaveInstance() {
    //now defining Slave Volumes
    Map<String, String> snapShotToSlaveMounts = this.config.getSlaveMounts();
    int ephemerals = config.getSlaveInstanceType().getSpec().ephemerals;
    slaveDeviceMapper = new DeviceMapper(config.getMode(), snapShotToSlaveMounts, ephemerals);
    slaveBlockDeviceMappings = new ArrayList<>();
    // configure volumes first ...
    if (!snapShotToSlaveMounts.isEmpty()) {
        log.info(V, "configure slave volumes");
        slaveBlockDeviceMappings = createBlockDeviceMappings(slaveDeviceMapper);
    }//ww w  .  j a  v a  2  s. c  om
    // configure ephemeral devices
    List<BlockDeviceMapping> ephemeralList = new ArrayList<>();
    if (ephemerals > 0) {
        for (int i = 0; i < ephemerals; ++i) {
            BlockDeviceMapping temp = new BlockDeviceMapping();
            String virtualName = "ephemeral" + i;
            String deviceName = "/dev/sd" + ephemeral(i);
            temp.setVirtualName(virtualName);
            temp.setDeviceName(deviceName);
            ephemeralList.add(temp);
        }
    }

    slaveBlockDeviceMappings.addAll(ephemeralList);

    return this;
}

From source file:eu.stratosphere.nephele.instance.ec2.EC2CloudManager.java

License:Apache License

/**
 * Requests (allocates) instances (VMs) from Amazon EC2.
 * //from  w  ww . java  2 s .c  o  m
 * @param awsAccessId
 *        the access ID into AWS
 * @param awsSecretKey
 *        the secret key used to generate signatures for authentication
 * @param instancesToBeRequested
 *        Map containing desired instances types and count
 * @param sshKeyPair
 *        Optional parameter to insert an EC2 SSH key/value pair
 * @return
 *         List containing the instance IDs of the allocated instances.
 */
private LinkedList<String> allocateCloudInstance(final Configuration conf, final InstanceType type,
        final int mincount, final int maxcount) {

    final String awsAccessId = conf.getString(AWS_ACCESS_ID_KEY, null);
    final String awsSecretKey = conf.getString(AWS_SECRET_KEY_KEY, null);

    final String imageID = conf.getString(AWS_AMI_KEY, null);
    LOG.info("Read Amazon Machine Image from job configuration: " + imageID);

    final String jobManagerIPAddress = GlobalConfiguration.getString("jobmanager.rpc.address", null);
    if (jobManagerIPAddress == null) {
        LOG.error("JobManager IP address is not set (jobmanager.rpc.address)");
        return null;
    }
    final String sshKeyPair = conf.getString("job.ec2.sshkeypair", null);

    final AmazonEC2Client ec2client = EC2ClientFactory.getEC2Client(awsAccessId, awsSecretKey);
    final LinkedList<String> instanceIDs = new LinkedList<String>();

    // Iterate over instance types..

    final RunInstancesRequest request = new RunInstancesRequest(imageID, mincount, maxcount);
    request.setInstanceType(type.getIdentifier());

    // Set availability zone if configured
    String av = null;
    if (this.availabilityZone != null) {
        av = this.availabilityZone;
    }
    final String jobAV = conf.getString("job.ec2.availabilityzone", null);
    if (jobAV != null) {
        LOG.info("Found " + jobAV + " as job-specific preference for availability zone");
        av = jobAV;
    }

    if (av != null) {
        request.setPlacement(new Placement(av));
    }

    // TODO: Make this configurable!
    final BlockDeviceMapping bdm = new BlockDeviceMapping();
    bdm.setVirtualName("ephemeral0");
    bdm.setDeviceName("/dev/sdb1");

    if (sshKeyPair != null) {
        request.setKeyName(sshKeyPair);
    }

    final LinkedList<BlockDeviceMapping> bdmlist = new LinkedList<BlockDeviceMapping>();
    bdmlist.add(bdm);
    request.setBlockDeviceMappings(bdmlist);

    // Setting User-Data parameters
    request.setUserData(EC2Utilities.createTaskManagerUserData(jobManagerIPAddress));

    // Request instances!
    try {
        final RunInstancesResult result = ec2client.runInstances(request);

        for (Instance i : result.getReservation().getInstances()) {
            instanceIDs.add(i.getInstanceId());
        }
    } catch (AmazonClientException e) {
        // Only log the error here
        LOG.error(StringUtils.stringifyException(e));
    }

    return instanceIDs;
}

From source file:hudson.plugins.ec2.util.DeviceMappingParser.java

License:Open Source License

public static List<BlockDeviceMapping> parse(String customDeviceMapping) {

    List<BlockDeviceMapping> deviceMappings = new ArrayList<BlockDeviceMapping>();

    for (String mapping : customDeviceMapping.split(",")) {
        String[] mappingPair = mapping.split("=");
        String device = mappingPair[0];
        String blockDevice = mappingPair[1];

        BlockDeviceMapping deviceMapping = new BlockDeviceMapping().withDeviceName(device);

        if (blockDevice.equals("none")) {
            deviceMapping.setNoDevice("none");
        } else if (blockDevice.startsWith("ephemeral")) {
            deviceMapping.setVirtualName(blockDevice);
        } else {/*from ww  w  .j a  v  a2 s  .  c o m*/
            deviceMapping.setEbs(parseEbs(blockDevice));
        }

        deviceMappings.add(deviceMapping);
    }

    return deviceMappings;
}

From source file:org.xmlsh.aws.util.AWSEC2Command.java

License:BSD License

protected BlockDeviceMapping parseBlockDeviceMapping(String string) throws InvalidArgumentException {
    BlockDeviceMapping map = new BlockDeviceMapping();
    StringPair pair = new StringPair(string, '=');

    String device = pair.getLeft();
    // if( device.startsWith("/dev/"))
    // device = device.substring(5);

    if (!pair.hasRight()) {
        map.setNoDevice(device);/*from w w  w .  j av  a 2  s. c o  m*/
        return map;
    }

    String r = pair.getRight();
    if (r.equals("none")) {
        map.setNoDevice(device);
        return map;
    }

    map.setDeviceName(device);

    // Ephemeral = virtual ?
    if (!r.contains(":")) {
        map.setVirtualName(r);
        return map;
    }

    // Parse out the EBS stuff
    // [snapshot-id]:[volume-size]:[delete-on-termination]:[volume-type[:iops]]:[encrypted]

    String aebs[] = r.split(":");

    EbsBlockDevice ebs = new EbsBlockDevice();

    // [snapshot-id]:
    if (aebs.length >= 1) {
        String snapshotId = aebs[0];
        if (!Util.isBlank(snapshotId))
            ebs.setSnapshotId(snapshotId);

    }
    // :[volume-size]:
    if (aebs.length >= 2) {
        if (!Util.isBlank(aebs[1]))
            ebs.setVolumeSize(new Integer(aebs[1]));

    }

    // [delete-on-termination]:
    if (aebs.length >= 3) {
        if (!Util.isBlank(aebs[2]))
            ebs.setDeleteOnTermination(Boolean.valueOf(Util.parseBoolean(aebs[2])));

    }
    if (aebs.length >= 4) {
        // [volume-type[:iops]]:[encrypted]
        int i = 3;
        if (!Util.isBlank(aebs[i])) {
            ebs.setVolumeType(aebs[i]);
            if (aebs[i].equals(VolumeType.Io1.toString())) {
                i++;
                if (aebs.length <= i || Util.isBlank(aebs[i]))
                    throw new InvalidArgumentException(
                            "EBS block mapping with VolumeType :io1 MUST have PIOPS");
                ebs.setIops(Integer.valueOf(aebs[i]));
            }
            i++;
            if (aebs.length > i)
                ebs.setEncrypted(Util.parseBoolean(aebs[i]));
        }
    }

    map.setEbs(ebs);
    return map;

}