List of usage examples for com.amazonaws.services.ec2.model Instance getLaunchTime
public java.util.Date getLaunchTime()
The time the instance was launched.
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;// ww w . j av a 2 s . c o 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() }); }/*from w ww . j av a 2 s.c o 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.netflix.simianarmy.aws.conformity.rule.InstanceTooOld.java
License:Apache License
/** * Gets the launch time (in milliseconds) for a list of instance ids of the same region. The default * implementation is using an AWS client. The method can be overridden in subclasses to get the instance * launch times differently.//from w w w . j a v a 2s. c om * @param region * the region of the instances * @param instanceIds * the instance ids, all instances should be in the same region. * @return * the map from instance id to the launch time in milliseconds */ protected Map<String, Long> getInstanceLaunchTimes(String region, String... instanceIds) { Map<String, Long> result = Maps.newHashMap(); if (instanceIds == null || instanceIds.length == 0) { return result; } AWSClient awsClient = new AWSClient(region, awsCredentialsProvider); for (Instance instance : awsClient.describeInstances(instanceIds)) { if (instance.getLaunchTime() != null) { result.put(instance.getInstanceId(), instance.getLaunchTime().getTime()); } else { LOGGER.warn(String.format("No launch time found for instance %s", instance.getInstanceId())); } } return result; }
From source file:com.netflix.simianarmy.aws.janitor.crawler.InstanceJanitorCrawler.java
License:Apache License
private List<Resource> getInstanceResources(String... instanceIds) { List<Resource> resources = new LinkedList<Resource>(); AWSClient awsClient = getAWSClient(); Map<String, AutoScalingInstanceDetails> idToASGInstance = new HashMap<String, AutoScalingInstanceDetails>(); for (AutoScalingInstanceDetails instanceDetails : awsClient.describeAutoScalingInstances(instanceIds)) { idToASGInstance.put(instanceDetails.getInstanceId(), instanceDetails); }// w w w .j a va2 s . co m for (Instance instance : awsClient.describeInstances(instanceIds)) { Resource instanceResource = new AWSResource().withId(instance.getInstanceId()) .withRegion(getAWSClient().region()).withResourceType(AWSResourceType.INSTANCE) .withLaunchTime(instance.getLaunchTime()); for (Tag tag : instance.getTags()) { instanceResource.setTag(tag.getKey(), tag.getValue()); } String description = String.format("type=%s; host=%s", instance.getInstanceType(), instance.getPublicDnsName() == null ? "" : instance.getPublicDnsName()); instanceResource.setDescription(description); instanceResource.setOwnerEmail(getOwnerEmailForResource(instanceResource)); String asgName = getAsgName(instanceResource, idToASGInstance); if (asgName != null) { instanceResource.setAdditionalField(INSTANCE_FIELD_ASG_NAME, asgName); LOGGER.info(String.format("instance %s has a ASG tag name %s.", instanceResource.getId(), asgName)); } if (instance.getState() != null) { ((AWSResource) instanceResource).setAWSResourceState(instance.getState().getName()); } resources.add(instanceResource); } return resources; }
From source file:com.netflix.spinnaker.clouddriver.aws.agent.ReconcileClassicLinkSecurityGroupsAgent.java
License:Apache License
boolean isInstanceOldEnough(Instance instance) { return Optional.ofNullable(instance.getLaunchTime()).map(Date::getTime).map(Instant::ofEpochMilli) .map(i -> i.plusMillis(requiredInstanceLifetime)).map(i -> clock.instant().isAfter(i)) .orElse(false);//from ww w . j a va 2s . com }
From source file:com.pinterest.arcee.aws.EC2HostInfoDAOImpl.java
License:Apache License
@Override public List<HostBean> launchEC2Instances(GroupBean groupBean, int instanceCnt, String subnet) throws Exception { RunInstancesRequest request = new RunInstancesRequest(); request.setImageId(groupBean.getImage_id()); request.setInstanceType(groupBean.getInstance_type()); request.setKeyName("ops"); request.setSecurityGroupIds(Arrays.asList(groupBean.getSecurity_group())); request.setSubnetId(subnet);/*w w w. j a va 2 s . c om*/ request.setUserData(groupBean.getUser_data()); IamInstanceProfileSpecification iamRole = new IamInstanceProfileSpecification(); iamRole.setArn(groupBean.getIam_role()); request.setIamInstanceProfile(iamRole); request.setMinCount(instanceCnt); request.setMaxCount(instanceCnt); List<HostBean> newHosts = new ArrayList<>(); try { RunInstancesResult result = ec2Client.runInstances(request); List<Instance> instances = result.getReservation().getInstances(); LOG.info("Launch instances {}", instances.toString()); for (Instance instance : instances) { HostBean host = new HostBean(); host.setHost_name(instance.getInstanceId()); host.setHost_id(instance.getInstanceId()); host.setIp(instance.getPrivateIpAddress()); host.setGroup_name(groupBean.getGroup_name()); host.setState(HostState.PROVISIONED); host.setCreate_date(instance.getLaunchTime().getTime()); host.setLast_update(instance.getLaunchTime().getTime()); newHosts.add(host); } } catch (AmazonClientException ex) { LOG.error(String.format("Failed to call aws runInstances when launching host %s", newHosts.toString()), ex); throw new DeployInternalException( String.format("Failed to call aws runInstances when launching host %s", newHosts.toString()), ex); } return newHosts; }
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); }//from ww w . jav a 2s .c om awsInstance.setInstances(awsSimpleInstanceList); return awsInstance; }
From source file:com.yosanai.java.aws.console.panel.InstancesPanel.java
License:Open Source License
public void loadInstances() { new Thread(new Runnable() { @Override//from w w w .j a v a2 s . co m public void run() { DefaultTreeModel treeModel = (DefaultTreeModel) trInstances.getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot(); tblInstances.clearSelection(); trInstances.clearSelection(); rootNode.removeAllChildren(); treeModel.reload(); tblInstances.setModel(instancesTableModel); DescribeInstancesResult result = awsConnectionProvider.getConnection().describeInstances(); while (0 < instancesTableModel.getRowCount()) { instancesTableModel.removeRow(0); } for (Reservation reservation : result.getReservations()) { for (Instance instance : reservation.getInstances()) { String name = null; StringBuilder tags = new StringBuilder(); for (Tag tag : instance.getTags()) { tags.append(tag.getKey()); tags.append("="); tags.append(tag.getValue()); if (StringUtils.equalsIgnoreCase(nameTag, tag.getKey())) { name = tag.getValue(); } } try { boolean apiTermination = awsConnectionProvider .getApiTermination(instance.getInstanceId()); instancesTableModel.addRow(new Object[] { instance.getInstanceId(), instance.getPublicDnsName(), instance.getPublicIpAddress(), instance.getPrivateDnsName(), instance.getPrivateIpAddress(), apiTermination ? "Yes" : "No", instance.getState().getName(), instance.getInstanceType(), instance.getKeyName(), StringUtils.join(reservation.getGroupNames(), ","), instance.getPlacement().getAvailabilityZone(), DATE_FORMAT.format(instance.getLaunchTime()), tags.toString() }); DefaultMutableTreeNode instanceNode = new DefaultMutableTreeNode( new InstanceObjectWrapper(instance, name), false); rootNode.add(instanceNode); treeModel.reload(); } catch (Exception ex) { Logger.getLogger(InstancesPanel.class.getName()).log(Level.SEVERE, null, ex); } } } } }).start(); }
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 ava 2 s. c om*/ 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:de.unibi.cebitec.bibigrid.meta.aws.ListIntentAWS.java
private ListIntentAWS searchCluster() { Cluster cluster;/* w ww. ja v a 2s .c o m*/ // ================================= // == Instances DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest(); DescribeInstancesResult describeInstancesResult = ec2.describeInstances(describeInstancesRequest); List<Reservation> reservations = describeInstancesResult.getReservations(); for (Reservation r : reservations) { for (Instance i : r.getInstances()) { if (i.getState().getName().equals("pending") || i.getState().getName().equals("running") || i.getState().getName().equals("stopping") || i.getState().getName().equals("stopped")) { // check for cluster-id String clusterid = getValueforName(i.getTags(), "bibigrid-id"); String name = getValueforName(i.getTags(), "name"); String user = getValueforName(i.getTags(), "user"); if (clusterid == null && name != null) { // old style : use name to determine clusterid if (name.contains("master-") || name.contains("slave-")) { String[] tmp = name.split("-"); clusterid = tmp[tmp.length - 1]; } } if (clusterid == null) { // not an bibigrid instance : skip continue; } // check if map contains a value objekt if (clustermap.containsKey(clusterid)) { cluster = clustermap.get(clusterid); } else { cluster = new Cluster(); } // master//slave instance ? if (name != null && name.contains("master-")) { if (cluster.getMasterinstance() == null) { cluster.setMasterinstance(i.getInstanceId()); cluster.setStarted(dateformatter.format(i.getLaunchTime())); } else { log.error("Detect two master instances ({},{}) for cluster '{}' ", cluster.getMasterinstance(), i.getInstanceId(), clusterid); // ??? System.exit(1); } } else { cluster.addSlaveInstance(i.getInstanceId()); } //keyname - should be always the same for all instances of one cluster if (cluster.getKeyname() != null) { if (!cluster.getKeyname().equals(i.getKeyName())) { log.error("Detect two different keynames ({},{}) for cluster '{}'", cluster.getKeyname(), i.getKeyName(), clusterid); } } else { cluster.setKeyname(i.getKeyName()); } // user - should be always the same for all instances of one cluser if (user != null) { if (cluster.getUser() == null) { cluster.setUser(user); } else if (!cluster.getUser().equals(user)) { log.error("Detect two different users ({},{}) for cluster '{}'", cluster.getUser(), user, clusterid); } } clustermap.put(clusterid, cluster); } } } return this; }