Search in sources :

Example 1 with MessageProperties

use of com.dell.cpsd.paqx.fru.amqp.model.MessageProperties in project fru-paqx-parent by dellemc-symphony.

the class NodeDiscoveryImpl method discover.

/**
     * Looks up and invokes a Control Plane Provider to meet the required capability.
     *
     * @return A CompletableFuture that will be completed when the response is received from the Control Plane Provider
     */
@Override
public CompletableFuture<List<ListNodesResponse.Node>> discover() {
    final String requiredCapability = "rackhd-list-nodes";
    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();
                    ListNodesRequest requestMessage = new ListNodesRequest();
                    requestMessage.setMessageProperties(new MessageProperties().withCorrelationId(correlationId.toString()).withReplyTo(replyTo).withTimestamp(new Date()));
                    final CompletableFuture<List<ListNodesResponse.Node>> promise = new CompletableFuture<>();
                    requestResponseMatcher.onNext(correlationId.toString(), promise);
                    rabbitTemplate.convertAndSend(requestExchange, requestRoutingKey, requestMessage);
                    LOG.debug("Returning promise");
                    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(Collections.emptyList());
}
Also used : Capability(com.dell.cpsd.hdp.capability.registry.api.Capability) CapabilityProvider(com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider) ListNodesRequest(com.dell.cpsd.paqx.fru.amqp.model.ListNodesRequest) ListCapabilityProvidersResponse(com.dell.cpsd.hdp.capability.registry.client.callback.ListCapabilityProvidersResponse) ServiceTimeoutException(com.dell.cpsd.service.common.client.exception.ServiceTimeoutException) TopicExchange(org.springframework.amqp.core.TopicExchange) EndpointProperty(com.dell.cpsd.hdp.capability.registry.api.EndpointProperty) CompletableFuture(java.util.concurrent.CompletableFuture) MessageProperties(com.dell.cpsd.paqx.fru.amqp.model.MessageProperties) CapabilityRegistryException(com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException) ListNodesResponse(com.dell.cpsd.paqx.fru.amqp.model.ListNodesResponse)

Aggregations

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 ListNodesRequest (com.dell.cpsd.paqx.fru.amqp.model.ListNodesRequest)1 ListNodesResponse (com.dell.cpsd.paqx.fru.amqp.model.ListNodesResponse)1 MessageProperties (com.dell.cpsd.paqx.fru.amqp.model.MessageProperties)1 ServiceTimeoutException (com.dell.cpsd.service.common.client.exception.ServiceTimeoutException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TopicExchange (org.springframework.amqp.core.TopicExchange)1