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


Java StopInstancesRequest类代码示例

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


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

示例1: process

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

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

示例2: deactivateInstance

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

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

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

    runUntilReady();

    verify(ec2).stopInstances(any(StopInstancesRequest.class));

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

示例3: executeServiceOperation_Stop

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

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

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

    runUntilReady();

    verify(ec2).stopInstances(any(StopInstancesRequest.class));

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

示例4: stopInstance

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

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

示例5: stopInstances

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入依赖的package包/类
private void stopInstances(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    StopInstancesRequest request = new StopInstancesRequest();
    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");
    }
    StopInstancesResult result;
    try {
        result = ec2Client.stopInstances(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Stop Instances command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    LOG.trace("Stopping instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
    Message message = getMessageForResponse(exchange);
    message.setBody(result);        
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:EC2Producer.java

示例6: stopInstances

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入依赖的package包/类
@Override
public StopInstancesResult stopInstances(StopInstancesRequest stopInstancesRequest) {
    StopInstancesResult result = new StopInstancesResult();
    if (stopInstancesRequest.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.Running);
        InstanceState newState = new InstanceState();
        newState.setCode(16);
        newState.setName(InstanceStateName.Stopped);
        sc.setPreviousState(previousState);
        sc.setCurrentState(newState);
        sc.setInstanceId("test-1");
        coll.add(sc);
        result.setStoppingInstances(coll);
    } else {
        throw new AmazonServiceException("The image-id doesn't exists");
    }
    return result;        
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:AmazonEC2ClientMock.java

示例7: stopForRegion

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入依赖的package包/类
private List<VMInformation> stopForRegion(VMRegion region, List<String> instanceIds) {
    List<VMInformation> result = new ArrayList<VMInformation>();
    try {
        asynchEc2Client.setEndpoint(region.getEndpoint());
        List<VMInformation> instances = describeInstances(instanceIds.toArray(new String[instanceIds.size()]));
        List<String> ids = new ArrayList<String>();
        for (VMInformation info : instances) {
            ids.add(info.getInstanceId());
        }
        if (ids.size() > 0) {
            StopInstancesRequest stopInstancesRequest = new StopInstancesRequest(ids);
            StopInstancesResult stopResult = asynchEc2Client.stopInstances(stopInstancesRequest);
            List<InstanceStateChange> stoppingInstances = stopResult.getStoppingInstances();
            result = new AmazonDataConverter().processStateChange(stoppingInstances);
        }
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
        throw new RuntimeException(ex);
    }
    return result;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:22,代码来源:AmazonInstance.java

示例8: testStopInstanceStopping

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

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

	final StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(INSTANCE_ID);
	final StopInstancesResult stopInstancesResult = new StopInstancesResult().withStoppingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Stopping)));

	Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	Mockito.doReturn(stopInstancesResult).when(amazonEC2Client).stopInstances(stopInstancesRequest);

	amazonEC2Service.stopInstance(INSTANCE_ID);

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

示例9: testStopInstanceStopped

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

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

	final StopInstancesRequest stopInstancesRequest = new StopInstancesRequest().withInstanceIds(INSTANCE_ID);
	final StopInstancesResult stopInstancesResult = new StopInstancesResult().withStoppingInstances(new InstanceStateChange().withCurrentState(new InstanceState().withName(InstanceStateName.Stopped)));

	Mockito.doReturn(describeInstanceStatusResult).when(amazonEC2Client).describeInstanceStatus(describeInstanceStatusRequest);
	Mockito.doReturn(stopInstancesResult).when(amazonEC2Client).stopInstances(stopInstancesRequest);

	amazonEC2Service.stopInstance(INSTANCE_ID);

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

示例10: stopInstances

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入依赖的package包/类
/**
 * Stop specified instances (power-on the instances).
 *
 * @param instanceIDs
 *            IDs of the instances to stop
 * @return a list of state changes for the instances
 */
public static List<InstanceStateChange> stopInstances(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 stop request with args as instance IDs to stop running instances
    StopInstancesRequest request = new StopInstancesRequest();
    request.withInstanceIds(instanceIDs);
    StopInstancesResult result = amazonEC2Client.stopInstances(request);

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

示例11: process_DEACTIVATION_REQUESTED

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

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

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

示例12: process_STOP_REQUESTED

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

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

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

示例13: testStopInstance

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

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

示例14: reset

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入依赖的package包/类
private void reset(AmazonEC2AsyncClient client, ResourceOperationRequest pr,
                    DefaultAdapterContext c) {
    if (!c.child.powerState.equals(ComputeService.PowerState.ON)) {
        logWarning(() -> String.format("Cannot perform a reset on this EC2 instance. " +
                        "The machine should be in powered on state"));
        c.taskManager.patchTaskToFailure(new IllegalStateException("Incorrect power state. Expected the machine " +
                "to be powered on "));
        return;
    }

    // The stop action for reset is a force stop. So we use the withForce method to set the force parameter to TRUE
    // This is similar to unplugging the machine from the power circuit.
    // The OS and the applications are forcefully stopped.
    StopInstancesRequest stopRequest  = new StopInstancesRequest();
    stopRequest.withInstanceIds(c.child.id).withForce(Boolean.TRUE);
    client.stopInstancesAsync(stopRequest,
            new AWSAsyncHandler<StopInstancesRequest, StopInstancesResult>() {
                @Override
                protected void handleError(Exception e) {
                    c.taskManager.patchTaskToFailure(e);
                }

                @Override
                protected void handleSuccess(StopInstancesRequest request, StopInstancesResult result) {

                    AWSUtils.waitForTransitionCompletion(getHost(),
                            result.getStoppingInstances(), "stopped", client, (is, e) -> {
                                if (e != null) {
                                    onError(e);
                                    return;
                                }
                                //Instances will be started only if they're successfully stopped
                                startInstance(client,c);
                            });
                }
            });
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:38,代码来源:AWSResetService.java

示例15: stopVMsUsingEC2Client

import com.amazonaws.services.ec2.model.StopInstancesRequest; //导入依赖的package包/类
/**
 * Stop instances on the AWS endpoint for the set of instance Ids that are passed in.
 *
 * @param client
 * @param host
 * @param instanceIdsToStop
 * @throws Throwable
 */
public static void stopVMsUsingEC2Client(AmazonEC2AsyncClient client, VerificationHost host,
        List<String> instanceIdsToStop) throws Throwable {
    StopInstancesRequest stopRequest = new StopInstancesRequest(instanceIdsToStop);
    AsyncHandler<StopInstancesRequest, StopInstancesResult> stopHandler = new AWSStopHandlerAsync(
            host);
    client.stopInstancesAsync(stopRequest, stopHandler);
    waitForInstancesToBeStopped(client, host, instanceIdsToStop);

}
 
开发者ID:vmware,项目名称:photon-model,代码行数:18,代码来源:TestAWSSetupUtils.java


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