Search in sources :

Example 1 with ClusterOperationResponse

use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse in project fru-paqx-parent by dellemc-symphony.

the class vCenterServiceImpl method requestHostRemoval.

@Override
public CompletableFuture<ClusterOperationResponse> requestHostRemoval(final EndpointCredentials vcenterCredentials, final String clusterId, final String hostname) {
    final String requiredCapability = "vcenter-remove-host";
    try {
        final ListCapabilityProvidersResponse listCapabilityProvidersResponse = capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(5));
        for (final CapabilityProvider capabilityProvider : listCapabilityProvidersResponse.getResponse()) {
            for (final Capability capability : capabilityProvider.getCapabilities()) {
                LOG.debug("Found capability {}", capability.getProfile());
                if (requiredCapability.equals(capability.getProfile())) {
                    LOG.debug("Found matching capability {}", capability.getProfile());
                    final List<EndpointProperty> endpointProperties = capability.getProviderEndpoint().getEndpointProperties();
                    final Map<String, String> amqpProperties = endpointProperties.stream().collect(Collectors.toMap(EndpointProperty::getName, EndpointProperty::getValue));
                    final String requestExchange = amqpProperties.get("request-exchange");
                    final String requestRoutingKey = amqpProperties.get("request-routing-key");
                    final TopicExchange responseExchange = new TopicExchange(amqpProperties.get("response-exchange"));
                    final String responseRoutingKey = amqpProperties.get("response-routing-key").replace("{replyTo}", "." + replyTo);
                    amqpAdmin.declareBinding(BindingBuilder.bind(responseQueue).to(responseExchange).with(responseRoutingKey));
                    LOG.debug("Adding binding {} {}", responseExchange.getName(), responseRoutingKey);
                    final UUID correlationId = UUID.randomUUID();
                    final ClusterOperationRequestMessage requestMessage = new ClusterOperationRequestMessage();
                    requestMessage.setCredentials(new Credentials(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername()));
                    final ClusterOperationRequest clusterOperationRequest = new ClusterOperationRequest();
                    clusterOperationRequest.setHostName(hostname);
                    //TODO: If not required remove the cluster id
                    clusterOperationRequest.setClusterID(clusterId);
                    clusterOperationRequest.setClusterOperation(ClusterOperationRequest.ClusterOperation.REMOVE_HOST);
                    requestMessage.setClusterOperationRequest(clusterOperationRequest);
                    try {
                        new URL(vcenterCredentials.getEndpointUrl());
                    } catch (MalformedURLException e) {
                        final CompletableFuture<ClusterOperationResponse> promise = new CompletableFuture<>();
                        promise.completeExceptionally(e);
                        return promise;
                    }
                    final CompletableFuture<ClusterOperationResponse> promise = vcenterClusterOperationAsyncAcknowledgement.register(correlationId.toString());
                    LOG.info("Host removal request with correlation id [{}]", correlationId.toString());
                    rabbitTemplate.convertAndSend(requestExchange, requestRoutingKey, requestMessage);
                    return promise;
                }
            }
        }
    } catch (CapabilityRegistryException e) {
        LOG.error("Failed while looking up Capability Registry for {}", requiredCapability, e);
    } catch (ServiceTimeoutException e) {
        LOG.error("Service timed out while querying Capability Registry");
    }
    LOG.error("Unable to find required capability: {}", requiredCapability);
    return CompletableFuture.completedFuture(null);
}
Also used : MalformedURLException(java.net.MalformedURLException) Capability(com.dell.cpsd.hdp.capability.registry.api.Capability) CapabilityProvider(com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider) ClusterOperationRequest(com.dell.cpsd.virtualization.capabilities.api.ClusterOperationRequest) ListCapabilityProvidersResponse(com.dell.cpsd.hdp.capability.registry.client.callback.ListCapabilityProvidersResponse) ClusterOperationResponse(com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse) ServiceTimeoutException(com.dell.cpsd.service.common.client.exception.ServiceTimeoutException) URL(java.net.URL) TopicExchange(org.springframework.amqp.core.TopicExchange) EndpointProperty(com.dell.cpsd.hdp.capability.registry.api.EndpointProperty) ClusterOperationRequestMessage(com.dell.cpsd.virtualization.capabilities.api.ClusterOperationRequestMessage) CompletableFuture(java.util.concurrent.CompletableFuture) CapabilityRegistryException(com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException) UUID(java.util.UUID) EndpointCredentials(com.dell.cpsd.paqx.fru.rest.dto.EndpointCredentials) Credentials(com.dell.cpsd.virtualization.capabilities.api.Credentials)

Example 2 with ClusterOperationResponse

use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse in project fru-paqx-parent by dellemc-symphony.

the class WorkflowResource method removeHostFromVCenter.

@POST
@Path("{jobId}/remove-host-from-vcenter")
public void removeHostFromVCenter(@Suspended final AsyncResponse asyncResponse, @PathParam("jobId") String jobId, @Context UriInfo uriInfo) {
    asyncResponse.setTimeoutHandler(asyncResponse1 -> asyncResponse1.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("{\"status\":\"timeout\"}").build()));
    asyncResponse.setTimeout(10, TimeUnit.SECONDS);
    //
    final String thisStep = findStepFromPath(uriInfo);
    final Job job = workflowService.findJob(UUID.fromString(jobId));
    final JobRepresentation jobRepresentation = new JobRepresentation(job);
    //TODO find out where to get the hostname from
    final String hostname = "";
    //TODO find out where to get the cluster id from
    final String clusterId = "";
    final CompletableFuture<ClusterOperationResponse> clusterOperationResponseCompletableFuture = vcenterService.requestHostRemoval(job.getVcenterCredentials(), hostname, clusterId);
    clusterOperationResponseCompletableFuture.thenAccept(clusterOperationResponse -> {
        LOG.info("Host Removal from VCenter Cluster Response: [{}]", clusterOperationResponse);
        if (ClusterOperationResponseMessage.Status.SUCCESS.value().equals(clusterOperationResponse.getStatus())) {
            final NextStep nextStep = workflowService.findNextStep(job.getWorkflow(), thisStep);
            if (nextStep != null) {
                workflowService.advanceToNextStep(job, thisStep);
                jobRepresentation.addLink(createNextStepLink(uriInfo, job, nextStep.getNextStep()), findMethodFromStep(nextStep.getNextStep()));
            }
            asyncResponse.resume(Response.ok(jobRepresentation).build());
        } else {
            jobRepresentation.addLink(createRetryStepLink(uriInfo, job, thisStep));
            jobRepresentation.setLastResponse(clusterOperationResponse.getStatus());
            asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build());
        }
        LOG.info("Completing response");
        asyncResponse.resume(Response.ok(jobRepresentation).build());
        LOG.debug("Completed response");
    });
}
Also used : JobRepresentation(com.dell.cpsd.paqx.fru.rest.representation.JobRepresentation) Job(com.dell.cpsd.paqx.fru.rest.domain.Job) ClusterOperationResponse(com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse) NextStep(com.dell.cpsd.paqx.fru.valueobject.NextStep)

Example 3 with ClusterOperationResponse

use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse in project fru-paqx-parent by dellemc-symphony.

the class VCenterClusterOperationsResponseHandler method executeOperation.

@Override
protected void executeOperation(final ClusterOperationResponseMessage clusterOperationResponseMessage) throws Exception {
    LOG.info("Received message {}", clusterOperationResponseMessage);
    final String correlationId = clusterOperationResponseMessage.getMessageProperties().getCorrelationId();
    final ClusterOperationResponse clusterOperationResponse = new ClusterOperationResponse(clusterOperationResponseMessage.getStatus().value());
    final CompletableFuture<ClusterOperationResponse> completableFuture = asyncRequests.get(correlationId);
    LOG.info("Completing expectation for  {} {}", correlationId, completableFuture);
    if (completableFuture != null) {
        final boolean complete = completableFuture.complete(clusterOperationResponse);
        LOG.info("Completed expectation for  {} {} {}", correlationId, completableFuture, complete);
        asyncRequests.remove(correlationId);
    }
}
Also used : ClusterOperationResponse(com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse)

Example 4 with ClusterOperationResponse

use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse in project fru-paqx-parent by dellemc-symphony.

the class vCenterServiceImpl method requestHostAddition.

@Override
public CompletableFuture<ClusterOperationResponse> requestHostAddition(final EndpointCredentials vcenterCredentials, final String hostname, final String clusterId, final String hostUsername, final String hostPassword) {
    final String requiredCapability = "vcenter-addhostvcenter";
    try {
        final ListCapabilityProvidersResponse listCapabilityProvidersResponse = capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(5));
        for (final CapabilityProvider capabilityProvider : listCapabilityProvidersResponse.getResponse()) {
            for (final Capability capability : capabilityProvider.getCapabilities()) {
                LOG.debug("Found capability {}", capability.getProfile());
                if (requiredCapability.equals(capability.getProfile())) {
                    LOG.debug("Found matching capability {}", capability.getProfile());
                    final List<EndpointProperty> endpointProperties = capability.getProviderEndpoint().getEndpointProperties();
                    final Map<String, String> amqpProperties = endpointProperties.stream().collect(Collectors.toMap(EndpointProperty::getName, EndpointProperty::getValue));
                    final String requestExchange = amqpProperties.get("request-exchange");
                    final String requestRoutingKey = amqpProperties.get("request-routing-key");
                    final TopicExchange responseExchange = new TopicExchange(amqpProperties.get("response-exchange"));
                    final String responseRoutingKey = amqpProperties.get("response-routing-key").replace("{replyTo}", "." + replyTo);
                    amqpAdmin.declareBinding(BindingBuilder.bind(responseQueue).to(responseExchange).with(responseRoutingKey));
                    LOG.debug("Adding binding {} {}", responseExchange.getName(), responseRoutingKey);
                    final UUID correlationId = UUID.randomUUID();
                    final ClusterOperationRequestMessage requestMessage = new ClusterOperationRequestMessage();
                    requestMessage.setCredentials(new Credentials(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername()));
                    final ClusterOperationRequest clusterOperationRequest = new ClusterOperationRequest();
                    clusterOperationRequest.setHostName(hostname);
                    clusterOperationRequest.setClusterID(clusterId);
                    clusterOperationRequest.setUserName(hostUsername);
                    clusterOperationRequest.setPassword(hostPassword);
                    clusterOperationRequest.setClusterOperation(ClusterOperationRequest.ClusterOperation.ADD_HOST);
                    requestMessage.setClusterOperationRequest(clusterOperationRequest);
                    try {
                        new URL(vcenterCredentials.getEndpointUrl());
                    } catch (MalformedURLException e) {
                        final CompletableFuture<ClusterOperationResponse> promise = new CompletableFuture<>();
                        promise.completeExceptionally(e);
                        return promise;
                    }
                    final CompletableFuture<ClusterOperationResponse> promise = vcenterClusterOperationAsyncAcknowledgement.register(correlationId.toString());
                    LOG.info("Host addition request with correlation id [{}]", correlationId.toString());
                    rabbitTemplate.convertAndSend(requestExchange, requestRoutingKey, requestMessage);
                    return promise;
                }
            }
        }
    } catch (CapabilityRegistryException e) {
        LOG.error("Failed while looking up Capability Registry for {}", requiredCapability, e);
    } catch (ServiceTimeoutException e) {
        LOG.error("Service timed out while querying Capability Registry");
    }
    LOG.error("Unable to find required capability: {}", requiredCapability);
    return CompletableFuture.completedFuture(null);
}
Also used : MalformedURLException(java.net.MalformedURLException) Capability(com.dell.cpsd.hdp.capability.registry.api.Capability) CapabilityProvider(com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider) ClusterOperationRequest(com.dell.cpsd.virtualization.capabilities.api.ClusterOperationRequest) ListCapabilityProvidersResponse(com.dell.cpsd.hdp.capability.registry.client.callback.ListCapabilityProvidersResponse) ClusterOperationResponse(com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse) ServiceTimeoutException(com.dell.cpsd.service.common.client.exception.ServiceTimeoutException) URL(java.net.URL) TopicExchange(org.springframework.amqp.core.TopicExchange) EndpointProperty(com.dell.cpsd.hdp.capability.registry.api.EndpointProperty) ClusterOperationRequestMessage(com.dell.cpsd.virtualization.capabilities.api.ClusterOperationRequestMessage) CompletableFuture(java.util.concurrent.CompletableFuture) CapabilityRegistryException(com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException) UUID(java.util.UUID) EndpointCredentials(com.dell.cpsd.paqx.fru.rest.dto.EndpointCredentials) Credentials(com.dell.cpsd.virtualization.capabilities.api.Credentials)

Example 5 with ClusterOperationResponse

use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse in project fru-paqx-parent by dellemc-symphony.

the class WorkflowResource method addHostTovCenter.

@POST
@Path("{jobId}/add-host-to-vcenter")
public void addHostTovCenter(@Suspended final AsyncResponse asyncResponse, @PathParam("jobId") String jobId, @Context UriInfo uriInfo) {
    asyncResponse.setTimeoutHandler(asyncResponse1 -> asyncResponse1.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("{\"status\":\"timeout\"}").build()));
    asyncResponse.setTimeout(10, TimeUnit.SECONDS);
    final String thisStep = findStepFromPath(uriInfo);
    final Job job = workflowService.findJob(UUID.fromString(jobId));
    final JobRepresentation jobRepresentation = new JobRepresentation(job);
    //TODO find out where to get the hostname from
    final String hostname = "";
    //TODO find out where to get the cluster id from
    final String clusterId = "";
    final String hostUsername = "";
    final String hostPassword = "";
    final CompletableFuture<ClusterOperationResponse> clusterOperationResponseCompletableFuture = vcenterService.requestHostAddition(job.getVcenterCredentials(), hostname, clusterId, hostUsername, hostPassword);
    clusterOperationResponseCompletableFuture.thenAccept(clusterOperationResponse -> {
        LOG.info("Host Addition to the VCenter Cluster Response: [{}]", clusterOperationResponse);
        if (ClusterOperationResponseMessage.Status.SUCCESS.value().equals(clusterOperationResponse.getStatus())) {
            final NextStep nextStep = workflowService.findNextStep(job.getWorkflow(), thisStep);
            if (nextStep != null) {
                workflowService.advanceToNextStep(job, thisStep);
                jobRepresentation.addLink(createNextStepLink(uriInfo, job, nextStep.getNextStep()), findMethodFromStep(nextStep.getNextStep()));
            }
            asyncResponse.resume(Response.ok(jobRepresentation).build());
        } else {
            jobRepresentation.addLink(createRetryStepLink(uriInfo, job, thisStep));
            jobRepresentation.setLastResponse(clusterOperationResponse.getStatus());
            asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build());
        }
        LOG.info("Completing response");
        asyncResponse.resume(Response.ok(jobRepresentation).build());
        LOG.debug("Completed response");
    });
}
Also used : JobRepresentation(com.dell.cpsd.paqx.fru.rest.representation.JobRepresentation) Job(com.dell.cpsd.paqx.fru.rest.domain.Job) ClusterOperationResponse(com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse) NextStep(com.dell.cpsd.paqx.fru.valueobject.NextStep)

Aggregations

ClusterOperationResponse (com.dell.cpsd.paqx.fru.rest.dto.vcenter.ClusterOperationResponse)5 Capability (com.dell.cpsd.hdp.capability.registry.api.Capability)2 CapabilityProvider (com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider)2 EndpointProperty (com.dell.cpsd.hdp.capability.registry.api.EndpointProperty)2 CapabilityRegistryException (com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException)2 ListCapabilityProvidersResponse (com.dell.cpsd.hdp.capability.registry.client.callback.ListCapabilityProvidersResponse)2 Job (com.dell.cpsd.paqx.fru.rest.domain.Job)2 EndpointCredentials (com.dell.cpsd.paqx.fru.rest.dto.EndpointCredentials)2 JobRepresentation (com.dell.cpsd.paqx.fru.rest.representation.JobRepresentation)2 NextStep (com.dell.cpsd.paqx.fru.valueobject.NextStep)2 ServiceTimeoutException (com.dell.cpsd.service.common.client.exception.ServiceTimeoutException)2 ClusterOperationRequest (com.dell.cpsd.virtualization.capabilities.api.ClusterOperationRequest)2 ClusterOperationRequestMessage (com.dell.cpsd.virtualization.capabilities.api.ClusterOperationRequestMessage)2 Credentials (com.dell.cpsd.virtualization.capabilities.api.Credentials)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 TopicExchange (org.springframework.amqp.core.TopicExchange)2