com.amazonaws.services.ec2.model.StopInstancesResult Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.StopInstancesResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsInstanceConnectorTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void awsClientSetup() {
    when(awsClient.getAmazonEC2Client(any(AwsSessionCredentialProvider.class))).thenReturn(amazonEC2Client);
    when(awsClient.getAmazonEC2Client(any(BasicAWSCredentials.class))).thenReturn(amazonEC2Client);
    when(awsClient.getInstanceProfileProvider()).thenReturn(instanceProfileCredentialsProvider);

    CloudContext context = new CloudContext(1L, "context", "AWS", "AWS",
            Location.location(Region.region("region")), "user", "account");
    CloudCredential credential = new CloudCredential("id", "alma",
            Map.of("accessKey", "ac", "secretKey", "secret"), false);
    authenticatedContext = awsAuthenticator.authenticate(context, credential);

    StopInstancesResult stopInstancesResult = new StopInstancesResult();
    StartInstancesResult startInstanceResult = new StartInstancesResult();
    when(amazonEC2Client.stopInstances(any(StopInstancesRequest.class))).thenReturn(stopInstancesResult);
    when(amazonEC2Client.startInstances(any(StartInstancesRequest.class))).thenReturn(startInstanceResult);

    inputList = getCloudInstances();
}
 
Example #2
Source File: StopInstancesExample.java    From aws-mock with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: AwsInstanceProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
public void stop(AwsProcessClient awsProcessClient, Long instanceNo) {
    AwsInstance awsInstance = awsInstanceDao.read(instanceNo);
    String instanceId = awsInstance.getInstanceId();

    // イベントログ出力
    Instance instance = instanceDao.read(instanceNo);
    processLogger.debug(null, instance, "AwsInstanceStop",
            new Object[] { awsProcessClient.getPlatform().getPlatformName(), instanceId });

    // インスタンスの停止
    StopInstancesRequest request = new StopInstancesRequest();
    request.withInstanceIds(instanceId);
    StopInstancesResult result = awsProcessClient.getEc2Client().stopInstances(request);
    List<InstanceStateChange> stoppingInstances = result.getStoppingInstances();

    // API実行結果チェック
    if (stoppingInstances.size() == 0) {
        // インスタンス停止失敗時
        throw new AutoException("EPROCESS-000128", instanceId);

    } else if (stoppingInstances.size() > 1) {
        // 複数のインスタンスが停止した場合
        AutoException exception = new AutoException("EPROCESS-000130", instanceId);
        exception.addDetailInfo("result=" + stoppingInstances);
        throw exception;
    }

    // ログ出力
    if (log.isInfoEnabled()) {
        log.info(MessageUtils.getMessage("IPROCESS-100113", instanceId));
    }

    // データベース更新
    awsInstance.setStatus(stoppingInstances.get(0).getCurrentState().getName());
    awsInstanceDao.update(awsInstance);
}
 
Example #4
Source File: InstanceImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public StopInstancesResult stop(StopInstancesRequest request,
        ResultCapture<StopInstancesResult> extractor) {

    ActionResult result = resource.performAction("Stop", request,
            extractor);

    if (result == null) return null;
    return (StopInstancesResult) result.getData();
}
 
Example #5
Source File: InstanceImpl.java    From aws-sdk-java-resources with Apache License 2.0 5 votes vote down vote up
@Override
public StopInstancesResult stop(ResultCapture<StopInstancesResult> extractor
        ) {

    StopInstancesRequest request = new StopInstancesRequest();
    return stop(request, extractor);
}
 
Example #6
Source File: BaseTest.java    From aws-mock with MIT License 5 votes vote down vote up
/**
 * Stop instances.
 *
 * @param instanceIds
 *            instances' IDs
 * @return list of instances change
 */
protected final List<InstanceStateChange> stopInstances(
        final Collection<String> instanceIds) {
    log.info("Stop instances:" + toString(instanceIds));
    StopInstancesRequest request = new StopInstancesRequest();
    request.setInstanceIds(instanceIds);
    StopInstancesResult result = amazonEC2Client.stopInstances(request);
    return result.getStoppingInstances();
}
 
Example #7
Source File: InstanceImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public StopInstancesResult stop(StopInstancesRequest request) {
    return stop(request, null);
}
 
Example #8
Source File: InstanceImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public StopInstancesResult stop() {
    return stop((ResultCapture<StopInstancesResult>)null);
}
 
Example #9
Source File: Instance.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>Stop</code> action.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Instance</code> resource, and any conflicting parameter value set
 * in the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>InstanceIds.0</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The response of the low-level client operation associated with
 *         this resource action.
 * @see StopInstancesRequest
 */
StopInstancesResult stop(StopInstancesRequest request);
 
Example #10
Source File: Instance.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>Stop</code> action and use a ResultCapture to retrieve
 * the low-level client response.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>Instance</code> resource, and any conflicting parameter value set
 * in the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>InstanceIds.0</code></b>
 *         - mapped from the <code>Id</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @return The response of the low-level client operation associated with
 *         this resource action.
 * @see StopInstancesRequest
 */
StopInstancesResult stop(StopInstancesRequest request,
        ResultCapture<StopInstancesResult> extractor);
 
Example #11
Source File: Instance.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * The convenient method form for the <code>Stop</code> action.
 *
 * @see #stop(StopInstancesRequest)
 */
StopInstancesResult stop();
 
Example #12
Source File: Instance.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * The convenient method form for the <code>Stop</code> action.
 *
 * @see #stop(StopInstancesRequest, ResultCapture)
 */
StopInstancesResult stop(ResultCapture<StopInstancesResult> extractor);