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

The following examples show how to use com.amazonaws.services.ec2.model.StartInstancesResult. 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: StartInstancesExample.java    From aws-mock with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: AwsInstanceProcess.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
public void start(AwsProcessClient awsProcessClient, Long instanceNo) {
    AwsInstance awsInstance = awsInstanceDao.read(instanceNo);
    String instanceId = awsInstance.getInstanceId();

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

    // インスタンスの起動
    StartInstancesRequest request = new StartInstancesRequest();
    request.withInstanceIds(instanceId);
    StartInstancesResult result = awsProcessClient.getEc2Client().startInstances(request);
    List<InstanceStateChange> startingInstances = result.getStartingInstances();

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

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

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

    // データベース更新
    awsInstance.setStatus(startingInstances.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 StartInstancesResult start(StartInstancesRequest request,
        ResultCapture<StartInstancesResult> extractor) {

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

    if (result == null) return null;
    return (StartInstancesResult) 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 StartInstancesResult start(ResultCapture<StartInstancesResult>
        extractor) {

    StartInstancesRequest request = new StartInstancesRequest();
    return start(request, extractor);
}
 
Example #6
Source File: BaseTest.java    From aws-mock with MIT License 5 votes vote down vote up
/**
 * Start instances.
 *
 * @param instanceIds
 *            instances' IDs
 * @return list of instances change
 */
protected final List<InstanceStateChange> startInstances(
        final Collection<String> instanceIds) {
    log.info("Start instances:" + toString(instanceIds));

    StartInstancesRequest request = new StartInstancesRequest();
    request.setInstanceIds(instanceIds);
    StartInstancesResult result = amazonEC2Client.startInstances(request);
    return result.getStartingInstances();
}
 
Example #7
Source File: InstanceImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public StartInstancesResult start(StartInstancesRequest request) {
    return start(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 StartInstancesResult start() {
    return start((ResultCapture<StartInstancesResult>)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>Start</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 StartInstancesRequest
 */
StartInstancesResult start(StartInstancesRequest 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>Start</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 StartInstancesRequest
 */
StartInstancesResult start(StartInstancesRequest request,
        ResultCapture<StartInstancesResult> 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>Start</code> action.
 *
 * @see #start(StartInstancesRequest)
 */
StartInstancesResult start();
 
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>Start</code> action.
 *
 * @see #start(StartInstancesRequest, ResultCapture)
 */
StartInstancesResult start(ResultCapture<StartInstancesResult> extractor);