Refine search
/*** * Get list of EC2 {@link Instance}s for a auto scaling group * * @param groupName Auto scaling group name * @param status Instance status (eg. running) * @return List of EC2 instances found for the input auto scaling group */ public List<Instance> getInstancesForGroup(String groupName, String status) { final AmazonEC2 amazonEC2 = getEc2Client(); final DescribeInstancesResult instancesResult = amazonEC2.describeInstances(new DescribeInstancesRequest() .withFilters(new Filter().withName("tag:aws:autoscaling:groupName").withValues(groupName))); final List<Instance> instances = new ArrayList<>(); for (Reservation reservation : instancesResult.getReservations()) { for (Instance instance : reservation.getInstances()) { if (null == status|| null == instance.getState() || status.equals(instance.getState().getName())) { instances.add(instance); LOGGER.info("Found instance: " + instance + " which qualified filter: " + status); } else { LOGGER.info("Found instance: " + instance + " but did not qualify for filter: " + status); } } } return instances; }
public InstanceState unmarshall(StaxUnmarshallerContext context) throws Exception { InstanceState instanceState = new InstanceState(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { XMLEvent xmlEvent = context.nextEvent(); if (xmlEvent.isEndDocument()) return instanceState; if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) { if (context.testExpression("code", targetDepth)) { instanceState.setCode(IntegerStaxUnmarshaller.getInstance().unmarshall(context)); continue; } if (context.testExpression("name", targetDepth)) { instanceState.setName(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent.isEndElement()) { if (context.getCurrentDepth() < originalDepth) { return instanceState; } } } }
return false; Instance other = (Instance) obj; if (other.getAmiLaunchIndex() == null ^ this.getAmiLaunchIndex() == null) return false; if (other.getAmiLaunchIndex() != null && other.getAmiLaunchIndex().equals(this.getAmiLaunchIndex()) == false) return false; if (other.getImageId() == null ^ this.getImageId() == null) if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == false) return false; if (other.getStateTransitionReason() == null ^ this.getStateTransitionReason() == null)
for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) { if ("terminated".equalsIgnoreCase(instance.getState().getName())) { continue; Map<String, String> tags = toMap(instance.getTags()); if ("agent".equals(tags.get("galaxy:role")) && environment.equals(tags.get("galaxy:environment"))) { String portTag = tags.get("galaxy:port"); if (portTag == null) { if (invalidInstances.add(instance.getInstanceId())) { log.error("Instance %s does not have a galaxy:port tag", instance.getInstanceId());
Instance other = (Instance)obj; if (other.getInstanceId() == null ^ this.getInstanceId() == null) return false; if (other.getInstanceId() != null && other.getInstanceId().equals(this.getInstanceId()) == false) return false; if (other.getImageId() == null ^ this.getImageId() == null) return false; if (other.getImageId() != null && other.getImageId().equals(this.getImageId()) == false) return false; if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == false) return false; if (other.getPrivateDnsName() == null ^ this.getPrivateDnsName() == null) return false; if (other.getPrivateDnsName() != null && other.getPrivateDnsName().equals(this.getPrivateDnsName()) == false) return false;
public EC2Instance(Instance instance) { this.id = instance.getInstanceId(); this.type = instance.getInstanceType(); this.lifecycle = instance.getInstanceLifecycle(); this.hypervisor = instance.getHypervisor(); this.az = instance.getPlacement().getAvailabilityZone(); this.privateHostname = instance.getPrivateDnsName(); this.architecture = instance.getArchitecture(); this.state = instance.getState().getName(); this.ramdisk = instance.getRamdiskId(); this.subnet = instance.getSubnetId();
/** * Constructs and returns an BasicInstance object, using information from <code>ec2</code> * * @param ec2 * @return */ protected static Instance toInstance( com.amazonaws.services.ec2.model.Instance ec2 ) { Instance instance; BasicInstanceSpec spec; spec = new BasicInstanceSpec(); spec.setImageId( ec2.getImageId() ); spec.setKeyName( ec2.getKeyName() ); spec.setType( ec2.getInstanceType() ); instance = new BasicInstance( ec2.getInstanceId(), spec, InstanceState.fromValue( ec2.getState().getName() ), ec2.getPrivateDnsName(), ec2.getPublicDnsName(), ec2.getPrivateIpAddress(), ec2.getPublicIpAddress() ); return instance; }
for ( com.amazonaws.services.ec2.model.Instance in : reservation.getInstances() ) { stateStr = in.getState().getName(); LOG.info( "{} is {}", in.getInstanceId(), in.getState().getName() ); if ( in.getState().getName().equals( state.toString() ) ) { instanceIdCopy.remove( in.getInstanceId() );
/** * @see org.apache.airavata.xbaya.ui.widgets.TableRenderable#getValue(int) */ @Override public Object getValue(int index) { switch (index) { case 0: return this.instance.getInstanceId(); case 1: return this.instance.getImageId(); case 2: return this.instance.getRootDeviceType(); case 3: return this.instance.getInstanceType(); case 4: return this.instance.getState().getName(); case 5: return this.instance.getKeyName(); case 6: return this.instance.getMonitoring().getState(); case 7: return this.instance.getVirtualizationType(); case 8: return this.instance.getPlacement().getGroupName(); default: return null; } }
"state %s " + "and monitoring state %s", instance.getInstanceId(), instance.getImageId(), instance.getInstanceType(), instance.getState().getName(), instance.getMonitoring().getState());
@Override public EsInstance createFromEC2(Instance awsInstance) throws Exception { Preconditions.checkNotNull(awsInstance); EsInstance esInstance = new EsInstance(); esInstance.setId(awsInstance.getInstanceId()); esInstance.setState(awsInstance.getState().getName()); esInstance.setLocation(awsInstance.getPlacement().getAvailabilityZone()); //Region=location-last char. This is what CMDBV1 and people on internet do. //There should be a better way. Right now, keep as what it is esInstance.setRegion( esInstance.getLocation().substring(0, esInstance.getLocation().length() - 1)); esInstance.setAwsLaunchTime(awsInstance.getLaunchTime()); esInstance.setSubnetId(awsInstance.getSubnetId()); esInstance.setVpcId(awsInstance.getVpcId()); //Convert AWS instance to a map of property bags and save it. esInstance.getCloud() .put("aws", getAwsInstanceProperties(awsInstance)); Date utcNow = DateTime.now(DateTimeZone.UTC).toDate(); esInstance.setCreatedTime(utcNow); esInstance.setUpdatedTime(utcNow); return esInstance; } }
if (isEc2ProvisionedAmiSlave(i.getTags(), description) && isEc2ProvisionedJenkinsSlave(i.getTags(), jenkinsServerUrl) && (template == null || template.getAmi().equals(i.getImageId()))) { InstanceStateName stateName = InstanceStateName.fromValue(i.getState().getName()); if (stateName != InstanceStateName.Terminated && stateName != InstanceStateName.ShuttingDown &&
private boolean waitForInstanceStatusRunning(Instance instance) { String instanceId = instance.getInstanceId(); DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest().withInstanceIds(instanceId); int counter = 0; while (counter++ < maxSleepIterations) { sleepMillis(sleepMillis); DescribeInstancesResult result = ec2.describeInstances(describeInstancesRequest); for (Reservation reservation : result.getReservations()) { for (Instance reserved : reservation.getInstances()) { if (reserved.getPublicIpAddress() != null && AWS_RUNNING_STATE.equals(reserved.getState().getName())) { return true; } } } } return false; }
private static String ip(Instance instance) { String ip = instance.getPublicIpAddress(); if( ip != null && ip.length() != 0 ) if( instance.getState().getName().equals("running") ) return ip; return null; }
public Map<String, Instance> findExistingInstances(final String instanceType) { final Map<String, Instance> instances = new HashMap<>(); final DescribeInstancesResult describeInstancesResult = this.ec2client.describeInstances(new DescribeInstancesRequest() .withFilters(this.getInstanceFilters(instanceType))); // Check for existing EC2 instances that fit the filter criteria and use those. for (final Reservation reservation : describeInstancesResult.getReservations()) { for (final Instance instance : reservation.getInstances()) { // If we found any existing EC2 instances put them into the instances variable. System.out.format("Reservations %s (%s): %s%n", instance.getInstanceId(), instance.getState().getName(), instance.getSecurityGroups().get(0).getGroupName()); instances.put(instance.getInstanceId(), instance); } } return instances; }
public String waitUntilRunningAndGetPublicDnsName() { // Give Amazon some time to settle before we ask it for information sleep(5); for (; ; ) { DescribeInstancesRequest describe = new DescribeInstancesRequest().withInstanceIds(asList(instanceId)); Instance instance = ec2.describeInstances(describe).getReservations().get(0).getInstances().get(0); if (instance.getState().getName().equals("running")) { return instance.getPublicDnsName(); } logger.info("Instance {} is still {}. Waiting...", instanceId, instance.getState().getName()); sleep(1); } }
instanceResult.getReservations().stream() .flatMap(r -> r.getInstances().stream()) .filter(i -> i.getVpcId() == null) .filter(i -> Optional.ofNullable(i.getState()).filter(is -> is.getCode() == RUNNING_STATE).isPresent()) .filter(this::isInstanceOldEnough) .map(i -> new ClassicLinkInstance().withInstanceId(i.getInstanceId()).withVpcId(classicLinkVpcId).withTags(i.getTags())) .forEach(cli -> classicLinkInstances.put(cli.getInstanceId(), cli));
private static boolean allInstancesStarted(DescribeInstancesResult describeInstancesResult, int port) { for (Reservation reservation : describeInstancesResult.getReservations()) { for (com.amazonaws.services.ec2.model.Instance instance : reservation.getInstances()) { if (instance.getState() == null || instance.getState().getCode() == null) { return false; } // is it running? int state = instance.getState().getCode(); if (state == STATE_PENDING || instance.getPublicDnsName() == null) { return false; } // can we talk to it yet? try { Resources.toByteArray(new URL(format("http://%s:%s/v1/slot", instance.getPublicDnsName(), port))); } catch (Exception e) { return false; } } } return true; } }
/** * Converts the ec2 instance to a turbine instance. * @param ec2 EC2 instance. * @return Turbine instance. */ public com.netflix.turbine.discovery.Instance convert(final Instance ec2) { final boolean state = InstanceStateName.fromValue( ec2.getState().getName() ) == InstanceStateName.Running; return new com.netflix.turbine.discovery.Instance( ec2.getPrivateIpAddress(), this.cluster, state ); } }