Search in sources :

Example 1 with EndpointConfigRequest

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());
}
Also used : EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)

Example 2 with EndpointConfigRequest

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));
}
Also used : EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)

Example 3 with EndpointConfigRequest

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);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)

Example 4 with EndpointConfigRequest

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);
    }));
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) CertificateInfoServiceErrorResponse(com.vmware.photon.controller.model.support.CertificateInfoServiceErrorResponse) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) ServiceDocument(com.vmware.xenon.common.ServiceDocument) Utils(com.vmware.xenon.common.Utils) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) Map(java.util.Map) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) ResourcePoolService(com.vmware.photon.controller.model.resources.ResourcePoolService) URI(java.net.URI) SINGLE_ASSIGNMENT(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SINGLE_ASSIGNMENT) EnumSet(java.util.EnumSet) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ENDPOINT_LINK_PROP_NAME(com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PhotonModelAdaptersConfigAccessService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersConfigAccessService) OPTIONAL(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.OPTIONAL) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) TaskUtils.sendFailurePatch(com.vmware.photon.controller.model.tasks.TaskUtils.sendFailurePatch) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) TaskState(com.vmware.xenon.common.TaskState) TaskService(com.vmware.xenon.services.common.TaskService) AdapterTypePath(com.vmware.photon.controller.model.UriPaths.AdapterTypePath) STORE_ONLY(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption.STORE_ONLY) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) UriPaths(com.vmware.photon.controller.model.UriPaths) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) OperationSequence(com.vmware.xenon.common.OperationSequence) SERVICE_USE(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption.SERVICE_USE) ResourceEnumerationTaskState(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService.ResourceEnumerationTaskState) Operation(com.vmware.xenon.common.Operation) CertificateInfo(com.vmware.photon.controller.model.support.CertificateInfo) ScheduledTaskState(com.vmware.photon.controller.model.tasks.ScheduledTaskService.ScheduledTaskState) TaskStage(com.vmware.xenon.common.TaskState.TaskStage) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PropertyIndexingOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyIndexingOption) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)

Example 5 with EndpointConfigRequest

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);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) HashMap(java.util.HashMap) ServiceEndpointLocator(com.vmware.photon.controller.model.util.ServiceEndpointLocator) Level(java.util.logging.Level) Utils(com.vmware.xenon.common.Utils) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) INVENTORY_SERVICE(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster.INVENTORY_SERVICE) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE_CODE) Collectors(java.util.stream.Collectors) ServiceHost(com.vmware.xenon.common.ServiceHost) PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_ENDPOINT_NOT_UNIQUE_MESSAGE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) Consumer(java.util.function.Consumer) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) Stream(java.util.stream.Stream) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils.buildUri(com.vmware.xenon.common.UriUtils.buildUri) Optional(java.util.Optional) PhotonModelAdaptersRegistryService(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Operation(com.vmware.xenon.common.Operation) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Stream(java.util.stream.Stream) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)9 RequestType (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType)5 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)5 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)5 DeferredResult (com.vmware.xenon.common.DeferredResult)5 LocalizableValidationException (com.vmware.xenon.common.LocalizableValidationException)5 Operation (com.vmware.xenon.common.Operation)5 Utils (com.vmware.xenon.common.Utils)5 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)5 URI (java.net.URI)5 HashMap (java.util.HashMap)5 List (java.util.List)5 EndpointService (com.vmware.photon.controller.model.resources.EndpointService)4 ENDPOINT_LINK_PROP_NAME (com.vmware.photon.controller.model.ComputeProperties.ENDPOINT_LINK_PROP_NAME)3 UriPaths (com.vmware.photon.controller.model.UriPaths)3 AdapterTypePath (com.vmware.photon.controller.model.UriPaths.AdapterTypePath)3 PhotonModelAdapterConfig (com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig)3 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)3 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)3 PhotonModelUriUtils.createInventoryUri (com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri)3