Search in sources :

Example 1 with BasicFuture

use of org.apache.http.concurrent.BasicFuture in project pipeline-aws-plugin by jenkinsci.

the class EventPrinter method waitAndPrintStackEvents.

public void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter, long pollIntervalMillis) throws ExecutionException {
    final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
    waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)), new WaiterHandler() {

        @Override
        public void onWaitSuccess(AmazonWebServiceRequest request) {
            waitResult.completed(request);
        }

        @Override
        public void onWaitFailure(Exception e) {
            waitResult.failed(e);
        }
    });
    this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}
Also used : DescribeStacksRequest(com.amazonaws.services.cloudformation.model.DescribeStacksRequest) BasicFuture(org.apache.http.concurrent.BasicFuture) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) WaiterHandler(com.amazonaws.waiters.WaiterHandler) ExecutionException(java.util.concurrent.ExecutionException) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)

Example 2 with BasicFuture

use of org.apache.http.concurrent.BasicFuture in project acceptance-test-harness by jenkinsci.

the class LocalSlaveController method install.

@Override
public Future<Slave> install(Jenkins jenkins) {
    // Just to make sure the dumb slave is set up properly, we should seed it
    // with a FS root and executors
    final DumbSlave s = jenkins.slaves.create(DumbSlave.class);
    s.asLocal();
    s.save();
    s.waitUntilOnline();
    BasicFuture<Slave> b = new BasicFuture<>(null);
    b.completed(s);
    return b;
}
Also used : DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) Slave(org.jenkinsci.test.acceptance.po.Slave) BasicFuture(org.apache.http.concurrent.BasicFuture) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave)

Example 3 with BasicFuture

use of org.apache.http.concurrent.BasicFuture in project herd by FINRAOS.

the class MockS3OperationsImpl method copyFile.

/**
 * {@inheritDoc} <p/> <p> This implementation simulates a copyFile operation. </p> <p> This method copies files in-memory. </p> <p> The result {@link Copy}
 * has the following properties: <dl> <p/> <dt>description</dt> <dd>"MockTransfer"</dd> <p/> <dt>state</dt> <dd>{@link TransferState#Completed}</dd> <p/>
 * <dt>transferProgress.totalBytesToTransfer</dt> <dd>1024</dd> <p/> <dt>transferProgress.updateProgress</dt> <dd>1024</dd> <p/> </dl> <p/> All other
 * properties are set as default. </p> <p> This operation takes the following hints when suffixed in copyObjectRequest.sourceKey: <dl> <p/>
 * <dt>MOCK_S3_FILE_NAME_SERVICE_EXCEPTION</dt> <dd>Throws a AmazonServiceException</dd> <p/> </dl> </p>
 */
@Override
public Copy copyFile(final CopyObjectRequest copyObjectRequest, TransferManager transferManager) {
    LOGGER.debug("copyFile(): copyObjectRequest.getSourceBucketName() = " + copyObjectRequest.getSourceBucketName() + ", copyObjectRequest.getSourceKey() = " + copyObjectRequest.getSourceKey() + ", copyObjectRequest.getDestinationBucketName() = " + copyObjectRequest.getDestinationBucketName() + ", copyObjectRequest.getDestinationKey() = " + copyObjectRequest.getDestinationKey());
    if (copyObjectRequest.getSourceKey().endsWith(MOCK_S3_FILE_NAME_SERVICE_EXCEPTION)) {
        throw new AmazonServiceException(null);
    }
    String sourceBucketName = copyObjectRequest.getSourceBucketName();
    String sourceKey = copyObjectRequest.getSourceKey();
    MockS3Bucket mockSourceS3Bucket = getOrCreateBucket(sourceBucketName);
    MockS3Object mockSourceS3Object = mockSourceS3Bucket.getObjects().get(sourceKey);
    if (mockSourceS3Object == null) {
        AmazonServiceException amazonServiceException = new AmazonServiceException(S3Operations.ERROR_CODE_NO_SUCH_KEY);
        amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_NO_SUCH_KEY);
        throw amazonServiceException;
    }
    // Set the result CopyImpl and TransferProgress.
    TransferProgress transferProgress = new TransferProgress();
    transferProgress.setTotalBytesToTransfer(mockSourceS3Object.getObjectMetadata().getContentLength());
    transferProgress.updateProgress(mockSourceS3Object.getObjectMetadata().getContentLength());
    CopyImpl copy = new CopyImpl(MOCK_TRANSFER_DESCRIPTION, transferProgress, null, null);
    copy.setState(TransferState.Completed);
    // If an invalid KMS Id was passed in, mark the transfer as failed and return an exception via the transfer monitor.
    if (copyObjectRequest.getSSEAwsKeyManagementParams() != null) {
        final String kmsId = copyObjectRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId();
        if (kmsId.startsWith(MOCK_KMS_ID_FAILED_TRANSFER)) {
            copy.setState(TransferState.Failed);
            copy.setMonitor(new TransferMonitor() {

                @Override
                public Future<?> getFuture() {
                    if (!kmsId.equals(MOCK_KMS_ID_FAILED_TRANSFER_NO_EXCEPTION)) {
                        throw new AmazonServiceException("Key '" + copyObjectRequest.getSSEAwsKeyManagementParams().getAwsKmsKeyId() + "' does not exist (Service: Amazon S3; Status Code: 400; Error Code: KMS.NotFoundException; Request ID: 1234567890123456)");
                    }
                    // We don't want an exception to be thrown so return a basic future that won't throw an exception.
                    BasicFuture<?> future = new BasicFuture<Void>(null);
                    future.completed(null);
                    return future;
                }

                @Override
                public boolean isDone() {
                    return true;
                }
            });
        } else if (kmsId.startsWith(MOCK_KMS_ID_CANCELED_TRANSFER)) {
            // If the KMS indicates a cancelled transfer, just update the state to canceled.
            copy.setState(TransferState.Canceled);
        }
    }
    // If copy operation is marked as completed, perform the actual file copy in memory.
    if (copy.getState().equals(TransferState.Completed)) {
        String destinationBucketName = copyObjectRequest.getDestinationBucketName();
        String destinationObjectKey = copyObjectRequest.getDestinationKey();
        String destinationObjectVersion = MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED.equals(destinationBucketName) ? UUID.randomUUID().toString() : null;
        String destinationObjectKeyVersion = destinationObjectKey + (destinationObjectVersion != null ? destinationObjectVersion : "");
        ObjectMetadata objectMetadata = copyObjectRequest.getNewObjectMetadata();
        MockS3Object mockDestinationS3Object = new MockS3Object();
        mockDestinationS3Object.setKey(destinationObjectKey);
        mockDestinationS3Object.setVersion(destinationObjectVersion);
        mockDestinationS3Object.setData(Arrays.copyOf(mockSourceS3Object.getData(), mockSourceS3Object.getData().length));
        mockDestinationS3Object.setObjectMetadata(objectMetadata);
        MockS3Bucket mockDestinationS3Bucket = getOrCreateBucket(destinationBucketName);
        mockDestinationS3Bucket.getObjects().put(destinationObjectKey, mockDestinationS3Object);
        mockDestinationS3Bucket.getVersions().put(destinationObjectKeyVersion, mockDestinationS3Object);
    }
    return copy;
}
Also used : TransferMonitor(com.amazonaws.services.s3.transfer.internal.TransferMonitor) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress) BasicFuture(org.apache.http.concurrent.BasicFuture) AmazonServiceException(com.amazonaws.AmazonServiceException) CopyImpl(com.amazonaws.services.s3.transfer.internal.CopyImpl) Future(java.util.concurrent.Future) BasicFuture(org.apache.http.concurrent.BasicFuture) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 4 with BasicFuture

use of org.apache.http.concurrent.BasicFuture in project pipeline-aws-plugin by jenkinsci.

the class EventPrinter method waitAndPrintChangeSetEvents.

public void waitAndPrintChangeSetEvents(String stack, String changeSet, Waiter<DescribeChangeSetRequest> waiter, long pollIntervalMillis) throws ExecutionException {
    final BasicFuture<AmazonWebServiceRequest> waitResult = new BasicFuture<>(null);
    waiter.runAsync(new WaiterParameters<>(new DescribeChangeSetRequest().withStackName(stack).withChangeSetName(changeSet)), new WaiterHandler() {

        @Override
        public void onWaitSuccess(AmazonWebServiceRequest request) {
            waitResult.completed(request);
        }

        @Override
        public void onWaitFailure(Exception e) {
            waitResult.failed(e);
        }
    });
    this.waitAndPrintEvents(stack, pollIntervalMillis, waitResult);
}
Also used : BasicFuture(org.apache.http.concurrent.BasicFuture) DescribeChangeSetRequest(com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) WaiterHandler(com.amazonaws.waiters.WaiterHandler) ExecutionException(java.util.concurrent.ExecutionException) AmazonCloudFormationException(com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)

Aggregations

BasicFuture (org.apache.http.concurrent.BasicFuture)4 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)2 AmazonCloudFormationException (com.amazonaws.services.cloudformation.model.AmazonCloudFormationException)2 WaiterHandler (com.amazonaws.waiters.WaiterHandler)2 ExecutionException (java.util.concurrent.ExecutionException)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DescribeChangeSetRequest (com.amazonaws.services.cloudformation.model.DescribeChangeSetRequest)1 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 TransferProgress (com.amazonaws.services.s3.transfer.TransferProgress)1 CopyImpl (com.amazonaws.services.s3.transfer.internal.CopyImpl)1 TransferMonitor (com.amazonaws.services.s3.transfer.internal.TransferMonitor)1 Future (java.util.concurrent.Future)1 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)1 Slave (org.jenkinsci.test.acceptance.po.Slave)1