当前位置: 首页>>代码示例>>Java>>正文


Java StartInstancesRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.StartInstancesRequest的典型用法代码示例。如果您正苦于以下问题:Java StartInstancesRequest类的具体用法?Java StartInstancesRequest怎么用?Java StartInstancesRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StartInstancesRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了StartInstancesRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: activateInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Test
public void activateInstance() throws Exception {

    parameters.put(PropertyHandler.FLOW_STATE,
            new Setting(PropertyHandler.FLOW_STATE,
                    FlowState.ACTIVATION_REQUESTED.name()));
    parameters.put(PropertyHandler.OPERATION, new Setting(
            PropertyHandler.OPERATION, Operation.EC2_ACTIVATION.name()));

    ec2mock.createDescribeInstancesResult("instance1", "running", "1.2.3.4");
    ec2mock.createDescribeInstanceStatusResult("instance1", "ok", "ok",
            "ok");
    ec2mock.createDescribeImagesResult(IMAGE_ID);
    ec2mock.createRunInstancesResult(INSTANCE_ID);

    runUntilReady();

    verify(ec2).startInstances(any(StartInstancesRequest.class));

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:AWSControllerIT.java

示例2: executeServiceOperation_Start

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Test
public void executeServiceOperation_Start() throws Exception {

    parameters.put(PropertyHandler.FLOW_STATE, new Setting(
            PropertyHandler.FLOW_STATE, FlowState.START_REQUESTED.name()));
    parameters.put(PropertyHandler.OPERATION, new Setting(
            PropertyHandler.OPERATION, Operation.EC2_OPERATION.name()));

    ec2mock.createDescribeInstancesResult("instance1", "running", "1.2.3.4");
    ec2mock.createDescribeInstanceStatusResult("instance1", "ok", "ok",
            "ok");
    ec2mock.createDescribeImagesResult(IMAGE_ID);
    ec2mock.createRunInstancesResult(INSTANCE_ID);

    runUntilReady();

    verify(ec2).startInstances(any(StartInstancesRequest.class));

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:AWSControllerIT.java

示例3: process

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Override
public void process(Instance instance) {
    ec2UserClient.amazonEC2Async().startInstancesAsync(
            new StartInstancesRequest().withInstanceIds(instance.getInstanceId()),
            new AsyncHandler<StartInstancesRequest, StartInstancesResult>() {
                @Override
                public void onError(Exception exception) {
                    log.warn("something went wrong starting the server {}",
                            exception.getLocalizedMessage());
                }

                @Override
                public void onSuccess(StartInstancesRequest request, StartInstancesResult result) {
                    onSuccessStart(instance);
                }
            });
}
 
开发者ID:peavers,项目名称:swordfish-service,代码行数:18,代码来源:EC2StartImpl.java

示例4: startInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
StartInstancesResult startInstance(InstanceRequest instanceRequest, Context context) {
	AmazonEC2Async client = createEC2Client();
	try {
		StartInstancesRequest req = new StartInstancesRequest();
		req.setInstanceIds(Arrays.asList(instanceRequest.getInstanceId()));
		Future<StartInstancesResult> result = client.startInstancesAsync(req);
		while (!result.isDone()) {
			Thread.sleep(100);
		}
		return result.get();

	} catch (Exception e) {
		throw new RuntimeException("unexpected error has occured in the start instance request.", e);
	} finally {
		client.shutdown();
	}
}
 
开发者ID:uzresk,项目名称:aws-auto-operations-using-lambda,代码行数:18,代码来源:InstanceStartFunction.java

示例5: startInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
private void startInstance(AmazonEC2AsyncClient client, DefaultAdapterContext c) {
    StartInstancesRequest startRequest  = new StartInstancesRequest();
    startRequest.withInstanceIds(c.child.id);
    client.startInstancesAsync(startRequest,
            new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {

                @Override
                protected void handleError(Exception e) {
                    c.taskManager.patchTaskToFailure(e);
                }

                @Override
                protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
                    AWSUtils.waitForTransitionCompletion(getHost(),
                            result.getStartingInstances(), "running",
                            client, (is, e) -> {
                                if (e == null) {
                                    c.taskManager.finishTask();
                                } else {
                                    c.taskManager.patchTaskToFailure(e);
                                }
                            });
                }
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:26,代码来源:AWSResetService.java

示例6: startInstances

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
private void startInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    StartInstancesRequest request = new StartInstancesRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withInstanceIds(instanceIds);
    } else {
        throw new IllegalArgumentException("Instances Ids must be specified");
    }
    StartInstancesResult result;
    try {
        result = ec2Client.startInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Start Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    LOG.trace("Starting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
    Message message = getMessageForResponse(exchange);
    message.setBody(result);        
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:EC2Producer.java

示例7: startInstances

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Override
public StartInstancesResult startInstances(StartInstancesRequest startInstancesRequest) {
    StartInstancesResult result = new StartInstancesResult();
    if (startInstancesRequest.getInstanceIds().get(0).equals("test-1")) {
        Collection<InstanceStateChange> coll = new ArrayList<InstanceStateChange>();
        InstanceStateChange sc = new InstanceStateChange();
        InstanceState previousState = new InstanceState();
        previousState.setCode(80);
        previousState.setName(InstanceStateName.Stopped);
        InstanceState newState = new InstanceState();
        newState.setCode(16);
        newState.setName(InstanceStateName.Running);
        sc.setPreviousState(previousState);
        sc.setCurrentState(newState);
        sc.setInstanceId("test-1");
        coll.add(sc);
        result.setStartingInstances(coll);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;       
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:AmazonEC2ClientMock.java

示例8: testStartInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Test
public void testStartInstance() {

	final DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withIncludeAllInstances(true).withInstanceIds(INSTANCE_ID);
	final DescribeInstanceStatusResult describeInstanceStatusResult = new DescribeInstanceStatusResult().withInstanceStatuses(new InstanceStatus().withInstanceState(new InstanceState().withName(InstanceStateName.Stopped)));

	final StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(INSTANCE_ID);
	final StartInstancesResult startInstancesResult = new StartInstancesResult().withStartingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Running)));

	Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	Mockito.doReturn(startInstancesResult).when(amazonEC2Client).startInstances(startInstancesRequest);

	amazonEC2Service.startInstance(INSTANCE_ID);

	final InOrder inOrder = Mockito.inOrder(amazonEC2Client);
	inOrder.verify(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	inOrder.verify(amazonEC2Client).startInstances(startInstancesRequest);
}
 
开发者ID:Sylvain-Bugat,项目名称:aws-ec2-start-stop-tools,代码行数:19,代码来源:AmazonEC2ServiceTest.java

示例9: startInstances

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
/**
 * Start specified instances (power-on the instances).
 *
 * @param instanceIDs
 *            IDs of the instances start
 * @return a list of state changes for the instances
 */
public static List<InstanceStateChange> startInstances(final List<String> instanceIDs) {
    // pass any credentials as aws-mock does not authenticate them at all
    AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
    AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);

    // the mock endpoint for ec2 which runs on your computer
    String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
    amazonEC2Client.setEndpoint(ec2Endpoint);

    // send the start request with args as instance IDs to start existing instances
    StartInstancesRequest request = new StartInstancesRequest();
    request.withInstanceIds(instanceIDs);
    StartInstancesResult result = amazonEC2Client.startInstances(request);

    return result.getStartingInstances();
}
 
开发者ID:treelogic-swe,项目名称:aws-mock,代码行数:24,代码来源:StartInstancesExample.java

示例10: process_ACTIVATION_REQUESTED

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Test
public void process_ACTIVATION_REQUESTED() throws Exception {
    // given
    ph.setOperation(Operation.EC2_ACTIVATION);
    ph.setState(FlowState.ACTIVATION_REQUESTED);

    // when
    InstanceStatus result = ec2proc.process();

    // then
    assertFalse(result.isReady());
    assertEquals(FlowState.STARTING, ph.getState());
    verify(ec2).startInstances(any(StartInstancesRequest.class));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:EC2ProcessorTest.java

示例11: process_START_REQUESTED

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Test
public void process_START_REQUESTED() throws Exception {
    // given
    ph.setOperation(Operation.EC2_OPERATION);
    ph.setState(FlowState.START_REQUESTED);

    // when
    InstanceStatus result = ec2proc.process();

    // then
    assertFalse(result.isReady());
    assertEquals(FlowState.STARTING, ph.getState());
    verify(ec2).startInstances(any(StartInstancesRequest.class));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:15,代码来源:EC2ProcessorTest.java

示例12: testStartInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
@Test
public void testStartInstance() throws Exception {
    ec2comm.startInstance("instance1");
    ArgumentCaptor<StartInstancesRequest> arg1 = ArgumentCaptor
            .forClass(StartInstancesRequest.class);
    verify(ec2).startInstances(arg1.capture());
    StartInstancesRequest val = arg1.getValue();

    assertEquals(1, val.getInstanceIds().size());
    assertEquals("instance1", val.getInstanceIds().get(0));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:EC2CommunicationTest.java

示例13: startInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
/**
 * start the instance and on success updates the disk and compute state to reflect the detach information.
 */
private void startInstance(AmazonEC2AsyncClient client, DiskContext c, DeferredResult<DiskContext> dr) {
    StartInstancesRequest startRequest  = new StartInstancesRequest();
    startRequest.withInstanceIds(c.baseAdapterContext.child.id);
    client.startInstancesAsync(startRequest,
            new AWSAsyncHandler<StartInstancesRequest, StartInstancesResult>() {

                @Override
                protected void handleError(Exception e) {
                    dr.fail(e);
                }

                @Override
                protected void handleSuccess(StartInstancesRequest request, StartInstancesResult result) {
                    AWSUtils.waitForTransitionCompletion(getHost(),
                            result.getStartingInstances(), "running",
                            client, (is, e) -> {
                                if (e != null) {
                                    dr.fail(e);
                                    return;
                                }

                                logInfo(() -> String.format(
                                        "[AWSComputeDiskDay2Service] Successfully started the "
                                                + "instance %s",
                                        result.getStartingInstances().get(0).getInstanceId()));
                                updateComputeAndDiskState(dr, c);
                            });
                }
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:34,代码来源:AWSComputeDiskDay2Service.java

示例14: startInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
public static InstanceStateChange startInstance(AmazonEC2 ec2, String instanceId) {
	StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(instanceId);
	StartInstancesResult startInstancesResult = ec2.startInstances(startInstancesRequest);
	List<InstanceStateChange> instanceStateChange = startInstancesResult.getStartingInstances();
	for (InstanceStateChange stateChange : instanceStateChange) {
		return stateChange;
	}
	return null;
}
 
开发者ID:betahikaru,项目名称:ec2-util,代码行数:10,代码来源:AwsEc2Client.java

示例15: startInstance

import com.amazonaws.services.ec2.model.StartInstancesRequest; //导入依赖的package包/类
/**
 * Check the instance status and order to start it if it's stopped.
 * 
 * @param instanceId Instance du start
 */
public void startInstance(final String instanceId) {

	LOG.entry();
	LOG.info("Starting instance {}", instanceId);

	// Check the instance state
	final InstanceStateName instanteState = getInstanceStatus(instanceId);
	if (InstanceStateName.Stopped != instanteState) {

		final String message = "Instance " + instanceId + " is not stopped, current state: " + instanteState;
		LOG.error(message);
		final AmazonClientException exception = new AmazonClientException(message);
		LOG.exit(exception);
		throw exception;
	}

	// Start instance order
	final StartInstancesRequest startInstancesRequest = new StartInstancesRequest().withInstanceIds(instanceId);
	final StartInstancesResult startInstancesResult = amazonEC2Client.startInstances(startInstancesRequest);
	final List<InstanceStateChange> instanceStateChangeList = startInstancesResult.getStartingInstances();

	for (final InstanceStateChange instanceStateChange : instanceStateChangeList) {

		LOG.info("Instance {} has changing state: {} -> {}", instanceStateChange.getInstanceId(), instanceStateChange.getPreviousState(), instanceStateChange.getCurrentState());
	}

	LOG.info("Instance {} is starting", instanceId);
	LOG.exit();
}
 
开发者ID:Sylvain-Bugat,项目名称:aws-ec2-start-stop-tools,代码行数:35,代码来源:AmazonEC2Service.java


注:本文中的com.amazonaws.services.ec2.model.StartInstancesRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。