All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dell.cpsd.rcm.evaluation.client.amqp.AmqpRcmEvaluationManager Maven / Gradle / Ivy

Go to download

This repository contains the source code for the rcm evaluation service API. Use this repository to share contracts between services so you can create POJOs using defined JSON schemas and to create message transformers for the RCM evaluation service.

The newest version!
/**
 * Copyright © 2017 Dell Inc. or its subsidiaries.  All Rights Reserved.
 * Dell EMC Confidential/Proprietary Information
 */

package com.dell.cpsd.rcm.evaluation.client.amqp;

import com.dell.cpsd.common.logging.ILogger;
import com.dell.cpsd.rcm.evaluation.client.IRcmEvaluationConfiguration;
import com.dell.cpsd.rcm.evaluation.client.RcmEvaluationServiceException;
import com.dell.cpsd.rcm.evaluation.client.amqp.consumer.IAmqpRcmEvaluationConsumer;
import com.dell.cpsd.rcm.evaluation.client.amqp.consumer.IAmqpRcmEvaluationMessageHandler;
import com.dell.cpsd.rcm.evaluation.client.amqp.producer.IAmqpRcmEvaluationProducer;
import com.dell.cpsd.rcm.evaluation.client.callback.SystemRcmEvaluationResponse;
import com.dell.cpsd.rcm.evaluation.client.log.RFESLoggingManager;
import com.dell.cpsd.rcm.evaluation.client.log.RFESMessageCode;
import com.dell.cpsd.rcm.evaluation.service.api.ElementVersionDatum;
import com.dell.cpsd.rcm.evaluation.service.api.RcmEvaluationErrorMessage;
import com.dell.cpsd.rcm.evaluation.service.api.RcmEvaluationResult;
import com.dell.cpsd.rcm.evaluation.service.api.ReleaseControlMatrix;
import com.dell.cpsd.rcm.evaluation.service.api.SystemRcmEvaluationMessage;
import com.dell.cpsd.service.common.client.callback.IServiceCallback;
import com.dell.cpsd.service.common.client.callback.ServiceCallback;
import com.dell.cpsd.service.common.client.callback.ServiceError;
import com.dell.cpsd.service.common.client.exception.ServiceTimeoutException;
import com.dell.cpsd.service.common.client.manager.AbstractServiceCallbackManager;
import com.dell.cpsd.service.common.client.task.ServiceTask;

import java.util.List;
import java.util.UUID;

/**
 * This class is responsible for sending and processing messages to and from
 * the service.
 * 
 * 

* Copyright © 2017 Dell Inc. or its subsidiaries. All Rights Reserved. * Dell EMC Confidential/Proprietary Information *

* * @version 1.0 * * @since SINCE-TBD */ public class AmqpRcmEvaluationManager extends AbstractServiceCallbackManager implements IAmqpRcmEvaluationMessageHandler { /* * The logger for this class. */ private static final ILogger LOGGER = RFESLoggingManager.getLogger(AmqpRcmEvaluationManager.class); /* * The routing key for the response message queue used by the consumer */ private String routingKey = null; /* * The configuration used by this service manager */ private IRcmEvaluationConfiguration configuration = null; /* * The service message producer */ private IAmqpRcmEvaluationProducer rcmEvaluationProducer = null; /* * The service message consumer */ private IAmqpRcmEvaluationConsumer rcmEvaluationConsumer = null; /** * AmqpRcmEvaluationManager constructor. * * @param configuration The configuration used by this manager. * * @throws IllegalArgumentException Thrown if the configuration is null. * * @since 1.0 */ public AmqpRcmEvaluationManager(IRcmEvaluationConfiguration configuration) { super(); if (configuration == null) { throw new IllegalArgumentException("The configuration is not set."); } this.configuration = configuration; this.setRcmEvaluationConsumer(configuration.getRcmEvaluationConsumer()); this.setRcmEvaluationProducer(configuration.getRcmEvaluationProducer()); this.setRoutingKey(this.rcmEvaluationConsumer.getRoutingKey()); this.rcmEvaluationConsumer.setRcmEvaluationMessageHandler(this); } /** * This evaluates an RCM for a system and returns the response with the * result. * * @param releaseControlMatrix The release content matrix. * @param elementVersionData The component version data. * * @return The response with the result of the system RCM evaluation. * * @throws RcmEvaluationServiceException Thrown if the request fails. * @throws ServiceTimeoutException Thrown if the request times out. * * @since 1.0 */ public SystemRcmEvaluationResponse evaluateSystemRcm( final ReleaseControlMatrix releaseControlMatrix, final List elementVersionData, final long timeout) throws RcmEvaluationServiceException, ServiceTimeoutException { if (this.isShutDown()) { String lmessage = LOGGER.error(RFESMessageCode.MANAGER_SHUTDOWN_E.getMessageCode()); throw new RcmEvaluationServiceException(lmessage); } // create a correlation identifier for the operation final String requestId = UUID.randomUUID().toString(); final ServiceCallback callback = new ServiceCallback(); // the infinite timeout is used for the task because it is handled with // this synchronous call. final ServiceTask> task = new ServiceTask>(requestId, callback, timeout); // add the callback using the correlation identifier as key this.addServiceTask(requestId, task); // publish message to evaluate the RCM for a system try { this.rcmEvaluationProducer.publishEvaluateSystemRcm(releaseControlMatrix, elementVersionData, requestId, this.routingKey); } catch (Exception exception) { // remove the callback if the message cannot be published this.removeServiceTask(requestId); Object[] lparams = {exception.getMessage()}; String lmessage = LOGGER.error( RFESMessageCode.PUBLISH_MESSAGE_FAIL_E.getMessageCode(), lparams, exception); throw new RcmEvaluationServiceException(lmessage, exception); } // wait from the response from the service this.waitForServiceCallback(callback, requestId, timeout); // check to see if a error has been handled by the manager final ServiceError error = callback.getServiceError(); // throw a exception using the message in the error if (error != null) { throw new RcmEvaluationServiceException(error.getErrorMessage()); } // if there was no error, then return the response return callback.getServiceResponse(); } /** * {@inheritDoc} */ @Override public void handleSystemRcmEvaluation(final SystemRcmEvaluationMessage message) { if (message == null) { return; } final String correlationId = message.getCorrelationId(); final IServiceCallback callback = this.removeServiceCallback(correlationId); if (callback == null) { return; } final List results = message.getRcmEvaluationResults(); final SystemRcmEvaluationResponse response = new SystemRcmEvaluationResponse(correlationId, results); // TODO : Take the callback processing off the message thread try { ((ServiceCallback)callback).handleServiceResponse(response); } catch (Exception exception) { // log the exception thrown by the compute callback Object[] lparams = {"handleServiceResponse", exception.getMessage()}; LOGGER.error(RFESMessageCode.ERROR_CALLBACK_FAIL_E.getMessageCode(), lparams, exception); } } /** * {@inheritDoc} */ @Override public void handleEvaluationServiceError(final RcmEvaluationErrorMessage message) { if (message == null) { return; } final String correlationId = message.getCorrelationId(); final IServiceCallback callback = this.removeServiceCallback(correlationId); if (callback == null) { return; } final String errorCode = message.getErrorCode(); final String errorMessage = message.getErrorMessage(); final ServiceError error = new ServiceError(correlationId, errorCode, errorMessage); // TODO : Take the callback processing off the message thread try { callback.handleServiceError(error); } catch (Exception exception) { // log the exception thrown by the callback Object[] lparams = {"handleServiceError", exception.getMessage()}; LOGGER.error(RFESMessageCode.ERROR_CALLBACK_FAIL_E.getMessageCode(), lparams, exception); } } /** * {@inheritDoc} */ @Override public void release() { super.release(); this.configuration = null; } /** * This returns the routing key used by the service consumer to * consume responses or error messages. * * @return The routing key. * * @since Vision 3.x.x */ public String getRoutingKey() { return this.routingKey; } /** * This sets the compute result routing key used by the service consumer to * consume responses or error messages. * * @param routingKey The routing key. * * @throws IllegalArgumentException Thrown if the routing key is null. * * @since Vision 3.x.x */ public void setRoutingKey(String routingKey) { if (routingKey == null) { throw new IllegalArgumentException("The routing key is not set."); } this.routingKey = routingKey; } /** * This returns the service message producer. * * @return The service message producer. * * @since SINCE-TBD */ public IAmqpRcmEvaluationProducer getRcmEvaluationProducer() { return this.rcmEvaluationProducer; } /** * This sets the service message producer. * * @param rcmEvaluationProducer The service message producer. * * @throws IllegalArgumentException Thrown if the producer is null. * * @since SINCE-TBD */ protected void setRcmEvaluationProducer( final IAmqpRcmEvaluationProducer rcmEvaluationProducer) { if (rcmEvaluationProducer == null) { throw new IllegalArgumentException("The service producer is null."); } this.rcmEvaluationProducer = rcmEvaluationProducer; } /** * This returns the service message consumer. * * @return The service message consumer. * * @since SINCE-TBD */ public IAmqpRcmEvaluationConsumer getRcmEvaluationConsumer() { return this.rcmEvaluationConsumer; } /** * This sets the service message consumer. * * @param rcmEvaluationConsumer The service consumer. * * @throws IllegalArgumentException Thrown if the consumer is null. * * @since SINCE-TBD */ protected void setRcmEvaluationConsumer( final IAmqpRcmEvaluationConsumer rcmEvaluationConsumer) { if (rcmEvaluationConsumer == null) { throw new IllegalArgumentException("The service consumer is null."); } this.rcmEvaluationConsumer = rcmEvaluationConsumer; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy