use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.HostMaintenanceModeResponse in project fru-paqx-parent by dellemc-symphony.
the class HostMaintenanceModeResponseHandler method executeOperation.
@Override
protected void executeOperation(final HostMaintenanceModeResponseMessage responseMessage) throws Exception {
LOG.info("Received message {}", responseMessage);
final String correlationId = responseMessage.getMessageProperties().getCorrelationId();
final HostMaintenanceModeResponse hostMaintenanceModeResponse = new HostMaintenanceModeResponse(responseMessage.getStatus().value());
final CompletableFuture<HostMaintenanceModeResponse> completableFuture = asyncRequests.get(correlationId);
LOG.info("Completing expectation for {} {}", correlationId, completableFuture);
if (completableFuture != null) {
final boolean complete = completableFuture.complete(hostMaintenanceModeResponse);
LOG.info("Completed expectation for {} {} {}", correlationId, completableFuture, complete);
asyncRequests.remove(correlationId);
}
}
use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.HostMaintenanceModeResponse 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);
}
use of com.dell.cpsd.paqx.fru.rest.dto.vcenter.HostMaintenanceModeResponse in project fru-paqx-parent by dellemc-symphony.
the class WorkflowResource method enterMaintenanceMode.
@POST
@Path("{jobId}/enter-maintanence-mode")
public void enterMaintenanceMode(@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);
//TODO find out where to get the hostname from
final String hostname = "";
final CompletableFuture<HostMaintenanceModeResponse> hostMaintenanceModeCompletableFuture = vcenterService.requestHostMaintenanceModeEnable(job.getVcenterCredentials(), hostname);
hostMaintenanceModeCompletableFuture.thenAccept(hostMaintenanceModeResponse -> {
LOG.info("Host Maintenance Mode Response: [{}]", hostMaintenanceModeResponse);
if (HostMaintenanceModeResponseMessage.Status.SUCCESS.value().equals(hostMaintenanceModeResponse.getStatus())) {
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()));
}
asyncResponse.resume(Response.ok(jobRepresentation).build());
} else {
jobRepresentation.addLink(createRetryStepLink(uriInfo, job, thisStep));
jobRepresentation.setLastResponse(hostMaintenanceModeResponse.getStatus());
asyncResponse.resume(Response.status(Response.Status.BAD_REQUEST).build());
}
LOG.info("Completing response");
asyncResponse.resume(Response.ok(jobRepresentation).build());
LOG.debug("Completed response");
});
}
Aggregations