use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class AzureEaEndpointAdapterService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
EndpointConfigRequest body = op.getBody(EndpointConfigRequest.class);
if (body.requestType == RequestType.CHECK_IF_ACCOUNT_EXISTS) {
checkIfAccountExistsAndGetExistingDocuments(body, op);
return;
}
EndpointAdapterUtils.handleEndpointRequest(this, op, body, credentials(), computeDesc(), compute(), endpoint(), validate());
}
use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class AzureEndpointAdapterService method handlePatch.
@Override
public void handlePatch(Operation op) {
if (!op.hasBody()) {
op.fail(new IllegalArgumentException("body is required"));
return;
}
EndpointConfigRequest body = op.getBody(EndpointConfigRequest.class);
if (body.requestType == RequestType.CHECK_IF_ACCOUNT_EXISTS) {
checkIfAccountExistsAndGetExistingDocuments(body, op);
return;
}
EndpointAdapterUtils.handleEndpointRequest(this, op, body, credentials(), computeDesc(), compute(), endpoint(), validate(body));
}
use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class EndpointAllocationTaskService method invokeAdapter.
private void invokeAdapter(EndpointAllocationTaskState currentState, SubStage next) {
CompletionHandler c = (o, e) -> {
if (e != null) {
sendFailurePatch(this, currentState, e);
return;
}
EndpointConfigRequest req = new EndpointConfigRequest();
req.isMockRequest = currentState.options.contains(TaskOption.IS_MOCK);
req.requestType = RequestType.ENHANCE;
req.tenantLinks = currentState.tenantLinks;
req.resourceReference = createInventoryUri(this.getHost(), currentState.endpointState.documentSelfLink);
ServiceDocument subTask = o.getBody(ServiceDocument.class);
req.taskReference = UriUtils.buildUri(this.getHost(), subTask.documentSelfLink);
req.endpointProperties = currentState.endpointState.endpointProperties;
sendEnhanceRequest(req, currentState);
};
createSubTask(c, next, currentState);
}
use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class EndpointAllocationTaskService method invokeAdapterForUniquenessCheck.
/**
* RequestType = CHECK_IF_ACCOUNT_EXISTS
* Invokes the cloud provider specific adapter with the passed in credentials to verify
* if the cloud provider account has already been configured aprior. If it a compute host
* has already been created corresponding to the given cloud account then it is updated
* to reflect the endpointLink for the currently being configured endpoint.
*/
private void invokeAdapterForUniquenessCheck(EndpointAllocationTaskState currentState, SubStage nextStage) {
EndpointConfigRequest req = new EndpointConfigRequest();
req.isMockRequest = currentState.options.contains(TaskOption.IS_MOCK);
req.requestType = RequestType.CHECK_IF_ACCOUNT_EXISTS;
req.tenantLinks = currentState.tenantLinks;
req.resourceReference = UriUtils.buildUri(getHost(), currentState.endpointState.documentSelfLink);
req.taskReference = UriUtils.buildUri(this.getHost(), getSelfLink());
req.endpointProperties = currentState.endpointState.endpointProperties;
sendRequest(Operation.createPatch(currentState.adapterReference).setBody(req).setCompletion((o, e) -> {
if (e != null) {
logWarning("PATCH to endpoint config adapter service %s, failed: %s", o.getUri(), e.toString());
sendFailurePatch(this, currentState, e);
return;
}
EndpointConfigRequest returnedRequest = o.getBody(EndpointConfigRequest.class);
EndpointAllocationTaskState state = createUpdateSubStageTask(nextStage);
state.accountAlreadyExists = returnedRequest.accountAlreadyExists;
state.existingComputeState = returnedRequest.existingComputeState;
state.existingComputeDescription = returnedRequest.existingComputeDescription;
sendSelfPatch(state);
}));
}
use of com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest in project photon-model by vmware.
the class EndpointAdapterUtils method configureEndpoint.
private static void configureEndpoint(StatelessService service, EndpointConfigRequest body, BiConsumer<AuthCredentialsServiceState, Retriever> credEnhancer, BiConsumer<ComputeDescription, Retriever> descEnhancer, BiConsumer<ComputeState, Retriever> compEnhancer, BiConsumer<EndpointState, Retriever> endpointEnhancer) {
TaskManager tm = new TaskManager(service, body.taskReference, body.resourceLink());
Consumer<Throwable> onFailure = tm::patchTaskToFailure;
Consumer<Operation> onSuccess = (op) -> {
EndpointState endpoint = op.getBody(EndpointState.class);
op.complete();
AuthCredentialsServiceState authState = new AuthCredentialsServiceState();
Map<String, String> props = new HashMap<>(body.endpointProperties);
props.put(MOCK_REQUEST, String.valueOf(body.isMockRequest));
props.put(ENDPOINT_REFERENCE_URI, body.resourceReference.toString());
Retriever r = Retriever.of(props);
try {
credEnhancer.accept(authState, r);
ComputeDescription cd = new ComputeDescription();
descEnhancer.accept(cd, r);
ComputeState cs = new ComputeState();
cs.powerState = PowerState.ON;
compEnhancer.accept(cs, r);
EndpointState es = new EndpointState();
es.endpointProperties = new HashMap<>();
es.regionId = r.get(EndpointConfigRequest.REGION_KEY).orElse(null);
endpointEnhancer.accept(es, r);
Stream<Operation> operations = Stream.of(Pair.of(authState, endpoint.authCredentialsLink), Pair.of(cd, endpoint.computeDescriptionLink), Pair.of(cs, endpoint.computeLink), Pair.of(es, endpoint.documentSelfLink)).map((p) -> Operation.createPatch(createInventoryUri(service.getHost(), p.right)).setBody(p.left).setReferer(service.getUri()));
applyChanges(tm, service, endpoint, operations);
} catch (Exception e) {
tm.patchTaskToFailure(e);
}
};
AdapterUtils.getServiceState(service, body.resourceReference, onSuccess, onFailure);
}
Aggregations