use of com.dell.cpsd.storage.capabilities.api.ListStorageRequestMessage 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);
}
Aggregations