Search in sources :

Example 1 with VCenterHostPowerOperationStatus

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

the class VCenterHostPowerOperationResponseHandler method executeOperation.

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

Example 2 with VCenterHostPowerOperationStatus

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

the class vCenterServiceImpl method requestHostPowerOff.

@Override
public CompletableFuture<VCenterHostPowerOperationStatus> requestHostPowerOff(EndpointCredentials vcenterCredentials, String hostname) {
    final String requiredCapability = "vcenter-powercommand";
    try {
        final ListCapabilityProvidersResponse listCapabilityProvidersResponse = capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(5));
        if (listCapabilityProvidersResponse == null) {
            return CompletableFuture.completedFuture(null);
        }
        final List<CapabilityProvider> capabilityProviders = listCapabilityProvidersResponse.getResponse();
        for (CapabilityProvider capabilityProvider : capabilityProviders) {
            for (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();
                    HostPowerOperationRequestMessage requestMessage = new HostPowerOperationRequestMessage();
                    requestMessage.setMessageProperties(new MessageProperties().withCorrelationId(correlationId.toString()).withReplyTo(replyTo).withTimestamp(new Date()));
                    try {
                        new URL(vcenterCredentials.getEndpointUrl());
                    } catch (MalformedURLException e) {
                        final CompletableFuture<VCenterHostPowerOperationStatus> promise = new CompletableFuture<>();
                        promise.completeExceptionally(e);
                        return promise;
                    }
                    final Credentials credentials = new Credentials(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername());
                    requestMessage.setCredentials(credentials);
                    //TODO hostname is blank BUT SHOULD be filled with appropriate data
                    PowerOperationRequest powerOperationRequest = new PowerOperationRequest(hostname, PowerOperationRequest.PowerOperation.POWER_OFF);
                    requestMessage.setPowerOperationRequest(powerOperationRequest);
                    final CompletableFuture<VCenterHostPowerOperationStatus> promise = vCenterHostPowerAsyncAcknowledgement.register(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");
    }
    return 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) HostPowerOperationRequestMessage(com.dell.cpsd.virtualization.capabilities.api.HostPowerOperationRequestMessage) ListCapabilityProvidersResponse(com.dell.cpsd.hdp.capability.registry.client.callback.ListCapabilityProvidersResponse) ServiceTimeoutException(com.dell.cpsd.service.common.client.exception.ServiceTimeoutException) Date(java.util.Date) URL(java.net.URL) TopicExchange(org.springframework.amqp.core.TopicExchange) EndpointProperty(com.dell.cpsd.hdp.capability.registry.api.EndpointProperty) CompletableFuture(java.util.concurrent.CompletableFuture) PowerOperationRequest(com.dell.cpsd.virtualization.capabilities.api.PowerOperationRequest) VCenterHostPowerOperationStatus(com.dell.cpsd.paqx.fru.rest.dto.VCenterHostPowerOperationStatus) MessageProperties(com.dell.cpsd.virtualization.capabilities.api.MessageProperties) 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 3 with VCenterHostPowerOperationStatus

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

the class WorkflowResource method powerOffEsxiHostForRemoval.

@POST
@Path("{jobId}/power-off-esxi-host-for-removal")
public void powerOffEsxiHostForRemoval(@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 = "";
    final CompletableFuture<VCenterHostPowerOperationStatus> vCenterHostPowerOperationStatusCompletableFuture = vcenterService.requestHostPowerOff(job.getVcenterCredentials(), hostname);
    vCenterHostPowerOperationStatusCompletableFuture.thenAccept(hostPowerOperationStatus -> {
        LOG.info("Host Power Off Response: [{}]", hostPowerOperationStatus);
        if (HostPowerOperationResponseMessage.Status.SUCCESS.value().equals(hostPowerOperationStatus.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(hostPowerOperationStatus.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 : VCenterHostPowerOperationStatus(com.dell.cpsd.paqx.fru.rest.dto.VCenterHostPowerOperationStatus) JobRepresentation(com.dell.cpsd.paqx.fru.rest.representation.JobRepresentation) Job(com.dell.cpsd.paqx.fru.rest.domain.Job) NextStep(com.dell.cpsd.paqx.fru.valueobject.NextStep)

Aggregations

VCenterHostPowerOperationStatus (com.dell.cpsd.paqx.fru.rest.dto.VCenterHostPowerOperationStatus)3 Capability (com.dell.cpsd.hdp.capability.registry.api.Capability)1 CapabilityProvider (com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider)1 EndpointProperty (com.dell.cpsd.hdp.capability.registry.api.EndpointProperty)1 CapabilityRegistryException (com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException)1 ListCapabilityProvidersResponse (com.dell.cpsd.hdp.capability.registry.client.callback.ListCapabilityProvidersResponse)1 Job (com.dell.cpsd.paqx.fru.rest.domain.Job)1 EndpointCredentials (com.dell.cpsd.paqx.fru.rest.dto.EndpointCredentials)1 JobRepresentation (com.dell.cpsd.paqx.fru.rest.representation.JobRepresentation)1 NextStep (com.dell.cpsd.paqx.fru.valueobject.NextStep)1 ServiceTimeoutException (com.dell.cpsd.service.common.client.exception.ServiceTimeoutException)1 Credentials (com.dell.cpsd.virtualization.capabilities.api.Credentials)1 HostPowerOperationRequestMessage (com.dell.cpsd.virtualization.capabilities.api.HostPowerOperationRequestMessage)1 MessageProperties (com.dell.cpsd.virtualization.capabilities.api.MessageProperties)1 PowerOperationRequest (com.dell.cpsd.virtualization.capabilities.api.PowerOperationRequest)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Date (java.util.Date)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1