Search in sources :

Example 11 with TaskManager

use of com.vmware.photon.controller.model.adapters.util.TaskManager in project photon-model by vmware.

the class AWSNetworkClient method deleteNATGateway.

/**
 * Delete a NAT Gateway
 * It waits for the NAT gateway to get into the Deleted state before returning.
 */
public DeferredResult<Void> deleteNATGateway(String natGatewayId, TaskManager taskManager, long taskExpirationMicros) {
    DeleteNatGatewayRequest req = new DeleteNatGatewayRequest().withNatGatewayId(natGatewayId);
    String message = "Delete AWS NAT Gateway with id [" + natGatewayId + "].";
    AWSDeferredResultAsyncHandler<DeleteNatGatewayRequest, DeleteNatGatewayResult> handler = new AWSDeferredResultAsyncHandler<>(this.service, message);
    this.client.deleteNatGatewayAsync(req, handler);
    return handler.toDeferredResult().thenCompose(ignore -> waitForNatGatewayState(natGatewayId, taskManager, taskExpirationMicros, AWSTaskStatusChecker.AWS_DELETED_NAME)).thenApply(ignore -> null);
}
Also used : AWSTaskStatusChecker(com.vmware.photon.controller.model.adapters.awsadapter.AWSTaskStatusChecker) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) ReleaseAddressRequest(com.amazonaws.services.ec2.model.ReleaseAddressRequest) AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AttachInternetGatewayRequest(com.amazonaws.services.ec2.model.AttachInternetGatewayRequest) AssociateRouteTableRequest(com.amazonaws.services.ec2.model.AssociateRouteTableRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) NatGateway(com.amazonaws.services.ec2.model.NatGateway) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) CreateNatGatewayResult(com.amazonaws.services.ec2.model.CreateNatGatewayResult) DeleteSubnetResult(com.amazonaws.services.ec2.model.DeleteSubnetResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) AWS_MAIN_ROUTE_ASSOCIATION(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_MAIN_ROUTE_ASSOCIATION) StatelessService(com.vmware.xenon.common.StatelessService) CreateRouteResult(com.amazonaws.services.ec2.model.CreateRouteResult) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) List(java.util.List) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) CreateNatGatewayRequest(com.amazonaws.services.ec2.model.CreateNatGatewayRequest) AssociateRouteTableResult(com.amazonaws.services.ec2.model.AssociateRouteTableResult) DeleteRouteTableRequest(com.amazonaws.services.ec2.model.DeleteRouteTableRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) DescribeRouteTablesResult(com.amazonaws.services.ec2.model.DescribeRouteTablesResult) ROUTE_DEST_ALL(com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.ROUTE_DEST_ALL) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) DomainType(com.amazonaws.services.ec2.model.DomainType) DeleteNatGatewayResult(com.amazonaws.services.ec2.model.DeleteNatGatewayResult) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) CreateRouteTableResult(com.amazonaws.services.ec2.model.CreateRouteTableResult) ArrayList(java.util.ArrayList) CreateVpcResult(com.amazonaws.services.ec2.model.CreateVpcResult) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) Filter(com.amazonaws.services.ec2.model.Filter) RouteTable(com.amazonaws.services.ec2.model.RouteTable) Subnet(com.amazonaws.services.ec2.model.Subnet) CreateVpcRequest(com.amazonaws.services.ec2.model.CreateVpcRequest) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) CreateTagsResult(com.amazonaws.services.ec2.model.CreateTagsResult) ReleaseAddressResult(com.amazonaws.services.ec2.model.ReleaseAddressResult) Vpc(com.amazonaws.services.ec2.model.Vpc) DeleteRouteTableResult(com.amazonaws.services.ec2.model.DeleteRouteTableResult) CreateInternetGatewayResult(com.amazonaws.services.ec2.model.CreateInternetGatewayResult) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) CreateRouteTableRequest(com.amazonaws.services.ec2.model.CreateRouteTableRequest) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) CreateRouteRequest(com.amazonaws.services.ec2.model.CreateRouteRequest) DeleteNatGatewayResult(com.amazonaws.services.ec2.model.DeleteNatGatewayResult) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest)

Example 12 with TaskManager

use of com.vmware.photon.controller.model.adapters.util.TaskManager in project photon-model by vmware.

the class AWSNetworkClient method waitForNatGatewayState.

/**
 * Wait for NAT Gateway to go into the desired state
 */
private DeferredResult<String> waitForNatGatewayState(String natGatewayId, TaskManager taskManager, long taskExpirationMicros, String desiredState) {
    DeferredResult<String> waitCompleted = new DeferredResult<>();
    AWSTaskStatusChecker.create(this.client, natGatewayId, desiredState, (ignore) -> waitCompleted.complete(natGatewayId), taskManager, this.service, taskExpirationMicros).start(new NatGateway());
    return waitCompleted;
}
Also used : AWSTaskStatusChecker(com.vmware.photon.controller.model.adapters.awsadapter.AWSTaskStatusChecker) DescribeSubnetsRequest(com.amazonaws.services.ec2.model.DescribeSubnetsRequest) DescribeVpcsRequest(com.amazonaws.services.ec2.model.DescribeVpcsRequest) ReleaseAddressRequest(com.amazonaws.services.ec2.model.ReleaseAddressRequest) AllocateAddressRequest(com.amazonaws.services.ec2.model.AllocateAddressRequest) AttachInternetGatewayRequest(com.amazonaws.services.ec2.model.AttachInternetGatewayRequest) AssociateRouteTableRequest(com.amazonaws.services.ec2.model.AssociateRouteTableRequest) DescribeSubnetsResult(com.amazonaws.services.ec2.model.DescribeSubnetsResult) NatGateway(com.amazonaws.services.ec2.model.NatGateway) CreateTagsRequest(com.amazonaws.services.ec2.model.CreateTagsRequest) CreateNatGatewayResult(com.amazonaws.services.ec2.model.CreateNatGatewayResult) DeleteSubnetResult(com.amazonaws.services.ec2.model.DeleteSubnetResult) DeleteSubnetRequest(com.amazonaws.services.ec2.model.DeleteSubnetRequest) DeleteVpcRequest(com.amazonaws.services.ec2.model.DeleteVpcRequest) AWS_MAIN_ROUTE_ASSOCIATION(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_MAIN_ROUTE_ASSOCIATION) StatelessService(com.vmware.xenon.common.StatelessService) CreateRouteResult(com.amazonaws.services.ec2.model.CreateRouteResult) DescribeInternetGatewaysResult(com.amazonaws.services.ec2.model.DescribeInternetGatewaysResult) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) List(java.util.List) DescribeRouteTablesRequest(com.amazonaws.services.ec2.model.DescribeRouteTablesRequest) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) CreateNatGatewayRequest(com.amazonaws.services.ec2.model.CreateNatGatewayRequest) AssociateRouteTableResult(com.amazonaws.services.ec2.model.AssociateRouteTableResult) DeleteRouteTableRequest(com.amazonaws.services.ec2.model.DeleteRouteTableRequest) AllocateAddressResult(com.amazonaws.services.ec2.model.AllocateAddressResult) CreateSubnetRequest(com.amazonaws.services.ec2.model.CreateSubnetRequest) DescribeRouteTablesResult(com.amazonaws.services.ec2.model.DescribeRouteTablesResult) ROUTE_DEST_ALL(com.vmware.photon.controller.model.adapters.awsadapter.AWSNetworkService.ROUTE_DEST_ALL) DeleteInternetGatewayRequest(com.amazonaws.services.ec2.model.DeleteInternetGatewayRequest) DomainType(com.amazonaws.services.ec2.model.DomainType) DeleteNatGatewayResult(com.amazonaws.services.ec2.model.DeleteNatGatewayResult) CreateSubnetResult(com.amazonaws.services.ec2.model.CreateSubnetResult) CreateRouteTableResult(com.amazonaws.services.ec2.model.CreateRouteTableResult) ArrayList(java.util.ArrayList) CreateVpcResult(com.amazonaws.services.ec2.model.CreateVpcResult) DescribeVpcsResult(com.amazonaws.services.ec2.model.DescribeVpcsResult) Filter(com.amazonaws.services.ec2.model.Filter) RouteTable(com.amazonaws.services.ec2.model.RouteTable) Subnet(com.amazonaws.services.ec2.model.Subnet) CreateVpcRequest(com.amazonaws.services.ec2.model.CreateVpcRequest) AWS_TAG_NAME(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_TAG_NAME) CreateTagsResult(com.amazonaws.services.ec2.model.CreateTagsResult) ReleaseAddressResult(com.amazonaws.services.ec2.model.ReleaseAddressResult) Vpc(com.amazonaws.services.ec2.model.Vpc) DeleteRouteTableResult(com.amazonaws.services.ec2.model.DeleteRouteTableResult) CreateInternetGatewayResult(com.amazonaws.services.ec2.model.CreateInternetGatewayResult) DetachInternetGatewayRequest(com.amazonaws.services.ec2.model.DetachInternetGatewayRequest) DeleteNatGatewayRequest(com.amazonaws.services.ec2.model.DeleteNatGatewayRequest) AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) CreateRouteTableRequest(com.amazonaws.services.ec2.model.CreateRouteTableRequest) InternetGateway(com.amazonaws.services.ec2.model.InternetGateway) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) DescribeInternetGatewaysRequest(com.amazonaws.services.ec2.model.DescribeInternetGatewaysRequest) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) CreateRouteRequest(com.amazonaws.services.ec2.model.CreateRouteRequest) NatGateway(com.amazonaws.services.ec2.model.NatGateway) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 13 with TaskManager

use of com.vmware.photon.controller.model.adapters.util.TaskManager in project photon-model by vmware.

the class AWSCostStatsService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    op.complete();
    ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
    TaskManager taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
    if (statsRequest.isMockRequest) {
        // patch status to parent task
        taskManager.finishTask();
        return;
    }
    AWSCostStatsCreationContext statsData = new AWSCostStatsCreationContext(statsRequest);
    statsData.taskManager = taskManager;
    handleCostStatsCreationRequest(statsData);
}
Also used : ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager)

Example 14 with TaskManager

use of com.vmware.photon.controller.model.adapters.util.TaskManager in project photon-model by vmware.

the class AzureStatsService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    ComputeStatsRequest statsRequest = op.getBody(ComputeStatsRequest.class);
    op.complete();
    TaskManager taskManager = new TaskManager(this, statsRequest.taskReference, statsRequest.resourceLink());
    if (statsRequest.isMockRequest) {
        // patch status to parent task
        taskManager.finishTask();
        return;
    }
    AzureStatsDataHolder statsData = new AzureStatsDataHolder();
    statsData.statsRequest = statsRequest;
    statsData.taskManager = taskManager;
    getVMDescription(statsData);
}
Also used : ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager)

Example 15 with TaskManager

use of com.vmware.photon.controller.model.adapters.util.TaskManager in project photon-model by vmware.

the class VSphereAdapterInstanceService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    op.setStatusCode(Operation.STATUS_CODE_CREATED);
    op.complete();
    ComputeInstanceRequest request = op.getBody(ComputeInstanceRequest.class);
    TaskManager mgr = new TaskManager(this, request.taskReference, request.resourceLink());
    if (request.isMockRequest) {
        handleMockRequest(mgr);
        return;
    }
    ProvisionContext.populateContextThen(this, createInitialContext(request, op), ctx -> {
        switch(request.requestType) {
            case CREATE:
                handleCreateInstance(ctx);
                break;
            case DELETE:
                handleDeleteInstance(ctx);
                break;
            default:
                Throwable error = new IllegalStateException("Unsupported requestType " + request.requestType);
                ctx.fail(error);
        }
    });
}
Also used : TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) ComputeInstanceRequest(com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)

Aggregations

TaskManager (com.vmware.photon.controller.model.adapters.util.TaskManager)21 StatelessService (com.vmware.xenon.common.StatelessService)9 DeferredResult (com.vmware.xenon.common.DeferredResult)8 List (java.util.List)8 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)7 Operation (com.vmware.xenon.common.Operation)7 URI (java.net.URI)7 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)6 ArrayList (java.util.ArrayList)6 Connection (com.vmware.photon.controller.model.adapters.vsphere.util.connection.Connection)4 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)4 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)4 PhotonModelUriUtils (com.vmware.photon.controller.model.util.PhotonModelUriUtils)4 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)4 TaskStage (com.vmware.xenon.common.TaskState.TaskStage)4 QueryTask (com.vmware.xenon.services.common.QueryTask)4 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)3 DatacenterLister (com.vmware.photon.controller.model.adapters.vsphere.util.finders.DatacenterLister)3 Element (com.vmware.photon.controller.model.adapters.vsphere.util.finders.Element)3 RpcException (com.vmware.photon.controller.model.adapters.vsphere.vapi.RpcException)3