Search in sources :

Example 1 with SecurityGroupInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest in project photon-model by vmware.

the class AWSLoadBalancerService method provisionSecurityGroup.

private DeferredResult<AWSLoadBalancerContext> provisionSecurityGroup(AWSLoadBalancerContext context) {
    SecurityGroupInstanceRequest req = buildSecurityGroupInstanceRequest(context.provisionedSecurityGroupState, InstanceRequestType.CREATE, context);
    Operation operation = Operation.createPatch(this, AWSSecurityGroupService.SELF_LINK).setBody(req);
    return sendWithDeferredResult(operation, SecurityGroupState.class).thenApply(sgs -> {
        context.provisionedSecurityGroupState = sgs;
        return context;
    });
}
Also used : SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Operation(com.vmware.xenon.common.Operation)

Example 2 with SecurityGroupInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest in project photon-model by vmware.

the class AWSSecurityGroupService method handlePatch.

@Override
public void handlePatch(Operation op) {
    if (!op.hasBody()) {
        op.fail(new IllegalArgumentException("body is required"));
        return;
    }
    SecurityGroupInstanceRequest request = op.getBody(SecurityGroupInstanceRequest.class);
    // initialize request context
    AWSSecurityGroupContext context = new AWSSecurityGroupContext(this, op, request);
    if (context.isAsync()) {
        // Immediately complete the Operation from calling task.
        op.complete();
    }
    DeferredResult.completed(context).thenCompose(this::populateContext).thenCompose(this::handleSecurityGroupInstanceRequest).whenComplete((o, e) -> {
        // Once done patch the calling task with correct stage.
        if (e == null) {
            if (context.isAsync()) {
                context.taskManager.finishTask();
            } else {
                context.operation.setBody(context.securityGroup);
                context.operation.complete();
            }
        } else {
            if (context.isAsync()) {
                context.taskManager.patchTaskToFailure(e);
            } else {
                context.operation.fail(e);
            }
        }
    });
}
Also used : SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest)

Example 3 with SecurityGroupInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest in project photon-model by vmware.

the class AWSLoadBalancerService method buildSecurityGroupInstanceRequest.

private SecurityGroupInstanceRequest buildSecurityGroupInstanceRequest(SecurityGroupState securityGroupState, InstanceRequestType type, AWSLoadBalancerContext context) {
    SecurityGroupInstanceRequest req = new SecurityGroupInstanceRequest();
    req.requestType = type;
    req.resourceReference = UriUtils.extendUri(ClusterUtil.getClusterUri(getHost(), ServiceTypeCluster.INVENTORY_SERVICE), securityGroupState.documentSelfLink);
    req.authCredentialsLink = securityGroupState.authCredentialsLink;
    req.resourcePoolLink = securityGroupState.resourcePoolLink;
    req.isMockRequest = context.request.isMockRequest;
    req.customProperties = new HashMap<>();
    req.customProperties.put(NETWORK_STATE_ID_PROP_NAME, context.vpcId);
    return req;
}
Also used : SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest)

Example 4 with SecurityGroupInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest in project photon-model by vmware.

the class ProvisionSecurityGroupTaskService method patchAdapter.

private void patchAdapter(ProvisionSecurityGroupTaskState taskState, String subTaskLink) {
    if (subTaskLink == null) {
        createSubTask(taskState, link -> patchAdapter(taskState, link));
        return;
    }
    taskState.securityGroupDescriptionLinks.forEach(sgLink -> sendRequest(Operation.createGet(UriUtils.buildUri(this.getHost(), sgLink)).setCompletion((o, e) -> {
        if (e != null) {
            // don't fail the task; just update the subtask, which will
            // handle the failure if necessary
            ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(sgLink, e);
            updateSubTask(subTaskLink, subTaskPatchBody);
            return;
        }
        SecurityGroupState securityGroupState = o.getBody(SecurityGroupState.class);
        SecurityGroupInstanceRequest req = toReq(securityGroupState, taskState, sgLink, subTaskLink);
        sendRequest(Operation.createPatch(securityGroupState.instanceAdapterReference).setBody(req).setCompletion((oo, ee) -> {
            if (ee != null) {
                ResourceOperationResponse subTaskPatchBody = ResourceOperationResponse.fail(sgLink, ee);
                updateSubTask(subTaskLink, subTaskPatchBody);
            }
        }));
    })));
}
Also used : SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest) Operation(com.vmware.xenon.common.Operation) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) Set(java.util.Set) ProvisionSecurityGroupTaskState(com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Consumer(java.util.function.Consumer) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) Utils(com.vmware.xenon.common.Utils) UriPaths(com.vmware.photon.controller.model.UriPaths) Map(java.util.Map) UriUtils(com.vmware.xenon.common.UriUtils) TaskState(com.vmware.xenon.common.TaskState) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) EXPAND(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.EXPAND) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest.InstanceRequestType) TaskService(com.vmware.xenon.services.common.TaskService) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) FIXED_ITEM_NAME(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.FIXED_ITEM_NAME) ResourceOperationResponse(com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse) SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)

Example 5 with SecurityGroupInstanceRequest

use of com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest in project photon-model by vmware.

the class ProvisionSecurityGroupTaskService method toReq.

private SecurityGroupInstanceRequest toReq(SecurityGroupState securityGroupState, ProvisionSecurityGroupTaskState taskState, String securityGroupDescriptionLink, String subTaskLink) {
    SecurityGroupInstanceRequest req = new SecurityGroupInstanceRequest();
    req.requestType = taskState.requestType;
    req.resourceReference = createInventoryUri(this.getHost(), securityGroupDescriptionLink);
    req.authCredentialsLink = securityGroupState.authCredentialsLink;
    req.resourcePoolLink = securityGroupState.resourcePoolLink;
    req.taskReference = UriUtils.buildUri(getHost(), subTaskLink);
    req.isMockRequest = taskState.isMockRequest;
    req.customProperties = taskState.customProperties;
    return req;
}
Also used : SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest)

Aggregations

SecurityGroupInstanceRequest (com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest)5 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)2 Operation (com.vmware.xenon.common.Operation)2 UriPaths (com.vmware.photon.controller.model.UriPaths)1 ResourceOperationResponse (com.vmware.photon.controller.model.adapterapi.ResourceOperationResponse)1 InstanceRequestType (com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest.InstanceRequestType)1 ProvisionSecurityGroupTaskState (com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.ProvisionSecurityGroupTaskState)1 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)1 EXPAND (com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.EXPAND)1 FIXED_ITEM_NAME (com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.FIXED_ITEM_NAME)1 PropertyUsageOption (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption)1 OPTIONAL (com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL)1 TaskState (com.vmware.xenon.common.TaskState)1 UriUtils (com.vmware.xenon.common.UriUtils)1 Utils (com.vmware.xenon.common.Utils)1 TaskService (com.vmware.xenon.services.common.TaskService)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1