Search in sources :

Example 1 with ConsulRegistryResult

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

the class VCenterConsulRegisterResponseHandler method executeOperation.

@Override
protected void executeOperation(final ConsulRegisterResponseMessage responseMessage) throws Exception {
    LOG.info("Received message {}", responseMessage);
    final String correlationId = responseMessage.getMessageProperties().getCorrelationId();
    final ResponseInfo responseInfo = responseMessage.getResponseInfo();
    final boolean success = responseInfo.getMessage().startsWith("SUCCESS");
    final ConsulRegistryResult consulRegistryResult = new ConsulRegistryResult(success, responseInfo.getMessage());
    final CompletableFuture<ConsulRegistryResult> completableFuture = asyncRequests.get(correlationId);
    LOG.info("Completing expectation for  {} {}", correlationId, completableFuture);
    if (completableFuture != null) {
        final boolean complete = completableFuture.complete(consulRegistryResult);
        LOG.info("Completed expectation for  {} {} {}", correlationId, completableFuture, complete);
        asyncRequests.remove(correlationId);
    }
}
Also used : ResponseInfo(com.dell.cpsd.virtualization.capabilities.api.ResponseInfo) ConsulRegistryResult(com.dell.cpsd.paqx.fru.dto.ConsulRegistryResult)

Example 2 with ConsulRegistryResult

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

the class WorkflowResource method capturevCenter.

@POST
@Consumes("application/vnd.dellemc.vcenter.endpoint+json")
@Path("{jobId}/{step}")
public void capturevCenter(@Suspended final AsyncResponse asyncResponse, @PathParam("jobId") String jobId, @PathParam("step") String step, @Context UriInfo uriInfo, EndpointCredentials vCenterCredentials) {
    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);
    try {
        new URL(vCenterCredentials.getEndpointUrl());
    } catch (MalformedURLException e) {
        LOG.warn("Invalid URL found {}", vCenterCredentials.getEndpointUrl());
        jobRepresentation.addLink(createRetryStepLink(uriInfo, job, thisStep));
        jobRepresentation.setLastResponse(e.getLocalizedMessage());
        Response.status(Response.Status.BAD_REQUEST).entity(jobRepresentation).build();
        return;
    }
    final CompletableFuture<ConsulRegistryResult> consulRegistryResultCompletableFuture = vcenterService.requestConsulRegistration(vCenterCredentials);
    consulRegistryResultCompletableFuture.thenAccept(consulRegistryResult -> {
        if (consulRegistryResult.isSuccess()) {
            LOG.info("Consul registration successfully completed");
            job.addVcenterCredentials(vCenterCredentials);
            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 {
            LOG.info("Consul registration failed {}", consulRegistryResult.getDescription());
            jobRepresentation.addLink(createRetryStepLink(uriInfo, job, thisStep));
            jobRepresentation.setLastResponse(consulRegistryResult.getDescription());
            asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).entity(jobRepresentation).build());
        }
    });
}
Also used : ConsulRegistryResult(com.dell.cpsd.paqx.fru.dto.ConsulRegistryResult) MalformedURLException(java.net.MalformedURLException) JobRepresentation(com.dell.cpsd.paqx.fru.rest.representation.JobRepresentation) Job(com.dell.cpsd.paqx.fru.rest.domain.Job) URL(java.net.URL) NextStep(com.dell.cpsd.paqx.fru.valueobject.NextStep)

Example 3 with ConsulRegistryResult

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

the class vCenterServiceImpl method requestConsulRegistration.

public CompletableFuture<ConsulRegistryResult> requestConsulRegistration(final EndpointCredentials vcenterCredentials) {
    final String requiredCapability = "vcenter-consul-register";
    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();
                    ConsulRegisterRequestMessage requestMessage = new ConsulRegisterRequestMessage();
                    requestMessage.setMessageProperties(new MessageProperties().withCorrelationId(correlationId.toString()).withReplyTo(replyTo).withTimestamp(new Date()));
                    try {
                        new URL(vcenterCredentials.getEndpointUrl());
                    } catch (MalformedURLException e) {
                        final CompletableFuture<ConsulRegistryResult> promise = new CompletableFuture<>();
                        promise.completeExceptionally(e);
                        return promise;
                    }
                    final RegistrationInfo registrationInfo = new RegistrationInfo(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername());
                    requestMessage.setRegistrationInfo(registrationInfo);
                    final CompletableFuture<ConsulRegistryResult> promise = consulRegisterAsyncAcknowledgement.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");
    }
    LOG.error("Unable to find required capability: {}", requiredCapability);
    return CompletableFuture.completedFuture(null);
}
Also used : ConsulRegistryResult(com.dell.cpsd.paqx.fru.dto.ConsulRegistryResult) RegistrationInfo(com.dell.cpsd.virtualization.capabilities.api.RegistrationInfo) MalformedURLException(java.net.MalformedURLException) Capability(com.dell.cpsd.hdp.capability.registry.api.Capability) CapabilityProvider(com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider) 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) ConsulRegisterRequestMessage(com.dell.cpsd.virtualization.capabilities.api.ConsulRegisterRequestMessage) CompletableFuture(java.util.concurrent.CompletableFuture) MessageProperties(com.dell.cpsd.virtualization.capabilities.api.MessageProperties) CapabilityRegistryException(com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException) UUID(java.util.UUID)

Aggregations

ConsulRegistryResult (com.dell.cpsd.paqx.fru.dto.ConsulRegistryResult)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 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 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 ConsulRegisterRequestMessage (com.dell.cpsd.virtualization.capabilities.api.ConsulRegisterRequestMessage)1 MessageProperties (com.dell.cpsd.virtualization.capabilities.api.MessageProperties)1 RegistrationInfo (com.dell.cpsd.virtualization.capabilities.api.RegistrationInfo)1 ResponseInfo (com.dell.cpsd.virtualization.capabilities.api.ResponseInfo)1 Date (java.util.Date)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TopicExchange (org.springframework.amqp.core.TopicExchange)1