Example usage for com.amazonaws.services.ec2.model Instance getRootDeviceType

List of usage examples for com.amazonaws.services.ec2.model Instance getRootDeviceType

Introduction

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

Prototype


public String getRootDeviceType() 

Source Link

Document

The root device type used by the AMI.

Usage

From source file:com.automata.cloudcore.xmlbindings.RunningInstancesItemType.java

License:Open Source License

public RunningInstancesItemType(Instance instance) {
    this.instanceId = instance.getInstanceId();
    InstanceStateType instanceStateType = new InstanceStateType();
    instanceStateType.setName(instance.getInstanceLifecycle());
    //instanceStateType.setCode();
    this.instanceState = instanceStateType;
    this.privateDnsName = instance.getPrivateDnsName();
    this.imageId = instance.getImageId();
    this.dnsName = instance.getPublicDnsName();
    //this.reason   = instance.get
    this.keyName = instance.getKeyName();
    if (instance.getStateTransitionReason() != null)
        this.reason = instance.getStateTransitionReason().toString();
    this.amiLaunchIndex = instance.getAmiLaunchIndex().toString();
    //this.productCodes = instance.getProductCodes();
    this.instanceType = instance.getInstanceType();
    //this.launchTime = instance.getLaunchTime();
    //this.placement = instance.getPlacement();
    this.kernelId = instance.getKernelId();
    this.ramdiskId = instance.getRamdiskId();
    this.platform = instance.getPlatform();

    InstanceMonitoringStateType instanceMonitoringStateType;
    instanceMonitoringStateType = new InstanceMonitoringStateType();
    instanceMonitoringStateType.setState(instance.getMonitoring().toString());
    this.monitoring = instanceMonitoringStateType;

    this.subnetId = instance.getSubnetId();
    this.vpcId = instance.getVpcId();
    this.privateIpAddress = instance.getPrivateIpAddress();
    this.ipAddress = instance.getPublicIpAddress();
    this.sourceDestCheck = instance.getSourceDestCheck();
    //this.groupSet = 

    if (instance.getStateReason() != null) {
        StateReasonType stateReasonType = new StateReasonType();
        stateReasonType.setMessage(instance.getStateReason().getMessage());
        this.stateReason = stateReasonType;
    }//  ww  w . j av  a  2  s  .co  m
    this.architecture = instance.getArchitecture();
    this.rootDeviceType = instance.getRootDeviceType();
    this.rootDeviceName = instance.getRootDeviceName();

    /*BlockDeviceMappingsType blockDeviceMappingsType = new BlockDeviceMappingsType();
    List<BlockDeviceMapping> blockDeviceMappingList = new ArrayList<BlockDeviceMapping>();
    BlockDeviceMapping blockDeviceMapping = new BlockDeviceMapping();
    for (){
               
    }
            
    blockDeviceMappingsType = 
    this.blockDeviceMapping = instance.getBlockDeviceMappings();*/
    this.instanceLifecycle = instance.getInstanceLifecycle();
    this.spotInstanceRequestId = instance.getSpotInstanceRequestId();

    if (instance.getLicense() != null) {
        InstanceLicenseResponseType instanceLicenseResponseType;
        instanceLicenseResponseType = new InstanceLicenseResponseType();
        instanceLicenseResponseType.setPool(instance.getLicense().getPool());
        this.license = instanceLicenseResponseType;
    }

    this.virtualizationType = instance.getVirtualizationType();
    this.clientToken = instance.getClientToken();

    /*ResourceTagSetType resourceTagSetType;
    ResourceTagSetItemType resourceTagSetItemType;
    List<ResourceTagSetItemType> resourceTagSetItemTypeList;
            
    resourceTagSetItemTypeList = new ArrayList<ResourceTagSetItemType>();
            
    resourceTagSetType = new ResourceTagSetType();
    resourceTagSetType.getItem()
    this.tagSet = instance.getTags();
    this.hypervisor = instance.get*/
}

From source file:com.clouck.model.aws.ec2.Ec2Instance.java

@Override
@SuppressWarnings("rawtypes")
protected boolean isEqual(AbstractResource newResource) {
    Instance oldInstance = this.getResource();
    Ec2Instance newEc2Instance = (Ec2Instance) newResource;
    Instance newInstance = newEc2Instance.getResource();

    if (notEqual(oldInstance.getInstanceId(), newInstance.getInstanceId()))
        return false;
    if (notEqual(oldInstance.getImageId(), newInstance.getImageId()))
        return false;
    if (notEqual(oldInstance.getState(), newInstance.getState()))
        return false;
    if (notEqual(oldInstance.getPrivateDnsName(), newInstance.getPrivateDnsName()))
        return false;
    if (notEqual(oldInstance.getPublicDnsName(), newInstance.getPublicDnsName()))
        return false;
    if (notEqual(oldInstance.getStateTransitionReason(), newInstance.getStateTransitionReason()))
        return false;
    if (notEqual(oldInstance.getKeyName(), newInstance.getKeyName()))
        return false;
    if (notEqual(oldInstance.getAmiLaunchIndex(), newInstance.getAmiLaunchIndex()))
        return false;
    if (notEqualCollection(oldInstance.getProductCodes(), newInstance.getProductCodes()))
        return false;
    if (notEqual(oldInstance.getInstanceType(), newInstance.getInstanceType()))
        return false;
    if (notEqual(oldInstance.getLaunchTime(), newInstance.getLaunchTime()))
        return false;
    if (notEqual(oldInstance.getPlacement(), newInstance.getPlacement()))
        return false;
    if (notEqual(oldInstance.getKernelId(), newInstance.getKernelId()))
        return false;
    if (notEqual(oldInstance.getRamdiskId(), newInstance.getRamdiskId()))
        return false;
    if (notEqual(oldInstance.getPlatform(), newInstance.getPlatform()))
        return false;
    if (notEqual(oldInstance.getMonitoring(), newInstance.getMonitoring()))
        return false;
    if (notEqual(oldInstance.getSubnetId(), newInstance.getSubnetId()))
        return false;
    if (notEqual(oldInstance.getVpcId(), newInstance.getVpcId()))
        return false;
    if (notEqual(oldInstance.getPrivateIpAddress(), newInstance.getPrivateIpAddress()))
        return false;
    if (notEqual(oldInstance.getPublicIpAddress(), newInstance.getPublicIpAddress()))
        return false;
    if (notEqual(oldInstance.getStateReason(), newInstance.getStateReason()))
        return false;
    if (notEqual(oldInstance.getArchitecture(), newInstance.getArchitecture()))
        return false;
    if (notEqual(oldInstance.getRootDeviceType(), newInstance.getRootDeviceType()))
        return false;
    if (notEqual(oldInstance.getRootDeviceName(), newInstance.getRootDeviceName()))
        return false;
    if (notEqualCollection(oldInstance.getBlockDeviceMappings(), newInstance.getBlockDeviceMappings()))
        return false;
    if (notEqual(oldInstance.getVirtualizationType(), newInstance.getVirtualizationType()))
        return false;
    if (notEqual(oldInstance.getInstanceLifecycle(), newInstance.getInstanceLifecycle()))
        return false;
    if (notEqual(oldInstance.getSpotInstanceRequestId(), newInstance.getSpotInstanceRequestId()))
        return false;
    if (notEqual(oldInstance.getLicense(), newInstance.getLicense()))
        return false;
    if (notEqual(oldInstance.getClientToken(), newInstance.getClientToken()))
        return false;
    if (notEqualCollection(oldInstance.getTags(), newInstance.getTags()))
        return false;
    if (notEqualCollection(oldInstance.getSecurityGroups(), newInstance.getSecurityGroups()))
        return false;
    if (notEqual(oldInstance.getSourceDestCheck(), newInstance.getSourceDestCheck()))
        return false;
    if (notEqual(oldInstance.getHypervisor(), newInstance.getHypervisor()))
        return false;
    if (notEqualNetworkInterfaces(oldInstance.getNetworkInterfaces(), newInstance.getNetworkInterfaces()))
        return false;
    if (notEqual(oldInstance.getIamInstanceProfile(), newInstance.getIamInstanceProfile()))
        return false;
    if (notEqual(oldInstance.getEbsOptimized(), newInstance.getEbsOptimized()))
        return false;
    if (notEqual(this.getTerminationProtection(), newEc2Instance.getTerminationProtection()))
        return false;
    if (notEqual(this.getShutdownBehavior(), newEc2Instance.getShutdownBehavior()))
        return false;
    if (notEqual(this.getUserData(), newEc2Instance.getUserData()))
        return false;

    return true;//from  w ww .  j  ava2  s  . co  m
}

From source file:com.haskins.cloudtrailviewer.dialog.resourcedetail.detailpanels.EC2InstanceDetail.java

License:Open Source License

private void buildUI(DescribeInstancesResult detail) {

    JTabbedPane tabs = new JTabbedPane();
    tabs.add("Instance", primaryScrollPane);
    tabs.add("Tags", tagsScrollPane);

    this.add(tabs, BorderLayout.CENTER);

    List<Reservation> reservations = detail.getReservations();
    if (!reservations.isEmpty()) {

        Reservation reservation = reservations.get(0);
        List<Instance> instances = reservation.getInstances();
        if (!instances.isEmpty()) {

            Instance instance = instances.get(0);

            if (instance.getAmiLaunchIndex() != null) {
                primaryTableModel.addRow(new Object[] { "AMI Launch Index", instance.getAmiLaunchIndex() });
            }/*  w  w  w  . j a va 2 s.co  m*/
            if (instance.getArchitecture() != null) {
                primaryTableModel.addRow(new Object[] { "Architecture", instance.getArchitecture() });
            }
            if (instance.getAmiLaunchIndex() != null) {
                primaryTableModel.addRow(new Object[] { "Block Mapping Device", "" });
            }
            if (instance.getClientToken() != null) {
                primaryTableModel.addRow(new Object[] { "Client Token", instance.getClientToken() });
            }
            primaryTableModel.addRow(new Object[] { "EBS Optimised", instance.isEbsOptimized() });
            if (instance.getHypervisor() != null) {
                primaryTableModel.addRow(new Object[] { "Hypervisor", instance.getHypervisor() });
            }
            if (instance.getIamInstanceProfile() != null) {
                primaryTableModel.addRow(
                        new Object[] { "Instance Profile", instance.getIamInstanceProfile().toString() });
            }
            if (instance.getImageId() != null) {
                primaryTableModel.addRow(new Object[] { "Image Id", instance.getImageId() });
            }
            if (instance.getInstanceId() != null) {
                primaryTableModel.addRow(new Object[] { "Instance Id", instance.getInstanceId() });
            }
            if (instance.getInstanceLifecycle() != null) {
                primaryTableModel.addRow(new Object[] { "Instance Lifecyle", instance.getInstanceLifecycle() });
            }
            if (instance.getInstanceType() != null) {
                primaryTableModel.addRow(new Object[] { "Instance Type", instance.getInstanceType() });
            }
            if (instance.getKernelId() != null) {
                primaryTableModel.addRow(new Object[] { "Kernel Id", instance.getKernelId() });
            }
            if (instance.getKeyName() != null) {
                primaryTableModel.addRow(new Object[] { "Key Name", instance.getKeyName() });
            }
            if (instance.getLaunchTime() != null) {
                primaryTableModel.addRow(new Object[] { "Launch Time", instance.getLaunchTime() });
            }
            if (instance.getMonitoring() != null) {
                primaryTableModel.addRow(new Object[] { "Monitoring", instance.getMonitoring().toString() });
            }
            if (instance.getPlacement() != null) {
                primaryTableModel
                        .addRow(new Object[] { "Placement", instance.getPlacement().getAvailabilityZone() });
            }
            if (instance.getPlatform() != null) {
                primaryTableModel.addRow(new Object[] { "Platform", instance.getPlatform() });
            }
            if (instance.getPrivateDnsName() != null) {
                primaryTableModel.addRow(new Object[] { "Private DNS Name", instance.getPrivateDnsName() });
            }
            if (instance.getPrivateIpAddress() != null) {
                primaryTableModel.addRow(new Object[] { "Private IP Address", instance.getPrivateIpAddress() });
            }
            if (instance.getAmiLaunchIndex() != null) {
                primaryTableModel.addRow(new Object[] { "Product Codes", "" });
            }
            if (instance.getPublicDnsName() != null) {
                primaryTableModel.addRow(new Object[] { "Public DNS Name", instance.getPublicDnsName() });
            }
            if (instance.getPublicIpAddress() != null) {
                primaryTableModel.addRow(new Object[] { "Public IP Address", instance.getPublicIpAddress() });
            }
            if (instance.getRamdiskId() != null) {
                primaryTableModel.addRow(new Object[] { "Ram Disk Id", instance.getRamdiskId() });
            }
            if (instance.getRootDeviceName() != null) {
                primaryTableModel.addRow(new Object[] { "Root Device Name", instance.getRootDeviceName() });
            }
            if (instance.getRootDeviceType() != null) {
                primaryTableModel.addRow(new Object[] { "Root Device Type", instance.getRootDeviceType() });
            }
            if (instance.getAmiLaunchIndex() != null) {
                primaryTableModel.addRow(new Object[] { "Security Groups", "" });
            }
            if (instance.getSourceDestCheck() != null) {
                primaryTableModel
                        .addRow(new Object[] { "Source Destination Check", instance.getSourceDestCheck() });
            }
            if (instance.getSpotInstanceRequestId() != null) {
                primaryTableModel.addRow(
                        new Object[] { "Spot Instance Request Id", instance.getSpotInstanceRequestId() });
            }
            if (instance.getSriovNetSupport() != null) {
                primaryTableModel
                        .addRow(new Object[] { "Sriov network Support", instance.getSriovNetSupport() });
            }
            if (instance.getState() != null) {
                primaryTableModel.addRow(new Object[] { "State", instance.getState().getName() });
            }
            if (instance.getStateReason() != null) {
                primaryTableModel
                        .addRow(new Object[] { "State Reason", instance.getStateReason().getMessage() });
            }
            if (instance.getSubnetId() != null) {
                primaryTableModel.addRow(new Object[] { "Subnet Id", instance.getSubnetId() });
            }
            if (instance.getVirtualizationType() != null) {
                primaryTableModel
                        .addRow(new Object[] { "Virtualisation Type", instance.getVirtualizationType() });
            }
            if (instance.getVpcId() != null) {
                primaryTableModel.addRow(new Object[] { "Vpc Id", instance.getVpcId() });
            }

            List<Tag> tags = instance.getTags();
            for (Tag tag : tags) {
                tagsTableModel.addRow(new Object[] { tag.getKey(), tag.getValue() });
            }
        }
    }
}

From source file:com.sequenceiq.samples.web.transformers.ReservationTransformer.java

public AWSReservation transform(Reservation reservation) {
    AWSReservation awsInstance = new AWSReservation(reservation.getOwnerId(), reservation.getReservationId(),
            reservation.getRequesterId());
    awsInstance.setGroupNames(reservation.getGroupNames());
    awsInstance.setGroups(reservation.getGroups());
    List<AwsSimpleInstance> awsSimpleInstanceList = new ArrayList<>();
    for (Instance item : reservation.getInstances()) {
        AwsSimpleInstance instance = new AwsSimpleInstance();
        instance.setAmiLaunchIndex(item.getAmiLaunchIndex());
        instance.setArchitecture(item.getArchitecture());
        instance.setClientToken(item.getClientToken());
        instance.setImageId(item.getImageId());
        instance.setInstanceId(item.getInstanceId());
        instance.setState(item.getState());
        instance.setPrivateDnsName(item.getPrivateDnsName());
        instance.setPublicDnsName(item.getPublicDnsName());
        instance.setStateTransitionReason(item.getStateTransitionReason());
        instance.setKeyName(item.getKeyName());
        instance.setAmiLaunchIndex(item.getAmiLaunchIndex());
        instance.setInstanceType(item.getInstanceType());
        instance.setLaunchTime(item.getLaunchTime());
        instance.setPlacement(item.getPlacement());
        instance.setKernelId(item.getKernelId());
        instance.setRamdiskId(item.getRamdiskId());
        instance.setPlatform(item.getPlatform());
        instance.setMonitoring(item.getMonitoring());
        instance.setSubnetId(item.getSubnetId());
        instance.setVpcId(item.getVpcId());
        instance.setPrivateIpAddress(item.getPrivateIpAddress());
        instance.setPublicIpAddress(item.getPublicIpAddress());
        instance.setStateReason(item.getStateReason());
        instance.setArchitecture(item.getArchitecture());
        instance.setRootDeviceType(item.getRootDeviceType());
        instance.setRootDeviceName(item.getRootDeviceName());
        instance.setVirtualizationType(item.getVirtualizationType());
        instance.setInstanceLifecycle(item.getInstanceLifecycle());
        instance.setSpotInstanceRequestId(item.getSpotInstanceRequestId());
        instance.setLicense(item.getLicense());
        instance.setClientToken(item.getClientToken());
        awsSimpleInstanceList.add(instance);
    }// w w w.ja v  a 2s  . co  m
    awsInstance.setInstances(awsSimpleInstanceList);
    return awsInstance;
}

From source file:com.vb.aws.services.compute.ec2.EC2UtilsImpl.java

/**
 * This method returns all EBS root volumes.
 * @return /*ww w .  java  2s.co  m*/
 */
public List<Volume> getAllEBSRootVolumes() {

    List<Instance> allInstances = getAllInstances();
    List<Volume> allEBSRootVolumes = new ArrayList<>();

    for (Instance instance : allInstances) {

        //We need volumes of type only EBS.
        if (instance.getRootDeviceType().equalsIgnoreCase(DeviceType.Ebs.toString())) {
            String rootDeviceName = instance.getRootDeviceName();
            List<InstanceBlockDeviceMapping> instanceBlockDeviceMappings = instance.getBlockDeviceMappings();
            for (InstanceBlockDeviceMapping instanceBlockDeviceMapping : instanceBlockDeviceMappings) {
                if (instanceBlockDeviceMapping.getDeviceName().equalsIgnoreCase(rootDeviceName)) {
                    String volumeId = instanceBlockDeviceMapping.getEbs().getVolumeId();
                    Volume volume = new Volume().withVolumeId(volumeId);
                    allEBSRootVolumes.add(volume);
                }
            }
        }
    }

    System.out.println("INFO: Number of EBS Root Volumes : " + allEBSRootVolumes.size());
    List<String> volumeIds = allEBSRootVolumes.stream().map(e -> e.getVolumeId()).collect(Collectors.toList());
    System.out.println("INFO: EBS Root Volumes : " + volumeIds);

    return allEBSRootVolumes;
}

From source file:com.zotoh.cloudapi.aws.EC2Instance.java

License:Open Source License

private VirtualMachine toVM(String owner, Instance r) {
    AWSAPI api = new AWSAPI();
    String s;//from  ww  w.  j  a va  2  s.c  o  m
    VirtualMachine vm = null;
    if (r != null) {
        vm = new VirtualMachine();
        vm.setPersistent(true);// if EBS backed, yes (i think)
        vm.setProviderOwnerId(owner);
        vm.setCurrentState(AWSAPI.toVmState(r.getState().getName()));
        vm.setArchitecture(AWSAPI.toArch(r.getArchitecture()));
        vm.setClonable(false);
        vm.setCreationTimestamp(r.getLaunchTime().getTime());
        vm.setDescription("");
        vm.setImagable(true);
        vm.setLastBootTimestamp(vm.getCreationTimestamp());
        vm.setLastPauseTimestamp(0L);
        vm.setName(r.getInstanceId());
        vm.setPausable(false); // only if EBS backed
        vm.setPlatform(AWSAPI.toPlat(r.getPlatform()));
        vm.setPrivateDnsAddress(r.getPrivateDnsName());
        vm.setPrivateIpAddresses(new String[] { nsb(r.getPrivateIpAddress()) });
        vm.setProduct(api.findProduct(r.getInstanceType()));
        vm.setProviderAssignedIpAddressId(r.getPublicDnsName());
        vm.setPublicDnsAddress(r.getPublicDnsName());
        vm.setPublicIpAddresses(new String[] { nsb(r.getPublicIpAddress()) });
        vm.setRebootable(true);
        vm.setTerminationTimestamp(0L);
        vm.setProviderDataCenterId(r.getPlacement() == null ? "" : r.getPlacement().getAvailabilityZone());
        vm.setProviderMachineImageId(r.getImageId());
        vm.setProviderRegionId(_svc.getCloud().getContext().getRegionId());
        vm.setProviderVirtualMachineId(r.getInstanceId());

        s = r.getRootDeviceType();
        if ("ebs".equals(s)) {
            vm.setPausable(true);
        }
        vm.addTag("rootdevicetype", s);

    }
    return vm;
}

From source file:jp.aws.test.ec2.EC2Instance.java

License:Apache License

/**
 * ?//w  w  w. jav a 2  s.  co m
 *
 * @note - ????????
 * @return
 * @throws Exception
 */
public List<EC2Item> list() {

    List<EC2Item> ec2ItemList = new ArrayList<EC2Item>();

    // 
    this.clientManager.changeRegion();

    // Reservation?List?
    List<Reservation> reservationList = this.clientManager.ec2().describeInstances().getReservations();

    for (Reservation reservation : reservationList) {
        // EC2?Instance?List?
        List<Instance> instanceList = reservation.getInstances();

        for (Instance instance : instanceList) {
            EC2Item ec2Item = new EC2Item();

            // com.amazonaws.services.ec2.model.Instance
            // http://docs.amazonwebservices.com/AWSAndroidSDK/latest/javadoc/com/amazonaws/services/ec2/model/Instance.html
            ec2Item.architecture = instance.getArchitecture(); // i386,
            // x86_64
            ec2Item.instanceId = instance.getInstanceId(); // i-xxxxxxxx
            ec2Item.instanceType = instance.getInstanceType(); // t1.micro
            ec2Item.keyName = instance.getKeyName(); //
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            ec2Item.launchTime = sdf.format(instance.getLaunchTime()); // 2012-01-01
            // 01:02:03
            // +9:00
            ec2Item.privateDnsName = instance.getPrivateDnsName(); // domU-xxx.compute-1.internal
            ec2Item.privateIpAddress = instance.getPrivateIpAddress(); // 10.xxx.xxx.xxx
            ec2Item.publicDnsName = instance.getPublicDnsName(); // ec2-xxx.compute-1.amazonaws.com
            ec2Item.publicIpAddress = instance.getPublicIpAddress(); // 201.xxx.xxx.xxx
            ec2Item.rootDeviceType = instance.getRootDeviceType(); // ebs /
            // s3
            ec2Item.rootDeviceName = instance.getRootDeviceName(); // /dev/sda1)
            StringBuilder builder = new StringBuilder();
            List<GroupIdentifier> sgs = instance.getSecurityGroups(); // default
            for (GroupIdentifier sg : sgs) {
                builder.append(sg.getGroupName());
                builder.append(", ");
            }
            ec2Item.securityGroups = builder.toString();
            ec2Item.stateName = instance.getState().getName(); // Runnning
            ec2Item.imageId = instance.getImageId(); // ami-xxxxxxxx
            ec2Item.platform = instance.getPlatform(); // Windows
            builder.setLength(0); // ?
            List<Tag> tags = instance.getTags(); // tag
            for (Tag tag : tags) {
                builder.append(tag.getValue());
                builder.append(", ");
            }
            ec2Item.availabilityZone = instance.getPlacement().getAvailabilityZone(); // AvailabilityZone

            // ?
            ec2ItemList.add(ec2Item);
        }
    }

    return ec2ItemList;
}

From source file:org.elasticdroid.model.ds.SerializableInstance.java

License:Open Source License

/**
 * Constructor. Initialises all of the members with data from the instance passed in as param.
 * @param instance The Instance object to use to initialise this data.
 * @param securityGroups The security groups associated with the Reservation that created this 
 * instance.//from  w w  w  .jav a  2s . c o  m
 */
public SerializableInstance(Instance instance, List<String> securityGroupNames) {
    //get all of the data required
    instanceId = instance.getInstanceId();
    stateName = instance.getState().getName();
    stateCode = instance.getState().getCode();
    instanceType = instance.getInstanceType();
    keyName = instance.getKeyName();
    platform = instance.getPlatform();
    launchTime = instance.getLaunchTime().getTime();//save in milliseconds since epoch
    publicIpAddress = instance.getPublicIpAddress();
    publicDnsName = instance.getPublicDnsName();
    imageId = instance.getImageId();
    rootDeviceType = instance.getRootDeviceType();

    //security groups are not per-instance, but per-reservation
    //AWS allows you to launch multiple instances with the same characteristics. These 
    //instances constitute a reservation! :) However, key pairs are still stored individually;
    //this jars with me. Probably a misunderstanding on my part.
    this.securityGroupNames = securityGroupNames;

    //setting tagName is a little harder. If there is a tag in the AWS cloud with key="name"
    //save the value of the tag to tagName. If not, set to null
    tagName = null; //set to null by default
    for (Tag tag : instance.getTags()) {
        //do not use ignore case, cuz otherwise when we tag instances using ElDroid we coul
        //end up with multiple. If that doesn't make sense, please please trust me.
        if (tag.getKey().equals("Name")) {
            tagName = tag.getValue();
            break;
        }
    }
}

From source file:org.occiware.clouddriver.util.InstanceDataFactory.java

License:Apache License

/**
 *
 * @param instance//from w  ww  .j  a  v a2 s.c  o m
 * @param instanceDO
 */
private static void buildBasicInstanceData(Instance instance, InstanceDO instanceDO) {
    instanceDO.setInstanceId(instance.getInstanceId());
    instanceDO.setImageId(instance.getImageId());
    instanceDO.setAmiLaunchIndex(instance.getAmiLaunchIndex());
    instanceDO.setArchitecture(instance.getArchitecture());
    instanceDO.setOptimizedEbsIO(instance.getEbsOptimized());
    instanceDO.setEnaSupport(instance.getEnaSupport());
    instanceDO.setHypervisor(instance.getHypervisor());
    instanceDO.setInstanceType(instance.getInstanceType());
    instanceDO.setKernelId(instance.getKernelId());
    instanceDO.setInstanceLifeCycle(instance.getInstanceLifecycle());
    instanceDO.setPlatform(instance.getPlatform());
    instanceDO.setPrivateDnsName(instance.getPrivateDnsName());
    instanceDO.setPrivateIpAddress(instance.getPrivateIpAddress());
    instanceDO.setPublicDnsName(instance.getPublicDnsName());
    instanceDO.setPublicIpAddress(instance.getPublicIpAddress());
    instanceDO.setSourceDestCheck(instance.getSourceDestCheck());
    instanceDO.setKeyPairName(instance.getKeyName());
    instanceDO.setLaunchTime(instance.getLaunchTime());
    instanceDO.setRamDiskId(instance.getRamdiskId());
    instanceDO.setRootDeviceName(instance.getRootDeviceName());
    instanceDO.setRootDeviceType(instance.getRootDeviceType());
    instanceDO.setSpotInstanceRequestId(instance.getSpotInstanceRequestId());
    instanceDO.setSriovNetSuppport(instance.getSriovNetSupport());
    instanceDO.setStateTransitionReason(instance.getStateTransitionReason());
    instanceDO.setSubnetId(instance.getSubnetId());
    instanceDO.setVirtualizationType(instance.getVirtualizationType());
    instanceDO.setVpcId(instance.getVpcId());
}

From source file:org.openinfinity.cloud.application.worker.component.EC2Worker.java

License:Apache License

private boolean createCluster(Cluster cluster, String service, EC2Wrapper ec2, String zone, int cloud,
        String key, String secretKey, String image, String instanceType, String needsLoadBalancer)
        throws WorkerException {
    String lbAddresses = "";
    boolean hasLoadBalancer = false;
    String threadName = Thread.currentThread().getName();

    String securityGroupName = "C" + Integer.toString(cluster.getId());
    String securityGroupId = ec2.createSecurityGroup(securityGroupName,
            "Cluster " + Integer.toString(cluster.getId()) + " security group");
    cluster.setSecurityGroupId(securityGroupId);
    cluster.setSecurityGroupName(securityGroupName);
    clusterService.updateCluster(cluster);
    if (cloud == InstanceService.CLOUD_TYPE_AMAZON) {
        //String adminPortalAddress = PropertyManager.getProperty("cloudadmin.worker.adminportal.address.amazon");
        //   ec2.authorizeIPs(cluster.getSecurityGroupName(), "0.0.0.0/0", 22, 22, "tcp");
        String cmtGroup = PropertyManager.getProperty("cloudadmin.worker.cmt.securitygroup.amazon");
        String securityGroupOwner = PropertyManager.getProperty("cloudadmin.worker.amazon.securitygroup.owner");
        //ec2.authorizeIPs(cluster.getSecurityGroupName(), adminPortalAddress+"/32", 22, 22, "tcp");
        //ec2.authorizeIPs(cluster.getSecurityGroupName(), adminPortalAddress+"/32", 8181, 8181, "tcp");
        ec2.authorizeGroup(cluster.getSecurityGroupName(), cmtGroup, securityGroupOwner, 22, 22, "tcp");
        ec2.authorizeGroup(cluster.getSecurityGroupName(), cmtGroup, securityGroupOwner, 8181, 8181, "tcp");
        ec2.authorizeGroup(cluster.getSecurityGroupName(), cluster.getSecurityGroupName(), securityGroupOwner,
                0, 65535, "tcp");
        ec2.authorizeGroup(cluster.getSecurityGroupName(), cluster.getSecurityGroupName(), securityGroupOwner,
                0, 65535, "udp");
        ec2.authorizeGroup(cmtGroup, cluster.getSecurityGroupName(), securityGroupOwner, 0, 65535, "tcp");
        ec2.authorizeGroup(cmtGroup, cluster.getSecurityGroupName(), securityGroupOwner, 0, 65535, "udp");
    } else if (cloud == InstanceService.CLOUD_TYPE_EUCALYPTUS) {
        String adminPortalAddress = PropertyManager.getProperty("cloudadmin.worker.adminportal.address");
        //   ec2.authorizeIPs(cluster.getSecurityGroupName(), "0.0.0.0/0", 22, 22, "tcp");
        ec2.authorizeIPs(cluster.getSecurityGroupName(), adminPortalAddress + "/32", 22, 22, "tcp");
        ec2.authorizeIPs(cluster.getSecurityGroupName(), adminPortalAddress + "/32", 8181, 8181, "tcp");
    }//from w  w  w  . java  2  s. c  o  m
    List<String> securityGroups = new ArrayList<String>();
    securityGroups.add(cluster.getSecurityGroupName());
    List<com.amazonaws.services.ec2.model.Instance> instances = new ArrayList<com.amazonaws.services.ec2.model.Instance>();
    if (needsLoadBalancer != null && needsLoadBalancer.equalsIgnoreCase("yes")) {
        if (cloud == InstanceService.CLOUD_TYPE_AMAZON) {
            /* Maybe in the future   String lbDns = ec2.createLoadBalancer(cluster.getLbName(), zone, key);
               if (lbDns == null) {
                  throw new WorkerException("Error creating load balancer for service " + service);
               }
               cluster.setLbDns(lbDns);
               ec2.setAppCookieStickiness("JSESSIONID", "JavaSessionPolicy", cluster.getLbName());
               ec2.setLoadBalancerPoliciesOfListener("JavaSessionPolicy", cluster.getLbName(), 80); */
            /* currently just use the same instance based balancing as in euca */
            Reservation reservation = ec2.createInstance(imageId(cloud, service, 0), 1, key, zone, "m1.small",
                    securityGroups);
            if (reservation == null) {
                ec2.deleteSecurityGroup(cluster.getSecurityGroupName());
                throw new WorkerException("Error creating virtual machines for service " + service);
            }
            instances.addAll(reservation.getInstances());
        } else {
            //cluster.setNumberOfMachines(cluster.getNumberOfMachines()+1);

            Reservation reservation = ec2.createInstance(imageId(cloud, service, 0), 1, key, zone, "m1.small",
                    securityGroups);
            if (reservation == null) {
                ec2.deleteSecurityGroup(cluster.getSecurityGroupName());
                throw new WorkerException("Error creating virtual machines for service " + service);
            }
            instances.addAll(reservation.getInstances());
        }
        clusterService.updateCluster(cluster);
        hasLoadBalancer = true;
    }

    Reservation reservation = ec2.createInstance(image, cluster.getNumberOfMachines(), key, zone, instanceType,
            securityGroups);
    if (reservation == null) {
        ec2.deleteLoadBalancer(cluster.getLbName(), cluster.getLbInstanceId());
        ec2.deleteSecurityGroup(cluster.getSecurityGroupName());
        throw new WorkerException("Error creating virtual machines for service " + service);
    }
    instances.addAll(reservation.getInstances());
    Iterator<com.amazonaws.services.ec2.model.Instance> ite = instances.iterator();
    Collection<String> machinesToTag = new ArrayList<String>();
    //   Collection<com.amazonaws.services.elasticloadbalancing.model.Instance> lbInstanceList = new ArrayList<com.amazonaws.services.elasticloadbalancing.model.Instance>();
    boolean loadBalancerMarked = false;
    while (ite.hasNext()) {

        com.amazonaws.services.ec2.model.Instance tempInstance = ite.next();
        Machine machine = new Machine();
        machine.setName(cluster.getName());
        machine.setCloud(cloud);

        machine.setInstanceId(tempInstance.getInstanceId());
        LOG.debug(threadName + ": Instance " + tempInstance.getInstanceId() + " root device type: "
                + tempInstance.getRootDeviceType());
        if (tempInstance.getInstanceType().equalsIgnoreCase("m1.small") && !loadBalancerMarked
                && hasLoadBalancer && tempInstance.getRootDeviceType().equalsIgnoreCase("instance-store")) {
            machine.setType("loadbalancer");
            loadBalancerMarked = true;
            cluster.setLbInstanceId(machine.getInstanceId());
            clusterService.updateCluster(cluster);
        } else {
            machine.setType("clustermember");

            if (cluster.getEbsVolumesUsed() > 0) {
                String volumeId = ec2.createVolume(cluster.getEbsVolumesUsed(), zone);
                machine.setEbsVolumeId(volumeId);
                machine.setEbsVolumeSize(cluster.getEbsVolumesUsed());
            }
        }
        int maxWait = 500;
        while ((tempInstance.getPrivateDnsName().equals("0.0.0.0")
                || tempInstance.getPrivateDnsName().startsWith("euca-0-0-0-0")) && maxWait > 0) {
            LOG.info(threadName + ": Could not get IP address yet, waiting for a moment");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                LOG.error(threadName + ": Something interrupted my sleep: " + e.getMessage());
            }
            maxWait--;
            tempInstance = ec2.describeInstance(tempInstance.getInstanceId());
        }
        LOG.info(threadName + ": Private dns name: " + tempInstance.getPrivateDnsName());
        LOG.info(threadName + ": Private IP address: " + tempInstance.getPrivateIpAddress());
        /*   AuthorizationRoute ip = new AuthorizationRoute();
           if(tempInstance.getPrivateIpAddress() == null) {
              ip.setCidrIp(tempInstance.getPrivateDnsName()+"/32");
           } else {
              ip.setCidrIp(tempInstance.getPrivateIpAddress()+"/32");
           }
           ip.setClusterId(cluster.getId());
           ip.setInstanceId(cluster.getInstanceId());
           ip.setFromPort(0);
           ip.setToPort(65535);
           ip.setProtocol("tcp");
           ip.setSecurityGroupName(cluster.getSecurityGroupName());
           arService.addIP(ip); */
        machine.setDnsName(tempInstance.getPublicDnsName());
        machine.setPrivateDnsName(tempInstance.getPrivateDnsName());
        machine.setState(tempInstance.getState().getName());
        machine.setClusterId(cluster.getId());
        if (cloud == InstanceService.CLOUD_TYPE_AMAZON) {
            machine.setUserName("ec2-user");
        } else {
            machine.setUserName("root");
        }
        machine.setConfigured(0);
        machine.setRunning(1);

        machineService.addMachine(machine);

        // Usage Service implementation
        Instance instance = instanceService.getInstance(cluster.getInstanceId());
        try {
            usageService.startVirtualMachineUsageMonitoring(instance.getOrganizationid(), cluster.getType(),
                    cluster.getId(), machine.getId());
        } catch (Exception e) {
            LOG.error(threadName + ": Error starting usage monitoring");
        }

        machinesToTag.add(tempInstance.getInstanceId());
        /*   if(tempInstance.getInstanceType().equalsIgnoreCase("m1.small")) {
              com.amazonaws.services.elasticloadbalancing.model.Instance lbI = new com.amazonaws.services.elasticloadbalancing.model.Instance();
              lbI.setInstanceId(tempInstance.getInstanceId());
              lbInstanceList.add(lbI);
           } */

    }
    //LOG.info("Addresses: "+lbAddresses);
    Tag clusterNameTag = new Tag();
    clusterNameTag.setKey("Name");
    clusterNameTag.setValue(cluster.getName());
    Collection<Tag> tags = new ArrayList<Tag>();
    tags.add(clusterNameTag);
    ec2.setTags(tags, machinesToTag);
    /*   if(needsLoadBalancer != null && needsLoadBalancer.equalsIgnoreCase("yes")) {
          ec2.registerInstancesToLoadBalancer(lbInstanceList, cluster.getLbName(), lbAddresses, secretKey);
       } */

    return true;
}