Search in sources :

Example 1 with ScaleIOSystemDataRestRep

use of com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep in project fru-paqx-parent by dellemc-symphony.

the class ListStorageResponseHandler method executeOperation.

@Override
protected void executeOperation(final ListStorageResponseMessage listStorageResponseMessage) throws Exception {
    LOG.info("Received message {}", listStorageResponseMessage);
    final String correlationId = listStorageResponseMessage.getMessageProperties().getCorrelationId();
    final ScaleIOSystemDataRestRep scaleIOSystemDataRestRep = listStorageResponseMessage.getScaleIOSystemDataRestRep();
    final CompletableFuture<ScaleIOSystemDataRestRep> completableFuture = asyncRequests.get(correlationId);
    LOG.info("Completing expectation for  {} {}", correlationId, completableFuture);
    // TODO: write to data service
    if (completableFuture != null) {
        final boolean complete = completableFuture.complete(scaleIOSystemDataRestRep);
        LOG.info("Completed expectation for  {} {} {}", correlationId, completableFuture, complete);
        asyncRequests.remove(correlationId);
    }
}
Also used : ScaleIOSystemDataRestRep(com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep)

Example 2 with ScaleIOSystemDataRestRep

use of com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep in project fru-paqx-parent by dellemc-symphony.

the class ScaleIOServiceImpl method listStorage.

public CompletableFuture<ScaleIOSystemDataRestRep> listStorage(final EndpointCredentials scaleIOCredentials) {
    final String requiredCapability = "coprhd-list-storage";
    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();
                    ListStorageRequestMessage requestMessage = new ListStorageRequestMessage();
                    MessageProperties messageProperties = new MessageProperties();
                    messageProperties.setCorrelationId((correlationId.toString()));
                    messageProperties.setReplyTo(replyTo);
                    messageProperties.setTimestamp(new Date());
                    requestMessage.setMessageProperties(messageProperties);
                    try {
                        new URL(scaleIOCredentials.getEndpointUrl());
                    } catch (MalformedURLException e) {
                        final CompletableFuture<ScaleIOSystemDataRestRep> promise = new CompletableFuture<>();
                        promise.completeExceptionally(e);
                        return promise;
                    }
                    requestMessage.setEndpointURL(scaleIOCredentials.getEndpointUrl());
                    requestMessage.setPassword(scaleIOCredentials.getPassword());
                    requestMessage.setUserName(scaleIOCredentials.getUsername());
                    final CompletableFuture<ScaleIOSystemDataRestRep> promise = asyncAcknowledgement.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 : MalformedURLException(java.net.MalformedURLException) Capability(com.dell.cpsd.hdp.capability.registry.api.Capability) CapabilityProvider(com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider) ScaleIOSystemDataRestRep(com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep) 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) MessageProperties(com.dell.cpsd.storage.capabilities.api.MessageProperties) CapabilityRegistryException(com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException) ListStorageRequestMessage(com.dell.cpsd.storage.capabilities.api.ListStorageRequestMessage) UUID(java.util.UUID)

Example 3 with ScaleIOSystemDataRestRep

use of com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep in project fru-paqx-parent by dellemc-symphony.

the class ListStorageHandlerTest method isCompletedWhenReceivingResponse.

@Test
public void isCompletedWhenReceivingResponse() throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    ListStorageResponseHandler handler = new ListStorageResponseHandler(null);
    final CompletableFuture<ScaleIOSystemDataRestRep> future = handler.register("test-001");
    future.whenComplete((systemRest, throwable) -> countDownLatch.countDown());
    ListStorageResponseMessage listResponse = new ListStorageResponseMessage();
    ScaleIOSystemDataRestRep scaleIOSystemDataRestRep = new ScaleIOSystemDataRestRep();
    scaleIOSystemDataRestRep.setSystemVersionName("some.test");
    listResponse.getScaleIOSystemDataRestRep();
    MessageProperties messageProperties = new MessageProperties();
    messageProperties.setCorrelationId("test-001");
    listResponse.setMessageProperties(messageProperties);
    handler.executeOperation(listResponse);
    Assert.assertTrue("Timeout before completion", countDownLatch.await(1, TimeUnit.SECONDS));
}
Also used : MessageProperties(com.dell.cpsd.storage.capabilities.api.MessageProperties) ListStorageResponseMessage(com.dell.cpsd.storage.capabilities.api.ListStorageResponseMessage) ScaleIOSystemDataRestRep(com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with ScaleIOSystemDataRestRep

use of com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep in project fru-paqx-parent by dellemc-symphony.

the class DataServiceImplTest method getData.

@Test
public void getData() {
    UUID jobId = UUID.randomUUID();
    dataServiceUnderTest.saveScaleioData(jobId, new ScaleIOSystemDataRestRep());
    FRUSystemData taskData = dataServiceUnderTest.getData(jobId);
    assertNotNull(taskData);
}
Also used : FRUSystemData(com.dell.cpsd.paqx.fru.dto.FRUSystemData) ScaleIOSystemDataRestRep(com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with ScaleIOSystemDataRestRep

use of com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep in project fru-paqx-parent by dellemc-symphony.

the class WorkflowResource method discoverScaleIO.

@POST
@Path("{jobId}/start-scaleio-data-collection")
public void discoverScaleIO(@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);
    jobRepresentation.addLink(createRetryStepLink(uriInfo, job, thisStep));
    //
    final CompletableFuture<ScaleIOSystemDataRestRep> systemRestCompletableFuture = scaleIOService.listStorage(job.getScaleIOCredentials());
    systemRestCompletableFuture.thenAccept(scaleIOSystemDataRestRep -> {
        dataService.saveScaleioData(UUID.fromString(jobId), scaleIOSystemDataRestRep);
        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()));
        }
        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) ScaleIOSystemDataRestRep(com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep) Job(com.dell.cpsd.paqx.fru.rest.domain.Job) NextStep(com.dell.cpsd.paqx.fru.valueobject.NextStep)

Aggregations

ScaleIOSystemDataRestRep (com.dell.cpsd.storage.capabilities.api.ScaleIOSystemDataRestRep)5 MessageProperties (com.dell.cpsd.storage.capabilities.api.MessageProperties)2 UUID (java.util.UUID)2 Test (org.junit.Test)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 FRUSystemData (com.dell.cpsd.paqx.fru.dto.FRUSystemData)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 ListStorageRequestMessage (com.dell.cpsd.storage.capabilities.api.ListStorageRequestMessage)1 ListStorageResponseMessage (com.dell.cpsd.storage.capabilities.api.ListStorageResponseMessage)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Date (java.util.Date)1 CompletableFuture (java.util.concurrent.CompletableFuture)1