diff options
18 files changed, 1512 insertions, 169 deletions
diff --git a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java index cfe786865..86a864efc 100644 --- a/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-http/src/main/java/org/onap/policy/clamp/controlloop/participant/http/main/handler/ControlLoopElementHandler.java @@ -37,6 +37,7 @@ import org.apache.commons.lang3.tuple.Pair; 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; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType; import org.onap.policy.clamp.controlloop.participant.http.main.models.ConfigRequest; import org.onap.policy.clamp.controlloop.participant.http.main.webclient.ClHttpClient; import org.onap.policy.clamp.controlloop.participant.intermediary.api.ControlLoopElementListener; @@ -90,7 +91,26 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl @Override public void controlLoopElementStateChange(ToscaConceptIdentifier controlLoopId, UUID controlLoopElementId, ControlLoopState currentState, ControlLoopOrderedState newState) throws PfModelException { - // Implementation not needed for http participant + switch (newState) { + case UNINITIALISED: + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.UNINITIALISED, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + break; + case PASSIVE: + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.PASSIVE, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + break; + case RUNNING: + intermediaryApi.updateControlLoopElementState(controlLoopId, + controlLoopElementId, newState, ControlLoopState.RUNNING, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + break; + default: + LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState); + break; + } } /** @@ -108,6 +128,9 @@ public class ControlLoopElementHandler implements ControlLoopElementListener, Cl .getValidator().validate(configRequest); if (violations.isEmpty()) { invokeHttpClient(configRequest); + intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), + ControlLoopOrderedState.PASSIVE, ControlLoopState.PASSIVE, + ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); } else { LOGGER.error("Violations found in the config request parameters: {}", violations); throw new ValidationException("Constraint violations in the config request"); diff --git a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java index 0de25072d..d1556ea08 100644 --- a/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java +++ b/participant/participant-impl/participant-impl-http/src/test/java/handler/ClElementHandlerTest.java @@ -29,9 +29,11 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Spy; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; import org.onap.policy.clamp.controlloop.participant.http.main.handler.ControlLoopElementHandler; +import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -46,6 +48,9 @@ class ClElementHandlerTest { @Spy private ControlLoopElementHandler controlLoopElementHandler = new ControlLoopElementHandler(); + @Mock + private ParticipantIntermediaryApi participantIntermediaryApi; + private CommonTestData commonTestData = new CommonTestData(); private static ToscaServiceTemplate serviceTemplate; diff --git a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java index a5d1f8841..e1e9195eb 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/main/java/org/onap/policy/clamp/controlloop/participant/kubernetes/handler/ControlLoopElementHandler.java @@ -103,7 +103,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { chartMap.remove(controlLoopElementId); podStatusMap.remove(chart.getReleaseName()); } catch (ServiceException se) { - LOGGER.warn("deletion of Helm deployment failed", se); + LOGGER.warn("Deletion of Helm deployment failed", se); } } break; @@ -118,7 +118,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); break; default: - LOGGER.warn("cannot transition from state {} to state {}", currentState, newState); + LOGGER.warn("Cannot transition from state {} to state {}", currentState, newState); break; } } @@ -148,7 +148,7 @@ public class ControlLoopElementHandler implements ControlLoopElementListener { checkPodStatus(chartInfo, config.uninitializedToPassiveTimeout, config.podStatusCheckInterval); intermediaryApi.updateControlLoopElementState(controlLoopId, element.getId(), - ControlLoopOrderedState.PASSIVE, ControlLoopState.UNINITIALISED, + ControlLoopOrderedState.PASSIVE, ControlLoopState.PASSIVE, ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); } catch (ServiceException | CoderException | IOException e) { 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 40dc901db..ac135b0d3 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 @@ -169,7 +169,7 @@ public class ControlLoopHandler { var controlLoop = controlLoopMap.get(stateChangeMsg.getControlLoopId()); if (controlLoop == null) { - var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK); controlLoopAck.setParticipantId(participantId); controlLoopAck.setParticipantType(participantType); controlLoopAck.setMessage("Control loop " + stateChangeMsg.getControlLoopId() @@ -368,7 +368,7 @@ public class ControlLoopHandler { private void handleStateChange(ControlLoop controlLoop, final ControlLoopOrderedState orderedState) { if (orderedState.equals(controlLoop.getOrderedState())) { - var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); + var controlLoopAck = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK); controlLoopAck.setParticipantId(participantId); controlLoopAck.setParticipantType(participantType); controlLoopAck.setMessage("Control loop is already in state " + orderedState); 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 ea7d84501..0734cb9c7 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 @@ -262,14 +262,19 @@ public class ParticipantHandler { public void handleParticipantRegisterAck(ParticipantRegisterAck participantRegisterAckMsg) { LOGGER.debug("ParticipantRegisterAck message received as responseTo {}", participantRegisterAckMsg.getResponseTo()); + statusToPassive(); + publisher.sendParticipantStatus(makeHeartbeat(false)); + } + + private void statusToPassive() { if (ParticipantHealthStatus.UNKNOWN.equals(this.healthStatus)) { this.healthStatus = ParticipantHealthStatus.HEALTHY; } - if (ParticipantState.UNKNOWN.equals(this.state)) { + if (ParticipantState.UNKNOWN.equals(this.state) || ParticipantState.TERMINATED.equals(this.state)) { this.state = ParticipantState.PASSIVE; } - publisher.sendParticipantStatus(makeHeartbeat(false)); + } /** @@ -303,6 +308,7 @@ public class ParticipantHandler { participantUpdateMsg.getParticipantId()); if (!participantUpdateMsg.getParticipantDefinitionUpdates().isEmpty()) { + statusToPassive(); // This message is to commission the controlloop for (ParticipantDefinition participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) { if (participantDefinition.getParticipantType().equals(participantType)) { @@ -311,7 +317,7 @@ public class ParticipantHandler { } } } else { - // This message is to decommision the controlloop + // This message is to decommission the controlloop clElementDefsOnThisParticipant.clear(); this.state = ParticipantState.TERMINATED; } @@ -374,12 +380,12 @@ public class ParticipantHandler { private List<ControlLoopInfo> getControlLoopInfoList() { List<ControlLoopInfo> controlLoopInfoList = new ArrayList<>(); - for (Map.Entry<ToscaConceptIdentifier, ControlLoop> entry : controlLoopHandler.getControlLoopMap().entrySet()) { - ControlLoopInfo clInfo = new ControlLoopInfo(); + for (var entry : controlLoopHandler.getControlLoopMap().entrySet()) { + var clInfo = new ControlLoopInfo(); clInfo.setControlLoopId(entry.getKey()); - ControlLoopStatistics clStatitistics = new ControlLoopStatistics(); + var clStatitistics = new ControlLoopStatistics(); clStatitistics.setControlLoopId(entry.getKey()); - ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList(); + var clElementStatisticsList = new ClElementStatisticsList(); clElementStatisticsList .setClElementStatistics(entry.getValue().getElements().values() .stream() diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java index 20292633b..a031cfaf6 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandler.java @@ -41,6 +41,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessage; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck; @@ -145,7 +146,11 @@ public class SupervisionHandler { */ public void handleParticipantMessage(ParticipantRegister participantRegisterMessage) { LOGGER.debug("Participant Register received {}", participantRegisterMessage); - + try { + checkParticipant(participantRegisterMessage, ParticipantState.UNKNOWN, ParticipantHealthStatus.UNKNOWN); + } catch (PfModelException | ControlLoopException svExc) { + LOGGER.warn("error saving participant {}", participantRegisterMessage.getParticipantId(), svExc); + } participantRegisterAckPublisher.send(participantRegisterMessage.getMessageId(), participantRegisterMessage.getParticipantId(), participantRegisterMessage.getParticipantType()); } @@ -160,8 +165,8 @@ public class SupervisionHandler { LOGGER.debug("Participant Deregister received {}", participantDeregisterMessage); try { var participantList = - participantProvider.getParticipants(participantDeregisterMessage.getParticipantId().getName(), - participantDeregisterMessage.getParticipantId().getVersion()); + participantProvider.getParticipants(participantDeregisterMessage.getParticipantId().getName(), + participantDeregisterMessage.getParticipantId().getVersion()); if (participantList != null) { for (Participant participant : participantList) { @@ -171,7 +176,8 @@ public class SupervisionHandler { participantProvider.updateParticipants(participantList); } } catch (PfModelException pfme) { - LOGGER.warn("Model exception occured {}", participantDeregisterMessage.getParticipantId()); + LOGGER.warn("Model exception occured with participant id {}", + participantDeregisterMessage.getParticipantId()); } participantDeregisterAckPublisher.send(participantDeregisterMessage.getMessageId()); @@ -187,8 +193,8 @@ public class SupervisionHandler { LOGGER.debug("Participant Update Ack received {}", participantUpdateAckMessage); try { var participantList = - participantProvider.getParticipants(participantUpdateAckMessage.getParticipantId().getName(), - participantUpdateAckMessage.getParticipantId().getVersion()); + participantProvider.getParticipants(participantUpdateAckMessage.getParticipantId().getName(), + participantUpdateAckMessage.getParticipantId().getVersion()); if (participantList != null) { for (Participant participant : participantList) { @@ -199,7 +205,8 @@ public class SupervisionHandler { LOGGER.warn("Participant not found in database {}", participantUpdateAckMessage.getParticipantId()); } } catch (PfModelException pfme) { - LOGGER.warn("Model exception occured {}", participantUpdateAckMessage.getParticipantId()); + LOGGER.warn("Model exception occured with participant id {}", + participantUpdateAckMessage.getParticipantId()); } } @@ -248,9 +255,8 @@ public class SupervisionHandler { try { var controlLoop = controlLoopProvider.getControlLoop(controlLoopAckMessage.getControlLoopId()); if (controlLoop != null) { - var updated = updateState(controlLoop, controlLoopAckMessage - .getControlLoopResultMap().entrySet()) - || setPrimed(controlLoop); + var updated = updateState(controlLoop, controlLoopAckMessage.getControlLoopResultMap().entrySet()); + updated |= setPrimed(controlLoop); if (updated) { controlLoopProvider.updateControlLoop(controlLoop); } @@ -258,13 +264,13 @@ public class SupervisionHandler { LOGGER.warn("ControlLoop not found in database {}", controlLoopAckMessage.getControlLoopId()); } } catch (PfModelException pfme) { - LOGGER.warn("Model exception occured {}", controlLoopAckMessage.getControlLoopId()); + LOGGER.warn("Model exception occured with ControlLoop Id {}", controlLoopAckMessage.getControlLoopId()); } } } - private boolean updateState(ControlLoop controlLoop, Set<Map.Entry<UUID, ControlLoopElementAck>> - controlLoopResultSet) { + private boolean updateState(ControlLoop controlLoop, + Set<Map.Entry<UUID, ControlLoopElementAck>> controlLoopResultSet) { var updated = false; for (var clElementAck : controlLoopResultSet) { var element = controlLoop.getElements().get(clElementAck.getKey()); @@ -281,8 +287,9 @@ public class SupervisionHandler { if (clElements != null) { Boolean primedFlag = true; var checkOpt = controlLoop.getElements().values().stream() - .filter(clElement -> (!clElement.getState().equals(ControlLoopState.PASSIVE) - || !clElement.getState().equals(ControlLoopState.RUNNING))).findAny(); + .filter(clElement -> (!clElement.getState().equals(ControlLoopState.PASSIVE) + || !clElement.getState().equals(ControlLoopState.RUNNING))) + .findAny(); if (checkOpt.isEmpty()) { primedFlag = false; } @@ -351,8 +358,7 @@ public class SupervisionHandler { } } - private void superviseControlLoopPassivation(ControlLoop controlLoop) - throws ControlLoopException { + private void superviseControlLoopPassivation(ControlLoop controlLoop) throws ControlLoopException { switch (controlLoop.getState()) { case PASSIVE: exceptionOccured(Response.Status.NOT_ACCEPTABLE, @@ -405,34 +411,39 @@ public class SupervisionHandler { } } - private void superviseParticipant(ParticipantStatus participantStatusMessage) - throws PfModelException, ControlLoopException { - if (participantStatusMessage.getParticipantId() == null) { + private void checkParticipant(ParticipantMessage participantMessage, ParticipantState participantState, + ParticipantHealthStatus healthStatus) throws ControlLoopException, PfModelException { + if (participantMessage.getParticipantId() == null) { exceptionOccured(Response.Status.NOT_FOUND, "Participant ID on PARTICIPANT_STATUS message is null"); } - - List<Participant> participantList = - participantProvider.getParticipants(participantStatusMessage.getParticipantId().getName(), - participantStatusMessage.getParticipantId().getVersion()); + List<Participant> participantList = participantProvider.getParticipants( + participantMessage.getParticipantId().getName(), participantMessage.getParticipantId().getVersion()); if (CollectionUtils.isEmpty(participantList)) { var participant = new Participant(); - participant.setName(participantStatusMessage.getParticipantId().getName()); - participant.setVersion(participantStatusMessage.getParticipantId().getVersion()); - participant.setDefinition(participantStatusMessage.getParticipantId()); - participant.setParticipantType(participantStatusMessage.getParticipantType()); - participant.setParticipantState(participantStatusMessage.getState()); - participant.setHealthStatus(participantStatusMessage.getHealthStatus()); + participant.setName(participantMessage.getParticipantId().getName()); + participant.setVersion(participantMessage.getParticipantId().getVersion()); + participant.setDefinition(participantMessage.getParticipantId()); + participant.setParticipantType(participantMessage.getParticipantType()); + participant.setParticipantState(participantState); + participant.setHealthStatus(healthStatus); participantList.add(participant); participantProvider.createParticipants(participantList); } else { for (Participant participant : participantList) { - participant.setParticipantState(participantStatusMessage.getState()); - participant.setHealthStatus(participantStatusMessage.getHealthStatus()); + participant.setParticipantState(participantState); + participant.setHealthStatus(healthStatus); } participantProvider.updateParticipants(participantList); } + } + + private void superviseParticipant(ParticipantStatus participantStatusMessage) + throws PfModelException, ControlLoopException { + + checkParticipant(participantStatusMessage, participantStatusMessage.getState(), + participantStatusMessage.getHealthStatus()); monitoringProvider.createParticipantStatistics(List.of(participantStatusMessage.getParticipantStatistics())); } diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java index 684711677..df7efbe9c 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java @@ -22,7 +22,9 @@ package org.onap.policy.clamp.controlloop.runtime.supervision; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; @@ -53,11 +55,13 @@ import org.springframework.stereotype.Component; public class SupervisionScanner { private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class); - private HandleCounter<ToscaConceptIdentifier> controlLoopCounter = new HandleCounter<>(); - private HandleCounter<ToscaConceptIdentifier> participantStatusCounter = new HandleCounter<>(); - private HandleCounter<Pair<ToscaConceptIdentifier, ToscaConceptIdentifier>> participantUpdateCounter = + private final HandleCounter<ToscaConceptIdentifier> controlLoopCounter = new HandleCounter<>(); + private final HandleCounter<ToscaConceptIdentifier> participantStatusCounter = new HandleCounter<>(); + private final HandleCounter<Pair<ToscaConceptIdentifier, ToscaConceptIdentifier>> participantUpdateCounter = new HandleCounter<>(); + private final Map<ToscaConceptIdentifier, Integer> phaseMap = new HashMap<>(); + private final ControlLoopProvider controlLoopProvider; private final PolicyModelsProvider modelsProvider; private final ControlLoopStateChangePublisher controlLoopStateChangePublisher; @@ -224,7 +228,6 @@ public class SupervisionScanner { int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()); minSpNotCompleted = Math.min(minSpNotCompleted, startPhase); } - } if (completed) { @@ -239,7 +242,12 @@ public class SupervisionScanner { } else { LOGGER.debug("control loop scan: transition from state {} to {} not completed", controlLoop.getState(), controlLoop.getOrderedState()); - if (counterCheck) { + + if (minSpNotCompleted != phaseMap.getOrDefault(controlLoop.getKey().asIdentifier(), 0) + && ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) { + phaseMap.put(controlLoop.getKey().asIdentifier(), minSpNotCompleted); + sendControlLoopMsg(controlLoop, minSpNotCompleted); + } else if (counterCheck) { handleCounter(controlLoop, minSpNotCompleted); } } @@ -247,6 +255,7 @@ public class SupervisionScanner { private void clearFaultAndCounter(ControlLoop controlLoop) { controlLoopCounter.clear(controlLoop.getKey().asIdentifier()); + phaseMap.clear(); } private void handleCounter(ControlLoop controlLoop, int startPhase) { @@ -258,17 +267,22 @@ public class SupervisionScanner { if (controlLoopCounter.getDuration(id) > controlLoopCounter.getMaxWaitMs()) { if (controlLoopCounter.count(id)) { - if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) { - LOGGER.debug("retry message ControlLoopUpdate"); - controlLoopUpdatePublisher.send(controlLoop, startPhase); - } else { - LOGGER.debug("retry message ControlLoopStateChange"); - controlLoopStateChangePublisher.send(controlLoop); - } + phaseMap.put(id, startPhase); + sendControlLoopMsg(controlLoop, startPhase); } else { LOGGER.debug("report ControlLoop fault"); controlLoopCounter.setFault(id); } } } + + private void sendControlLoopMsg(ControlLoop controlLoop, int startPhase) { + if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) { + LOGGER.debug("retry message ControlLoopUpdate"); + controlLoopUpdatePublisher.send(controlLoop, startPhase); + } else { + LOGGER.debug("retry message ControlLoopStateChange"); + controlLoopStateChangePublisher.send(controlLoop); + } + } } diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java index 3e038f3fc..b0ea00913 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java @@ -35,12 +35,11 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup; import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; -import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -56,9 +55,8 @@ class CommissioningProviderTest { private static final String TOSCA_SERVICE_TEMPLATE_YAML = "src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml"; private static final String COMMON_TOSCA_SERVICE_TEMPLATE_YAML = - "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml"; + "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml"; private static final String TEMPLATE_IS_NULL = ".*serviceTemplate is marked non-null but is null"; - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); private PolicyModelsProvider modelsProvider = null; private ControlLoopProvider clProvider = null; @@ -92,10 +90,9 @@ class CommissioningProviderTest { clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); - CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider, - null, participantProvider); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + CommissioningProvider provider = + new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); + ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null); assertThat(listOfTemplates).isEmpty(); @@ -131,15 +128,14 @@ class CommissioningProviderTest { clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); - CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider, - null, participantProvider); + CommissioningProvider provider = + new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); // Test Service template is null assertThatThrownBy(() -> provider.createControlLoopDefinitions(null)).hasMessageMatching(TEMPLATE_IS_NULL); List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null); assertThat(listOfTemplates).isEmpty(); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); // Response should return the number of node templates present in the service template List<ToscaConceptIdentifier> affectedDefinitions = @@ -158,23 +154,22 @@ class CommissioningProviderTest { void testGetToscaServiceTemplate() throws Exception { ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions"); modelsProvider = - CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); + CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); - CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider, - null, participantProvider); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils - .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + CommissioningProvider provider = + new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); + ToscaServiceTemplate serviceTemplate = + InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML); provider.createControlLoopDefinitions(serviceTemplate); ToscaServiceTemplate returnedServiceTemplate = provider.getToscaServiceTemplate(null, null); assertThat(returnedServiceTemplate).isNotNull(); - Map<String, ToscaNodeTemplate> nodeTemplates = returnedServiceTemplate - .getToscaTopologyTemplate().getNodeTemplates(); + Map<String, ToscaNodeTemplate> nodeTemplates = + returnedServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(); assertThat(nodeTemplates).hasSize(8); } @@ -188,15 +183,14 @@ class CommissioningProviderTest { void testGetToscaServiceTemplateReduced() throws Exception { ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions"); modelsProvider = - CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); + CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); - CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider, - null, participantProvider); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils - .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + CommissioningProvider provider = + new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); + ToscaServiceTemplate serviceTemplate = + InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML); provider.createControlLoopDefinitions(serviceTemplate); @@ -218,29 +212,23 @@ class CommissioningProviderTest { ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions"); modelsProvider = - CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); + CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); - CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider, - null, participantProvider); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils - .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + CommissioningProvider provider = + new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); + ToscaServiceTemplate serviceTemplate = + InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML); provider.createControlLoopDefinitions(serviceTemplate); mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); - Map<String, Class<?>> sections = Map.of( - "all", ToscaServiceTemplate.class, - "data_types", ToscaDataType.class, - "capability_types", ToscaCapabilityType.class, - "node_types", ToscaNodeType.class, - "relationship_types", ToscaRelationshipType.class, - "policy_types", ToscaPolicyType.class, - "topology_template", ToscaTopologyTemplate.class, - "node_templates", List.class); + Map<String, Class<?>> sections = Map.of("all", ToscaServiceTemplate.class, "data_types", ToscaDataType.class, + "capability_types", ToscaCapabilityType.class, "node_types", ToscaNodeType.class, "relationship_types", + ToscaRelationshipType.class, "policy_types", ToscaPolicyType.class, "topology_template", + ToscaTopologyTemplate.class, "node_templates", List.class); for (Map.Entry<String, Class<?>> entry : sections.entrySet()) { String returnedServiceTemplateSchema = provider.getToscaServiceTemplateSchema(entry.getKey()); @@ -250,8 +238,7 @@ class CommissioningProviderTest { if (entry.getKey().equals("node_templates")) { mapper.acceptJsonFormatVisitor( - mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class), - visitor); + mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class), visitor); } else { mapper.acceptJsonFormatVisitor(mapper.constructType(entry.getValue()), visitor); } @@ -275,10 +262,9 @@ class CommissioningProviderTest { clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); - CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider, - null, participantProvider); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + CommissioningProvider provider = + new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); + ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null); assertThat(listOfTemplates).isEmpty(); @@ -305,10 +291,9 @@ class CommissioningProviderTest { clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters()); - CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider, - null, participantProvider); - ToscaServiceTemplate serviceTemplate = yamlTranslator - .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); + CommissioningProvider provider = + new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); + ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); provider.getControlLoopDefinitions(null, null); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java index 481192927..4a5a6e2a3 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java @@ -40,10 +40,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.parallel.Execution; import org.junit.jupiter.api.parallel.ExecutionMode; import org.onap.policy.clamp.controlloop.models.messages.rest.commissioning.CommissioningResponse; +import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup; import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; -import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; @@ -64,8 +63,8 @@ class CommissioningControllerTest extends CommonRestController { private static final String TOSCA_SERVICE_TEMPLATE_YAML = "src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml"; private static final String COMMON_TOSCA_SERVICE_TEMPLATE_YAML = - "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml"; - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); + "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml"; + private static final String COMMISSIONING_ENDPOINT = "commission"; private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); private static ToscaServiceTemplate commonPropertiesServiceTemplate = new ToscaServiceTemplate(); @@ -84,11 +83,9 @@ class CommissioningControllerTest extends CommonRestController { @BeforeAll public static void setUpBeforeClass() throws Exception { - serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), - ToscaServiceTemplate.class); - commonPropertiesServiceTemplate = yamlTranslator.fromYaml(ResourceUtils - .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), - ToscaServiceTemplate.class); + serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + commonPropertiesServiceTemplate = + InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML); } @BeforeEach @@ -146,8 +143,7 @@ class CommissioningControllerTest extends CommonRestController { void testQueryToscaServiceTemplate() throws Exception { createFullEntryInDbWithCommonProps(); - Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT - + "/toscaservicetemplate"); + Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaservicetemplate"); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); ToscaServiceTemplate template = rawresp.readEntity(ToscaServiceTemplate.class); @@ -160,8 +156,8 @@ class CommissioningControllerTest extends CommonRestController { void testQueryToscaServiceTemplateSchema() throws Exception { createFullEntryInDbWithCommonProps(); - Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT - + "/toscaServiceTemplateSchema"); + Invocation.Builder invocationBuilder = + super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaServiceTemplateSchema"); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); String schema = rawresp.readEntity(String.class); @@ -174,7 +170,7 @@ class CommissioningControllerTest extends CommonRestController { createFullEntryInDbWithCommonProps(); Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT - + "/getCommonOrInstanceProperties" + "?common=true&name=ToscaServiceTemplateSimple&version=1.0.0"); + + "/getCommonOrInstanceProperties" + "?common=true&name=ToscaServiceTemplateSimple&version=1.0.0"); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); @@ -244,7 +240,7 @@ class CommissioningControllerTest extends CommonRestController { void testQueryElementsBadRequest() throws Exception { createEntryInDB(); - //Call get elements with no info + // Call get elements with no info Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements"); Response resp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), resp.getStatus()); @@ -255,8 +251,8 @@ class CommissioningControllerTest extends CommonRestController { void testQueryElements() throws Exception { createEntryInDB(); - Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements" - + "?name=org.onap.domain.pmsh.PMSHControlLoopDefinition"); + Invocation.Builder invocationBuilder = super.sendRequest( + COMMISSIONING_ENDPOINT + "/elements" + "?name=org.onap.domain.pmsh.PMSHControlLoopDefinition"); Response rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); List<?> entityList = rawresp.readEntity(List.class); @@ -270,7 +266,7 @@ class CommissioningControllerTest extends CommonRestController { createEntryInDB(); Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT); - //Call delete with no info + // Call delete with no info Response resp = invocationBuilder.delete(); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); @@ -282,7 +278,7 @@ class CommissioningControllerTest extends CommonRestController { Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "?name=" + serviceTemplate.getName() + "&version=" + serviceTemplate.getVersion()); - //Call delete with no info + // Call delete with no info Response resp = invocationBuilder.delete(); assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); @@ -305,7 +301,7 @@ class CommissioningControllerTest extends CommonRestController { // Delete entries from the DB after relevant tests private synchronized void deleteEntryInDB(String name, String version) throws Exception { try (PolicyModelsProvider modelsProvider = new PolicyModelsProviderFactory() - .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) { + .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) { if (!modelsProvider.getServiceTemplateList(null, null).isEmpty()) { modelsProvider.deleteServiceTemplate(name, version); } @@ -314,7 +310,7 @@ class CommissioningControllerTest extends CommonRestController { private synchronized void createFullEntryInDbWithCommonProps() throws Exception { try (PolicyModelsProvider modelsProvider = new PolicyModelsProviderFactory() - .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) { + .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) { deleteEntryInDB(commonPropertiesServiceTemplate.getName(), commonPropertiesServiceTemplate.getVersion()); modelsProvider.createServiceTemplate(commonPropertiesServiceTemplate); } diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java index 24272e308..abf0cfc3e 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java @@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.util.ArrayList; -import java.util.List; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -53,8 +52,6 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDer import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher; import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher; import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; -import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -97,8 +94,6 @@ class ControlLoopInstantiationProviderTest { private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - private static SupervisionHandler supervisionHandler; private static CommissioningProvider commissioningProvider; private static ControlLoopProvider clProvider; @@ -107,8 +102,7 @@ class ControlLoopInstantiationProviderTest { @BeforeAll public static void setUpBeforeClass() throws Exception { - serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_TEMPLATE_YAML), - ToscaServiceTemplate.class); + serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML); } /** diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java index c107986a5..5aa68657c 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java @@ -23,21 +23,18 @@ package org.onap.policy.clamp.controlloop.runtime.instantiation; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; -import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; -import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstancePropertiesResponse; import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand; import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse; -import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; +import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -47,7 +44,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; public class InstantiationUtils { private static final Coder CODER = new StandardCoder(); - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); + private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); /** * Gets the ControlLoops from Resource. @@ -128,20 +125,17 @@ public class InstantiationUtils { } /** - * Store ToscaServiceTemplate from resource to DB. + * Get ToscaServiceTemplate from resource. * * @param path path of the resource - * @param commissioningProvider The CommissioningProvider - * @throws PfModelException if an error occurs */ - public static void storeToscaServiceTemplate(String path, CommissioningProvider commissioningProvider) - throws PfModelException, ControlLoopException { + public static ToscaServiceTemplate getToscaServiceTemplate(String path) { - ToscaServiceTemplate template = - yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(path), ToscaServiceTemplate.class); - - commissioningProvider.deleteControlLoopDefinition(null, null); - - commissioningProvider.createControlLoopDefinitions(template); + try { + return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class); + } catch (CoderException e) { + fail("Cannot read or decode " + path); + return null; + } } } diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java index 5a15687c5..2e01be289 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java @@ -46,8 +46,6 @@ import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParame import org.onap.policy.clamp.controlloop.runtime.main.rest.InstantiationController; import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData; import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; -import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; @@ -87,9 +85,6 @@ class InstantiationControllerTest extends CommonRestController { private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - - @Autowired private ClRuntimeParameterGroup clRuntimeParameterGroup; @@ -104,8 +99,7 @@ class InstantiationControllerTest extends CommonRestController { @BeforeAll public static void setUpBeforeClass() throws Exception { - serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_TEMPLATE_YAML), - ToscaServiceTemplate.class); + serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML); } @BeforeEach diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java new file mode 100644 index 000000000..25ce61122 --- /dev/null +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionHandlerTest.java @@ -0,0 +1,270 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.controlloop.runtime.supervision; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyMap; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ControlLoopAck; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantStatus; +import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck; +import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils; +import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider; +import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher; +import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpdatePublisher; +import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDeregisterAckPublisher; +import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher; +import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class SupervisionHandlerTest { + private static final String CL_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/controlloops/ControlLoops.json"; + private static final ToscaConceptIdentifier identifier = new ToscaConceptIdentifier("PMSHInstance0Crud", "1.0.1"); + private static final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("ParticipantId", "1.0.0"); + private static final ToscaConceptIdentifier participantType = + new ToscaConceptIdentifier("ParticipantType", "1.0.0"); + + @Test + void testTriggerControlLoopSupervisionEmpty() throws ControlLoopException, PfModelException, CoderException { + var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class), + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class), + mock(ParticipantUpdatePublisher.class)); + + assertThatThrownBy(() -> handler.triggerControlLoopSupervision(List.of())) + .hasMessageMatching("The list of control loops for supervision is empty"); + } + + @Test + void testTriggerControlLoopSupervision() throws ControlLoopException, PfModelException, CoderException { + var controlLoopProvider = mock(ControlLoopProvider.class); + var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class); + var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class), + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), controlLoopUpdatePublisher, + mock(ParticipantUpdatePublisher.class)); + + handler.triggerControlLoopSupervision(List.of(identifier)); + + verify(controlLoopUpdatePublisher).send(any(ControlLoop.class)); + verify(controlLoopProvider).updateControlLoop(any(ControlLoop.class)); + } + + @Test + void testHandleControlLoopStateChangeAckMessage() throws PfModelException, CoderException { + var controlLoopProvider = mock(ControlLoopProvider.class); + var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class), + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class), + mock(ParticipantUpdatePublisher.class)); + var controlLoopAckMessage = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_STATECHANGE_ACK); + controlLoopAckMessage.setControlLoopResultMap(Map.of()); + controlLoopAckMessage.setControlLoopId(identifier); + + handler.handleControlLoopStateChangeAckMessage(controlLoopAckMessage); + + verify(controlLoopProvider).updateControlLoop(any(ControlLoop.class)); + } + + @Test + void testHandleControlLoopUpdateAckMessage() throws PfModelException, CoderException { + var controlLoopAckMessage = new ControlLoopAck(ParticipantMessageType.CONTROLLOOP_UPDATE_ACK); + controlLoopAckMessage.setParticipantId(participantId); + controlLoopAckMessage.setParticipantType(participantType); + controlLoopAckMessage.setControlLoopResultMap(Map.of()); + controlLoopAckMessage.setControlLoopId(identifier); + var controlLoopProvider = mock(ControlLoopProvider.class); + var handler = createSupervisionHandler(controlLoopProvider, mock(ParticipantProvider.class), + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class), + mock(ParticipantUpdatePublisher.class)); + + handler.handleControlLoopUpdateAckMessage(controlLoopAckMessage); + + verify(controlLoopProvider).updateControlLoop(any(ControlLoop.class)); + } + + @Test + void testHandleParticipantDeregister() throws PfModelException, CoderException { + var participant = new Participant(); + participant.setName(participantId.getName()); + participant.setVersion(participantId.getVersion()); + participant.setParticipantType(participantType); + + var participantProvider = mock(ParticipantProvider.class); + when(participantProvider.getParticipants(eq(participantId.getName()), eq(participantId.getVersion()))) + .thenReturn(List.of(participant)); + + var participantDeregisterMessage = new ParticipantDeregister(); + participantDeregisterMessage.setMessageId(UUID.randomUUID()); + participantDeregisterMessage.setParticipantId(participantId); + participantDeregisterMessage.setParticipantType(participantType); + var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class); + var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider, + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + participantDeregisterAckPublisher, mock(ControlLoopUpdatePublisher.class), + mock(ParticipantUpdatePublisher.class)); + + handler.handleParticipantMessage(participantDeregisterMessage); + + verify(participantProvider).updateParticipants(anyList()); + verify(participantDeregisterAckPublisher).send(eq(participantDeregisterMessage.getMessageId())); + } + + @Test + void testHandleParticipantRegister() throws PfModelException, CoderException { + var participant = new Participant(); + participant.setName(participantId.getName()); + participant.setVersion(participantId.getVersion()); + participant.setParticipantType(participantType); + + var participantRegisterMessage = new ParticipantRegister(); + participantRegisterMessage.setMessageId(UUID.randomUUID()); + participantRegisterMessage.setParticipantId(participantId); + participantRegisterMessage.setParticipantType(participantType); + var participantProvider = mock(ParticipantProvider.class); + var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class); + var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider, + mock(MonitoringProvider.class), participantRegisterAckPublisher, + mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class), + mock(ParticipantUpdatePublisher.class)); + + handler.handleParticipantMessage(participantRegisterMessage); + + verify(participantProvider).createParticipants(anyList()); + verify(participantRegisterAckPublisher).send(eq(participantRegisterMessage.getMessageId()), eq(participantId), + eq(participantType)); + } + + @Test + void testParticipantUpdateAck() throws PfModelException, CoderException { + var participant = new Participant(); + participant.setName(participantId.getName()); + participant.setVersion(participantId.getVersion()); + participant.setParticipantType(participantType); + + var participantProvider = mock(ParticipantProvider.class); + when(participantProvider.getParticipants(eq(participantId.getName()), eq(participantId.getVersion()))) + .thenReturn(List.of(participant)); + + var participantUpdateAckMessage = new ParticipantUpdateAck(); + participantUpdateAckMessage.setParticipantId(participantId); + participantUpdateAckMessage.setParticipantType(participantType); + participantUpdateAckMessage.setState(ParticipantState.PASSIVE); + var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider, + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class), + mock(ParticipantUpdatePublisher.class)); + + handler.handleParticipantMessage(participantUpdateAckMessage); + + verify(participantProvider).updateParticipants(anyList()); + } + + @Test + void testHandleParticipantStatus() throws PfModelException, CoderException { + var participantStatusMessage = new ParticipantStatus(); + participantStatusMessage.setParticipantId(participantId); + participantStatusMessage.setParticipantType(participantType); + participantStatusMessage.setState(ParticipantState.PASSIVE); + participantStatusMessage.setHealthStatus(ParticipantHealthStatus.HEALTHY); + participantStatusMessage.setParticipantStatistics(new ParticipantStatistics()); + + var participantProvider = mock(ParticipantProvider.class); + var monitoringProvider = mock(MonitoringProvider.class); + var handler = createSupervisionHandler(mock(ControlLoopProvider.class), participantProvider, monitoringProvider, + mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), + mock(ControlLoopUpdatePublisher.class), mock(ParticipantUpdatePublisher.class)); + handler.handleParticipantMessage(participantStatusMessage); + + verify(participantProvider).createParticipants(anyList()); + verify(monitoringProvider).createParticipantStatistics(anyList()); + } + + @Test + void testHandleSendCommissionMessage() throws PfModelException, CoderException { + var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); + var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class), + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class), + participantUpdatePublisher); + handler.handleSendCommissionMessage(Map.of()); + + verify(participantUpdatePublisher).send(anyMap(), eq(true)); + } + + @Test + void testHandleSendDeCommissionMessage() throws PfModelException, CoderException { + var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); + var handler = createSupervisionHandler(mock(ControlLoopProvider.class), mock(ParticipantProvider.class), + mock(MonitoringProvider.class), mock(ParticipantRegisterAckPublisher.class), + mock(ParticipantDeregisterAckPublisher.class), mock(ControlLoopUpdatePublisher.class), + participantUpdatePublisher); + handler.handleSendDeCommissionMessage(); + + verify(participantUpdatePublisher).send(anyMap(), eq(false)); + } + + private SupervisionHandler createSupervisionHandler(ControlLoopProvider controlLoopProvider, + ParticipantProvider participantProvider, MonitoringProvider monitoringProvider, + ParticipantRegisterAckPublisher participantRegisterAckPublisher, + ParticipantDeregisterAckPublisher participantDeregisterAckPublisher, + ControlLoopUpdatePublisher controlLoopUpdatePublisher, + ParticipantUpdatePublisher participantUpdatePublisher) throws PfModelException, CoderException { + var controlLoopsCreate = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Crud"); + + var controlLoop = controlLoopsCreate.getControlLoopList().get(0); + controlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE); + + var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class); + + when(controlLoopProvider.getControlLoop(eq(identifier))).thenReturn(controlLoop); + + return new SupervisionHandler(controlLoopProvider, participantProvider, monitoringProvider, + controlLoopUpdatePublisher, controlLoopStateChangePublisher, participantRegisterAckPublisher, + participantDeregisterAckPublisher, participantUpdatePublisher); + + } +} diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java index 1bf445734..47cc6f1dc 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java @@ -22,6 +22,7 @@ package org.onap.policy.clamp.controlloop.runtime.supervision; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -40,6 +41,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; +import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher; import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpdatePublisher; import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusReqPublisher; @@ -52,6 +54,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; class SupervisionScannerTest { + private static final String TOSCA_SERVICE_TEMPLATE_YAML = + "src/test/resources/rest/servicetemplates/tosca-for-smoke-testing.yaml"; + @Test void testScannerOrderedStateEqualsToState() throws PfModelException { var controlLoopProvider = mock(ControlLoopProvider.class); @@ -131,6 +136,50 @@ class SupervisionScannerTest { } @Test + void testSendControlLoopMsgUpdate() throws PfModelException { + var controlLoop = new ControlLoop(); + controlLoop.setState(ControlLoopState.UNINITIALISED2PASSIVE); + controlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE); + controlLoop.setElements(Map.of(UUID.randomUUID(), + createHttpElement(ControlLoopState.UNINITIALISED, ControlLoopOrderedState.PASSIVE))); + + var controlLoopProvider = mock(ControlLoopProvider.class); + when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop)); + + ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + var modelsProvider = mock(PolicyModelsProvider.class); + when(modelsProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate)); + + var participantProvider = mock(ParticipantProvider.class); + var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class); + var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class); + var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class); + var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); + var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner"); + + var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider, + controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider, + participantStatusReqPublisher, participantUpdatePublisher, clRuntimeParameterGroup); + + supervisionScanner.run(false); + + verify(controlLoopUpdatePublisher).send(any(ControlLoop.class), anyInt()); + } + + private ControlLoopElement createHttpElement(ControlLoopState state, ControlLoopOrderedState orderedState) { + var element = new ControlLoopElement(); + element.setDefinition(new ToscaConceptIdentifier( + "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement", "1.2.3")); + element.setState(state); + element.setOrderedState(orderedState); + element.setParticipantId(new ToscaConceptIdentifier("HttpParticipant0", "1.0.0")); + element.setParticipantType( + new ToscaConceptIdentifier("org.onap.k8s.controlloop.HttpControlLoopParticipant", "2.3.4")); + + return element; + } + + @Test void testScanParticipant() throws PfModelException { var controlLoopProvider = mock(ControlLoopProvider.class); var controlLoop = new ControlLoop(); diff --git a/runtime-controlloop/src/test/resources/rest/servicetemplates/tosca-for-smoke-testing.yaml b/runtime-controlloop/src/test/resources/rest/servicetemplates/tosca-for-smoke-testing.yaml new file mode 100644 index 000000000..f69755e2b --- /dev/null +++ b/runtime-controlloop/src/test/resources/rest/servicetemplates/tosca-for-smoke-testing.yaml @@ -0,0 +1,966 @@ +tosca_definitions_version: tosca_simple_yaml_1_3 +data_types: + onap.datatypes.ToscaConceptIdentifier: + derived_from: tosca.datatypes.Root + properties: + name: + type: string + required: true + version: + type: string + required: true + onap.datatype.controlloop.Target: + derived_from: tosca.datatypes.Root + description: Definition for a entity in A&AI to perform a control loop operation on + properties: + targetType: + type: string + description: Category for the target type + required: true + constraints: + - valid_values: + - VNF + - VM + - VFMODULE + - PNF + entityIds: + type: map + description: | + Map of values that identify the resource. If none are provided, it is assumed that the + entity that generated the ONSET event will be the target. + required: false + metadata: + clamp_possible_values: ClampExecution:CSAR_RESOURCES + entry_schema: + type: string + onap.datatype.controlloop.Actor: + derived_from: tosca.datatypes.Root + description: An actor/operation/target definition + properties: + actor: + type: string + description: The actor performing the operation. + required: true + metadata: + clamp_possible_values: Dictionary:DefaultActors,ClampExecution:CDS/actor + operation: + type: string + description: The operation the actor is performing. + metadata: + clamp_possible_values: Dictionary:DefaultOperations,ClampExecution:CDS/operation + required: true + target: + type: onap.datatype.controlloop.Target + description: The resource the operation should be performed on. + required: true + payload: + type: map + description: Name/value pairs of payload information passed by Policy to the actor + required: false + metadata: + clamp_possible_values: ClampExecution:CDS/payload + entry_schema: + type: string + onap.datatype.controlloop.Operation: + derived_from: tosca.datatypes.Root + description: An operation supported by an actor + properties: + id: + type: string + description: Unique identifier for the operation + required: true + description: + type: string + description: A user-friendly description of the intent for the operation + required: false + operation: + type: onap.datatype.controlloop.Actor + description: The definition of the operation to be performed. + required: true + timeout: + type: integer + description: The amount of time for the actor to perform the operation. + required: true + retries: + type: integer + description: The number of retries the actor should attempt to perform the operation. + required: true + default: 0 + success: + type: string + description: Points to the operation to invoke on success. A value of "final_success" indicates and end to the operation. + required: false + default: final_success + failure: + type: string + description: Points to the operation to invoke on Actor operation failure. + required: false + default: final_failure + failure_timeout: + type: string + description: Points to the operation to invoke when the time out for the operation occurs. + required: false + default: final_failure_timeout + failure_retries: + type: string + description: Points to the operation to invoke when the current operation has exceeded its max retries. + required: false + default: final_failure_retries + failure_exception: + type: string + description: Points to the operation to invoke when the current operation causes an exception. + required: false + default: final_failure_exception + failure_guard: + type: string + description: Points to the operation to invoke when the current operation is blocked due to guard policy enforcement. + required: false + default: final_failure_guard + onap.datatypes.monitoring.managedObjectDNsBasic: + constraints: [] + properties: + DN: + name: DN + type: string + typeVersion: 0.0.0 + description: Managed object distinguished name + required: true + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.managedObjectDNsBasic + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + onap.datatypes.monitoring.managedObjectDNsBasics: + constraints: [] + properties: + managedObjectDNsBasic: + name: managedObjectDNsBasic + type: map + typeVersion: 0.0.0 + description: Managed object distinguished name object + required: true + constraints: [] + entry_schema: + type: onap.datatypes.monitoring.managedObjectDNsBasic + typeVersion: 0.0.0 + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.managedObjectDNsBasics + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + onap.datatypes.monitoring.measurementGroup: + constraints: [] + properties: + measurementTypes: + name: measurementTypes + type: list + typeVersion: 0.0.0 + description: List of measurement types + required: true + constraints: [] + entry_schema: + type: onap.datatypes.monitoring.measurementTypes + typeVersion: 0.0.0 + constraints: [] + metadata: {} + managedObjectDNsBasic: + name: managedObjectDNsBasic + type: list + typeVersion: 0.0.0 + description: List of managed object distinguished names + required: true + constraints: [] + entry_schema: + type: onap.datatypes.monitoring.managedObjectDNsBasics + typeVersion: 0.0.0 + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.measurementGroup + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + onap.datatypes.monitoring.measurementGroups: + constraints: [] + properties: + measurementGroup: + name: measurementGroup + type: map + typeVersion: 0.0.0 + description: Measurement Group + required: true + constraints: [] + entry_schema: + type: onap.datatypes.monitoring.measurementGroup + typeVersion: 0.0.0 + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.measurementGroups + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + onap.datatypes.monitoring.measurementType: + constraints: [] + properties: + measurementType: + name: measurementType + type: string + typeVersion: 0.0.0 + description: Measurement type + required: true + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.measurementType + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + onap.datatypes.monitoring.measurementTypes: + constraints: [] + properties: + measurementType: + name: measurementType + type: map + typeVersion: 0.0.0 + description: Measurement type object + required: true + constraints: [] + entry_schema: + type: onap.datatypes.monitoring.measurementType + typeVersion: 0.0.0 + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.measurementTypes + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + onap.datatypes.monitoring.nfFilter: + constraints: [] + properties: + modelNames: + name: modelNames + type: list + typeVersion: 0.0.0 + description: List of model names + required: true + constraints: [] + entry_schema: + type: string + typeVersion: 0.0.0 + constraints: [] + metadata: {} + modelInvariantIDs: + name: modelInvariantIDs + type: list + typeVersion: 0.0.0 + description: List of model invariant IDs + required: true + constraints: [] + entry_schema: + type: string + typeVersion: 0.0.0 + constraints: [] + metadata: {} + modelVersionIDs: + name: modelVersionIDs + type: list + typeVersion: 0.0.0 + description: List of model version IDs + required: true + constraints: [] + entry_schema: + type: string + typeVersion: 0.0.0 + constraints: [] + metadata: {} + nfNames: + name: nfNames + type: list + typeVersion: 0.0.0 + description: List of network functions + required: true + constraints: [] + entry_schema: + type: string + typeVersion: 0.0.0 + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.nfFilter + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + onap.datatypes.monitoring.subscription: + constraints: [] + properties: + measurementGroups: + name: measurementGroups + type: list + typeVersion: 0.0.0 + description: Measurement Groups + required: true + constraints: [] + entry_schema: + type: onap.datatypes.monitoring.measurementGroups + typeVersion: 0.0.0 + constraints: [] + metadata: {} + fileBasedGP: + name: fileBasedGP + type: integer + typeVersion: 0.0.0 + description: File based granularity period + required: true + constraints: [] + metadata: {} + fileLocation: + name: fileLocation + type: string + typeVersion: 0.0.0 + description: ROP file location + required: true + constraints: [] + metadata: {} + subscriptionName: + name: subscriptionName + type: string + typeVersion: 0.0.0 + description: Name of the subscription + required: true + constraints: [] + metadata: {} + administrativeState: + name: administrativeState + type: string + typeVersion: 0.0.0 + description: State of the subscription + required: true + constraints: + - valid_values: + - LOCKED + - UNLOCKED + metadata: {} + nfFilter: + name: nfFilter + type: map + typeVersion: 0.0.0 + description: Network function filter + required: true + constraints: [] + entry_schema: + type: onap.datatypes.monitoring.nfFilter + typeVersion: 0.0.0 + constraints: [] + metadata: {} + name: onap.datatypes.monitoring.subscription + version: 0.0.0 + derived_from: tosca.datatypes.Root + metadata: {} + org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.RestRequest: + version: 1.0.0 + derived_from: tosca.datatypes.Root + properties: + restRequestId: + type: onap.datatypes.ToscaConceptIdentifier + typeVersion: 1.0.0 + required: true + description: The name and version of a REST request to be sent to a REST endpoint + httpMethod: + type: string + required: true + constraints: + - valid_values: [POST, PUT, GET, DELETE] + description: The REST method to use + path: + type: string + required: true + description: The path of the REST request relative to the base URL + body: + type: string + required: false + description: The body of the REST request for PUT and POST requests + expectedResponse: + type: integer + required: true + constraints: [] + description: THe expected HTTP status code for the REST request + org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.ConfigurationEntity: + version: 1.0.0 + derived_from: tosca.datatypes.Root + properties: + configurationEntityId: + type: onap.datatypes.ToscaConceptIdentifier + typeVersion: 1.0.0 + required: true + description: The name and version of a Configuration Entity to be handled by the HTTP Control Loop Element + restSequence: + type: list + entry_schema: + type: org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.RestRequest + typeVersion: 1.0.0 + description: A sequence of REST commands to send to the REST endpoint +policy_types: + onap.policies.Monitoring: + derived_from: tosca.policies.Root + description: a base policy type for all policies that govern monitoring provisioning + version: 1.0.0 + name: onap.policies.Monitoring + onap.policies.Sirisha: + derived_from: tosca.policies.Root + description: a base policy type for all policies that govern monitoring provisioning + version: 1.0.0 + name: onap.policies.Sirisha + onap.policies.monitoring.dcae-pm-subscription-handler: + properties: + pmsh_policy: + name: pmsh_policy + type: onap.datatypes.monitoring.subscription + typeVersion: 0.0.0 + description: PMSH Policy JSON + required: false + constraints: [] + metadata: {} + name: onap.policies.monitoring.dcae-pm-subscription-handler + version: 1.0.0 + derived_from: onap.policies.Monitoring + metadata: {} + onap.policies.controlloop.operational.Common: + derived_from: tosca.policies.Root + version: 1.0.0 + name: onap.policies.controlloop.operational.Common + description: | + Operational Policy for Control Loop execution. Originated in Frankfurt to support TOSCA Compliant + Policy Types. This does NOT support the legacy Policy YAML policy type. + properties: + id: + type: string + description: The unique control loop id. + required: true + timeout: + type: integer + description: | + Overall timeout for executing all the operations. This timeout should equal or exceed the total + timeout for each operation listed. + required: true + abatement: + type: boolean + description: Whether an abatement event message will be expected for the control loop from DCAE. + required: true + default: false + trigger: + type: string + description: Initial operation to execute upon receiving an Onset event message for the Control Loop. + required: true + operations: + type: list + description: List of operations to be performed when Control Loop is triggered. + required: true + entry_schema: + type: onap.datatype.controlloop.Operation + onap.policies.controlloop.operational.common.Apex: + derived_from: onap.policies.controlloop.operational.Common + type_version: 1.0.0 + version: 1.0.0 + name: onap.policies.controlloop.operational.common.Apex + description: Operational policies for Apex PDP + properties: + engineServiceParameters: + type: string + description: The engine parameters like name, instanceCount, policy implementation, parameters etc. + required: true + eventInputParameters: + type: string + description: The event input parameters. + required: true + eventOutputParameters: + type: string + description: The event output parameters. + required: true + javaProperties: + type: string + description: Name/value pairs of properties to be set for APEX if needed. + required: false +node_types: + org.onap.policy.clamp.controlloop.Participant: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + requred: false + org.onap.policy.clamp.controlloop.ControlLoopElement: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + required: false + metadata: + common: true + description: Specifies the organization that provides the control loop element + participant_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + metadata: + common: true + participantType: + type: onap.datatypes.ToscaConceptIdentifier + required: true + metadata: + common: true + description: The identity of the participant type that hosts this type of Control Loop Element + startPhase: + type: integer + required: false + constraints: + - greater_or_equal: 0 + metadata: + common: true + description: A value indicating the start phase in which this control loop element will be started, the + first start phase is zero. Control Loop Elements are started in their start_phase order and stopped + in reverse start phase order. Control Loop Elements with the same start phase are started and + stopped simultaneously + uninitializedToPassiveTimeout: + type: integer + required: false + constraints: + - greater_or_equal: 0 + default: 60 + metadata: + common: true + description: The maximum time in seconds to wait for a state chage from uninitialized to passive + passiveToRunningTimeout: + type: integer + required: false + constraints: + - greater_or_equal: 0 + default: 60 + metadata: + common: true + description: The maximum time in seconds to wait for a state chage from passive to running + runningToPassiveTimeout: + type: integer + required: false + constraints: + - greater_or_equal: 0 + default: 60 + metadata: + common: true + description: The maximum time in seconds to wait for a state chage from running to passive + passiveToUninitializedTimeout: + type: integer + required: false + constraints: + - greater_or_equal: 0 + default: 60 + metadata: + common: true + description: The maximum time in seconds to wait for a state chage from passive to uninitialized + org.onap.policy.clamp.controlloop.ControlLoop: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + required: false + metadata: + common: true + description: Specifies the organization that provides the control loop element + elements: + type: list + required: true + metadata: + common: true + entry_schema: + type: onap.datatypes.ToscaConceptIdentifier + description: Specifies a list of control loop element definitions that make up this control loop definition + org.onap.policy.clamp.controlloop.PolicyControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement + properties: + policy_type_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + policy_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: false + org.onap.policy.clamp.controlloop.DerivedPolicyControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.PolicyControlLoopElement + properties: + policy_type_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + policy_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: false + org.onap.policy.clamp.controlloop.DerivedDerivedPolicyControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.DerivedPolicyControlLoopElement + properties: + policy_type_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + policy_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: false + org.onap.policy.clamp.controlloop.CDSControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement + properties: + cds_blueprint_id: + type: onap.datatypes.ToscaConceptIdentifier + requred: true + org.onap.policy.clamp.controlloop.K8SMicroserviceControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement + properties: + chart: + type: string + required: true + configs: + type: list + required: false + requirements: + type: string + requred: false + templates: + type: list + required: false + entry_schema: + values: + type: string + requred: true + org.onap.policy.clamp.controlloop.HttpControlLoopElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement + properties: + baseUrl: + type: string + required: true + description: The base URL to be prepended to each path, identifies the host for the REST endpoints. + httpHeaders: + type: map + required: false + entry_schema: + type: string + description: HTTP headers to send on REST requests + configurationEntities: + type: map + required: true + entry_schema: + type: org.onap.datatypes.policy.clamp.controlloop.httpControlLoopElement.ConfigurationEntity + typeVersion: 1.0.0 + description: The connfiguration entities the Control Loop Element is managing and their associated REST requests + +topology_template: + inputs: + pmsh_monitoring_policy: + type: onap.datatypes.ToscaConceptIdentifier + description: The ID of the PMSH monitoring policy to use + default: + name: MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test + version: 1.0.0 + pmsh_operational_policy: + type: onap.datatypes.ToscaConceptIdentifier + description: The ID of the PMSH operational policy to use + default: + name: operational.apex.pmcontrol + version: 1.0.0 + node_templates: + org.onap.policy.controlloop.PolicyControlLoopParticipant: + version: 2.3.1 + type: org.onap.policy.clamp.controlloop.Participant + type_version: 1.0.1 + description: Participant for DCAE microservices + properties: + provider: ONAP + org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.PolicyControlLoopElement + type_version: 1.0.0 + description: Control loop element for the monitoring policy for Performance Management Subscription Handling + properties: + provider: Ericsson + participant_id: + name: org.onap.PM_Policy + version: 1.0.0 + participantType: + name: org.onap.policy.controlloop.PolicyControlLoopParticipant + version: 2.3.1 + policy_type_id: + name: onap.policies.monitoring.pm-subscription-handler + version: 1.0.0 + policy_id: + get_input: pmsh_monitoring_policy + org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.PolicyControlLoopElement + type_version: 1.0.0 + description: Control loop element for the operational policy for Performance Management Subscription Handling + properties: + provider: Ericsson + participant_id: + name: org.onap.PM_Policy + version: 1.0.0 + participantType: + name: org.onap.policy.controlloop.PolicyControlLoopParticipant + version: 2.3.1 + policy_type_id: + name: onap.policies.operational.pm-subscription-handler + version: 1.0.0 + policy_id: + get_input: pmsh_operational_policy + org.onap.domain.pmsh.DerivedPolicyControlLoopElement: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.DerivedPolicyControlLoopElement + type_version: 1.0.0 + description: Control loop for Performance Management Subscription Handling + properties: + provider: Ericsson + participantType: + name: org.onap.policy.controlloop.PolicyControlLoopParticipant + version: 2.3.1 + participant_id: + name: org.onap.PM_Policy + version: 1.0.0 + org.onap.domain.pmsh.DerivedDerivedPolicyControlLoopElement: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.DerivedDerivedPolicyControlLoopElement + type_version: 1.0.0 + description: Control loop for Performance Management Subscription Handling + properties: + provider: Ericsson + participantType: + name: org.onap.policy.controlloop.PolicyControlLoopParticipant + version: 2.3.1 + participant_id: + name: org.onap.PM_Policy + version: 1.0.0 + org.onap.k8s.controlloop.K8SControlLoopParticipant: + version: 2.3.4 + type: org.onap.policy.clamp.controlloop.Participant + type_version: 1.0.1 + description: Participant for K8S + properties: + provider: ONAP + org.onap.domain.database.PMSH_K8SMicroserviceControlLoopElement: + # Chart from new repository + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.K8SMicroserviceControlLoopElement + type_version: 1.0.0 + description: Control loop element for the K8S microservice for PMSH + properties: + provider: ONAP + participant_id: + name: K8sParticipant0 + version: 1.0.0 + participantType: + name: org.onap.k8s.controlloop.K8SControlLoopParticipant + version: 2.3.4 + chart: + chartId: + name: dcae-pmsh + version: 8.0.0 + namespace: onap + releaseName: pmshms + repository: + repoName: chartmuseum + protocol: http + address: 10.152.183.120 + port: 80 + userName: onapinitializer + password: demo123456! + overrideParams: + global.masterPassword: test + + org.onap.domain.database.Local_K8SMicroserviceControlLoopElement: + # Chart installation without passing repository info + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.K8SMicroserviceControlLoopElement + type_version: 1.0.0 + description: Control loop element for the K8S microservice for local chart + properties: + provider: ONAP + participant_id: + name: K8sParticipant0 + version: 1.0.0 + participantType: + name: org.onap.k8s.controlloop.K8SControlLoopParticipant + version: 2.3.4 + chart: + chartId: + name: nginx-ingress + version: 0.9.1 + releaseName: nginxms + namespace: test + org.onap.controlloop.HttpControlLoopParticipant: + version: 2.3.4 + type: org.onap.policy.clamp.controlloop.Participant + type_version: 1.0.1 + description: Participant for Http requests + properties: + provider: ONAP + org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement: + # Consul http config for PMSH. + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.HttpControlLoopElement + type_version: 1.0.1 + description: Control loop element for the http requests of PMSH microservice + properties: + provider: ONAP + participant_id: + name: HttpParticipant0 + version: 1.0.0 + participantType: + name: org.onap.k8s.controlloop.HttpControlLoopParticipant + version: 2.3.4 + uninitializedToPassiveTimeout: 180 + startPhase: 1 + baseUrl: http://10.152.183.51:8500 + httpHeaders: + Content-Type: application/json + configurationEntities: + - configurationEntityId: + name: entity1 + version: 1.0.1 + restSequence: + - restRequestId: + name: request1 + version: 1.0.1 + httpMethod: PUT + path: v1/kv/dcae-pmsh2 + body: '{ + "control_loop_name":"pmsh-control-loop", + "operational_policy_name":"pmsh-operational-policy", + "aaf_password":"demo123456!", + "aaf_identity":"dcae@dcae.onap.org", + "cert_path":"/opt/app/pmsh/etc/certs/cert.pem", + "key_path":"/opt/app/pmsh/etc/certs/key.pem", + "ca_cert_path":"/opt/app/pmsh/etc/certs/cacert.pem", + "enable_tls":"true", + "pmsh_policy":{ + "subscription":{ + "subscriptionName":"ExtraPM-All-gNB-R2B", + "administrativeState":"UNLOCKED", + "fileBasedGP":15, + "fileLocation":"\/pm\/pm.xml", + "nfFilter":{ + "nfNames":[ + "^pnf.*", + "^vnf.*" + ], + "modelInvariantIDs":[ + ], + "modelVersionIDs":[ + ], + "modelNames":[ + ] + }, + "measurementGroups":[ + { + "measurementGroup":{ + "measurementTypes":[ + { + "measurementType":"countera" + }, + { + "measurementType":"counterb" + } + ], + "managedObjectDNsBasic":[ + { + "DN":"dna" + }, + { + "DN":"dnb" + } + ] + } + }, + { + "measurementGroup":{ + "measurementTypes":[ + { + "measurementType":"counterc" + }, + { + "measurementType":"counterd" + } + ], + "managedObjectDNsBasic":[ + { + "DN":"dnc" + }, + { + "DN":"dnd" + } + ] + } + } + ] + } + }, + "streams_subscribes":{ + "aai_subscriber":{ + "type":"message_router", + "dmaap_info":{ + "topic_url":"https://10.152.183.151:3905/events/AAI_EVENT", + "client_role":"org.onap.dcae.aaiSub", + "location":"san-francisco", + "client_id":"1575976809466" + } + }, + "policy_pm_subscriber":{ + "type":"message_router", + "dmaap_info":{ + "topic_url":"https://10.152.183.151:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS", + "client_role":"org.onap.dcae.pmSubscriber", + "location":"san-francisco", + "client_id":"1575876809456" + } + } + }, + "streams_publishes":{ + "policy_pm_publisher":{ + "type":"message_router", + "dmaap_info":{ + "topic_url":"https://10.152.183.151:3905/events/org.onap.dmaap.mr.PM_SUBSCRIPTIONS", + "client_role":"org.onap.dcae.pmPublisher", + "location":"san-francisco", + "client_id":"1475976809466" + } + }, + "other_publisher":{ + "type":"message_router", + "dmaap_info":{ + "topic_url":"https://10.152.183.151:3905/events/org.onap.dmaap.mr.SOME_OTHER_TOPIC", + "client_role":"org.onap.dcae.pmControlPub", + "location":"san-francisco", + "client_id":"1875976809466" + } + } + } + }' + expectedResponse: 200 + org.onap.domain.sample.GenericK8s_ControlLoopDefinition: + version: 1.2.3 + type: org.onap.policy.clamp.controlloop.ControlLoop + type_version: 1.0.0 + description: Control loop for Hello World + properties: + provider: ONAP + elements: + - name: org.onap.domain.database.PMSH_K8SMicroserviceControlLoopElement + version: 1.2.3 + - name: org.onap.domain.database.Local_K8SMicroserviceControlLoopElement + version: 1.2.3 + - name: org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement + version: 1.2.3 + - name: org.onap.domain.pmsh.DerivedPolicyControlLoopElement + version: 1.2.3 + - name: org.onap.domain.pmsh.DerivedDerivedPolicyControlLoopElement + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement + version: 1.2.3 diff --git a/runtime/src/main/docker/frontend/nginx/nginx.conf b/runtime/src/main/docker/frontend/nginx/nginx.conf index beeb2b1eb..a8fdc2a94 100644 --- a/runtime/src/main/docker/frontend/nginx/nginx.conf +++ b/runtime/src/main/docker/frontend/nginx/nginx.conf @@ -1,6 +1,6 @@ worker_processes 1; pid /var/run/nginx.pid; -error_log /dev/stdout info; +error_log /dev/stdout warn; events { } http { @@ -15,4 +15,4 @@ http { keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; - }
\ No newline at end of file + } diff --git a/runtime/src/main/java/org/onap/policy/clamp/clds/util/JsonUtils.java b/runtime/src/main/java/org/onap/policy/clamp/clds/util/JsonUtils.java index 909b240fb..7093952be 100644 --- a/runtime/src/main/java/org/onap/policy/clamp/clds/util/JsonUtils.java +++ b/runtime/src/main/java/org/onap/policy/clamp/clds/util/JsonUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ - * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights + * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,12 +40,16 @@ public class JsonUtils { protected static final Logger logger = LoggerFactory.getLogger(JsonUtils.class); - public static final Gson GSON = new GsonBuilder().setPrettyPrinting() + public static final Gson GSON = new GsonBuilder() + .registerTypeAdapter(Instant.class, new InstantSerializer()) + .registerTypeAdapter(Instant.class, new InstantDeserializer()) + .setPrettyPrinting() .registerTypeAdapter(SecureServicePermission.class, new SecureServicePermissionDeserializer()).create(); - public static final Gson GSON_JPA_MODEL = new GsonBuilder().setPrettyPrinting() + public static final Gson GSON_JPA_MODEL = new GsonBuilder() .registerTypeAdapter(Instant.class, new InstantSerializer()) .registerTypeAdapter(Instant.class, new InstantDeserializer()).setPrettyPrinting() + .setPrettyPrinting() .excludeFieldsWithoutExposeAnnotation().create(); private JsonUtils() { diff --git a/runtime/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file b/runtime/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file index 467409f47..8b75fc216 100644 --- a/runtime/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file +++ b/runtime/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file @@ -8,7 +8,15 @@ { "currentInstanceCount": 0, "desiredInstanceCount": 1, - "pdpInstances": [], + "pdpInstances": [ + { + "instanceId": "controlloop-f8287777-5f3e-4f0f-b21b-d8829c93f57b", + "pdpState": "ACTIVE", + "healthy": "HEALTHY", + "message": "Pdp Heartbeat", + "lastUpdate": "2021-09-29T02:51:21Z" + } + ], "pdpType": "apex", "policies": [ { @@ -31,7 +39,15 @@ { "currentInstanceCount": 0, "desiredInstanceCount": 1, - "pdpInstances": [], + "pdpInstances": [ + { + "instanceId": "drools-f8287777-5f3e-4f0f-b21b-d8829c93f57b", + "pdpState": "ACTIVE", + "healthy": "HEALTHY", + "message": "Pdp Heartbeat", + "lastUpdate": "2021-09-29T02:51:21Z" + } + ], "pdpType": "drools", "policies": [ { @@ -54,7 +70,15 @@ { "currentInstanceCount": 0, "desiredInstanceCount": 1, - "pdpInstances": [], + "pdpInstances": [ + { + "instanceId": "xacml-f8287777-5f3e-4f0f-b21b-d8829c93f57b", + "pdpState": "ACTIVE", + "healthy": "HEALTHY", + "message": "Pdp Heartbeat", + "lastUpdate": "2021-09-29T02:51:21Z" + } + ], "pdpType": "xacml", "policies": [], "properties": {}, @@ -76,7 +100,15 @@ { "currentInstanceCount": 0, "desiredInstanceCount": 1, - "pdpInstances": [], + "pdpInstances": [ + { + "instanceId": "monitoring-f8287777-5f3e-4f0f-b21b-d8829c93f57b", + "pdpState": "ACTIVE", + "healthy": "HEALTHY", + "message": "Pdp Heartbeat", + "lastUpdate": "2021-09-29T02:51:21Z" + } + ], "pdpType": "xacml", "policies": [ { |