本文整理汇总了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);
}
});
}
示例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));
}
示例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));
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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();
}
示例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));
}
示例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));
}
示例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));
}
示例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);
});
}
});
}
示例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);
}