Search in sources :

Example 1 with MaintenanceModeRequest

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

the class vCenterServiceImpl method requestHostMaintenanceModeEnable.

@Override
public CompletableFuture<HostMaintenanceModeResponse> requestHostMaintenanceModeEnable(final EndpointCredentials vcenterCredentials, final String hostname) {
    final String requiredCapability = "vcenter-enterMaintenance";
    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 HostMaintenanceModeRequestMessage requestMessage = new HostMaintenanceModeRequestMessage();
                    final MessageProperties messageProperties = new MessageProperties(new Date(), correlationId.toString(), replyTo);
                    requestMessage.setMessageProperties(messageProperties);
                    requestMessage.setCredentials(new Credentials(vcenterCredentials.getEndpointUrl(), vcenterCredentials.getPassword(), vcenterCredentials.getUsername()));
                    MaintenanceModeRequest maintenanceModeRequest = new MaintenanceModeRequest(hostname, Boolean.TRUE);
                    requestMessage.setMaintenanceModeRequest(maintenanceModeRequest);
                    try {
                        new URL(vcenterCredentials.getEndpointUrl());
                    } catch (MalformedURLException e) {
                        final CompletableFuture<HostMaintenanceModeResponse> promise = new CompletableFuture<>();
                        promise.completeExceptionally(e);
                        return promise;
                    }
                    final CompletableFuture<HostMaintenanceModeResponse> promise = hostMaintenanceModeAsyncAcknowledgement.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 CompletableFuture.completedFuture(null);
}
Also used : MalformedURLException(java.net.MalformedURLException) Capability(com.dell.cpsd.hdp.capability.registry.api.Capability) HostMaintenanceModeResponse(com.dell.cpsd.paqx.fru.rest.dto.vcenter.HostMaintenanceModeResponse) MaintenanceModeRequest(com.dell.cpsd.virtualization.capabilities.api.MaintenanceModeRequest) CapabilityProvider(com.dell.cpsd.hdp.capability.registry.api.CapabilityProvider) HostMaintenanceModeRequestMessage(com.dell.cpsd.virtualization.capabilities.api.HostMaintenanceModeRequestMessage) 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.virtualization.capabilities.api.MessageProperties) CapabilityRegistryException(com.dell.cpsd.hdp.capability.registry.client.CapabilityRegistryException) UUID(java.util.UUID) EndpointCredentials(com.dell.cpsd.paqx.fru.rest.dto.EndpointCredentials) Credentials(com.dell.cpsd.virtualization.capabilities.api.Credentials)

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 EndpointCredentials (com.dell.cpsd.paqx.fru.rest.dto.EndpointCredentials)1 HostMaintenanceModeResponse (com.dell.cpsd.paqx.fru.rest.dto.vcenter.HostMaintenanceModeResponse)1 ServiceTimeoutException (com.dell.cpsd.service.common.client.exception.ServiceTimeoutException)1 Credentials (com.dell.cpsd.virtualization.capabilities.api.Credentials)1 HostMaintenanceModeRequestMessage (com.dell.cpsd.virtualization.capabilities.api.HostMaintenanceModeRequestMessage)1 MaintenanceModeRequest (com.dell.cpsd.virtualization.capabilities.api.MaintenanceModeRequest)1 MessageProperties (com.dell.cpsd.virtualization.capabilities.api.MessageProperties)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Date (java.util.Date)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TopicExchange (org.springframework.amqp.core.TopicExchange)1