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;
});
}
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);
}
}
});
}
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;
}
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);
}
}));
})));
}
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;
}
Aggregations