hashCode = prime * hashCode + ((getAmiLaunchIndex() == null) ? 0 : getAmiLaunchIndex().hashCode()); hashCode = prime * hashCode + ((getImageId() == null) ? 0 : getImageId().hashCode()); hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().hashCode()); hashCode = prime * hashCode + ((getInstanceType() == null) ? 0 : getInstanceType().hashCode()); hashCode = prime * hashCode + ((getKernelId() == null) ? 0 : getKernelId().hashCode()); hashCode = prime * hashCode + ((getKeyName() == null) ? 0 : getKeyName().hashCode()); hashCode = prime * hashCode + ((getLaunchTime() == null) ? 0 : getLaunchTime().hashCode()); hashCode = prime * hashCode + ((getMonitoring() == null) ? 0 : getMonitoring().hashCode()); hashCode = prime * hashCode + ((getPlacement() == null) ? 0 : getPlacement().hashCode()); hashCode = prime * hashCode + ((getPlatform() == null) ? 0 : getPlatform().hashCode()); hashCode = prime * hashCode + ((getPrivateDnsName() == null) ? 0 : getPrivateDnsName().hashCode()); hashCode = prime * hashCode + ((getPrivateIpAddress() == null) ? 0 : getPrivateIpAddress().hashCode()); hashCode = prime * hashCode + ((getProductCodes() == null) ? 0 : getProductCodes().hashCode()); hashCode = prime * hashCode + ((getPublicDnsName() == null) ? 0 : getPublicDnsName().hashCode()); hashCode = prime * hashCode + ((getPublicIpAddress() == null) ? 0 : getPublicIpAddress().hashCode()); hashCode = prime * hashCode + ((getRamdiskId() == null) ? 0 : getRamdiskId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getStateTransitionReason() == null) ? 0 : getStateTransitionReason().hashCode()); hashCode = prime * hashCode + ((getSubnetId() == null) ? 0 : getSubnetId().hashCode()); hashCode = prime * hashCode + ((getVpcId() == null) ? 0 : getVpcId().hashCode()); hashCode = prime * hashCode + ((getArchitecture() == null) ? 0 : getArchitecture().hashCode()); hashCode = prime * hashCode + ((getBlockDeviceMappings() == null) ? 0 : getBlockDeviceMappings().hashCode()); hashCode = prime * hashCode + ((getClientToken() == null) ? 0 : getClientToken().hashCode()); hashCode = prime * hashCode + ((getEbsOptimized() == null) ? 0 : getEbsOptimized().hashCode()); hashCode = prime * hashCode + ((getEnaSupport() == null) ? 0 : getEnaSupport().hashCode()); hashCode = prime * hashCode + ((getHypervisor() == null) ? 0 : getHypervisor().hashCode()); hashCode = prime * hashCode + ((getIamInstanceProfile() == null) ? 0 : getIamInstanceProfile().hashCode()); hashCode = prime * hashCode + ((getInstanceLifecycle() == null) ? 0 : getInstanceLifecycle().hashCode()); hashCode = prime * hashCode + ((getElasticGpuAssociations() == null) ? 0 : getElasticGpuAssociations().hashCode());
public RunnerInstance( Instance instance ) { this.instance = instance; this.hostname = instance.getPublicDnsName(); this.ipv4Address = instance.getPublicIpAddress(); this.url = "https://" + instance.getPublicDnsName() + ":" + Runner.DEFAULT_SERVER_PORT + "/"; }
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; }
DescribeInstancesResult disresult = client.describeInstances( dis ); Reservation reservation = disresult.getReservations().iterator().next(); for ( com.amazonaws.services.ec2.model.Instance in : reservation.getInstances() ) { stateStr = in.getState().getName(); LOG.info( "{} is {}", in.getInstanceId(), in.getState().getName() ); stateStr.equals( InstanceState.Terminated.toString() ) ) { instanceIdCopy.remove( in.getInstanceId() ); stateStr.equals( InstanceState.Running.toString() ) ) { instanceIdCopy.remove( in.getInstanceId() ); stateStr.equals( InstanceState.Stopped.toString() ) ) { instanceIdCopy.remove( in.getInstanceId() ); if ( in.getState().getName().equals( state.toString() ) ) { instanceIdCopy.remove( in.getInstanceId() );
hashCode = prime * hashCode + ((getInstanceId() == null) ? 0 : getInstanceId().hashCode()); hashCode = prime * hashCode + ((getImageId() == null) ? 0 : getImageId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getPrivateDnsName() == null) ? 0 : getPrivateDnsName().hashCode()); hashCode = prime * hashCode + ((getPublicDnsName() == null) ? 0 : getPublicDnsName().hashCode()); hashCode = prime * hashCode + ((getStateTransitionReason() == null) ? 0 : getStateTransitionReason().hashCode()); hashCode = prime * hashCode + ((getKeyName() == null) ? 0 : getKeyName().hashCode()); hashCode = prime * hashCode + ((getAmiLaunchIndex() == null) ? 0 : getAmiLaunchIndex().hashCode()); hashCode = prime * hashCode + ((getProductCodes() == null) ? 0 : getProductCodes().hashCode()); hashCode = prime * hashCode + ((getInstanceType() == null) ? 0 : getInstanceType().hashCode()); hashCode = prime * hashCode + ((getLaunchTime() == null) ? 0 : getLaunchTime().hashCode()); hashCode = prime * hashCode + ((getPlacement() == null) ? 0 : getPlacement().hashCode()); hashCode = prime * hashCode + ((getKernelId() == null) ? 0 : getKernelId().hashCode()); hashCode = prime * hashCode + ((getRamdiskId() == null) ? 0 : getRamdiskId().hashCode()); hashCode = prime * hashCode + ((getPlatform() == null) ? 0 : getPlatform().hashCode()); hashCode = prime * hashCode + ((getMonitoring() == null) ? 0 : getMonitoring().hashCode()); hashCode = prime * hashCode + ((getSubnetId() == null) ? 0 : getSubnetId().hashCode()); hashCode = prime * hashCode + ((getVpcId() == null) ? 0 : getVpcId().hashCode()); hashCode = prime * hashCode + ((getPrivateIpAddress() == null) ? 0 : getPrivateIpAddress().hashCode()); hashCode = prime * hashCode + ((getPublicIpAddress() == null) ? 0 : getPublicIpAddress().hashCode()); hashCode = prime * hashCode + ((getStateReason() == null) ? 0 : getStateReason().hashCode()); hashCode = prime * hashCode + ((getArchitecture() == null) ? 0 : getArchitecture().hashCode()); hashCode = prime * hashCode + ((getRootDeviceType() == null) ? 0 : getRootDeviceType().hashCode()); hashCode = prime * hashCode + ((getRootDeviceName() == null) ? 0 : getRootDeviceName().hashCode()); hashCode = prime * hashCode + ((getBlockDeviceMappings() == null) ? 0 : getBlockDeviceMappings().hashCode()); hashCode = prime * hashCode + ((getVirtualizationType() == null) ? 0 : getVirtualizationType().hashCode()); hashCode = prime * hashCode + ((getInstanceLifecycle() == null) ? 0 : getInstanceLifecycle().hashCode()); hashCode = prime * hashCode + ((getSpotInstanceRequestId() == null) ? 0 : getSpotInstanceRequestId().hashCode()); hashCode = prime * hashCode + ((getClientToken() == null) ? 0 : getClientToken().hashCode());
DescribeInstancesRequest request = new DescribeInstancesRequest(); List<String> valuesT1 = new ArrayList<String>(); valuesT1.add("my-keypair-name"); Filter filter = new Filter("key-name", valuesT1); DescribeInstancesResult result = ec2.describeInstances(request.withFilters(filter)); List<Reservation> reservations = result.getReservations(); for (Reservation reservation : reservations) { List<Instance> instances = reservation.getInstances(); for (Instance instance : instances) { System.out.println(instance.getInstanceId()); } }
ec2.setEndpoint("ec2." + region + ".amazonaws.com"); DescribeInstancesResult describeInstancesResult = ec2.describeInstances(); List<Reservation> reservations = describeInstancesResult.getReservations(); List<Instance> instances = new ArrayList<Instance>(); for( Instance instance : reservation.getInstances() ) { String ip = ip(instance); if( ip != null ) { String name = null; if( instance.getTags().size() > 0 ) name = instance.getTags().get(0).getValue(); if( NAME.equals(name) ) instances.add(instance); for( Instance instance : runRes.getReservation().getInstances() ) ids.add(instance.getInstanceId()); String[] prv = new String[boxes]; for( int i = 0; i < boxes; i++ ) { pub[i] = instances.get(i).getPublicIpAddress(); prv[i] = instances.get(i).getPrivateIpAddress();
DescribeInstancesResult response = ec2.describeInstances(request); for(Reservation reservation : response.getReservations()) { for(Instance instance : reservation.getInstances()) { System.out.printf( "Found instance with id %s, " + "state %s " + "and monitoring state %s", instance.getInstanceId(), instance.getImageId(), instance.getInstanceType(), instance.getState().getName(), instance.getMonitoring().getState()); request.setNextToken(response.getNextToken()); if(response.getNextToken() == null) { done = true;
public String retriableCall() throws IllegalStateException { DescribeInstancesRequest desc = new DescribeInstancesRequest().withInstanceIds(getInstanceId()); DescribeInstancesResult res = client.describeInstances(desc); for (Reservation resr : res.getReservations()) { for (Instance ins : resr.getInstances()) { for (com.amazonaws.services.ec2.model.Tag tag : ins.getTags()) { if (tag.getKey().equals("aws:autoscaling:groupName")) return tag.getValue(); } } } throw new IllegalStateException("Couldn't determine ASG name"); } }.call();
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.group = instance.getPlacement().getGroupName(); this.tenancy = instance.getPlacement().getTenancy(); this.vpc = instance.getVpcId(); this.platform = instance.getPlatform(); this.kernel = instance.getKernelId(); this.key = instance.getKeyName(); this.image = instance.getImageId(); this.privateIP = instance.getPrivateIpAddress(); this.publicIP = instance.getPublicIpAddress(); this.publicHostname = instance.getPublicDnsName(); this.privateHostname = instance.getPrivateDnsName(); this.architecture = instance.getArchitecture(); this.state = instance.getState().getName(); this.ramdisk = instance.getRamdiskId(); this.subnet = instance.getSubnetId(); this.rootDeviceName = instance.getRootDeviceName(); this.rootDeviceType = instance.getRootDeviceType(); this.stateTransitionReason = instance.getStateTransitionReason(); this.spotInstanceRequest = instance.getSpotInstanceRequestId(); this.virtualizationType = instance.getVirtualizationType(); this.sourceDestCheck = instance.getSourceDestCheck(); this.launchTime = new DateTime(instance.getLaunchTime()); if (instance.getIamInstanceProfile() != null) {
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; } }
/** * 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; }
DescribeInstancesResult result= ec2.describeInstances(request); List <Reservation> list = result.getReservations(); for (Reservation res:list) { List <Instance> instanceList= res.getInstances(); for (Instance instance:instanceList){ System.out.println("Instance Public IP :" + instance.getPublicIpAddress()); } }
/** {@inheritDoc} */ @Override public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException { initClients(); List<String> instanceIds = new ArrayList<>(); DescribeLoadBalancersRequest req = new DescribeLoadBalancersRequest().withLoadBalancerNames(loadBalancerName); List<LoadBalancerDescription> descs = amazonELBClient.describeLoadBalancers(req).getLoadBalancerDescriptions(); for (LoadBalancerDescription desc : descs) { for (Instance instance : desc.getInstances()) instanceIds.add(instance.getInstanceId()); } DescribeInstancesRequest instReq = new DescribeInstancesRequest().withInstanceIds(instanceIds); List<Reservation> reservations = amazonEC2Client.describeInstances(instReq).getReservations(); List<InetSocketAddress> addrs = new ArrayList<>(); for (Reservation reservation : reservations) { List<com.amazonaws.services.ec2.model.Instance> instances = reservation.getInstances(); for (com.amazonaws.services.ec2.model.Instance instance : instances) addrs.add(new InetSocketAddress(instance.getPrivateIpAddress(), 0)); } return addrs; }
String getInstancePublicDnsName(String instanceId) { DescribeInstancesResult describeInstancesRequest = ec2.describeInstances(); List<Reservation> reservations = describeInstancesRequest.getReservations(); Set<Instance> allInstances = new HashSet<Instance>(); for (Reservation reservation : reservations) { for (Instance instance : reservation.getInstances()) { if (instance.getInstanceId().equals(instanceId)) return instance.getPublicDnsName(); } } return null; }
String reservation_id = run_response.getReservation().getInstances().get(0).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; } }
Preconditions.checkArgument(instance != null, "received null instance"); String id = instance.getInstanceId(); MachineState machineState = new InstanceStateToMachineState().apply(instance.getState()); DateTime launchtime = new DateTime(instance.getLaunchTime(), DateTimeZone.UTC); List<String> publicIps = new ArrayList<>(); List<String> privateIps = new ArrayList<>(); String publicIp = instance.getPublicIpAddress(); if (publicIp != null) { publicIps.add(publicIp); String privateIp = instance.getPrivateIpAddress(); if (privateIp != null) { privateIps.add(privateIp); if (instance.getSpotInstanceRequestId() != null) { cloudProvider = CloudProviders.AWS_SPOT; .machineSize(instance.getInstanceType()).membershipStatus(membershipStatus).serviceState(serviceState) .launchTime(launchtime).publicIps(publicIps).privateIps(privateIps).metadata(metadata).build();
@Override public InstanceType getInstanceType(String providerInstanceId) throws DuracloudInstanceNotAvailableException { DescribeInstancesResult result = describeInstance(providerInstanceId); try { // Allowed Values: pending, running, shutting-down, terminated String instanceType = result.getReservations().iterator().next().getInstances() .iterator().next().getInstanceType(); for (InstanceType it : InstanceType.values()) { if (convertDuracloudInstanceTypeToNative(it).equals(instanceType)) { return it; } } String message = "Unable to get instance type for EC2 instance with ID " + providerInstanceId + ": amazon instance type '" + instanceType + "' unknown to DuraCloud MC."; throw new DuraCloudRuntimeException(message); } catch(Exception e) { String message = "Unable to get instance type for EC2 instance with ID " + providerInstanceId + " due to error: " + e.getMessage(); log.error(message, e); throw new DuraCloudRuntimeException(message, e); } }