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

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

Introduction

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

Prototype


public String getStateTransitionReason() 

Source Link

Document

The reason for the most recent state transition.

Usage

From source file:ca.roussil.ec2instancestarter.SimpleEc2Service.java

License:Open Source License

/**
 * Wait for a instance to complete transitioning (i.e. status not being in
 * INSTANCE_STATE_IN_PROGRESS_SET or the instance no longer existing).
 * /* w  w  w.  j  a  v a  2 s  .co m*/
 * @param stateChangeList
 * @param instancebuilder
 * @param instanceId
 * @param BuildLogger
 * @throws InterruptedException
 * @throws Exception
 */
private final String waitForTransitionCompletion(List<InstanceStateChange> stateChangeList,
        final String desiredState, String instanceId) throws InterruptedException {

    Boolean transitionCompleted = false;
    InstanceStateChange stateChange = stateChangeList.get(0);
    String previousState = stateChange.getPreviousState().getName();
    String currentState = stateChange.getCurrentState().getName();
    String transitionReason = "";

    while (!transitionCompleted) {
        try {
            Instance instance = getSingleEc2InstanceById(instanceId);
            currentState = instance.getState().getName();
            if (previousState.equals(currentState)) {
                log.info("... '" + instanceId + "' is still in state " + currentState + " ...");
            } else {
                log.info("... '" + instanceId + "' entered state " + currentState + " ...");
                transitionReason = instance.getStateTransitionReason();
            }
            previousState = currentState;

            if (currentState.equals(desiredState)) {
                transitionCompleted = true;
            }
        } catch (AmazonServiceException ase) {
            log.error("Failed to describe instance '" + instanceId + "'!", ase);
            throw ase;
        }

        // Sleep for WAIT_FOR_TRANSITION_INTERVAL seconds until transition
        // has completed.
        if (!transitionCompleted) {
            Thread.sleep(WAIT_FOR_TRANSITION_INTERVAL);
        }
    }

    log.info("Transition of instance '" + instanceId + "' completed with state " + currentState + " ("
            + (StringUtils.isEmpty(transitionReason) ? "Unknown transition reason" : transitionReason) + ").");

    return currentState;
}

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;
    }//w w w. java  2s  . c  o 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 w w  . j  av  a 2  s .  c  o m
}

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 .j a  va 2  s  .co m
    awsInstance.setInstances(awsSimpleInstanceList);
    return awsInstance;
}

From source file:fr.xebia.cloud.amazon.aws.tools.AmazonAwsUtils.java

License:Apache License

/**
 * <p>//from w  w w .j av a  2  s . c  o m
 * Wait for the ec2 instance startup and returns it up to date
 * </p>
 * <p>
 * Note: some information are missing of the {@link Instance} returned by
 * {@link AmazonEC2#describeInstances(DescribeInstancesRequest)} as long as
 * the instance is not "running" (e.g. {@link Instance#getPublicDnsName()}).
 * </p>
 *
 * @param instance
 * @return up to date instances or <code>null</code> if the instance crashed
 *         at startup.
 */
@Nullable
public static Instance awaitForEc2Instance(@Nonnull Instance instance, @Nonnull AmazonEC2 ec2) {
    logger.trace("Wait for startup of {}: {}", instance.getInstanceId(), instance);

    try {
        // initially wait for 3 secs to prevent "InvalidInstanceID.NotFound, AWS Error Message: The instance ID 'i-2f79c967' does not exist"
        Thread.sleep(3 * 1000);
    } catch (InterruptedException e) {
        throw Throwables.propagate(e);
    }

    int counter = 0;
    while (InstanceStateName.Pending.equals(instance.getState()) || (instance.getPublicIpAddress() == null)
            || (instance.getPublicDnsName() == null)) {
        logger.trace("Wait for startup of {}: {}", instance.getInstanceId(), instance);
        try {
            // 3s because ec2 instance creation < 10 seconds
            Thread.sleep(3 * 1000);
        } catch (InterruptedException e) {
            throw Throwables.propagate(e);
        }
        DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest()
                .withInstanceIds(instance.getInstanceId());
        DescribeInstancesResult describeInstances = ec2.describeInstances(describeInstancesRequest);

        instance = Iterables.getOnlyElement(toEc2Instances(describeInstances.getReservations()));
        counter++;
        if (counter >= 20) {
            logger.warn("Timeout waiting for startup of {}: {}", instance);
            return instance;
        }
    }

    if (InstanceStateName.ShuttingDown.equals(instance.getState())
            || InstanceStateName.Terminated.equals(instance.getState())) {
        // typically a "Server.InternalError: Internal error on launch"
        logger.warn("Terminate and skip dying instance {} (stateReason={}, stateTransitionReason={}): {}",
                new Object[] { instance.getInstanceId(), instance.getStateReason(),
                        instance.getStateTransitionReason(), instance });
        try {
            ec2.terminateInstances(new TerminateInstancesRequest(Lists.newArrayList(instance.getInstanceId())));
        } catch (Exception e) {
            logger.warn("Silently ignore exception terminating dying instance {}: {}",
                    new Object[] { instance.getInstanceId(), instance, e });
        }

        return null;
    }

    logger.debug("Instance {} is started: {}", instance.getInstanceId(), instance);
    return instance;
}

From source file:org.excalibur.service.aws.ec2.EC2.java

License:Open Source License

/**
 * <p>// w  w  w.j av a2 s.  c  o m
 * Wait for the ec2 instances starting up and returns it up to date.
 * </p>
 * <p>
 * Note: some information are missing of the {@link Instance} returned by {@link AmazonEC2#describeInstances(DescribeInstancesRequest)} as long as
 * the instance is not "running" (e.g., {@link Instance#getPublicDnsName()}).
 * </p>
 * 
 * @param instanceToWaitRunningState
 * @return up to date instances or <code>null</code> if the instance crashed at startup.
 */
private Instance waitForInstanceRunningState(final Instance instanceToWaitRunningState) {
    Instance instance = instanceToWaitRunningState;

    int counter = 0;

    while (InstanceStateName.Pending.name().equalsIgnoreCase(instance.getState().getName())) //|| (instance.getPublicIpAddress() == null) || (instance.getPublicDnsName() == null)
    {
        String description = String.format("Waiting running state of the instance [%s]: [%s]",
                instance.getInstanceId(), instance);

        backoffForAttempt(counter + 1, description);

        instance = describeEC2Instance(instance.getInstanceId());
        counter++;

        if (counter >= MAX_RETRY_STATE) {
            LOG.warn("Timeout waiting for startup of [{}]: [{}]", instance.getInstanceId(),
                    instanceToWaitRunningState);
            return instanceToWaitRunningState;
        }
    }

    if (InstanceStateName.ShuttingDown.equals(instance.getState())
            || InstanceStateName.Terminated.equals(instance.getState())) {
        LOG.warn(
                "Terminating and skipping dying instance [{}] (stateReason=[{}], stateTransitionReason=[{}]): [{}]",
                instance.getInstanceId(), instance.getStateReason(), instance.getStateTransitionReason(),
                instance);

        this.terminateInstances(instance.getInstanceId());
        return null;
    }

    LOG.debug("Instance {} is running", instance.getInstanceId());
    return instance;
}

From source file:org.gridgain.grid.spi.cloud.ec2lite.GridEc2LiteCloudSpi.java

License:GNU General Public License

/**
 * Gets instance resource from EC2 instance.
 *
 * @param inst EC2 instance./*  www .  jav  a  2 s . com*/
 * @return Instance resource.
 */
private GridCloudSpiResourceAdapter createInstanceResource(Instance inst) {
    assert inst != null;

    Map<String, String> params = new HashMap<String, String>();

    params.put(INST_STATE_TRANS_REASON, inst.getStateTransitionReason());
    params.put(INST_KEY_PAIR_NAME, inst.getKeyName());
    params.put(INST_AMI_LAUNCH_IDX, String.valueOf(inst.getAmiLaunchIndex()));
    params.put(INST_LAUNCH_TIME, String.valueOf(inst.getLaunchTime()));
    params.put(INST_TYPE, inst.getInstanceType());
    params.put(INST_STATE, inst.getState().getName());
    params.put(INST_STATE_CODE, String.valueOf(inst.getState().getCode()));
    params.put(IMG_KERNEL_ID, inst.getKernelId());
    params.put(IMG_RAMDISK_ID, inst.getRamdiskId());
    params.put(INST_MON_STATE, inst.getMonitoring().getState());
    params.put(INST_PLACEMENT, inst.getPlacement().getAvailabilityZone());
    params.put(INST_PLATFORM, inst.getPlatform());
    params.put(INST_PRIV_DNS, inst.getPrivateDnsName());
    params.put(INST_PUB_DNS, inst.getPublicDnsName());

    params.put(PRODUCT_CODE_IDS, F.concat(F.transform(inst.getProductCodes(), new C1<ProductCode, String>() {
        @Override
        public String apply(ProductCode e) {
            return e.getProductCodeId();
        }
    }), VAL_DELIM));

    return new GridCloudSpiResourceAdapter(inst.getInstanceId(), CLD_INSTANCE, cloudId, params);
}

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

License:Apache License

/**
 *
 * @param instance//www  .  j  a va2  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.xmlsh.aws.util.AWSEC2Command.java

License:BSD License

protected void writeReservation(Reservation res) throws XMLStreamException {
    startElement("reservation");
    attribute("id", res.getReservationId());
    attribute("requester-id", res.getRequesterId());

    for (Instance inst : res.getInstances()) {
        startElement("instance");
        attribute("instance-id", inst.getInstanceId());
        attribute("image", inst.getImageId());
        attribute("key-name", inst.getKeyName());
        attribute("architecture", inst.getArchitecture());
        attribute("client-token", inst.getClientToken());
        attribute("lifecycle", Util.notNull(inst.getInstanceLifecycle()));
        attribute("instance-type", inst.getInstanceType());
        attribute("kernel-id", inst.getKernelId());
        attribute("platform", inst.getPlatform());
        attribute("private-dns", inst.getPrivateDnsName());
        attribute("private-ip", inst.getPrivateIpAddress());
        attribute("public-dns", inst.getPublicDnsName());
        attribute("public-ip", inst.getPublicIpAddress());
        attribute("ramdisk-id", inst.getRamdiskId());
        attribute("root-device-name", inst.getRootDeviceName());

        attribute("spot-request-id", inst.getSpotInstanceRequestId());
        attribute("state-transistion-reason", inst.getStateTransitionReason());
        attribute("subnet-id", inst.getSubnetId());
        attribute("state", inst.getState().getName());
        attribute("virtualization-type", inst.getVirtualizationType());
        attribute("vpcid", inst.getVpcId());
        attribute("ami-launch-index", inst.getAmiLaunchIndex().toString());
        attribute("launch-date", Util.formatXSDateTime(inst.getLaunchTime()));
        attribute("monitoring", inst.getMonitoring().getState());
        attribute("source-dest-check", getSourceCheck(inst));
        attribute("state-reason", getStateReason(inst));

        writeProductCodes(inst.getProductCodes());
        writeTags(inst.getTags());/*from w  w w . j av a  2s .co  m*/

        writePlacement(inst.getPlacement());

        writeInstanceBlockDeviceMappings(inst.getBlockDeviceMappings());

        endElement();

    }

    endElement();
}

From source file:web.component.impl.aws.AWSEC2Impl.java

@Override
public String getInstanceStateTransitionReason(String instanceId) {

    Instance existInstance = getExistEc2Instance(instanceId);
    return existInstance == null ? "Unknown reason" : existInstance.getStateTransitionReason();
}