diff options
Diffstat (limited to 'participant/participant-intermediary')
6 files changed, 52 insertions, 54 deletions
diff --git a/participant/participant-intermediary/pom.xml b/participant/participant-intermediary/pom.xml index df354d46c..aac80a4a2 100644 --- a/participant/participant-intermediary/pom.xml +++ b/participant/participant-intermediary/pom.xml @@ -28,7 +28,6 @@ <version>6.1.2-SNAPSHOT</version> </parent> - <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-intermediary</artifactId> <name>${project.artifactId}</name> <description>Common intermediary library for managing DMaaP participant messaging and holding participant and control diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java index d31ae1082..adc9c2393 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/api/ParticipantIntermediaryApi.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; import java.util.UUID; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; @@ -134,6 +133,7 @@ public interface ParticipantIntermediaryApi { * if participantHandler is not returned, there is no way to test state change messages * without dmaap simulator. * + * @return the participant handler */ ParticipantHandler getParticipantHandler(); } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java index 3128f1eaa..6926bc30b 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/comm/MessageSender.java @@ -34,7 +34,6 @@ import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.Parti import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantResponseStatus; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus; import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener; -import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ParticipantStatusPublisher; import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -72,7 +71,7 @@ public class MessageSender extends TimerTask implements Closeable { public void run() { LOGGER.debug("Sent heartbeat to CLAMP"); - ParticipantResponseDetails response = new ParticipantResponseDetails(); + var response = new ParticipantResponseDetails(); response.setResponseTo(null); response.setResponseStatus(ParticipantResponseStatus.PERIODIC); @@ -100,7 +99,7 @@ public class MessageSender extends TimerTask implements Closeable { * @param response the details to include in the response message */ public void sendResponse(ToscaConceptIdentifier controlLoopId, ParticipantResponseDetails response) { - ParticipantStatus status = new ParticipantStatus(); + var status = new ParticipantStatus(); // Participant related fields status.setParticipantType(participantHandler.getParticipantType()); @@ -109,12 +108,12 @@ public class MessageSender extends TimerTask implements Closeable { status.setHealthStatus(participantHandler.getHealthStatus()); // Control loop related fields - ControlLoops controlLoops = participantHandler.getControlLoopHandler().getControlLoops(); + var controlLoops = participantHandler.getControlLoopHandler().getControlLoops(); status.setControlLoopId(controlLoopId); status.setControlLoops(controlLoops); status.setResponse(response); - ParticipantStatistics participantStatistics = new ParticipantStatistics(); + var participantStatistics = new ParticipantStatistics(); participantStatistics.setTimeStamp(Instant.now()); participantStatistics.setParticipantId(participantHandler.getParticipantId()); participantStatistics.setHealthStatus(participantHandler.getHealthStatus()); diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java index cc2a66b58..18ee29f08 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ControlLoopHandler.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import lombok.Getter; +import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; @@ -49,6 +50,7 @@ import org.slf4j.LoggerFactory; /* * This class is responsible for managing the state of all control loops in the participant. */ +@NoArgsConstructor public class ControlLoopHandler implements Closeable { private static final Logger LOGGER = LoggerFactory.getLogger(ControlLoopHandler.class); @@ -63,8 +65,6 @@ public class ControlLoopHandler implements Closeable { @Getter private List<ControlLoopElementListener> listeners = new ArrayList<>(); - public ControlLoopHandler() {} - /** * Constructor, set the participant ID and messageSender. * @@ -85,7 +85,7 @@ public class ControlLoopHandler implements Closeable { public void registerControlLoopElementListener(ControlLoopElementListener listener) { listeners.add(listener); } - + /** * Handle a control loop element state change message. * @@ -95,7 +95,7 @@ public class ControlLoopHandler implements Closeable { * @return controlLoopElement the updated controlloop element */ public ControlLoopElement updateControlLoopElementState(UUID id, ControlLoopOrderedState orderedState, - ControlLoopState newState) { + ControlLoopState newState) { if (id == null) { return null; @@ -106,7 +106,7 @@ public class ControlLoopHandler implements Closeable { clElement.setOrderedState(orderedState); clElement.setState(newState); LOGGER.debug("Control loop element {} state changed to {}", id, newState); - ParticipantResponseDetails response = new ParticipantResponseDetails(); + var response = new ParticipantResponseDetails(); response.setResponseStatus(ParticipantResponseStatus.SUCCESS); response.setResponseMessage("ControlLoopElement state changed to {} " + newState); messageSender.sendResponse(response); @@ -141,14 +141,14 @@ public class ControlLoopHandler implements Closeable { return; } - ControlLoop controlLoop = controlLoopMap.get(stateChangeMsg.getControlLoopId()); + var controlLoop = controlLoopMap.get(stateChangeMsg.getControlLoopId()); if (controlLoop == null) { LOGGER.debug("Control loop {} does not use this participant", stateChangeMsg.getControlLoopId()); return; } - ParticipantResponseDetails response = new ParticipantResponseDetails(stateChangeMsg); + var response = new ParticipantResponseDetails(stateChangeMsg); handleState(controlLoop, response, stateChangeMsg.getOrderedState()); messageSender.sendResponse(response); } @@ -161,7 +161,7 @@ public class ControlLoopHandler implements Closeable { * @param orderedState controlloop ordered state */ private void handleState(final ControlLoop controlLoop, final ParticipantResponseDetails response, - ControlLoopOrderedState orderedState) { + ControlLoopOrderedState orderedState) { switch (orderedState) { case UNINITIALISED: handleUninitialisedState(controlLoop, orderedState, response); @@ -189,16 +189,16 @@ public class ControlLoopHandler implements Closeable { return; } - ControlLoop controlLoop = controlLoopMap.get(updateMsg.getControlLoopId()); + var controlLoop = controlLoopMap.get(updateMsg.getControlLoopId()); - ParticipantResponseDetails response = new ParticipantResponseDetails(updateMsg); + var response = new ParticipantResponseDetails(updateMsg); // TODO: Updates to existing ControlLoops are not supported yet (Addition/Removal of ControlLoop // elements to existing ControlLoop has to be supported). if (controlLoop != null) { response.setResponseStatus(ParticipantResponseStatus.FAIL); - response.setResponseMessage("Control loop " + updateMsg.getControlLoopId() - + " already defined on participant " + participantId); + response.setResponseMessage( + "Control loop " + updateMsg.getControlLoopId() + " already defined on participant " + participantId); messageSender.sendResponse(response); return; @@ -226,7 +226,7 @@ public class ControlLoopHandler implements Closeable { response.setResponseStatus(ParticipantResponseStatus.SUCCESS); response.setResponseMessage( - "Control loop " + updateMsg.getControlLoopId() + " defined on participant " + participantId); + "Control loop " + updateMsg.getControlLoopId() + " defined on participant " + participantId); messageSender.sendResponse(response); } @@ -239,15 +239,14 @@ public class ControlLoopHandler implements Closeable { * @param response participant response */ private void handleUninitialisedState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - final ParticipantResponseDetails response) { + final ParticipantResponseDetails response) { handleStateChange(controlLoop, orderedState, ControlLoopState.UNINITIALISED, response); controlLoopMap.remove(controlLoop.getKey().asIdentifier()); for (ControlLoopElementListener clElementListener : listeners) { try { for (ControlLoopElement element : controlLoop.getElements().values()) { - clElementListener.controlLoopElementStateChange(element.getId(), element.getState(), - orderedState); + clElementListener.controlLoopElementStateChange(element.getId(), element.getState(), orderedState); } } catch (PfModelException e) { LOGGER.debug("Control loop element update failed {}", controlLoop.getDefinition()); @@ -263,7 +262,7 @@ public class ControlLoopHandler implements Closeable { * @param response participant response */ private void handlePassiveState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - final ParticipantResponseDetails response) { + final ParticipantResponseDetails response) { handleStateChange(controlLoop, orderedState, ControlLoopState.PASSIVE, response); } @@ -275,19 +274,20 @@ public class ControlLoopHandler implements Closeable { * @param response participant response */ private void handleRunningState(final ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - final ParticipantResponseDetails response) { + final ParticipantResponseDetails response) { handleStateChange(controlLoop, orderedState, ControlLoopState.RUNNING, response); } - + /** * Method to update the state of control loop elements. * * @param controlLoop participant status in memory - * @param orderedState orderedState - * @param state new state of the control loop elements + * @param orderedState orderedState the new ordered state the participant should have + * @param newState new state of the control loop elements + * @param response the response to the state change request */ private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState, - ControlLoopState newState, ParticipantResponseDetails response) { + ControlLoopState newState, ParticipantResponseDetails response) { if (orderedState.equals(controlLoop.getOrderedState())) { response.setResponseStatus(ParticipantResponseStatus.SUCCESS); @@ -297,26 +297,24 @@ public class ControlLoopHandler implements Closeable { if (!CollectionUtils.isEmpty(controlLoop.getElements().values())) { controlLoop.getElements().values().forEach(element -> { - element.setState(newState); - element.setOrderedState(orderedState); - } - ); + element.setState(newState); + element.setOrderedState(orderedState); + }); } response.setResponseStatus(ParticipantResponseStatus.SUCCESS); - response.setResponseMessage("ControlLoop state changed from " + controlLoop.getOrderedState() - + " to " + orderedState); + response.setResponseMessage( + "ControlLoop state changed from " + controlLoop.getOrderedState() + " to " + orderedState); controlLoop.setOrderedState(orderedState); } - /** * Get control loops as a {@link ConrolLoops} class. * * @return the control loops */ public ControlLoops getControlLoops() { - ControlLoops controlLoops = new ControlLoops(); + var controlLoops = new ControlLoops(); controlLoops.setControlLoopList(new ArrayList<>(controlLoopMap.values())); return controlLoops; } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java index be2fa1a30..3eae27267 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/IntermediaryActivator.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.concurrent.atomic.AtomicReference; import javax.ws.rs.core.Response.Status; import lombok.Getter; -import lombok.experimental.Delegate; import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; @@ -70,21 +69,22 @@ public class IntermediaryActivator extends ServiceManagerContainer { * Instantiate the activator for participant. * * @param parameters the parameters for the participant intermediary + * @throws ControlLoopRuntimeException when the activation fails */ public IntermediaryActivator(final ParticipantIntermediaryParameters parameters) { this.parameters = parameters; topicSinks = - TopicEndpointManager.getManager().addTopicSinks(parameters.getClampControlLoopTopics().getTopicSinks()); + TopicEndpointManager.getManager().addTopicSinks(parameters.getClampControlLoopTopics().getTopicSinks()); - topicSources = TopicEndpointManager.getManager() - .addTopicSources(parameters.getClampControlLoopTopics().getTopicSources()); + topicSources = + TopicEndpointManager.getManager().addTopicSources(parameters.getClampControlLoopTopics().getTopicSources()); try { this.msgDispatcher = new MessageTypeDispatcher(MSG_TYPE_NAMES); } catch (final RuntimeException e) { throw new ControlLoopRuntimeException(Status.INTERNAL_SERVER_ERROR, - "topic message dispatcher failed to start", e); + "topic message dispatcher failed to start", e); } // @formatter:off @@ -131,17 +131,14 @@ public class IntermediaryActivator extends ServiceManagerContainer { */ private void registerMsgDispatcher() { msgDispatcher.register(ParticipantMessageType.PARTICIPANT_STATE_CHANGE.name(), - (ScoListener<ParticipantStateChange>) new ParticipantStateChangeListener( - participantHandler.get())); + (ScoListener<ParticipantStateChange>) new ParticipantStateChangeListener(participantHandler.get())); msgDispatcher.register(ParticipantMessageType.PARTICIPANT_HEALTH_CHECK.name(), - (ScoListener<ParticipantHealthCheck>) new ParticipantHealthCheckListener( - participantHandler.get())); + (ScoListener<ParticipantHealthCheck>) new ParticipantHealthCheckListener(participantHandler.get())); msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_STATE_CHANGE.name(), - (ScoListener<ParticipantControlLoopStateChange>) new ControlLoopStateChangeListener( - participantHandler.get())); + (ScoListener<ParticipantControlLoopStateChange>) new ControlLoopStateChangeListener( + participantHandler.get())); msgDispatcher.register(ParticipantMessageType.PARTICIPANT_CONTROL_LOOP_UPDATE.name(), - (ScoListener<ParticipantControlLoopUpdate>) new ControlLoopUpdateListener( - participantHandler.get())); + (ScoListener<ParticipantControlLoopUpdate>) new ControlLoopUpdateListener(participantHandler.get())); for (final TopicSource source : topicSources) { source.register(msgDispatcher); } @@ -158,6 +155,8 @@ public class IntermediaryActivator extends ServiceManagerContainer { /** * Return the participant handler. + * + * @return the participant handler */ public ParticipantHandler getParticipantHandler() { return participantHandler.get(); diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java index 980ab6ec1..913c050e3 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/controlloop/participant/intermediary/handler/ParticipantHandler.java @@ -90,7 +90,7 @@ public class ParticipantHandler implements Closeable { return; } - ParticipantResponseDetails response = new ParticipantResponseDetails(stateChangeMsg); + var response = new ParticipantResponseDetails(stateChangeMsg); switch (stateChangeMsg.getState()) { case PASSIVE: @@ -126,7 +126,7 @@ public class ParticipantHandler implements Closeable { * @param healthCheckMsg participant health check message */ public void handleParticipantHealthCheck(final ParticipantHealthCheck healthCheckMsg) { - ParticipantResponseDetails response = new ParticipantResponseDetails(healthCheckMsg); + var response = new ParticipantResponseDetails(healthCheckMsg); response.setResponseStatus(ParticipantResponseStatus.SUCCESS); response.setResponseMessage(healthStatus.toString()); @@ -194,6 +194,7 @@ public class ParticipantHandler implements Closeable { * * @param definition participant definition * @param participantState participant state + * @return the participant */ public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState participantState) { @@ -201,7 +202,7 @@ public class ParticipantHandler implements Closeable { LOGGER.debug("No participant with this ID {}", definition.getName()); return null; } - ParticipantResponseDetails response = new ParticipantResponseDetails(); + var response = new ParticipantResponseDetails(); handleStateChange(participantState, response); sender.sendResponse(response); return getParticipant(definition.getName(), definition.getVersion()); @@ -210,11 +211,13 @@ public class ParticipantHandler implements Closeable { /** * Get participants as a {@link Participant} class. * + * @param name the participant name to get + * @param version the version of the participant to get * @return the participant */ public Participant getParticipant(String name, String version) { if (participantId.getName().equals(name)) { - Participant participant = new Participant(); + var participant = new Participant(); participant.setDefinition(participantId); participant.setParticipantState(state); participant.setHealthStatus(healthStatus); |