use of com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider in project fru-paqx-parent by dellemc-symphony.
the class AboutResource method root.
@GET
public void root(@Suspended final AsyncResponse asyncResponse) {
asyncResponse.setTimeoutHandler(asyncResponse1 -> asyncResponse1.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("{\"status\":\"timeout\"}").build()));
asyncResponse.setTimeout(10, TimeUnit.SECONDS);
final AboutRepresentation representation = new AboutRepresentation();
requiredCapabilities().forEach(capability -> representation.addRequiredCapability(capability));
try {
final ListCapabilityProvidersResponse listCapabilityProvidersResponse = this.capabilityRegistryLookupManager.listCapabilityProviders(TimeUnit.SECONDS.toMillis(2L));
for (final CapabilityProvider capabilityProvider : listCapabilityProvidersResponse.getResponse()) {
final String provider = capabilityProvider.getIdentity().getName();
for (final Capability capability : capabilityProvider.getCapabilities()) {
representation.capabilityMetBy(capability.getProfile(), provider);
}
}
} catch (CapabilityRegistryException e) {
asyncResponse.resume(e);
return;
} catch (ServiceTimeoutException e) {
asyncResponse.resume(Response.status(Response.Status.REQUEST_TIMEOUT).build());
return;
}
asyncResponse.resume(Response.ok(representation).build());
LOG.debug("Completed response");
/* nodeDiscovery.discover().thenAccept(nodes ->
{
nodes.stream().forEach(node -> representation.addNode(node.getId(), node.getName(),node.getType()));
asyncResponse.resume(Response.ok(representation).build());
LOG.debug("Completed response");
});*/
LOG.debug("Exiting about resource");
}
use of com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider 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);
}
use of com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider 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;
}
use of com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider 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());
}
use of com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider in project fru-paqx-parent by dellemc-symphony.
the class vCenterServiceImpl method requestHostRemoval.
@Override
public CompletableFuture<ClusterOperationResponse> requestHostRemoval(final EndpointCredentials vcenterCredentials, final String clusterId, final String hostname) {
final String requiredCapability = "vcenter-remove-host";
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();
final ClusterOperationRequestMessage requestMessage = new ClusterOperationRequestMessage();
requestMessage.setCredentials(new Credentials(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername()));
final ClusterOperationRequest clusterOperationRequest = new ClusterOperationRequest();
clusterOperationRequest.setHostName(hostname);
//TODO: If not required remove the cluster id
clusterOperationRequest.setClusterID(clusterId);
clusterOperationRequest.setClusterOperation(ClusterOperationRequest.ClusterOperation.REMOVE_HOST);
requestMessage.setClusterOperationRequest(clusterOperationRequest);
try {
new URL(vcenterCredentials.getEndpointUrl());
} catch (MalformedURLException e) {
final CompletableFuture<ClusterOperationResponse> promise = new CompletableFuture<>();
promise.completeExceptionally(e);
return promise;
}
final CompletableFuture<ClusterOperationResponse> promise = vcenterClusterOperationAsyncAcknowledgement.register(correlationId.toString());
LOG.info("Host removal request with correlation id [{}]", 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