當前位置: 首頁>>代碼示例>>Java>>正文


Java Instance.getInstanceId方法代碼示例

本文整理匯總了Java中com.amazonaws.services.ec2.model.Instance.getInstanceId方法的典型用法代碼示例。如果您正苦於以下問題:Java Instance.getInstanceId方法的具體用法?Java Instance.getInstanceId怎麽用?Java Instance.getInstanceId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.ec2.model.Instance的用法示例。


在下文中一共展示了Instance.getInstanceId方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convertInstanceToServer

import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
private List<Server> convertInstanceToServer(List<Instance> instances) {
    List<Server> servers = new ArrayList<>();
    for (Instance instance : instances) {
        Server server = new Server(instance.getInstanceId());
        for (Tag tag : instance.getTags()) {
            if (tag != null && tag.getKey() != null
                    && tag.getKey().equals("Name")) {
                server.setName(tag.getValue());
            }
        }
        server.setStatus(instance.getState().getName());
        server.setType(instance.getInstanceType());
        server.setPublicIP(Arrays.asList(instance.getPublicIpAddress()));
        server.setPrivateIP(Arrays.asList(instance.getPrivateIpAddress()));
        servers.add(server);
    }
    return servers;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:EC2Processor.java

示例2: fetchMetrics

import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
@Override
public void fetchMetrics() {

	try {

		// For each instance fetch the ec2 cloud watch metrics
		List<Instance> instances = EC2Util.lookupElligibleInstances( ec2Client, namePrefix, nameRegex );
		for ( Instance instance : instances ) {

			String instanceId = instance.getInstanceId();
			for ( EC2CloudWatchMetric cloudWatchMetric : ec2CloudWatchMetrics ) {
				cloudWatchAccessor.lookupAndSaveMetricData( cloudWatchMetric, instanceId, EC2Util.TYPE_NAME );
			}

		}

	} catch ( CandlestackException e ) {
		LOGGER.error( "EC2MetricsFetcher encountered an error while trying to fetch metrics", e );
	}

}
 
開發者ID:CodeArcsInc,項目名稱:candlestack,代碼行數:22,代碼來源:EC2MetricsFetcher.java

示例3: checkInstanceIsManagedByDirector

import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
/**
 * Performs a sequence of strict instance ownership checks to avoid any potential harmful
 * accidents.
 *
 * @param instance the instance
 * @param template the template from which the instance was created, or <code>null</code>
 *                 if it is unknown (such as during a delete call)
 * @return the virtual instance ID
 * @throws IllegalStateException if the instance fails an ownership check
 */
private String checkInstanceIsManagedByDirector(Instance instance, EC2InstanceTemplate template) {
  String virtualInstanceId = getVirtualInstanceId(instance.getTags(), "instance");
  String instanceIds = instance.getInstanceId() + " / " + virtualInstanceId;
  String instanceKeyName = instance.getKeyName();

  if (template != null) {
    if (!template.getKeyName().equals(Optional.fromNullable(instanceKeyName))) {
      LOG.warn("Found unexpected key name: {} for instance: {}", instanceKeyName, instanceIds);
    }
    String instanceType = instance.getInstanceType();
    if (!template.getType().equals(instanceType)) {
      LOG.warn("Found unexpected type: {} for instance: {}", instanceType, instanceIds);
    }
    String instanceImageId = instance.getImageId();
    if (!template.getImage().equals(instanceImageId)) {
      LOG.warn("Found unexpected image: {} for instance: {}", instanceImageId, instanceIds);
    }
  }
  return virtualInstanceId;
}
 
開發者ID:cloudera,項目名稱:director-aws-plugin,代碼行數:31,代碼來源:EC2Provider.java

示例4: rebootInstance

import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
/**
 * Reboot an instance and make sure it comes back healthy
 */
private void rebootInstance(StackName stackName, String autoScalingGroupId, Instance instance) {

    final String healthCheckUrlTmpl = HEALTH_CHECK_MAP.get(stackName.getName());
    final String healthCheckUrl = String.format(healthCheckUrlTmpl, instance.getPublicDnsName());

    logger.info("Checking that instance health check is reachable...");
    waitForHealthCheckStatusCode(healthCheckUrl, HttpStatus.OK, EXPECTED_NUM_SUCCESSES_BEFORE_REBOOT);

    final String instanceId = instance.getInstanceId();
    logger.info("Setting instance state to standby: {}", instanceId);
    autoScalingService.setInstanceStateToStandby(autoScalingGroupId, instanceId);

    logger.info("Rebooting instance: {}", instanceId);
    ec2Service.rebootEc2Instance(instanceId);

    // wait for health check fail to confirm box reboot
    logger.info("Waiting for health check failure to confirm reboot...");
    waitForHealthCheckStatusCode(healthCheckUrl, HEALTH_CHECK_FAILED_CODE, EXPECTED_NUM_FAILURES_AFTER_REBOOT);

    // wait for health check pass to confirm instance is healthy after reboot
    logger.warn(Chalk.on(
            "If a proxy is required to talk to the EC2 instance, then make sure it is set up." +
            " Otherwise this command will never succeed.").yellow().toString());
    logger.info("Waiting for health check to pass again to confirm instance is healthy...");
    waitForHealthCheckStatusCode(healthCheckUrl, HttpStatus.OK, EXPECTED_NUM_SUCCESSES_AFTER_REBOOT);

    logger.info("Setting instance state to in-service: {}", instanceId);
    autoScalingService.setInstanceStateToInService(autoScalingGroupId, instanceId);
}
 
開發者ID:Nike-Inc,項目名稱:cerberus-lifecycle-cli,代碼行數:33,代碼來源:RollingRebootWithHealthCheckOperation.java

示例5: execute

import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
/**
 * Stop Ec2 Instance. Realease EIP for Ec2 Instance. Disassociate EIP.
 */
public int execute(Ec2CommandOptions options) throws FileNotFoundException {
	System.out.println(getClass().getName());
	String name = options.getName();
	InputStream inputStream = new FileInputStream(new File(options.getCredentialsPath()));
	ConfigProvider.loadConfigure(inputStream);
	AmazonEC2 ec2 = AwsEc2Client.getEc2();

	// Check Exists Instance
	Instance instance = AwsEc2Client.findInstanceByName(ec2, name);
	if (instance == null) {
		System.err.println("Not exists instance (name = " + name + ").");
		return 2;
	}
	String instanceId = instance.getInstanceId();
	String publicIp = instance.getPublicIpAddress();
	System.out.println("Exists instance (id = " + instanceId + ")");

	// Stop Ec2 Instance
	InstanceStateChange stateChange = AwsEc2Client.stopInstance(ec2, instanceId);
	AwsEc2Client.showStateChange(stateChange, "Stopping Instance");

	// Disassociate and Release Address
	if (publicIp != null) {
		Address address = AwsEc2Client.checkExistsAddress(ec2, publicIp);
		if (address != null) {
			AwsEc2Client.disassociateAddress(ec2, address);
			System.out.println("Disassociated Address (" + publicIp + ")");
			AwsEc2Client.releaseAddress(ec2, address);
			System.out.println("Released Address (" + publicIp + ")");
		}
	} else {
		System.out.println("No EIP.");
	}
	return 0;
}
 
開發者ID:betahikaru,項目名稱:ec2-util,代碼行數:39,代碼來源:Ec2StopCommand.java

示例6: getPropertyValue

import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
@Override
protected String getPropertyValue(Instance instance) {
  return instance.getInstanceId();
}
 
開發者ID:cloudera,項目名稱:director-aws-plugin,代碼行數:5,代碼來源:EC2Instance.java

示例7: startByName

import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
private int startByName(Ec2CommandOptions options) throws FileNotFoundException {
	String name = options.getName();
	InputStream inputStream = new FileInputStream(new File(options.getCredentialsPath()));
	ConfigProvider.loadConfigure(inputStream);
	AmazonEC2 ec2 = AwsEc2Client.getEc2();

	// Check Exists Instance
	Instance instance = AwsEc2Client.findInstanceByName(ec2, name);
	if (instance == null) {
		System.err.println("Not exists instance (name = " + name + ").");
		return 2;
	}
	String instanceId = instance.getInstanceId();
	System.out.println("Exists instance (id = " + instanceId + ")");

	// Start Ec2 Instance
	InstanceStateChange stateChange = AwsEc2Client.startInstance(ec2, instanceId);
	AwsEc2Client.showStateChange(stateChange, "Starting Instance");

	// Allocate Address
	DomainType domainType = (instance.getVpcId() == null) ? DomainType.Standard : DomainType.Vpc;
	Address address = AwsEc2Client.allocateAddress(ec2, domainType);
	String publicIp = address.getPublicIp();
	System.out.println("Allocated Address(" + publicIp + ", " + address.getAllocationId() + ")");
	if (address != null) {
		// TODO: Wait for Starting Instance.
		waitForStartingInstance();

		try {
			// Associate Address
			String associateAddress = AwsEc2Client.associateAddress(ec2, address, instanceId);
			System.out.println("Associated Address(" + publicIp + ", " + associateAddress + ")");

			String domain = options.getDomain();
			if (domain != null) {
				// Attach Domain to EIP
				AmazonRoute53 route53 = AwsRoute53Client.getRoute53();
				ChangeInfo attachedResult = AwsRoute53Client.attachDomainToEip(route53, publicIp, domain);
				if (attachedResult != null) {
					System.out.println("Attached domain(" + domain + ")");
				} else {
					System.err.println("Not Found Available Hosted Zone for specified Domain(" + domain + ")");
				}
			}
		} catch (AmazonServiceException e) {
			AwsEc2Client.releaseAddress(ec2, address);
			System.out.println("Released Address (" + publicIp + ")");
			return 2;
		}
	}
	return 0;
}
 
開發者ID:betahikaru,項目名稱:ec2-util,代碼行數:53,代碼來源:Ec2StartCommand.java


注:本文中的com.amazonaws.services.ec2.model.Instance.getInstanceId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。