From 43098043c4ef31d9d5dead66568d7d9482a6b165 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 25 Jan 2022 19:55:43 +0000 Subject: Rename TOSCA Control Loop to ACM This commit renames the TOSCA Control Loop functionality in CLAMP to Automation Composition Management. This review is a direct renaming review and, as everything is renamed together it is large. Issue-ID: POLICY-3939 Change-Id: I28f0a6dd889bf3570a4c1365ae9e71fc58db6d6c Signed-off-by: liamfallon --- .../controlloop/concepts/ClElementStatistics.java | 53 - .../concepts/ClElementStatisticsList.java | 33 - .../models/controlloop/concepts/ControlLoop.java | 116 - .../controlloop/concepts/ControlLoopElement.java | 89 - .../concepts/ControlLoopElementAck.java | 42 - .../concepts/ControlLoopElementDefinition.java | 64 - .../controlloop/concepts/ControlLoopInfo.java | 52 - .../concepts/ControlLoopOrderedState.java | 44 - .../controlloop/concepts/ControlLoopState.java | 63 - .../concepts/ControlLoopStatistics.java | 50 - .../models/controlloop/concepts/ControlLoops.java | 48 - .../models/controlloop/concepts/Participant.java | 77 - .../concepts/ParticipantDefinition.java | 59 - .../concepts/ParticipantHealthStatus.java | 52 - .../controlloop/concepts/ParticipantState.java | 61 - .../concepts/ParticipantStatistics.java | 52 - .../concepts/ParticipantStatisticsList.java | 33 - .../controlloop/concepts/ParticipantUpdates.java | 56 - .../controlloop/concepts/ParticipantUtils.java | 119 - .../concepts/JpaClElementStatistics.java | 196 -- .../persistence/concepts/JpaControlLoop.java | 263 -- .../concepts/JpaControlLoopElement.java | 253 -- .../persistence/concepts/JpaParticipant.java | 231 -- .../concepts/JpaParticipantStatistics.java | 239 -- .../provider/ClElementStatisticsProvider.java | 137 - .../persistence/provider/ControlLoopProvider.java | 279 -- .../persistence/provider/ParticipantProvider.java | 152 - .../provider/ParticipantStatisticsProvider.java | 138 - .../persistence/provider/ProviderUtils.java | 93 - .../provider/ServiceTemplateProvider.java | 261 -- .../repository/ClElementStatisticsRepository.java | 32 - .../repository/ControlLoopRepository.java | 31 - .../persistence/repository/FilterRepository.java | 53 - .../repository/FilterRepositoryImpl.java | 51 - .../repository/ParticipantRepository.java | 31 - .../ParticipantStatisticsRepository.java | 32 - .../repository/ToscaNodeTemplateRepository.java | 30 - .../repository/ToscaNodeTemplatesRepository.java | 29 - .../repository/ToscaServiceTemplateRepository.java | 30 - .../notification/ControlLoopNotification.java | 56 - .../dmaap/notification/ControlLoopStatus.java | 36 - .../messages/dmaap/participant/ControlLoopAck.java | 69 - .../dmaap/participant/ControlLoopStateChange.java | 60 - .../dmaap/participant/ControlLoopUpdate.java | 64 - .../dmaap/participant/ParticipantAckMessage.java | 115 - .../dmaap/participant/ParticipantDeregister.java | 51 - .../participant/ParticipantDeregisterAck.java | 51 - .../dmaap/participant/ParticipantMessage.java | 112 - .../dmaap/participant/ParticipantMessageType.java | 104 - .../dmaap/participant/ParticipantRegister.java | 51 - .../dmaap/participant/ParticipantRegisterAck.java | 51 - .../participant/ParticipantResponseStatus.java | 42 - .../dmaap/participant/ParticipantStatus.java | 78 - .../dmaap/participant/ParticipantStatusReq.java | 51 - .../dmaap/participant/ParticipantUpdate.java | 63 - .../dmaap/participant/ParticipantUpdateAck.java | 53 - .../models/messages/rest/GenericNameVersion.java | 30 - .../models/messages/rest/SimpleResponse.java | 37 - .../models/messages/rest/TypedSimpleResponse.java | 35 - .../rest/commissioning/CommissioningResponse.java | 38 - .../ControlLoopOrderStateResponse.java | 43 - .../rest/instantiation/ControlLoopPrimed.java | 32 - .../instantiation/ControlLoopPrimedResponse.java | 39 - .../instantiation/InstancePropertiesResponse.java | 38 - .../rest/instantiation/InstantiationCommand.java | 35 - .../InstantiationOrderStateResponse.java | 39 - .../rest/instantiation/InstantiationResponse.java | 38 - .../clamp/controlloop/models/rest/RestUtils.java | 43 - .../models/acm/concepts/AcElementStatistics.java | 53 + .../acm/concepts/AcElementStatisticsList.java | 33 + .../models/acm/concepts/AutomationComposition.java | 117 + .../acm/concepts/AutomationCompositionElement.java | 89 + .../concepts/AutomationCompositionElementAck.java | 42 + .../AutomationCompositionElementDefinition.java | 64 + .../acm/concepts/AutomationCompositionInfo.java | 52 + .../AutomationCompositionOrderedState.java | 47 + .../acm/concepts/AutomationCompositionState.java | 67 + .../concepts/AutomationCompositionStatistics.java | 50 + .../acm/concepts/AutomationCompositions.java | 48 + .../clamp/models/acm/concepts/Participant.java | 77 + .../models/acm/concepts/ParticipantDefinition.java | 60 + .../acm/concepts/ParticipantHealthStatus.java | 52 + .../models/acm/concepts/ParticipantState.java | 60 + .../models/acm/concepts/ParticipantStatistics.java | 52 + .../acm/concepts/ParticipantStatisticsList.java | 33 + .../models/acm/concepts/ParticipantUpdates.java | 56 + .../models/acm/concepts/ParticipantUtils.java | 123 + .../AutomationCompositionNotification.java | 56 + .../notification/AutomationCompositionStatus.java | 36 + .../participant/AutomationCompositionAck.java | 70 + .../AutomationCompositionStateChange.java | 60 + .../participant/AutomationCompositionUpdate.java | 64 + .../dmaap/participant/ParticipantAckMessage.java | 115 + .../dmaap/participant/ParticipantDeregister.java | 51 + .../participant/ParticipantDeregisterAck.java | 51 + .../dmaap/participant/ParticipantMessage.java | 112 + .../dmaap/participant/ParticipantMessageType.java | 104 + .../dmaap/participant/ParticipantRegister.java | 51 + .../dmaap/participant/ParticipantRegisterAck.java | 51 + .../participant/ParticipantResponseStatus.java | 42 + .../dmaap/participant/ParticipantStatus.java | 79 + .../dmaap/participant/ParticipantStatusReq.java | 51 + .../dmaap/participant/ParticipantUpdate.java | 63 + .../dmaap/participant/ParticipantUpdateAck.java | 53 + .../acm/messages/rest/GenericNameVersion.java | 30 + .../models/acm/messages/rest/SimpleResponse.java | 37 + .../acm/messages/rest/TypedSimpleResponse.java | 35 + .../rest/commissioning/CommissioningResponse.java | 38 + .../AutomationCompositionOrderStateResponse.java | 43 + .../instantiation/AutomationCompositionPrimed.java | 32 + .../AutomationCompositionPrimedResponse.java | 39 + .../instantiation/InstancePropertiesResponse.java | 38 + .../rest/instantiation/InstantiationCommand.java | 35 + .../InstantiationOrderStateResponse.java | 39 + .../rest/instantiation/InstantiationResponse.java | 38 + .../concepts/JpaAcElementStatistics.java | 196 ++ .../concepts/JpaAutomationComposition.java | 268 ++ .../concepts/JpaAutomationCompositionElement.java | 253 ++ .../acm/persistence/concepts/JpaParticipant.java | 231 ++ .../concepts/JpaParticipantStatistics.java | 239 ++ .../provider/AcElementStatisticsProvider.java | 139 + .../provider/AutomationCompositionProvider.java | 287 ++ .../persistence/provider/ParticipantProvider.java | 152 + .../provider/ParticipantStatisticsProvider.java | 138 + .../acm/persistence/provider/ProviderUtils.java | 93 + .../provider/ServiceTemplateProvider.java | 261 ++ .../repository/AcElementStatisticsRepository.java | 32 + .../AutomationCompositionRepository.java | 31 + .../persistence/repository/FilterRepository.java | 53 + .../repository/FilterRepositoryImpl.java | 51 + .../repository/ParticipantRepository.java | 31 + .../ParticipantStatisticsRepository.java | 32 + .../repository/ToscaNodeTemplateRepository.java | 30 + .../repository/ToscaNodeTemplatesRepository.java | 29 + .../repository/ToscaServiceTemplateRepository.java | 30 + .../policy/clamp/models/acm/rest/RestUtils.java | 43 + .../policy/clamp/models/acm/utils/AcmUtils.java | 152 + .../concepts/ClElementStatisticsTest.java | 67 - .../concepts/ControlLoopConceptPojosTest.java | 62 - .../concepts/ControlLoopElementTest.java | 103 - .../controlloop/concepts/ControlLoopTest.java | 160 - .../concepts/ParticipantStatisticsTest.java | 65 - .../controlloop/concepts/ParticipantTest.java | 84 - .../controlloop/concepts/ParticipantUtilsTest.java | 84 - .../concepts/DummyJpaClElementStatisticsChild.java | 28 - .../concepts/DummyJpaControlLoopChild.java | 28 - .../concepts/DummyJpaControlLoopElementChild.java | 28 - .../concepts/DummyJpaParticipantChild.java | 28 - .../DummyJpaParticipantStatisticsChild.java | 28 - .../concepts/JpaClElementStatisticsTest.java | 189 -- .../concepts/JpaControlLoopElementTest.java | 300 -- .../persistence/concepts/JpaControlLoopTest.java | 301 -- .../concepts/JpaParticipantStatisticsTest.java | 193 -- .../persistence/concepts/JpaParticipantTest.java | 254 -- .../persistence/concepts/PojosTest.java | 62 - .../provider/ClElementStatisticsProviderTest.java | 116 - .../provider/ControlLoopProviderTest.java | 290 -- .../provider/ParticipantProviderTest.java | 149 - .../ParticipantStatisticsProviderTest.java | 107 - .../provider/ServiceTemplateProviderTest.java | 169 - .../repository/FilterRepositoryImplTest.java | 106 - .../notification/ControlLoopNotificationTest.java | 83 - .../dmaap/notification/ControlLoopStatusTest.java | 48 - .../dmaap/notification/NotificationPojosTest.java | 58 - .../dmaap/participant/ControlLoopAckTest.java | 68 - .../participant/ControlLoopStateChangeTest.java | 65 - .../dmaap/participant/ControlLoopUpdateTest.java | 82 - .../participant/ParticipantAckMessageTest.java | 105 - .../participant/ParticipantDeregisterAckTest.java | 59 - .../participant/ParticipantDeregisterTest.java | 61 - .../dmaap/participant/ParticipantMessageTest.java | 107 - .../dmaap/participant/ParticipantMessageUtils.java | 55 - .../dmaap/participant/ParticipantPojosTest.java | 65 - .../participant/ParticipantRegisterAckTest.java | 59 - .../dmaap/participant/ParticipantRegisterTest.java | 61 - .../participant/ParticipantStatusReqTest.java | 56 - .../dmaap/participant/ParticipantStatusTest.java | 129 - .../participant/ParticipantUpdateAckTest.java | 59 - .../dmaap/participant/ParticipantUpdateTest.java | 101 - .../messages/rest/MessagesRestPojosTest.java | 59 - .../instantiation/InstantiationCommandTest.java | 60 - .../controlloop/models/rest/RestUtilsTest.java | 54 - .../acm/concepts/AcElementStatisticsTest.java | 67 + .../AutomationCompositionConceptPojosTest.java | 62 + .../concepts/AutomationCompositionElementTest.java | 103 + .../acm/concepts/AutomationCompositionTest.java | 160 + .../acm/concepts/ParticipantStatisticsTest.java | 65 + .../clamp/models/acm/concepts/ParticipantTest.java | 84 + .../models/acm/concepts/ParticipantUtilsTest.java | 91 + .../AutomationCompositionNotificationTest.java | 83 + .../AutomationCompositionStatusTest.java | 48 + .../dmaap/notification/NotificationPojosTest.java | 58 + .../participant/AutomationCompositionAckTest.java | 68 + .../AutomationCompositionStateChangeTest.java | 65 + .../AutomationCompositionUpdateTest.java | 82 + .../participant/ParticipantAckMessageTest.java | 105 + .../participant/ParticipantDeregisterAckTest.java | 59 + .../participant/ParticipantDeregisterTest.java | 61 + .../dmaap/participant/ParticipantMessageTest.java | 107 + .../dmaap/participant/ParticipantMessageUtils.java | 55 + .../dmaap/participant/ParticipantPojosTest.java | 65 + .../participant/ParticipantRegisterAckTest.java | 59 + .../dmaap/participant/ParticipantRegisterTest.java | 61 + .../participant/ParticipantStatusReqTest.java | 56 + .../dmaap/participant/ParticipantStatusTest.java | 129 + .../participant/ParticipantUpdateAckTest.java | 59 + .../dmaap/participant/ParticipantUpdateTest.java | 101 + .../acm/messages/rest/MessagesRestPojosTest.java | 59 + .../instantiation/InstantiationCommandTest.java | 60 + .../concepts/DummyJpaAcElementStatisticsChild.java | 28 + .../DummyJpaAutomationCompositionChild.java | 28 + .../DummyJpaAutomationCompositionElementChild.java | 28 + .../concepts/DummyJpaParticipantChild.java | 28 + .../DummyJpaParticipantStatisticsChild.java | 28 + .../concepts/JpaAcElementStatisticsTest.java | 189 ++ .../JpaAutomationCompositionElementTest.java | 315 ++ .../concepts/JpaAutomationCompositionTest.java | 310 ++ .../concepts/JpaParticipantStatisticsTest.java | 193 ++ .../persistence/concepts/JpaParticipantTest.java | 254 ++ .../models/acm/persistence/concepts/PojosTest.java | 62 + .../provider/AcElementStatisticsProviderTest.java | 116 + .../AutomationCompositionProviderTest.java | 305 ++ .../provider/ParticipantProviderTest.java | 149 + .../ParticipantStatisticsProviderTest.java | 107 + .../provider/ServiceTemplateProviderTest.java | 169 + .../repository/FilterRepositoryImplTest.java | 109 + .../clamp/models/acm/rest/RestUtilsTest.java | 54 + .../clamp/models/acm/utils/AcmUtilsTest.java | 149 + models/src/test/resources/META-INF/persistence.xml | 10 +- .../examples/acm/PMSubscriptionHandling.yaml | 3325 ++++++++++++++++++++ .../controlloop/PMSubscriptionHandling.yaml | 3325 -------------------- ...AutomationCompositionElementNoOrderedState.json | 13 + .../json/AutomationCompositionNoOrderedState.json | 12 + .../json/ControlLoopElementNoOrderedState.json | 13 - .../resources/json/ControlLoopNoOrderedState.json | 12 - .../providers/TestAcElementStatistics.json | 24 + .../providers/TestAutomationCompositions.json | 142 + .../providers/TestClElementStatistics.json | 24 - .../test/resources/providers/TestControlLoops.json | 142 - .../test/resources/providers/TestParticipant.json | 4 +- .../providers/UpdateAutomationCompositions.json | 73 + .../resources/providers/UpdateControlLoops.json | 73 - 242 files changed, 13748 insertions(+), 13369 deletions(-) delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsList.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementAck.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementDefinition.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopOrderedState.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopState.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantDefinition.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantState.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsList.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUpdates.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipant.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProvider.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProvider.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ClElementStatisticsRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ControlLoopRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImpl.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantStatisticsRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplateRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplatesRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaServiceTemplateRepository.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotification.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatus.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregister.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAck.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAck.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAck.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/GenericNameVersion.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/SimpleResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/TypedSimpleResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/commissioning/CommissioningResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopOrderStateResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimed.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommand.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationOrderStateResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationResponse.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatistics.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsList.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementAck.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementDefinition.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionOrderedState.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionState.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionStatistics.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantHealthStatus.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantState.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatistics.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsList.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotification.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatus.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAck.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdate.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregister.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAck.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAck.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReq.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdate.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAck.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/SimpleResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/TypedSimpleResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/commissioning/CommissioningResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimed.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimedResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommand.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationResponse.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatistics.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatistics.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProvider.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProvider.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AcElementStatisticsRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantStatisticsRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/rest/RestUtils.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/NotificationPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/MessagesRestPojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/PojosTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java create mode 100644 models/src/test/resources/examples/acm/PMSubscriptionHandling.yaml delete mode 100644 models/src/test/resources/examples/controlloop/PMSubscriptionHandling.yaml create mode 100644 models/src/test/resources/json/AutomationCompositionElementNoOrderedState.json create mode 100644 models/src/test/resources/json/AutomationCompositionNoOrderedState.json delete mode 100644 models/src/test/resources/json/ControlLoopElementNoOrderedState.json delete mode 100644 models/src/test/resources/json/ControlLoopNoOrderedState.json create mode 100644 models/src/test/resources/providers/TestAcElementStatistics.json create mode 100644 models/src/test/resources/providers/TestAutomationCompositions.json delete mode 100644 models/src/test/resources/providers/TestClElementStatistics.json delete mode 100644 models/src/test/resources/providers/TestControlLoops.json create mode 100644 models/src/test/resources/providers/UpdateAutomationCompositions.json delete mode 100644 models/src/test/resources/providers/UpdateControlLoops.json (limited to 'models/src') diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java deleted file mode 100644 index 4ef9bdcd9..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatistics.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.io.Serializable; -import java.time.Instant; -import java.util.UUID; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@NoArgsConstructor -@Data -@ToString -public class ClElementStatistics implements Serializable { - - private static final long serialVersionUID = 3284285693112271055L; - - @NonNull - private UUID id = UUID.randomUUID(); - - @NonNull - private ToscaConceptIdentifier participantId; - - @NonNull - private Instant timeStamp; - - @NonNull - private ControlLoopState controlLoopState; - - private long clElementUptime; - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsList.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsList.java deleted file mode 100644 index 166f1e48f..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsList.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -public class ClElementStatisticsList { - private List clElementStatistics; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java deleted file mode 100644 index cf22b7228..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoop.java +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.apache.commons.collections4.MapUtils; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; - -/** - * Class to represent a control loop instance. - */ -@NoArgsConstructor -@Data -@EqualsAndHashCode(callSuper = true) -public class ControlLoop extends ToscaEntity implements Comparable { - @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); - - @NonNull - private ControlLoopState state = ControlLoopState.UNINITIALISED; - - @NonNull - private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED; - - private Map elements; - - @NonNull - private Boolean primed = false; - - @Override - public String getType() { - return definition.getName(); - } - - @Override - public String getTypeVersion() { - return definition.getVersion(); - } - - /** - * Copy contructor, does a deep copy. - * - * @param otherControlLoop the other element to copy from - */ - public ControlLoop(final ControlLoop otherControlLoop) { - super(otherControlLoop); - this.definition = new ToscaConceptIdentifier(otherControlLoop.definition); - this.state = otherControlLoop.state; - this.orderedState = otherControlLoop.orderedState; - this.elements = PfUtils.mapMap(otherControlLoop.elements, ControlLoopElement::new); - this.primed = otherControlLoop.primed; - } - - @Override - public int compareTo(final ControlLoop other) { - return compareNameVersion(this, other); - } - - /** - * Set the ordered state on the control loop and on all its control loop elements. - * - * @param orderedState the state we want the control loop to transition to - */ - public void setCascadedOrderedState(final ControlLoopOrderedState orderedState) { - this.orderedState = orderedState; - - if (MapUtils.isEmpty(elements)) { - return; - } - - elements.values().forEach(element -> element.setOrderedState(orderedState)); - } - - /** - * Get a list of control loop element statistics. - * - * @param controlLoop the control loop - * @return List of ClElementStatistics - */ - public List getControlLoopElementStatisticsList(final ControlLoop controlLoop) { - if (MapUtils.isEmpty(controlLoop.elements)) { - return List.of(); - } - - return controlLoop.elements.values().stream().map(ControlLoopElement::getClElementStatistics) - .collect(Collectors.toList()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java deleted file mode 100644 index c7d85e4b6..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElement.java +++ /dev/null @@ -1,89 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; -import java.util.function.UnaryOperator; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.ToString; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -/** - * Class to represent a control loop instance. - */ -@NoArgsConstructor -@Data -@ToString -public class ControlLoopElement { - @NonNull - private UUID id = UUID.randomUUID(); - - @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); - - @NonNull - private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); - - @NonNull - private ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); - - @NonNull - private ControlLoopState state = ControlLoopState.UNINITIALISED; - - @NonNull - private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED; - - private ToscaServiceTemplate toscaServiceTemplateFragment; - - private String description; - - private ClElementStatistics clElementStatistics; - - // A map indexed by the property name. Each map entry is the serialized value of the property, - // which can be deserialized into an instance of the type of the property. - private Map propertiesMap = new LinkedHashMap<>(); - - /** - * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. - * - * @param otherElement the other element to copy from - */ - public ControlLoopElement(final ControlLoopElement otherElement) { - this.id = otherElement.id; - this.definition = new ToscaConceptIdentifier(otherElement.definition); - this.participantType = new ToscaConceptIdentifier(otherElement.participantType); - this.participantId = new ToscaConceptIdentifier(otherElement.participantId); - this.state = otherElement.state; - this.orderedState = otherElement.orderedState; - this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment; - this.description = otherElement.description; - this.clElementStatistics = otherElement.clElementStatistics; - this.propertiesMap = PfUtils.mapMap(otherElement.propertiesMap, UnaryOperator.identity()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementAck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementAck.java deleted file mode 100644 index 61b90c9e9..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementAck.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@AllArgsConstructor -@ToString -public class ControlLoopElementAck { - - // State of the controlLoopElement - private ControlLoopState state; - - // Result: Success/Fail. - private Boolean result; - - // Message indicating reason for failure - private String message; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementDefinition.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementDefinition.java deleted file mode 100644 index ae50b40ce..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementDefinition.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.function.UnaryOperator; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; -import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; - -/** - * Class to represent a control loop element definition instance. - */ -@Getter -@NoArgsConstructor -@Data -@ToString -public class ControlLoopElementDefinition { - - private ToscaConceptIdentifier clElementDefinitionId; - - // The definition of the Control Loop Element in TOSCA - private ToscaNodeTemplate controlLoopElementToscaNodeTemplate; - - // A map indexed by the property name. Each map entry is the serialized value of the property, - // which can be deserialized into an instance of the type of the property. - private Map commonPropertiesMap = new LinkedHashMap<>(); - - /** - * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. - * - * @param clElementDefinition the controlloop element definition to copy from - */ - public ControlLoopElementDefinition(final ControlLoopElementDefinition clElementDefinition) { - this.clElementDefinitionId = clElementDefinition.clElementDefinitionId; - this.controlLoopElementToscaNodeTemplate = - new ToscaNodeTemplate(clElementDefinition.controlLoopElementToscaNodeTemplate); - this.commonPropertiesMap = PfUtils.mapMap(clElementDefinition.commonPropertiesMap, UnaryOperator.identity()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java deleted file mode 100644 index 0c33606db..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopInfo.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a control loop info instance. - */ -@NoArgsConstructor -@Data -@ToString -public class ControlLoopInfo { - - private ToscaConceptIdentifier controlLoopId; - - private ControlLoopState state = ControlLoopState.UNINITIALISED; - - private ControlLoopStatistics controlLoopStatistics; - - /** - * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. - * - * @param otherElement the other element to copy from - */ - public ControlLoopInfo(final ControlLoopInfo otherElement) { - this.controlLoopId = otherElement.controlLoopId; - this.state = otherElement.state; - this.controlLoopStatistics = otherElement.controlLoopStatistics; - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopOrderedState.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopOrderedState.java deleted file mode 100644 index 91f90275e..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopOrderedState.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -public enum ControlLoopOrderedState { - /** - * The control loop or control loop element should become uninitialised on participants, it should not exist on - * participants. - */ - UNINITIALISED, - /** - * The control loop or control loop element should initialised on the participants and be passive, that is, it is - * not handling control loop messages yet. - */ - PASSIVE, - /** The control loop or control loop element should running and is executing control loops. */ - RUNNING; - - public boolean equalsControlLoopState(final ControlLoopState controlLoopState) { - return this.name().equals(controlLoopState.name()); - } - - public ControlLoopState asState() { - return ControlLoopState.valueOf(this.name()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopState.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopState.java deleted file mode 100644 index ff0d553af..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopState.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -public enum ControlLoopState { - /** - * The control loop or control loop element is not initialised on participants, it does not exist on participants. - */ - UNINITIALISED, - /** - * The control loop or control loop element is changing from unitialised to passive, it is being initialised onto - * participants. - */ - UNINITIALISED2PASSIVE, - /** - * The control loop or control loop element is initialised on the participants but is passive, that is, it is not - * handling control loop messages yet. - */ - PASSIVE, - /** - * The control loop or control loop element is changing from passive to running, the participants are preparing to - * execute control loops. - */ - PASSIVE2RUNNING, - /** The control loop or control loop element is running and is executing control loops. */ - RUNNING, - /** - * The control loop or control loop element is completing execution of current control loops but will not start - * running any more control loops and will become passive. - */ - RUNNING2PASSIVE, - /** - * The control loop or control loop element is changing from passive to unitialised, the control loop is being - * removed from participants. - */ - PASSIVE2UNINITIALISED; - - public boolean equalsControlLoopOrderedState(final ControlLoopOrderedState controlLoopOrderedState) { - return this.name().equals(controlLoopOrderedState.name()); - } - - public ControlLoopOrderedState asOrderedState() { - return ControlLoopOrderedState.valueOf(this.name()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java deleted file mode 100644 index 685947b13..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopStatistics.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.time.Instant; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@NoArgsConstructor -@Data -@ToString -public class ControlLoopStatistics { - - @NonNull - private ToscaConceptIdentifier controlLoopId; - - @NonNull - private Instant timeStamp; - - @NonNull - private ClElementStatisticsList clElementStatisticsList; - - private long eventCount; - private long lastExecutionTime; - private double averageExecutionTime; - private long upTime; - private long lastEnterTime; - private long lastStart; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java deleted file mode 100644 index 4ab406f3b..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoops.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.controlloop.models.controlloop.concepts; - -import java.util.ArrayList; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.models.base.PfUtils; - -@Getter -@Setter -@ToString -@NoArgsConstructor -@AllArgsConstructor -@EqualsAndHashCode -public class ControlLoops { - private List controlLoopList = new ArrayList<>(); - - /** - * Copy constructor, does a deep copy. - * - * @param otherControlLoops the other element to copy from - */ - public ControlLoops(final ControlLoops otherControlLoops) { - this.controlLoopList = PfUtils.mapList(controlLoopList, ControlLoop::new); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java deleted file mode 100644 index 198cf1a16..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/Participant.java +++ /dev/null @@ -1,77 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; - -/** - * Class to represent details of a running participant instance. - */ -@NoArgsConstructor -@Data -@EqualsAndHashCode(callSuper = true) -public class Participant extends ToscaEntity implements Comparable { - @NonNull - private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); - - @NonNull - private ParticipantState participantState = ParticipantState.UNKNOWN; - - @NonNull - private ParticipantHealthStatus healthStatus = ParticipantHealthStatus.UNKNOWN; - - @NonNull - private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(); - - @Override - public String getType() { - return definition.getName(); - } - - @Override - public String getTypeVersion() { - return definition.getVersion(); - } - - @Override - public int compareTo(final Participant other) { - return compareNameVersion(this, other); - } - - /** - * Copy constructor. - * - * @param otherParticipant the participant to copy from - */ - public Participant(Participant otherParticipant) { - super(otherParticipant); - this.definition = new ToscaConceptIdentifier(otherParticipant.definition); - this.participantState = otherParticipant.participantState; - this.healthStatus = otherParticipant.healthStatus; - this.participantType = otherParticipant.participantType; - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantDefinition.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantDefinition.java deleted file mode 100644 index 336b309ce..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantDefinition.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.ArrayList; -import java.util.List; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; -import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a participant definition update instance. - */ -@Getter -@NoArgsConstructor -@Data -@ToString -public class ParticipantDefinition { - - private ToscaConceptIdentifier participantId; - - private ToscaConceptIdentifier participantType; - - // List of ControlLoopElementDefinition values for a particular participant - private List controlLoopElementDefinitionList = new ArrayList<>(); - - /** - * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. - * - * @param participantDefinition the participant definition to copy from - */ - public ParticipantDefinition(final ParticipantDefinition participantDefinition) { - this.participantId = participantDefinition.participantId; - this.participantType = participantDefinition.participantType; - this.controlLoopElementDefinitionList = PfUtils.mapList( - participantDefinition.controlLoopElementDefinitionList, ControlLoopElementDefinition::new); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java deleted file mode 100644 index e7c5fecda..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantHealthStatus.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -/** - * Class to hold the possible values for health status of Participant. - */ -public enum ParticipantHealthStatus { - - /** - * Participant is healthy and working fine. - */ - HEALTHY, - - /** - * Participant is not healthy. - */ - NOT_HEALTHY, - - /** - * Participant is currently under test state and performing tests. - */ - TEST_IN_PROGRESS, - - /** - * The health status of the Participant is unknown. - */ - UNKNOWN, - - /** - * The health status of the Participant is off line. - */ - OFF_LINE -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantState.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantState.java deleted file mode 100644 index 1af32660d..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantState.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -/** - * Class to hold the possible values for mode of participant. - */ -public enum ParticipantState { - - /** - * Control Loop execution is unknown. - */ - UNKNOWN, - - /** - * Control Loop execution is always rejected. - */ - PASSIVE, - - /** - * Control Loop execution execution proceeds, but changes to domain state or context are not carried out. The - * participant returns an indication that it is running in SAFE mode together with the action it would have - * performed if it was operating in ACTIVE mode. - */ - SAFE, - - /** - * Control Loop execution execution proceeds and changes to domain and state are carried out in a test environment. - * The participant returns an indication that it is running in TEST mode together with the action it has performed - * on the test environment. - */ - TEST, - - /** - * Control Loop execution execution is executed in the live environment by the participant. - */ - ACTIVE, - - /** - * Control Loop execution execution is terminated and not available. - */ - TERMINATED -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java deleted file mode 100644 index 3a7b21fa1..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatistics.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.io.Serializable; -import java.time.Instant; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@NoArgsConstructor -@Data -@ToString -public class ParticipantStatistics implements Serializable { - private static final long serialVersionUID = 744036598792333124L; - - - @NonNull - private ToscaConceptIdentifier participantId; - - @NonNull - private Instant timeStamp; - - private ParticipantState state; - private ParticipantHealthStatus healthStatus; - private long eventCount; - private long lastExecutionTime; - private double averageExecutionTime; - private long upTime; - private long lastEnterTime; - private long lastStart; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsList.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsList.java deleted file mode 100644 index a69f96f85..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsList.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -public class ParticipantStatisticsList { - private List statisticsList; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUpdates.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUpdates.java deleted file mode 100644 index ea851b8c5..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUpdates.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.ArrayList; -import java.util.List; -import lombok.Data; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.ToString; -import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a participant definition update instance. - */ -@Getter -@NoArgsConstructor -@Data -@ToString -public class ParticipantUpdates { - - private ToscaConceptIdentifier participantId; - - // List of ControlLoopElement values for a particular participant - private List controlLoopElementList = new ArrayList<>(); - - /** - * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. - * - * @param participantUpdates the participant with updates to copy from - */ - public ParticipantUpdates(final ParticipantUpdates participantUpdates) { - this.participantId = participantUpdates.participantId; - this.controlLoopElementList = PfUtils.mapList( - participantUpdates.controlLoopElementList, ControlLoopElement::new); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java deleted file mode 100644 index c05311892..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtils.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import java.util.Map; -import javax.ws.rs.core.Response; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -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.models.base.PfModelRuntimeException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ParticipantUtils { - - private static final Coder CODER = new StandardCoder(); - private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement"; - - /** - * Finds participantType from a map of properties. - * - * @param properties Map of properties - * @return participantType - */ - public static ToscaConceptIdentifier findParticipantType(Map properties) { - var objParticipantType = properties.get("participantType"); - if (objParticipantType != null) { - try { - return CODER.decode(objParticipantType.toString(), ToscaConceptIdentifier.class); - } catch (CoderException e) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); - } - } - return null; - } - - /** - * Get the First StartPhase - * it depend of the state of the Control Loop - * and also from the all startPhase defined into the ToscaServiceTemplate. - * @param controlLoop the ControlLoop - * @param toscaServiceTemplate the ToscaServiceTemplate - * @return the First StartPhase - */ - public static int getFirstStartPhase(ControlLoop controlLoop, ToscaServiceTemplate toscaServiceTemplate) { - var minStartPhase = 1000; - var maxStartPhase = 0; - for (var element : controlLoop.getElements().values()) { - ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates() - .get(element.getDefinition().getName()); - int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()); - minStartPhase = Math.min(minStartPhase, startPhase); - maxStartPhase = Math.max(maxStartPhase, startPhase); - } - - return ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState()) - || ControlLoopState.PASSIVE2RUNNING.equals(controlLoop.getState()) ? minStartPhase - : maxStartPhase; - } - - /** - * Finds startPhase from a map of properties. - * - * @param properties Map of properties - * @return startPhase - */ - public static int findStartPhase(Map properties) { - var objParticipantType = properties.get("startPhase"); - if (objParticipantType != null) { - return Integer.valueOf(objParticipantType.toString()); - } - return 0; - } - - /** - * Checks If NodeTemplate Is ControlLoopElement. - * - * @param nodeTemplate the ToscaNodeTemplate - * @param toscaServiceTemplate the ToscaServiceTemplate - * @return true if NodeTemplate Is ControlLoopElement - */ - public static boolean checkIfNodeTemplateIsControlLoopElement(ToscaNodeTemplate nodeTemplate, - ToscaServiceTemplate toscaServiceTemplate) { - if (nodeTemplate.getType().contains(CONTROL_LOOP_ELEMENT)) { - return true; - } else { - var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType()); - if (nodeType != null) { - var derivedFrom = nodeType.getDerivedFrom(); - if (derivedFrom != null) { - return derivedFrom.contains(CONTROL_LOOP_ELEMENT); - } - } - } - return false; - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java deleted file mode 100644 index 956f1db02..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatistics.java +++ /dev/null @@ -1,196 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.models.controlloop.persistence.concepts; - -import java.io.Serializable; -import java.util.List; -import java.util.UUID; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.Table; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import org.apache.commons.lang3.builder.CompareToBuilder; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.onap.policy.models.base.validation.annotations.VerifyKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a controlloop element statistics in the database. - * - * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) - */ -@Entity -@Table(name = "ClElementStatistics") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@AllArgsConstructor -@EqualsAndHashCode(callSuper = false) -public class JpaClElementStatistics extends PfConcept implements PfAuthorative, Serializable { - - private static final long serialVersionUID = 621426717868738629L; - - @EmbeddedId - @VerifyKey - @NotNull - private PfReferenceTimestampKey key = new PfReferenceTimestampKey(); - - - @VerifyKey - @NotNull - // @formatter:off - @AttributeOverride(name = "name", column = @Column(name = "participant_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_version")) - private PfConceptKey participantId; - // @formatter: on - - @Column - @NotNull - private ControlLoopState state; - - @Column - private long clElementUptime; - - - /** - * The Default Constructor creates a {@link JpaClElementStatistics} object with a null key. - */ - public JpaClElementStatistics() { - this(new PfReferenceTimestampKey()); - } - - - /** - * The Key Constructor creates a {@link JpaClElementStatistics} object with the given Reference Timestamp key. - * - * @param key the key - */ - public JpaClElementStatistics(@NonNull final PfReferenceTimestampKey key) { - this(key, new PfConceptKey(), ControlLoopState.PASSIVE, 0L); - } - - /** - * The Key Constructor creates a {@link JpaClElementStatistics} object with all mandatory fields. - * - * @param key the key - * @param participantId the TOSCA definition of the control loop element - */ - public JpaClElementStatistics(@NonNull final PfReferenceTimestampKey key, - @NonNull final PfConceptKey participantId) { - this.key = key; - this.participantId = participantId; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public JpaClElementStatistics(@NonNull final JpaClElementStatistics copyConcept) { - super(copyConcept); - this.key = new PfReferenceTimestampKey(copyConcept.key); - this.participantId = new PfConceptKey(copyConcept.participantId); - this.state = copyConcept.state; - this.clElementUptime = copyConcept.clElementUptime; - } - - - /** - * Authorative constructor. - * - * @param authorativeConcept the authorative concept to copy from - */ - public JpaClElementStatistics(@NonNull final ClElementStatistics authorativeConcept) { - this.fromAuthorative(authorativeConcept); - } - - - - @Override - public ClElementStatistics toAuthorative() { - var clElementStatistics = new ClElementStatistics(); - clElementStatistics.setId(UUID.fromString(getKey().getReferenceKey().getLocalName())); - clElementStatistics.setTimeStamp(key.getInstant()); - clElementStatistics.setParticipantId(new ToscaConceptIdentifier(participantId)); - clElementStatistics.setControlLoopState(state); - clElementStatistics.setClElementUptime(clElementUptime); - - return clElementStatistics; - } - - @Override - public void fromAuthorative(@NonNull ClElementStatistics clElementStatistics) { - // @formatter:off - if (this.key == null || this.getKey().isNullKey()) { - this.setKey(new PfReferenceTimestampKey(clElementStatistics.getParticipantId().getName(), - clElementStatistics.getParticipantId().getVersion(), clElementStatistics.getId().toString(), - clElementStatistics.getTimeStamp())); - } - // @formatter:on - this.setParticipantId(clElementStatistics.getParticipantId().asConceptKey()); - this.setState(clElementStatistics.getControlLoopState()); - this.setClElementUptime(clElementStatistics.getClElementUptime()); - } - - @Override - public List getKeys() { - return getKey().getKeys(); - } - - @Override - public void clean() { - key.clean(); - participantId.clean(); - } - - - @Override - public int compareTo(PfConcept otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaClElementStatistics other = (JpaClElementStatistics) otherConcept; - return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state) - .append(this.clElementUptime, other.clElementUptime).toComparison(); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java deleted file mode 100644 index adc300607..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoop.java +++ /dev/null @@ -1,263 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.UUID; -import javax.persistence.AttributeOverride; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.ManyToMany; -import javax.persistence.Table; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import org.apache.commons.lang3.ObjectUtils; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.common.parameters.annotations.NotNull; -import org.onap.policy.common.parameters.annotations.Valid; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.validation.annotations.VerifyKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a control loop in the database. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -@Entity -@Table(name = "ControlLoop") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@EqualsAndHashCode(callSuper = false) -public class JpaControlLoop extends PfConcept implements PfAuthorative { - private static final long serialVersionUID = -4725410933242154805L; - - @EmbeddedId - @VerifyKey - @NotNull - private PfConceptKey key; - - // @formatter:off - @VerifyKey - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "definition_name")) - @AttributeOverride(name = "version", column = @Column(name = "definition_version")) - private PfConceptKey definition; - // @formatter:on - - @Column - @NotNull - private ControlLoopState state; - - @Column - @NotNull - private ControlLoopOrderedState orderedState; - - @Column - private String description; - - @Column - private Boolean primed; - - @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) - @NotNull - private Map<@NotNull UUID, @NotNull @Valid JpaControlLoopElement> elements; - - /** - * The Default Constructor creates a {@link JpaControlLoop} object with a null key. - */ - public JpaControlLoop() { - this(new PfConceptKey()); - } - - /** - * The Key Constructor creates a {@link JpaControlLoop} object with the given concept key. - * - * @param key the key - */ - public JpaControlLoop(@NonNull final PfConceptKey key) { - this(key, new PfConceptKey(), ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); - } - - /** - * The Key Constructor creates a {@link JpaControlLoop} object with all mandatory fields. - * - * @param key the key - * @param definition the TOSCA definition of the control loop - * @param state the state of the control loop - * @param elements the elements of the control looop in participants - */ - public JpaControlLoop(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, - @NonNull final ControlLoopState state, @NonNull final Map elements) { - this.key = key; - this.definition = definition; - this.state = state; - this.elements = elements; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public JpaControlLoop(@NonNull final JpaControlLoop copyConcept) { - super(copyConcept); - this.key = new PfConceptKey(copyConcept.key); - this.definition = new PfConceptKey(copyConcept.definition); - this.state = copyConcept.state; - this.orderedState = copyConcept.orderedState; - this.description = copyConcept.description; - this.elements = PfUtils.mapMap(copyConcept.elements, JpaControlLoopElement::new, new LinkedHashMap<>(0)); - this.primed = copyConcept.primed; - } - - /** - * Authorative constructor. - * - * @param authorativeConcept the authorative concept to copy from - */ - public JpaControlLoop(@NonNull final ControlLoop authorativeConcept) { - this.fromAuthorative(authorativeConcept); - } - - @Override - public ControlLoop toAuthorative() { - var controlLoop = new ControlLoop(); - - controlLoop.setName(getKey().getName()); - controlLoop.setVersion(getKey().getVersion()); - controlLoop.setDefinition(new ToscaConceptIdentifier(definition)); - controlLoop.setState(state); - controlLoop.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); - controlLoop.setDescription(description); - controlLoop.setElements(PfUtils.mapMap(elements, JpaControlLoopElement::toAuthorative, new LinkedHashMap<>(0))); - controlLoop.setPrimed(primed); - - return controlLoop; - } - - @Override - public void fromAuthorative(@NonNull final ControlLoop controlLoop) { - if (this.key == null || this.getKey().isNullKey()) { - this.setKey(new PfConceptKey(controlLoop.getName(), controlLoop.getVersion())); - } - - this.definition = controlLoop.getDefinition().asConceptKey(); - this.state = controlLoop.getState(); - this.orderedState = controlLoop.getOrderedState(); - this.description = controlLoop.getDescription(); - this.primed = controlLoop.getPrimed(); - - this.elements = new LinkedHashMap<>(controlLoop.getElements().size()); - for (Entry elementEntry : controlLoop.getElements().entrySet()) { - var jpaControlLoopElement = new JpaControlLoopElement(); - jpaControlLoopElement.setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString())); - jpaControlLoopElement.fromAuthorative(elementEntry.getValue()); - this.elements.put(elementEntry.getKey(), jpaControlLoopElement); - } - } - - @Override - public List getKeys() { - List keyList = getKey().getKeys(); - - keyList.add(definition); - - for (JpaControlLoopElement element : elements.values()) { - keyList.addAll(element.getKeys()); - } - - return keyList; - } - - @Override - public void clean() { - key.clean(); - definition.clean(); - description = (description == null ? null : description.trim()); - - for (JpaControlLoopElement element : elements.values()) { - element.clean(); - } - } - - @Override - public int compareTo(final PfConcept otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return this.getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaControlLoop other = (JpaControlLoop) otherConcept; - int result = key.compareTo(other.key); - if (result != 0) { - return result; - } - - result = definition.compareTo(other.definition); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(state, other.state); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(orderedState, other.orderedState); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(description, other.description); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(primed, other.primed); - if (result != 0) { - return result; - } - return PfUtils.compareObjects(elements, other.elements); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java deleted file mode 100644 index 22773e064..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElement.java +++ /dev/null @@ -1,253 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.models.controlloop.persistence.concepts; - -import java.util.List; -import java.util.UUID; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.Table; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import org.apache.commons.lang3.ObjectUtils; -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.common.parameters.annotations.NotNull; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.base.validation.annotations.VerifyKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a participant control loop element in the database. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -@Entity -@Table(name = "ControlLoopElement") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@EqualsAndHashCode(callSuper = false) -public class JpaControlLoopElement extends PfConcept implements PfAuthorative { - private static final long serialVersionUID = -1791732273187890213L; - - @EmbeddedId - @VerifyKey - @NotNull - private PfReferenceKey key; - - // @formatter:off - @VerifyKey - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "definition_name")) - @AttributeOverride(name = "version", column = @Column(name = "definition_version")) - private PfConceptKey definition; - - @VerifyKey - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "participant_type_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_type_version")) - private PfConceptKey participantType; - - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "participant_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_version")) - private PfConceptKey participantId; - // @formatter:on - - @Column - @NotNull - private ControlLoopState state; - - @Column - @NotNull - private ControlLoopOrderedState orderedState; - - @Column - private String description; - - /** - * The Default Constructor creates a {@link JpaControlLoopElement} object with a null key. - */ - public JpaControlLoopElement() { - this(new PfReferenceKey()); - } - - /** - * The Key Constructor creates a {@link JpaControlLoopElement} object with the given concept key. - * - * @param key the key - */ - public JpaControlLoopElement(@NonNull final PfReferenceKey key) { - this(key, new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED); - } - - /** - * The Key Constructor creates a {@link JpaControlLoopElement} object with all mandatory fields. - * - * @param key the key - * @param definition the TOSCA definition of the control loop element - * @param participantType the TOSCA definition of the participant running the control loop element - * @param state the state of the control loop - */ - public JpaControlLoopElement(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey definition, - @NonNull final PfConceptKey participantType, @NonNull final ControlLoopState state) { - this.key = key; - this.definition = definition; - this.participantType = participantType; - this.state = state; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public JpaControlLoopElement(@NonNull final JpaControlLoopElement copyConcept) { - super(copyConcept); - this.key = new PfReferenceKey(copyConcept.key); - this.definition = new PfConceptKey(copyConcept.definition); - this.participantType = new PfConceptKey(copyConcept.participantType); - this.participantId = new PfConceptKey(copyConcept.participantId); - this.state = copyConcept.state; - this.orderedState = copyConcept.orderedState; - this.description = copyConcept.description; - } - - /** - * Authorative constructor. - * - * @param authorativeConcept the authorative concept to copy from - */ - public JpaControlLoopElement(@NonNull final ControlLoopElement authorativeConcept) { - this.fromAuthorative(authorativeConcept); - } - - @Override - public ControlLoopElement toAuthorative() { - var element = new ControlLoopElement(); - - element.setId(UUID.fromString(getKey().getLocalName())); - element.setDefinition(new ToscaConceptIdentifier(definition)); - element.setParticipantType(new ToscaConceptIdentifier(participantType)); - element.setParticipantId(new ToscaConceptIdentifier(participantId)); - element.setState(state); - element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); - element.setDescription(description); - - return element; - } - - @Override - public void fromAuthorative(@NonNull final ControlLoopElement element) { - if (this.key == null || this.getKey().isNullKey()) { - this.setKey(new PfReferenceKey()); - getKey().setLocalName(element.getId().toString()); - } - - this.definition = element.getDefinition().asConceptKey(); - this.participantType = element.getParticipantType().asConceptKey(); - this.participantId = element.getParticipantId().asConceptKey(); - this.state = element.getState(); - this.orderedState = element.getOrderedState(); - this.description = element.getDescription(); - } - - @Override - public List getKeys() { - List keyList = getKey().getKeys(); - - keyList.add(definition); - keyList.add(participantType); - keyList.add(participantId); - - return keyList; - } - - @Override - public void clean() { - key.clean(); - definition.clean(); - participantType.clean(); - participantId.clean(); - - if (description != null) { - description = description.trim(); - } - } - - @Override - public int compareTo(final PfConcept otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return this.getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaControlLoopElement other = (JpaControlLoopElement) otherConcept; - int result = key.compareTo(other.key); - if (result != 0) { - return result; - } - - result = definition.compareTo(other.definition); - if (result != 0) { - return result; - } - - result = participantType.compareTo(other.participantType); - if (result != 0) { - return result; - } - - result = participantId.compareTo(other.participantId); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(state, other.state); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(orderedState, other.orderedState); - if (result != 0) { - return result; - } - - return ObjectUtils.compare(description, other.description); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipant.java deleted file mode 100644 index c8c26a8de..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipant.java +++ /dev/null @@ -1,231 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.Table; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import org.apache.commons.lang3.ObjectUtils; -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.common.parameters.annotations.NotNull; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.validation.annotations.VerifyKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a participant in the database. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -@Entity -@Table(name = "Participant") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@EqualsAndHashCode(callSuper = false) -public class JpaParticipant extends PfConcept implements PfAuthorative, Serializable { - private static final long serialVersionUID = -4697758484642403483L; - - @EmbeddedId - @VerifyKey - @NotNull - private PfConceptKey key; - - // @formatter:off - @VerifyKey - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "definition_name")) - @AttributeOverride(name = "version", column = @Column(name = "definition_version")) - private PfConceptKey definition; - // @formatter:on - - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "participant_type_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_type_version")) - private PfConceptKey participantType; - - @Column - @NotNull - private ParticipantState participantState; - - @Column - @NotNull - private ParticipantHealthStatus healthStatus; - - @Column - private String description; - - /** - * The Default Constructor creates a {@link JpaParticipant} object with a null key. - */ - public JpaParticipant() { - this(new PfConceptKey()); - } - - /** - * The Key Constructor creates a {@link JpaParticipant} object with the given concept key. - * - * @param key the key - */ - public JpaParticipant(@NonNull final PfConceptKey key) { - this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.UNKNOWN); - } - - /** - * The Key Constructor creates a {@link JpaParticipant} object with all mandatory fields. - * - * @param key the key - * @param definition the TOSCA definition of the participant - * @param participantState the state of the participant - * @param healthStatus the health state of the participant - */ - public JpaParticipant(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, - @NonNull final ParticipantState participantState, @NonNull ParticipantHealthStatus healthStatus) { - this.key = key; - this.definition = definition; - this.participantState = participantState; - this.healthStatus = healthStatus; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public JpaParticipant(@NonNull final JpaParticipant copyConcept) { - super(copyConcept); - this.key = new PfConceptKey(copyConcept.key); - this.definition = new PfConceptKey(copyConcept.definition); - this.participantState = copyConcept.participantState; - this.healthStatus = copyConcept.healthStatus; - this.description = copyConcept.description; - this.participantType = copyConcept.participantType; - } - - /** - * Authorative constructor. - * - * @param authorativeConcept the authorative concept to copy from - */ - public JpaParticipant(@NonNull final Participant authorativeConcept) { - this.fromAuthorative(authorativeConcept); - } - - @Override - public Participant toAuthorative() { - var participant = new Participant(); - - participant.setName(key.getName()); - participant.setVersion(key.getVersion()); - participant.setDefinition(new ToscaConceptIdentifier(definition)); - participant.setParticipantState(participantState); - participant.setHealthStatus(healthStatus); - participant.setDescription(description); - participant.setParticipantType(new ToscaConceptIdentifier(participantType)); - - return participant; - } - - @Override - public void fromAuthorative(@NonNull final Participant participant) { - if (this.key == null || this.getKey().isNullKey()) { - this.setKey(new PfConceptKey(participant.getName(), participant.getVersion())); - } - - this.definition = participant.getDefinition().asConceptKey(); - this.setParticipantState(participant.getParticipantState()); - this.setHealthStatus(participant.getHealthStatus()); - this.setDescription(participant.getDescription()); - this.participantType = participant.getParticipantType().asConceptKey(); - } - - @Override - public List getKeys() { - List keyList = getKey().getKeys(); - - keyList.add(definition); - keyList.add(participantType); - - return keyList; - } - - @Override - public void clean() { - key.clean(); - definition.clean(); - description = (description == null ? null : description.trim()); - participantType.clean(); - } - - @Override - public int compareTo(final PfConcept otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaParticipant other = (JpaParticipant) otherConcept; - int result = key.compareTo(other.key); - if (result != 0) { - return result; - } - - result = definition.compareTo(other.definition); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(participantState, other.participantState); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(healthStatus, other.healthStatus); - if (result != 0) { - return result; - } - - result = ObjectUtils.compare(participantType, other.participantType); - if (result != 0) { - return result; - } - - return ObjectUtils.compare(description, other.description); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java deleted file mode 100644 index 2e5188abe..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatistics.java +++ /dev/null @@ -1,239 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.models.controlloop.persistence.concepts; - -import java.io.Serializable; -import java.util.List; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.Table; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import org.apache.commons.lang3.builder.CompareToBuilder; -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.common.parameters.annotations.NotNull; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfTimestampKey; -import org.onap.policy.models.base.validation.annotations.VerifyKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent a control loop statistics in the database. - * - * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) - */ -@Entity -@Table(name = "ParticipantStatistics") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@AllArgsConstructor -@EqualsAndHashCode(callSuper = false) -public class JpaParticipantStatistics extends PfConcept implements PfAuthorative, Serializable { - - private static final long serialVersionUID = -5992214428190133190L; - - @EmbeddedId - @VerifyKey - @NotNull - private PfTimestampKey key; - - @VerifyKey - @NotNull - @AttributeOverride(name = "name", column = @Column(name = "participant_name")) - @AttributeOverride(name = "version", column = @Column(name = "participant_version")) - private PfConceptKey participantId; - - @Column - @NotNull - private ParticipantState state; - - @Column - @NotNull - private ParticipantHealthStatus healthStatus; - - @Column - private long eventCount; - - @Column - private long lastExecutionTime; - - @Column - private double averageExecutionTime; - - @Column - private long upTime; - - @Column - private long lastEnterTime; - - @Column - private long lastStart; - - - /** - * The Default Constructor creates a {@link JpaParticipantStatistics} object with a null key. - */ - public JpaParticipantStatistics() { - this(new PfTimestampKey()); - } - - /** - * The Key Constructor creates a {@link JpaParticipantStatistics} object with the given Timestamp key. - * - * @param key the key - */ - public JpaParticipantStatistics(@NonNull final PfTimestampKey key) { - this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.HEALTHY, 0L, 0L, 0.0d, 0L, 0L, - 0L); - } - - - /** - * The Key Constructor creates a {@link JpaParticipantStatistics} object with all mandatory fields. - * - * @param key the key - * @param participantId the TOSCA definition of the control loop participant - */ - public JpaParticipantStatistics(@NonNull final PfTimestampKey key, @NonNull final PfConceptKey participantId) { - this.key = key; - this.participantId = participantId; - } - - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public JpaParticipantStatistics(@NonNull final JpaParticipantStatistics copyConcept) { - super(copyConcept); - this.key = new PfTimestampKey(copyConcept.key); - this.participantId = new PfConceptKey(copyConcept.participantId); - this.state = copyConcept.state; - this.healthStatus = copyConcept.healthStatus; - this.eventCount = copyConcept.eventCount; - this.lastExecutionTime = copyConcept.lastExecutionTime; - this.averageExecutionTime = copyConcept.averageExecutionTime; - this.upTime = copyConcept.upTime; - this.lastEnterTime = copyConcept.lastEnterTime; - this.lastStart = copyConcept.lastStart; - } - - /** - * Authorative constructor. - * - * @param authorativeConcept the authorative concept to copy from - */ - public JpaParticipantStatistics(@NonNull final ParticipantStatistics authorativeConcept) { - this.fromAuthorative(authorativeConcept); - } - - - @Override - public int compareTo(PfConcept otherConcept) { - if (otherConcept == null) { - return -1; - } - if (this == otherConcept) { - return 0; - } - if (getClass() != otherConcept.getClass()) { - return getClass().getName().compareTo(otherConcept.getClass().getName()); - } - - final JpaParticipantStatistics other = (JpaParticipantStatistics) otherConcept; - // @formatter:off - return new CompareToBuilder() - .append(this.key, other.key) - .append(this.participantId, other.participantId) - .append(this.state, other.state) - .append(this.healthStatus, other.healthStatus) - .append(this.eventCount, other.eventCount) - .append(this.lastExecutionTime, other.lastExecutionTime) - .append(this.averageExecutionTime, other.averageExecutionTime) - .append(this.upTime, other.upTime) - .append(this.lastEnterTime, other.lastEnterTime) - .append(this.lastStart, other.lastStart).toComparison(); - // @formatter:on - } - - @Override - public ParticipantStatistics toAuthorative() { - var participantStatistics = new ParticipantStatistics(); - participantStatistics.setTimeStamp(key.getTimeStamp().toInstant()); - participantStatistics.setParticipantId(new ToscaConceptIdentifier(participantId)); - participantStatistics.setState(state); - participantStatistics.setHealthStatus(healthStatus); - participantStatistics.setAverageExecutionTime(averageExecutionTime); - participantStatistics.setEventCount(eventCount); - participantStatistics.setLastExecutionTime(lastExecutionTime); - participantStatistics.setUpTime(upTime); - participantStatistics.setLastEnterTime(lastEnterTime); - participantStatistics.setLastStart(lastStart); - - return participantStatistics; - } - - @Override - public void fromAuthorative(@NonNull final ParticipantStatistics participantStatistics) { - if (this.key == null || this.getKey().isNullKey()) { - this.setKey(new PfTimestampKey(participantStatistics.getParticipantId().getName(), - participantStatistics.getParticipantId().getVersion(), participantStatistics.getTimeStamp())); - } - this.setParticipantId(participantStatistics.getParticipantId().asConceptKey()); - this.setState(participantStatistics.getState()); - this.setHealthStatus(participantStatistics.getHealthStatus()); - this.setAverageExecutionTime(participantStatistics.getAverageExecutionTime()); - this.setEventCount(participantStatistics.getEventCount()); - this.setLastExecutionTime(participantStatistics.getLastExecutionTime()); - this.setUpTime(participantStatistics.getUpTime()); - this.setLastEnterTime(participantStatistics.getLastEnterTime()); - this.setLastStart(participantStatistics.getLastStart()); - - } - - @Override - public List getKeys() { - List keyList = getKey().getKeys(); - keyList.addAll(participantId.getKeys()); - return keyList; - } - - @Override - public void clean() { - key.clean(); - participantId.clean(); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java deleted file mode 100644 index 3a7fa9c87..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProvider.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; -import lombok.AllArgsConstructor; -import lombok.NonNull; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ClElementStatisticsRepository; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.onap.policy.models.dao.PfFilterParameters; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * This class provides the provision of information on control loop element statistics in the database to callers. - * - * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) - */ -@Service -@Transactional -@AllArgsConstructor -public class ClElementStatisticsProvider { - - private ClElementStatisticsRepository clElementStatisticsRepository; - - /** - * Creates control loop element statistics. - * - * @param clElementStatisticsList a specification of the CL element statistics to create - * @return the clElement statistics created - * @throws PfModelException on initiation errors - */ - public List createClElementStatistics( - @NonNull final List clElementStatisticsList) throws PfModelException { - - try { - var jpaClElementStatisticsList = ProviderUtils.getJpaAndValidateList(clElementStatisticsList, - JpaClElementStatistics::new, "control loop element statistics"); - - var jpaClElementStatisticsSaved = clElementStatisticsRepository.saveAll(jpaClElementStatisticsList); - - // Return the saved control loop element statistics - return asClElementStatisticsList(jpaClElementStatisticsSaved); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save control loop element statistics", e); - } - } - - /** - * Convert JPA clElement statistics list to clElement statistics list. - * - * @param jpaClElementStatistics the list to convert - * @return the clElement statistics list - */ - private List asClElementStatisticsList(List jpaClElementStatistics) { - return jpaClElementStatistics.stream().map(JpaClElementStatistics::toAuthorative).collect(Collectors.toList()); - } - - /** - * Get clElement statistics. - * - * @param name the name of the participant - * @param version version of the participant - * @param id of the control loop element - * @param timestamp timestamp of the statistics - * @return the clElement statistics found - */ - @Transactional(readOnly = true) - public List getClElementStatistics(final String name, final String version, final String id, - final Instant timestamp) { - if (name != null && version != null && timestamp != null && id != null) { - return asClElementStatisticsList(clElementStatisticsRepository - .findAllById(List.of(new PfReferenceTimestampKey(name, version, id, timestamp)))); - } else if (name != null) { - return getFilteredClElementStatistics(name, version, null, null, null, "DESC", 0); - } - return asClElementStatisticsList(clElementStatisticsRepository.findAll()); - } - - /** - * Get filtered clElement statistics. - * - * @param name the clElement name for the statistics to get - * @param version the clElement version for the statistics to get - * @param startTimeStamp startTimeStamp to filter statistics - * @param endTimeStamp endTimeStamp to filter statistics - * @param sortOrder sortOrder to query database - * @param getRecordNum Total query count from database - * @param filterMap the filters to apply to the get operation - * @return the clElement statistics found - */ - @Transactional(readOnly = true) - public List getFilteredClElementStatistics(final String name, final String version, - final Instant startTimeStamp, final Instant endTimeStamp, Map filterMap, - final String sortOrder, final int getRecordNum) { - - // @formatter:off - PfFilterParameters filterParams = PfFilterParameters - .builder() - .name(name) - .version(version) - .startTime(startTimeStamp) - .endTime(endTimeStamp) - .filterMap(filterMap) - .sortOrder(sortOrder) - .recordNum(getRecordNum) - .build(); - // @formatter:on - return asClElementStatisticsList( - clElementStatisticsRepository.getFiltered(JpaClElementStatistics.class, filterParams)); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java deleted file mode 100644 index a1b1045eb..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProvider.java +++ /dev/null @@ -1,279 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.models.controlloop.persistence.provider; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.persistence.EntityNotFoundException; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import lombok.AllArgsConstructor; -import lombok.NonNull; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ControlLoopRepository; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaNodeTemplateRepository; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaNodeTemplatesRepository; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * This class provides information on control loop concepts in the database to callers. - */ -@Service -@Transactional -@AllArgsConstructor -public class ControlLoopProvider { - - private final ControlLoopRepository controlLoopRepository; - private final ToscaNodeTemplateRepository toscaNodeTemplateRepository; - private final ToscaNodeTemplatesRepository toscaNodeTemplatesRepository; - - /** - * Get Control Loop. - * - * @param controlLoopId the ID of the control loop to get - * @return the control loop found - * @throws PfModelException on errors getting the control loop - */ - @Transactional(readOnly = true) - public ControlLoop getControlLoop(final ToscaConceptIdentifier controlLoopId) throws PfModelException { - try { - return controlLoopRepository.getById(controlLoopId.asConceptKey()).toAuthorative(); - } catch (EntityNotFoundException e) { - throw new PfModelException(Status.NOT_FOUND, "ControlLoop not found", e); - } - } - - /** - * Find Control Loop by controlLoopId. - * - * @param name the name of the control loop to get, null to get all control loops - * @param version the version of the control loop to get, null to get all control loops - * @return the control loop found - * @throws PfModelException on errors getting the control loop - */ - @Transactional(readOnly = true) - public Optional findControlLoop(@NonNull final String name, @NonNull final String version) - throws PfModelException { - return findControlLoop(new PfConceptKey(name, version)); - } - - /** - * Find Control Loop by controlLoopId. - * - * @param controlLoopId the ID of the control loop to get - * @return the control loop found - * @throws PfModelException on errors getting the control loop - */ - @Transactional(readOnly = true) - public Optional findControlLoop(final ToscaConceptIdentifier controlLoopId) throws PfModelException { - return findControlLoop(controlLoopId.asConceptKey()); - } - - private Optional findControlLoop(@NonNull final PfConceptKey key) throws PfModelException { - try { - return controlLoopRepository.findById(key).map(JpaControlLoop::toAuthorative); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Not valid parameter", e); - } - } - - /** - * Save Control Loop. - * - * @param controlLoop the control loop to update - * @return the updated control loop - * @throws PfModelException on errors updating the control loop - */ - public ControlLoop saveControlLoop(final ControlLoop controlLoop) throws PfModelException { - try { - var result = controlLoopRepository - .save(ProviderUtils.getJpaAndValidate(controlLoop, JpaControlLoop::new, "control loop")); - - // Return the saved participant - return result.toAuthorative(); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save controlLoop", e); - } - } - - /** - * Get All Control Loops. - * - * @return all control loops found - * @throws PfModelException on errors getting control loops - */ - @Transactional(readOnly = true) - public List getControlLoops() throws PfModelException { - - return ProviderUtils.asEntityList(controlLoopRepository.findAll()); - } - - /** - * Get Control Loops. - * - * @param name the name of the control loop to get, null to get all control loops - * @param version the version of the control loop to get, null to get all control loops - * @return the control loops found - * @throws PfModelException on errors getting control loops - */ - @Transactional(readOnly = true) - public List getControlLoops(final String name, final String version) throws PfModelException { - - return ProviderUtils.asEntityList(controlLoopRepository.getFiltered(JpaControlLoop.class, name, version)); - } - - /** - * Saves control loops. - * - * @param controlLoops a specification of the control loops to create - * @return the control loops created - * @throws PfModelException on errors creating control loops - */ - public List saveControlLoops(@NonNull final List controlLoops) throws PfModelException { - try { - var result = controlLoopRepository - .saveAll(ProviderUtils.getJpaAndValidateList(controlLoops, JpaControlLoop::new, "control loops")); - - // Return the saved participant - return ProviderUtils.asEntityList(result); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save ControlLoops", e); - } - } - - /** - * Saves Instance Properties to the database. - * - * @param serviceTemplate the service template - * @return a Map of tosca node templates - */ - public Map saveInstanceProperties(ToscaServiceTemplate serviceTemplate) { - Map savedNodeTemplates = new HashMap<>(); - - var jpaToscaNodeTemplates = new JpaToscaNodeTemplates(); - jpaToscaNodeTemplates.fromAuthorative(List.of(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates())); - - toscaNodeTemplatesRepository.save(jpaToscaNodeTemplates); - serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach(savedNodeTemplates::put); - - return savedNodeTemplates; - } - - /** - * Delete a control loop. - * - * @param name the name of the control loop to delete - * @param version the version of the control loop to delete - * @return the control loop deleted - * @throws PfModelException on errors deleting the control loop - */ - public ControlLoop deleteControlLoop(@NonNull final String name, @NonNull final String version) - throws PfModelException { - - var controlLoopKey = new PfConceptKey(name, version); - var jpaDeleteControlLoop = controlLoopRepository.findById(controlLoopKey); - - if (jpaDeleteControlLoop.isEmpty()) { - String errorMessage = - "delete of control loop \"" + controlLoopKey.getId() + "\" failed, control loop does not exist"; - throw new PfModelException(Response.Status.BAD_REQUEST, errorMessage); - } - - controlLoopRepository.deleteById(controlLoopKey); - - return jpaDeleteControlLoop.get().toAuthorative(); - } - - /** - * Deletes Instance Properties on the database. - * - * @param filteredToscaNodeTemplateMap filtered node templates map to delete - * @param filteredToscaNodeTemplateList filtered node template list to delete - */ - public void deleteInstanceProperties(Map filteredToscaNodeTemplateMap, - List filteredToscaNodeTemplateList) { - - var jpaToscaNodeTemplates = new JpaToscaNodeTemplates(); - jpaToscaNodeTemplates.fromAuthorative(List.of(filteredToscaNodeTemplateMap)); - - toscaNodeTemplatesRepository.save(jpaToscaNodeTemplates); - - filteredToscaNodeTemplateList.forEach(template -> { - var jpaToscaNodeTemplate = new JpaToscaNodeTemplate(template); - - toscaNodeTemplateRepository.delete(jpaToscaNodeTemplate); - }); - } - - /** - * Get All Node Templates. - * - * @return the list of node templates found - * @throws PfModelException on errors getting node templates - */ - @Transactional(readOnly = true) - public List getAllNodeTemplates() { - return ProviderUtils.asEntityList(toscaNodeTemplateRepository.findAll()); - } - - /** - * Get Node Templates. - * - * @param name the name of the node template to get, null to get all node templates - * @param version the version of the node template to get, null to get all node templates - * @return the node templates found - * @throws PfModelException on errors getting node templates - */ - @Transactional(readOnly = true) - public List getNodeTemplates(final String name, final String version) { - return ProviderUtils - .asEntityList(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version)); - } - - /** - * Get filtered node templates. - * - * @param filter the filter for the node templates to get - * @return the node templates found - * @throws PfModelException on errors getting node templates - */ - @Transactional(readOnly = true) - public List getFilteredNodeTemplates( - @NonNull final ToscaTypedEntityFilter filter) { - - return filter.filter(ProviderUtils.asEntityList(toscaNodeTemplateRepository - .getFiltered(JpaToscaNodeTemplate.class, filter.getName(), filter.getVersion()))); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProvider.java deleted file mode 100644 index 0c001c11c..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProvider.java +++ /dev/null @@ -1,152 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import java.util.List; -import java.util.Optional; -import javax.ws.rs.core.Response.Status; -import lombok.AllArgsConstructor; -import lombok.NonNull; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ParticipantRepository; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * This class provides information on participant concepts in the database to callers. - */ -@Service -@Transactional -@AllArgsConstructor -public class ParticipantProvider { - - private ParticipantRepository participantRepository; - - /** - * Get participants. - * - * @param name the name of the participant to get, null to get all participants - * @param version the version of the participant to get, null to get all participants - * @return the participants found - * @throws PfModelException on errors getting participants - */ - @Transactional(readOnly = true) - public List getParticipants(final String name, final String version) throws PfModelException { - - return ProviderUtils.asEntityList(participantRepository.getFiltered(JpaParticipant.class, name, version)); - } - - /** - * Get all participants. - * - * @return the participants found - * @throws PfModelException on errors getting policies - */ - @Transactional(readOnly = true) - public List getParticipants() throws PfModelException { - return ProviderUtils.asEntityList(participantRepository.findAll()); - } - - /** - * Get participant. - * - * @param name the name of the participant to get - * @param version the version of the participant to get - * @return the participant found - * @throws PfModelException on errors getting participant - */ - @Transactional(readOnly = true) - public Optional findParticipant(@NonNull final String name, @NonNull final String version) - throws PfModelException { - try { - return participantRepository.findById(new PfConceptKey(name, version)).map(JpaParticipant::toAuthorative); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in find Participant", e); - } - } - - /** - * Get filtered participants. - * - * @param filter the filter for the participants to get - * @return the participants found - * @throws PfModelException on errors getting policies - */ - @Transactional(readOnly = true) - public List getFilteredParticipants(@NonNull final ToscaTypedEntityFilter filter) - throws PfModelException { - - return filter.filter(ProviderUtils.asEntityList( - participantRepository.getFiltered(JpaParticipant.class, filter.getName(), filter.getVersion()))); - } - - /** - * Saves participant. - * - * @param participant participant to save - * @return the participant created - * @throws PfModelException on errors creating participants - */ - public Participant saveParticipant(@NonNull final Participant participant) throws PfModelException { - try { - var result = participantRepository - .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant")); - - // Return the saved participant - return result.toAuthorative(); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save Participant", e); - } - } - - /** - * Delete a participant. - * - * @param name the name of the participant to delete - * @param version the version of the participant to get - * @return the participant deleted - * @throws PfModelRuntimeException on errors deleting participants - */ - public Participant deleteParticipant(@NonNull final String name, @NonNull final String version) - throws PfModelException { - try { - var participantKey = new PfConceptKey(name, version); - - var jpaDeleteParticipantOpt = participantRepository.findById(participantKey); - - if (jpaDeleteParticipantOpt.isEmpty()) { - String errorMessage = - "delete of participant \"" + participantKey.getId() + "\" failed, participant does not exist"; - throw new PfModelRuntimeException(Status.BAD_REQUEST, errorMessage); - } - participantRepository.delete(jpaDeleteParticipantOpt.get()); - - return jpaDeleteParticipantOpt.get().toAuthorative(); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in delete Participant", e); - } - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java deleted file mode 100644 index bb4f3a5dd..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProvider.java +++ /dev/null @@ -1,138 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import javax.ws.rs.core.Response.Status; -import lombok.AllArgsConstructor; -import lombok.NonNull; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ParticipantStatisticsRepository; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfTimestampKey; -import org.onap.policy.models.dao.PfFilterParameters; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * This class provides the provision of information on participant statistics in the database to callers. - */ -@Service -@Transactional -@AllArgsConstructor -public class ParticipantStatisticsProvider { - - private ParticipantStatisticsRepository participantStatisticsRepository; - - /** - * Get Participant statistics. - * - * @param name the name of the participant statistics to get, null to get all stats - * @param version the version of the participant statistics to get, null to get all stats for a name - * @param timestamp the time stamp for the stats to get - * @return the participant statistics found - */ - @Transactional(readOnly = true) - public List getParticipantStatistics(final String name, final String version, - final Instant timestamp) { - if (name != null && version != null && timestamp != null) { - return asParticipantStatisticsList( - participantStatisticsRepository.findAllById(List.of(new PfTimestampKey(name, version, timestamp)))); - } else if (name != null) { - return getFilteredParticipantStatistics(name, version, timestamp, null, null, "DESC", 0); - } - return asParticipantStatisticsList(participantStatisticsRepository.findAll()); - } - - /** - * Get filtered participant statistics. - * - * @param name the participant name for the statistics to get - * @param version the participant version for the statistics to get - * @param startTimeStamp startTimeStamp to filter statistics - * @param endTimeStamp endTimeStamp to filter statistics - * @param sortOrder sortOrder to query database - * @param getRecordNum Total query count from database - * @param filterMap the filters to apply to the get operation - * @return the participant statistics found - */ - @Transactional(readOnly = true) - public List getFilteredParticipantStatistics(final String name, final String version, - final Instant startTimeStamp, final Instant endTimeStamp, Map filterMap, - final String sortOrder, final int getRecordNum) { - - // @formatter:off - PfFilterParameters filterParams = PfFilterParameters - .builder() - .name(name) - .version(version) - .startTime(startTimeStamp) - .endTime(endTimeStamp) - .filterMap(filterMap) - .sortOrder(sortOrder) - .recordNum(getRecordNum) - .build(); - // @formatter:on - - return asParticipantStatisticsList( - participantStatisticsRepository.getFiltered(JpaParticipantStatistics.class, filterParams)); - } - - /** - * Creates Participant statistics. - * - * @param participantStatisticsList a specification of the CL statistics to create - * @return the participant statistics created - * @throws PfModelException on errors creating participant statistics - */ - public List createParticipantStatistics( - @NonNull final List participantStatisticsList) throws PfModelException { - - try { - var jpaParticipantStatisticsList = ProviderUtils.getJpaAndValidateList(participantStatisticsList, - JpaParticipantStatistics::new, "Participant Statistics"); - - var jpaParticipantStatisticsSaved = participantStatisticsRepository.saveAll(jpaParticipantStatisticsList); - - // Return the saved participant statistics - return asParticipantStatisticsList(jpaParticipantStatisticsSaved); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save participant statistics", e); - } - } - - /** - * Convert JPA participant statistics list to participant statistics list. - * - * @param jpaParticipantStatisticsList the list to convert - * @return the participant statistics list - */ - private List asParticipantStatisticsList( - List jpaParticipantStatisticsList) { - - return jpaParticipantStatisticsList.stream().map(JpaParticipantStatistics::toAuthorative) - .collect(Collectors.toList()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java deleted file mode 100644 index 3b0400b4f..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ProviderUtils.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import java.util.ArrayList; -import java.util.List; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import javax.ws.rs.core.Response; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.onap.policy.common.parameters.BeanValidationResult; -import org.onap.policy.models.base.PfAuthorative; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class ProviderUtils { - - /** - * Convert a list of concepts to a list of Jpa objects. - * - * @param authorativeConceptList the list of concepts - * @param jpaSupplier the Jpa Supplier - * @param conceptDescription the description used for validation result - * @return the list of Jpa objects - */ - public static > List getJpaAndValidateList( - List authorativeConceptList, Supplier jpaSupplier, String conceptDescription) { - var validationResult = new BeanValidationResult(conceptDescription + " List", authorativeConceptList); - - List jpaConceptList = new ArrayList<>(authorativeConceptList.size()); - - for (A authorativeConcept : authorativeConceptList) { - var jpaConcept = jpaSupplier.get(); - jpaConcept.fromAuthorative(authorativeConcept); - jpaConceptList.add(jpaConcept); - - validationResult.addResult(jpaConcept.validate(conceptDescription)); - } - - if (!validationResult.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); - } - return jpaConceptList; - } - - protected static > J getJpaAndValidate(A authorativeConcept, - Supplier jpaSupplier, String conceptDescription) { - var validationResult = new BeanValidationResult(conceptDescription, authorativeConcept); - - var jpaConcept = jpaSupplier.get(); - jpaConcept.fromAuthorative(authorativeConcept); - - validationResult.addResult(jpaConcept.validate(conceptDescription)); - - if (!validationResult.isValid()) { - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); - } - return jpaConcept; - } - - /** - * Convert JPA control loop list to an authorative control loop list. - * - * @param the type of TOSCA entity - * @param the type of JPA TOSCA entity - * @param jpaEntityList the list to convert - * @return the authorative list - */ - public static > List asEntityList(List jpaEntityList) { - return jpaEntityList.stream().map(J::toAuthorative).collect(Collectors.toList()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProvider.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProvider.java deleted file mode 100644 index 8ff0dd102..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProvider.java +++ /dev/null @@ -1,261 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import lombok.RequiredArgsConstructor; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaServiceTemplateRepository; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@Transactional -@RequiredArgsConstructor -public class ServiceTemplateProvider { - - private final ToscaServiceTemplateRepository serviceTemplateRepository; - - /** - * Create service template. - * - * @param serviceTemplate the service template to be created - * @return the created service template - * @throws PfModelException on errors creating the service template - */ - public ToscaServiceTemplate createServiceTemplate(final ToscaServiceTemplate serviceTemplate) - throws PfModelException { - try { - var result = serviceTemplateRepository.save(ProviderUtils.getJpaAndValidate(serviceTemplate, - JpaToscaServiceTemplate::new, "toscaServiceTemplate")); - return result.toAuthorative(); - } catch (IllegalArgumentException e) { - throw new PfModelException(Status.BAD_REQUEST, "Error in save serviceTemplate", e); - } - } - - /** - * Delete service template. - * - * @param name the name of the service template to delete. - * @param version the version of the service template to delete. - * @return the TOSCA service template that was deleted - * @throws PfModelException on errors deleting policy types - */ - public ToscaServiceTemplate deleteServiceTemplate(final String name, final String version) throws PfModelException { - var serviceTemplateKey = new PfConceptKey(name, version); - var jpaDelete = serviceTemplateRepository.findById(serviceTemplateKey); - if (jpaDelete.isEmpty()) { - String errorMessage = "delete of serviceTemplate \"" + serviceTemplateKey.getId() - + "\" failed, serviceTemplate does not exist"; - throw new PfModelException(Response.Status.BAD_REQUEST, errorMessage); - } - serviceTemplateRepository.deleteById(serviceTemplateKey); - return jpaDelete.get().toAuthorative(); - } - - /** - * Get the requested control loop definitions. - * - * @param name the name of the definition to get, null for all definitions - * @param version the version of the definition to get, null for all definitions - * @return the control loop definitions - * @throws PfModelException on errors getting control loop definitions - */ - @Transactional(readOnly = true) - public ToscaServiceTemplate getToscaServiceTemplate(String name, String version) throws PfModelException { - var serviceTemplateKey = new PfConceptKey(name, version); - var jpaServiceTemplates = serviceTemplateRepository.findById(serviceTemplateKey); - if (jpaServiceTemplates.isEmpty()) { - throw new PfModelException(Status.NOT_FOUND, "Control Loop definitions not found"); - } - return jpaServiceTemplates.get().toAuthorative(); - } - - /** - * Get service templates. - * - * @return the topology templates found - * @throws PfModelException on errors getting service templates - */ - @Transactional(readOnly = true) - public List getAllServiceTemplates() throws PfModelException { - var jpaList = serviceTemplateRepository.findAll(); - return ProviderUtils.asEntityList(jpaList); - } - - /** - * Get service templates. - * - * @param name the name of the topology template to get, set to null to get all service templates - * @param version the version of the service template to get, set to null to get all service templates - * @return the topology templates found - * @throws PfModelException on errors getting service templates - */ - @Transactional(readOnly = true) - public List getServiceTemplateList(final String name, final String version) - throws PfModelException { - var jpaList = serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, name, version); - return ProviderUtils.asEntityList(jpaList); - } - - /** - * Get the initial node types with common or instance properties. - * - * @param fullNodeTypes map of all the node types in the specified template - * @param common boolean to indicate whether common or instance properties are required - * @return node types map that only has common properties - * @throws PfModelException on errors getting node type with common properties - */ - private Map getInitialNodeTypesMap(Map fullNodeTypes, - boolean common) { - - var tempNodeTypesMap = new HashMap(); - - fullNodeTypes.forEach((key, nodeType) -> { - var tempToscaNodeType = new ToscaNodeType(); - tempToscaNodeType.setName(key); - - var resultantPropertyMap = findCommonOrInstancePropsInNodeTypes(nodeType, common); - - if (!resultantPropertyMap.isEmpty()) { - tempToscaNodeType.setProperties(resultantPropertyMap); - tempNodeTypesMap.put(key, tempToscaNodeType); - } - }); - return tempNodeTypesMap; - } - - private Map findCommonOrInstancePropsInNodeTypes(ToscaNodeType nodeType, boolean common) { - - var tempCommonPropertyMap = new HashMap(); - var tempInstancePropertyMap = new HashMap(); - - nodeType.getProperties().forEach((propKey, prop) -> { - - if (prop.getMetadata() != null) { - prop.getMetadata().forEach((k, v) -> { - if (k.equals("common") && v.equals("true") && common) { - tempCommonPropertyMap.put(propKey, prop); - } else if (k.equals("common") && v.equals("false") && !common) { - tempInstancePropertyMap.put(propKey, prop); - } - - }); - } else { - tempInstancePropertyMap.put(propKey, prop); - } - }); - - if (tempCommonPropertyMap.isEmpty() && !common) { - return tempInstancePropertyMap; - } else { - return tempCommonPropertyMap; - } - } - - /** - * Get the node types derived from those that have common properties. - * - * @param initialNodeTypes map of all the node types in the specified template - * @param filteredNodeTypes map of all the node types that have common or instance properties - * @return all node types that have common properties including their children - * @throws PfModelException on errors getting node type with common properties - */ - private Map getFinalNodeTypesMap(Map initialNodeTypes, - Map filteredNodeTypes) { - for (var i = 0; i < initialNodeTypes.size(); i++) { - initialNodeTypes.forEach((key, nodeType) -> { - var tempToscaNodeType = new ToscaNodeType(); - tempToscaNodeType.setName(key); - - if (filteredNodeTypes.get(nodeType.getDerivedFrom()) != null) { - tempToscaNodeType.setName(key); - - var finalProps = new HashMap( - filteredNodeTypes.get(nodeType.getDerivedFrom()).getProperties()); - - tempToscaNodeType.setProperties(finalProps); - } else { - return; - } - filteredNodeTypes.putIfAbsent(key, tempToscaNodeType); - - }); - } - return filteredNodeTypes; - } - - /** - * Get the requested node types with common or instance properties. - * - * @param common boolean indicating common or instance properties - * @param serviceTemplate the ToscaServiceTemplate - * @return the node types with common or instance properties - * @throws PfModelException on errors getting node type properties - */ - public Map getCommonOrInstancePropertiesFromNodeTypes(boolean common, - ToscaServiceTemplate serviceTemplate) throws PfModelException { - var tempNodeTypesMap = this.getInitialNodeTypesMap(serviceTemplate.getNodeTypes(), common); - - return this.getFinalNodeTypesMap(serviceTemplate.getNodeTypes(), tempNodeTypesMap); - - } - - /** - * Get node templates with appropriate common or instance properties added. - * - * @param initialNodeTemplates map of all the node templates in the specified template - * @param nodeTypeProps map of all the node types that have common or instance properties including children - * @return all node templates with appropriate common or instance properties added - * @throws PfModelException on errors getting map of node templates with common or instance properties added - */ - public Map getDerivedCommonOrInstanceNodeTemplates( - Map initialNodeTemplates, Map nodeTypeProps) { - - var finalNodeTemplatesMap = new HashMap(); - - initialNodeTemplates.forEach((templateKey, template) -> { - if (nodeTypeProps.containsKey(template.getType())) { - var finalMergedProps = new HashMap(); - - nodeTypeProps.get(template.getType()).getProperties().forEach(finalMergedProps::putIfAbsent); - - template.setProperties(finalMergedProps); - - finalNodeTemplatesMap.put(templateKey, template); - } else { - return; - } - }); - return finalNodeTemplatesMap; - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ClElementStatisticsRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ClElementStatisticsRepository.java deleted file mode 100644 index 1e07a4fe6..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ClElementStatisticsRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ClElementStatisticsRepository - extends JpaRepository, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ControlLoopRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ControlLoopRepository.java deleted file mode 100644 index 1a5fd5a56..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ControlLoopRepository.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop; -import org.onap.policy.models.base.PfConceptKey; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ControlLoopRepository extends JpaRepository, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepository.java deleted file mode 100644 index ce1f3d8c3..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepository.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import java.util.List; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.dao.PfFilterParametersIntfc; - -public interface FilterRepository { - - /** - * Get an object from the database, referred to by concept key. - * - * @param the type of the object to get, a subclass of {@link PfConcept} - * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts - * of type T are returned, if name is not null and version is null, all versions of that concept matching the - * name are returned. - * @param filterParams filter parameters - * @return the objects that was retrieved from the database - */ - List getFiltered(Class someClass, PfFilterParametersIntfc filterParams); - - /** - * Get an object from the database, referred to by concept key. - * - * @param the type of the object to get, a subclass of {@link PfConcept} - * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts - * of type T are returned, if name is not null and version is null, all versions of that concept matching the - * name are returned. - * @param name the name of the object to get, null returns all objects - * @param version the version the object to get, null returns all objects for a specified name - * @return the objects that was retrieved from the database - */ - List getFiltered(Class someClass, String name, String version); -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImpl.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImpl.java deleted file mode 100644 index 0dc8fc373..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import java.util.List; -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import org.onap.policy.models.base.PfConcept; -import org.onap.policy.models.dao.PfDao; -import org.onap.policy.models.dao.PfFilterParametersIntfc; -import org.onap.policy.models.dao.impl.ProxyDao; -import org.springframework.stereotype.Repository; - -@Repository -public class FilterRepositoryImpl implements FilterRepository { - - @PersistenceContext - private EntityManager entityManager; - - protected PfDao getPfDao() { - return new ProxyDao(entityManager); - } - - @Override - public List getFiltered(Class someClass, PfFilterParametersIntfc filterParams) { - return getPfDao().getFiltered(someClass, filterParams); - } - - @Override - public List getFiltered(Class someClass, String name, String version) { - return getPfDao().getFiltered(someClass, name, version); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantRepository.java deleted file mode 100644 index 671d23bbe..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantRepository.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant; -import org.onap.policy.models.base.PfConceptKey; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ParticipantRepository extends JpaRepository, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantStatisticsRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantStatisticsRepository.java deleted file mode 100644 index 6fecd6143..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ParticipantStatisticsRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics; -import org.onap.policy.models.base.PfTimestampKey; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface ParticipantStatisticsRepository - extends JpaRepository, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplateRepository.java deleted file mode 100644 index a8f830fed..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplateRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ToscaNodeTemplateRepository - extends JpaRepository, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplatesRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplatesRepository.java deleted file mode 100644 index 7bd7d1013..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaNodeTemplatesRepository.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ToscaNodeTemplatesRepository extends JpaRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaServiceTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaServiceTemplateRepository.java deleted file mode 100644 index a5d5fe766..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/ToscaServiceTemplateRepository.java +++ /dev/null @@ -1,30 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ToscaServiceTemplateRepository - extends JpaRepository, FilterRepository { - -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotification.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotification.java deleted file mode 100644 index c6bbd81d6..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotification.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification; - -import com.google.gson.annotations.SerializedName; -import java.util.ArrayList; -import java.util.List; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.apache.commons.collections4.CollectionUtils; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ControlLoopNotification { - - /** - * Status of control loops that are being added to participants. - */ - @SerializedName("deployed-control-loops") - private List added = new ArrayList<>(); - - /** - * Status of policies that are being deleted from PDPs. - */ - @SerializedName("undeployed-control-loops") - private List deleted = new ArrayList<>(); - - - /** - * Determines if the notification is empty (i.e., has no added or delete control loop - * notifications). - * - * @return {@code true} if the notification is empty, {@code false} otherwise - */ - public boolean isEmpty() { - return (CollectionUtils.isEmpty(added) && CollectionUtils.isEmpty(deleted)); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatus.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatus.java deleted file mode 100644 index 033843e75..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatus.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.controlloop.models.messages.dmaap.notification; - -import com.google.gson.annotations.SerializedName; -import java.util.UUID; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@Data -@NoArgsConstructor -@AllArgsConstructor -public class ControlLoopStatus { - @SerializedName("control-loop-id") - private UUID id; - - private ToscaConceptIdentifier definition; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java deleted file mode 100644 index cdbfea4e2..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAck.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; -import java.util.function.UnaryOperator; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementAck; -import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent the CONTROLLOOP_ACK message that a participant sends - * to control loop runtime as an acknowledgement to either ControlLoopUpdate - * or ControlLoopStateChange message. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ControlLoopAck extends ParticipantAckMessage { - - private ToscaConceptIdentifier controlLoopId; - private Integer startPhase; - - // A map with ControlLoopElementID as its key, and a pair of result and message as value per - // ControlLoopElement. - private Map controlLoopResultMap = new LinkedHashMap<>(); - - /** - * Constructor for instantiating ParticipantRegisterAck class with message name. - * - */ - public ControlLoopAck(final ParticipantMessageType messageType) { - super(messageType); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ControlLoopAck(final ControlLoopAck source) { - super(source); - this.controlLoopId = source.controlLoopId; - this.controlLoopResultMap = PfUtils.mapMap(source.controlLoopResultMap, UnaryOperator.identity()); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java deleted file mode 100644 index e3b7049e1..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChange.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; - -/** - * Class to represent the CONTROL_LOOP_STATE_CHANGE message that the control loop runtime will send to - * participants to change the state of a control loop they are running. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ControlLoopStateChange extends ParticipantMessage { - private ControlLoopOrderedState orderedState; - private ControlLoopState currentState; - private Integer startPhase; - - /** - * Constructor for instantiating ControlLoopStateChange class with message name. - * - */ - public ControlLoopStateChange() { - super(ParticipantMessageType.CONTROL_LOOP_STATE_CHANGE); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ControlLoopStateChange(ControlLoopStateChange source) { - super(source); - - this.orderedState = source.orderedState; - this.currentState = source.currentState; - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java deleted file mode 100644 index f8a47c7c9..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdate.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUpdates; -import org.onap.policy.models.base.PfUtils; - -/** - * Class to represent the CONTROL_LOOP_UPDATE message that the control loop runtime sends to a participant. - * When a participant receives this message, it creates the control loop elements contained in the message and sets them - * to state PASSIVE. subsequent CONTROL_LOOP_STATE_CHANGE messages are used to activate the control loops. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ControlLoopUpdate extends ParticipantMessage { - - // A list of ParticipantUpdates instances which carries details of an updated participant. - private List participantUpdatesList = new ArrayList<>(); - private Integer startPhase = 0; - - /** - * Constructor for instantiating ControlLoopUpdate class with message name. - * - */ - public ControlLoopUpdate() { - super(ParticipantMessageType.CONTROL_LOOP_UPDATE); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ControlLoopUpdate(ControlLoopUpdate source) { - super(source); - - this.participantUpdatesList = PfUtils.mapList(source.participantUpdatesList, - ParticipantUpdates::new); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java deleted file mode 100644 index 8a1be69bd..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessage.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import java.util.UUID; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent participant Ack message. - */ -@Getter -@Setter -@ToString -public class ParticipantAckMessage { - - // The responseTo field should match the original request id in the request. - private UUID responseTo; - - // Result: Success/Fail. - private Boolean result; - - // Message indicating reason for failure - private String message; - - private ParticipantMessageType messageType; - - /** - * Participant Type, or {@code null} for messages from participants. - */ - private ToscaConceptIdentifier participantType; - - /** - * Participant ID, or {@code null} for messages from participants. - */ - private ToscaConceptIdentifier participantId; - - /** - * Participant State, or {@code null} for messages from participants. - */ - private ParticipantState state; - - /** - * Constructor for instantiating a participant ack message class. - * - * @param messageType the message type - */ - public ParticipantAckMessage(final ParticipantMessageType messageType) { - this.messageType = messageType; - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantAckMessage(ParticipantAckMessage source) { - this.responseTo = source.responseTo; - this.result = source.result; - this.message = source.message; - this.messageType = source.messageType; - this.participantType = source.participantType; - this.participantId = source.participantId; - this.state = source.state; - } - - /** - * Determines if this message applies to this participant type. - * - * @param participantType type of the participant to match against - * @param participantId id of the participant to match against - * @return {@code true} if this message applies to this participant, {@code false} otherwise - */ - public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, - @NonNull final ToscaConceptIdentifier participantId) { - // Broadcast message to all participants - if (this.participantType == null) { - return true; - } - - if (!participantType.equals(this.participantType)) { - return false; - } - - // Broadcast message to all control loop elements on this participant - if (this.participantId == null) { - return true; - } - - // Targeted message at this specific participant - return participantId.equals(this.participantId); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregister.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregister.java deleted file mode 100644 index 7705e3d0c..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregister.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Class to represent the PARTICIPANT_DEREGISTER message that all the participants send to control loop runtime. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantDeregister extends ParticipantMessage { - - /** - * Constructor for instantiating ParticipantDeregister class with message name. - * - */ - public ParticipantDeregister() { - super(ParticipantMessageType.PARTICIPANT_DEREGISTER); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantDeregister(final ParticipantDeregister source) { - super(source); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAck.java deleted file mode 100644 index 69406beb7..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAck.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Class to represent the PARTICIPANT_DEREGISTER_ACK message that control loop runtime sends to the participant. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantDeregisterAck extends ParticipantAckMessage { - - /** - * Constructor for instantiating ParticipantDeregisterAck class with message name. - * - */ - public ParticipantDeregisterAck() { - super(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantDeregisterAck(final ParticipantDeregisterAck source) { - super(source); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java deleted file mode 100644 index f98a88c3b..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessage.java +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import java.time.Instant; -import java.util.UUID; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NonNull; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Class to represent the base class for various messages that will be exchanged between the control loop runtime and - * participants. - */ -@Getter -@Setter -@ToString -public class ParticipantMessage { - @Setter(AccessLevel.NONE) - private ParticipantMessageType messageType; - - private UUID messageId = UUID.randomUUID(); - - /** - * Time-stamp, in milliseconds, when the message was created. Defaults to the current time. - */ - private Instant timestamp = Instant.now(); - - /** - * Participant Type, or {@code null} for messages from participants. - */ - private ToscaConceptIdentifier participantType; - - /** - * Participant ID, or {@code null} for messages from participants. - */ - private ToscaConceptIdentifier participantId; - - /** - * Control loop ID, or {@code null} for messages to participants. - */ - private ToscaConceptIdentifier controlLoopId; - - /** - * Constructor for instantiating a participant message class. - * - * @param messageType the message type - */ - public ParticipantMessage(final ParticipantMessageType messageType) { - this.messageType = messageType; - } - - /** - * Constructs the object, making a deep copy. Does not copy the request id or the time stamp. - * - * @param source source from which to copy - */ - public ParticipantMessage(final ParticipantMessage source) { - this.messageType = source.messageType; - this.participantType = source.participantType; - this.participantId = source.participantId; - this.controlLoopId = source.controlLoopId; - } - - /** - * Determines if this message applies to this participant type. - * - * @param participantType type of the participant to match against - * @param participantId id of the participant to match against - * @return {@code true} if this message applies to this participant, {@code false} otherwise - */ - public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, - @NonNull final ToscaConceptIdentifier participantId) { - // Broadcast message to all participants - if (this.participantType == null) { - return true; - } - - if (!participantType.equals(this.participantType)) { - return false; - } - - // Broadcast message to all control loop elements on this participant - if (this.participantId == null) { - return true; - } - - // Targeted message at this specific participant - return participantId.equals(this.participantId); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java deleted file mode 100644 index 62b8d20b0..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageType.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -/** - * Class to hold the possible values for the type of participant messages. - */ -public enum ParticipantMessageType { - - /** - * Used by participants to report status to the control loop runtime. - */ - PARTICIPANT_STATUS, - - /** - * Used by the controlloop runtime to change the state of participants, triggers a - * PARTICIPANT_STATUS message with the result of the PARTICIPANT_STATE_CHANGE operation. - */ - PARTICIPANT_STATE_CHANGE, - - /** - * Used by controlloop runtime to update the controlloops running on participants, triggers a - * PARTICIPANT_STATUS message with the result of the CONTROL_LOOP_UPDATE operation. - */ - CONTROL_LOOP_UPDATE, - - /** - * Used by controlloop runtime to change the state of controlloops in participants, triggers a - * PARTICIPANT_STATUS message with result of CONTROL_LOOP_STATE_CHANGE operation. - */ - CONTROL_LOOP_STATE_CHANGE, - - /** - * Used by the control loop runtime to order a health check on participants, triggers a - * PARTICIPANT_STATUS message with the result of the PARTICIPANT_HEALTH_CHECK operation. - */ - PARTICIPANT_HEALTH_CHECK, - - /** - * Used by participant to register itself with control loop runtime. - */ - PARTICIPANT_REGISTER, - - /** - * Used by control loop runtime to respond to participant registration. - */ - PARTICIPANT_REGISTER_ACK, - - /** - * Used by participant to deregister itself with control loop runtime. - */ - PARTICIPANT_DEREGISTER, - - /** - * Used by control loop runtime to respond to participant deregistration. - */ - PARTICIPANT_DEREGISTER_ACK, - - /** - * Used by control loop runtime to send ToscaServiceTemplate to participant. - */ - PARTICIPANT_UPDATE, - - /** - * Used by participant to acknowledge the receipt of Participant_Update message - * from control loop runtime. - */ - PARTICIPANT_UPDATE_ACK, - - /** - * Used by participant to acknowledge the receipt of ControlLoop_Update message - * from control loop runtime. - */ - CONTROLLOOP_UPDATE_ACK, - - /** - * Used by participant to acknowledge the receipt of ControlLoop_StateChange message - * from control loop runtime. - */ - CONTROLLOOP_STATECHANGE_ACK, - - /** - * Used by control loop runtime to request for ParticipantStatus message immediately. - */ - PARTICIPANT_STATUS_REQ -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java deleted file mode 100644 index af0149189..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegister.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Class to represent the PARTICIPANT_REGISTER message that all the participants send to control loop runtime. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantRegister extends ParticipantMessage { - - /** - * Constructor for instantiating ParticipantRegister class with message name. - * - */ - public ParticipantRegister() { - super(ParticipantMessageType.PARTICIPANT_REGISTER); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantRegister(final ParticipantRegister source) { - super(source); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAck.java deleted file mode 100644 index 28d51be93..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAck.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Class to represent the PARTICIPANT_REGISTER_ACK message that control loop runtime sends to registered participant. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantRegisterAck extends ParticipantAckMessage { - - /** - * Constructor for instantiating ParticipantRegisterAck class with message name. - * - */ - public ParticipantRegisterAck() { - super(ParticipantMessageType.PARTICIPANT_REGISTER_ACK); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantRegisterAck(final ParticipantRegisterAck source) { - super(source); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java deleted file mode 100644 index f014529b3..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantResponseStatus.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -/** - * Class to hold the possible values for participant response status. - */ -public enum ParticipantResponseStatus { - - /** - * participant operation was successful. - */ - SUCCESS, - - /** - * participant operation failed. - */ - FAIL, - - /** - * periodic response. - */ - PERIODIC -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java deleted file mode 100644 index 8600b4b5b..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatus.java +++ /dev/null @@ -1,78 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; -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.models.base.PfUtils; - -/** - * Class to represent the PARTICIPANT_STATUS message that all the participants send to the control loop runtime. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantStatus extends ParticipantMessage { - - // State and health status of the participant - private ParticipantState state; - private ParticipantHealthStatus healthStatus; - - private ParticipantStatistics participantStatistics; - - // A list of ParticipantDefinition updates, returned in response to ParticipantStatusReq only - private List participantDefinitionUpdates = new ArrayList<>(); - - // List of ControlLoopInfo types with ControlLoopId, its state and statistics - private List controlLoopInfoList = new ArrayList<>(); - - /** - * Constructor for instantiating ParticipantStatus class with message name. - * - */ - public ParticipantStatus() { - super(ParticipantMessageType.PARTICIPANT_STATUS); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantStatus(final ParticipantStatus source) { - super(source); - - this.state = source.state; - this.healthStatus = source.healthStatus; - this.participantStatistics = (source.participantStatistics == null ? null : new ParticipantStatistics()); - this.participantDefinitionUpdates = PfUtils.mapList(source.participantDefinitionUpdates, - ParticipantDefinition::new); - this.controlLoopInfoList = PfUtils.mapList(source.controlLoopInfoList, ControlLoopInfo::new); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java deleted file mode 100644 index 9242cea02..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReq.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Class to represent the PARTICIPANT_STATUS_REQ message that controlloop runtime - * sends to participants for an immediate ParticipantStatus from participants. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantStatusReq extends ParticipantMessage { - - /** - * Constructor for instantiating a participant status request class. - */ - public ParticipantStatusReq() { - super(ParticipantMessageType.PARTICIPANT_STATUS_REQ); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantStatusReq(final ParticipantStatusReq source) { - super(source); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java deleted file mode 100644 index 72db7d97e..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdate.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.models.messages.dmaap.participant; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; -import org.onap.policy.models.base.PfUtils; - -/** - * Class to represent the PARTICIPANT_UPDATE message that the control loop runtime sends to a participant. - * ControlLoop Runtime sends Control Loop Element Definitions and Common Parameter Values to Participants. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantUpdate extends ParticipantMessage { - - // A list of updates to ParticipantDefinitions - private List participantDefinitionUpdates = new ArrayList<>(); - - /** - * Constructor for instantiating ParticipantUpdate class with message name. - * - */ - public ParticipantUpdate() { - super(ParticipantMessageType.PARTICIPANT_UPDATE); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantUpdate(ParticipantUpdate source) { - super(source); - - this.participantDefinitionUpdates = PfUtils.mapList(source.participantDefinitionUpdates, - ParticipantDefinition::new); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAck.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAck.java deleted file mode 100644 index d38fa4bb2..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAck.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.models.messages.dmaap.participant; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Class to represent the PARTICIPANT_UPDATE_ACK message that registered participant sends to controlloop runtime. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ParticipantUpdateAck extends ParticipantAckMessage { - - /** - * Constructor for instantiating ParticipantUpdateAck class with message name. - * - */ - public ParticipantUpdateAck() { - super(ParticipantMessageType.PARTICIPANT_UPDATE_ACK); - } - - /** - * Constructs the object, making a deep copy. - * - * @param source source from which to copy - */ - public ParticipantUpdateAck(final ParticipantUpdateAck source) { - super(source); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/GenericNameVersion.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/GenericNameVersion.java deleted file mode 100644 index a48af9223..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/GenericNameVersion.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ============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.models.messages.rest; - -import lombok.Data; - -@Data -public class GenericNameVersion { - - private String name; - - private String version; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/SimpleResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/SimpleResponse.java deleted file mode 100644 index 2bd09c632..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/SimpleResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ============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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.controlloop.models.messages.rest; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Response returned when no extra output fields are needed. - */ -@Getter -@Setter -@ToString -public class SimpleResponse { - - /** - * Optional detailed message in error cases. - */ - private String errorDetails; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/TypedSimpleResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/TypedSimpleResponse.java deleted file mode 100644 index 199ac8ee1..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/TypedSimpleResponse.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============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.models.messages.rest; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -/** - * Response returned when no extra output fields are needed. - */ -@Getter -@Setter -@ToString -public class TypedSimpleResponse extends SimpleResponse { - private T response; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/commissioning/CommissioningResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/commissioning/CommissioningResponse.java deleted file mode 100644 index 6363db8d2..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/commissioning/CommissioningResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============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.models.messages.rest.commissioning; - -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Response to Commissioning requests that affect a change. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class CommissioningResponse extends SimpleResponse { - private List affectedControlLoopDefinitions; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopOrderStateResponse.java deleted file mode 100644 index dcc63a538..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopOrderStateResponse.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============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.models.messages.rest.instantiation; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.clamp.controlloop.models.messages.rest.GenericNameVersion; -import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; - - -/** - * Response to Commissioning requests that affect a change. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ControlLoopOrderStateResponse extends SimpleResponse { - - private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED; - - private List controlLoopIdentifierList = new ArrayList<>(); -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimed.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimed.java deleted file mode 100644 index d6e670060..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimed.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * ============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.models.messages.rest.instantiation; - -import lombok.Data; - -@Data -public class ControlLoopPrimed { - - private String name; - - private String version; - - private boolean primed; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java deleted file mode 100644 index 4d2dfaf01..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopPrimedResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ============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.models.messages.rest.instantiation; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; - - -/** - * Response to provide all primed controlLoops. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class ControlLoopPrimedResponse extends SimpleResponse { - - private List primedControlLoopsList = new ArrayList<>(); -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java deleted file mode 100644 index d8974d6e3..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstancePropertiesResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ============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.models.messages.rest.instantiation; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Response to Instance Properties requests that affect a change. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class InstancePropertiesResponse extends SimpleResponse { - private List affectedInstanceProperties = new ArrayList<>(); -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommand.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommand.java deleted file mode 100644 index 71b7ab92c..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============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.models.messages.rest.instantiation; - -import java.util.List; -import lombok.Data; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -@Data -public class InstantiationCommand { - // The state to which the control loops are to be set - private ControlLoopOrderedState orderedState; - - // The list of control loops on which the command is to be issued - private List controlLoopIdentifierList; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationOrderStateResponse.java deleted file mode 100644 index 1ddce7840..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationOrderStateResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.models.messages.rest.instantiation; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; - -/** - * Response to instantiation OrderState. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class InstantiationOrderStateResponse extends SimpleResponse { - - private ControlLoopOrderedState orderedState; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationResponse.java deleted file mode 100644 index d932f29ac..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============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.models.messages.rest.instantiation; - -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Response to Commissioning requests that affect a change. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class InstantiationResponse extends SimpleResponse { - private List affectedControlLoops; -} diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java deleted file mode 100644 index 6c12c2de7..000000000 --- a/models/src/main/java/org/onap/policy/clamp/controlloop/models/rest/RestUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============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.models.rest; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse; -import org.onap.policy.models.errors.concepts.ErrorResponseInfo; -import org.springframework.http.ResponseEntity; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class RestUtils { - - /** - * Convert an ErrorResponseInfo to a ResponseEntity. - * - * @param ex the ErrorResponseInfo - * @return the ResponseEntity - */ - public static ResponseEntity toSimpleResponse(ErrorResponseInfo ex) { - var resp = new SimpleResponse(); - resp.setErrorDetails(ex.getErrorResponse().getErrorMessage()); - return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp); - } -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatistics.java new file mode 100644 index 000000000..d1b1e31e8 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatistics.java @@ -0,0 +1,53 @@ +/*- + * ============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.models.acm.concepts; + +import java.io.Serializable; +import java.time.Instant; +import java.util.UUID; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@NoArgsConstructor +@Data +@ToString +public class AcElementStatistics implements Serializable { + + private static final long serialVersionUID = 3284285693112271055L; + + @NonNull + private UUID id = UUID.randomUUID(); + + @NonNull + private ToscaConceptIdentifier participantId; + + @NonNull + private Instant timeStamp; + + @NonNull + private AutomationCompositionState state; + + private long acElementUptime; + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsList.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsList.java new file mode 100644 index 000000000..3b8feb5f6 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsList.java @@ -0,0 +1,33 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +public class AcElementStatisticsList { + private List acElementStatistics; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java new file mode 100644 index 000000000..f6134782b --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationComposition.java @@ -0,0 +1,117 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.apache.commons.collections4.MapUtils; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; + +/** + * Class to represent an automation composition instance. + */ +@NoArgsConstructor +@Data +@EqualsAndHashCode(callSuper = true) +public class AutomationComposition extends ToscaEntity implements Comparable { + @NonNull + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + + @NonNull + private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; + + @NonNull + private AutomationCompositionOrderedState orderedState = AutomationCompositionOrderedState.UNINITIALISED; + + private Map elements; + + @NonNull + private Boolean primed = false; + + @Override + public String getType() { + return definition.getName(); + } + + @Override + public String getTypeVersion() { + return definition.getVersion(); + } + + /** + * Copy contructor, does a deep copy. + * + * @param otherAutomationComposition the other element to copy from + */ + public AutomationComposition(final AutomationComposition otherAutomationComposition) { + super(otherAutomationComposition); + this.definition = new ToscaConceptIdentifier(otherAutomationComposition.definition); + this.state = otherAutomationComposition.state; + this.orderedState = otherAutomationComposition.orderedState; + this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new); + this.primed = otherAutomationComposition.primed; + } + + @Override + public int compareTo(final AutomationComposition other) { + return compareNameVersion(this, other); + } + + /** + * Set the ordered state on the automation composition and on all its automation composition elements. + * + * @param orderedState the state we want the automation composition to transition to + */ + public void setCascadedOrderedState(final AutomationCompositionOrderedState orderedState) { + this.orderedState = orderedState; + + if (MapUtils.isEmpty(elements)) { + return; + } + + elements.values().forEach(element -> element.setOrderedState(orderedState)); + } + + /** + * Get a list of automation composition element statistics. + * + * @param automationComposition the automation composition + * @return List of AcElementStatistics + */ + public List getAutomationCompositionElementStatisticsList( + final AutomationComposition automationComposition) { + if (MapUtils.isEmpty(automationComposition.elements)) { + return List.of(); + } + + return automationComposition.elements.values().stream() + .map(AutomationCompositionElement::getAcElementStatistics).collect(Collectors.toList()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java new file mode 100644 index 000000000..046b77f76 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java @@ -0,0 +1,89 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.function.UnaryOperator; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Class to represent a automation composition instance. + */ +@NoArgsConstructor +@Data +@ToString +public class AutomationCompositionElement { + @NonNull + private UUID id = UUID.randomUUID(); + + @NonNull + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + + @NonNull + private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + + @NonNull + private ToscaConceptIdentifier participantId = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + + @NonNull + private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; + + @NonNull + private AutomationCompositionOrderedState orderedState = AutomationCompositionOrderedState.UNINITIALISED; + + private ToscaServiceTemplate toscaServiceTemplateFragment; + + private String description; + + private AcElementStatistics acElementStatistics; + + // A map indexed by the property name. Each map entry is the serialized value of the property, + // which can be deserialized into an instance of the type of the property. + private Map propertiesMap = new LinkedHashMap<>(); + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param otherElement the other element to copy from + */ + public AutomationCompositionElement(final AutomationCompositionElement otherElement) { + this.id = otherElement.id; + this.definition = new ToscaConceptIdentifier(otherElement.definition); + this.participantType = new ToscaConceptIdentifier(otherElement.participantType); + this.participantId = new ToscaConceptIdentifier(otherElement.participantId); + this.state = otherElement.state; + this.orderedState = otherElement.orderedState; + this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment; + this.description = otherElement.description; + this.acElementStatistics = otherElement.acElementStatistics; + this.propertiesMap = PfUtils.mapMap(otherElement.propertiesMap, UnaryOperator.identity()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementAck.java new file mode 100644 index 000000000..b100f28c0 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementAck.java @@ -0,0 +1,42 @@ +/*- + * ============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.models.acm.concepts; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@AllArgsConstructor +@ToString +public class AutomationCompositionElementAck { + + // State of the AutomationCompositionElement + private AutomationCompositionState state; + + // Result: Success/Fail. + private Boolean result; + + // Message indicating reason for failure + private String message; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementDefinition.java new file mode 100644 index 000000000..aebee0e2c --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementDefinition.java @@ -0,0 +1,64 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2022 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.models.acm.concepts; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.UnaryOperator; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; + +/** + * Class to represent an automation composition element definition instance. + */ +@Getter +@NoArgsConstructor +@Data +@ToString +public class AutomationCompositionElementDefinition { + + private ToscaConceptIdentifier acElementDefinitionId; + + // The definition of the Automation Composition Element in TOSCA + private ToscaNodeTemplate automationCompositionElementToscaNodeTemplate; + + // A map indexed by the property name. Each map entry is the serialized value of the property, + // which can be deserialized into an instance of the type of the property. + private Map commonPropertiesMap = new LinkedHashMap<>(); + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param acElementDefinition the automation composition element definition to copy from + */ + public AutomationCompositionElementDefinition(final AutomationCompositionElementDefinition acElementDefinition) { + this.acElementDefinitionId = acElementDefinition.acElementDefinitionId; + this.automationCompositionElementToscaNodeTemplate = + new ToscaNodeTemplate(acElementDefinition.automationCompositionElementToscaNodeTemplate); + this.commonPropertiesMap = PfUtils.mapMap(acElementDefinition.commonPropertiesMap, UnaryOperator.identity()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java new file mode 100644 index 000000000..dba8f553c --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java @@ -0,0 +1,52 @@ +/*- + * ============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.models.acm.concepts; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a automation composition info instance. + */ +@NoArgsConstructor +@Data +@ToString +public class AutomationCompositionInfo { + + private ToscaConceptIdentifier automationCompositionId; + + private AutomationCompositionState state = AutomationCompositionState.UNINITIALISED; + + private AutomationCompositionStatistics automationCompositionStatistics; + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param otherElement the other element to copy from + */ + public AutomationCompositionInfo(final AutomationCompositionInfo otherElement) { + this.automationCompositionId = otherElement.automationCompositionId; + this.state = otherElement.state; + this.automationCompositionStatistics = otherElement.automationCompositionStatistics; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionOrderedState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionOrderedState.java new file mode 100644 index 000000000..3be5ffa2f --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionOrderedState.java @@ -0,0 +1,47 @@ +/*- + * ============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.models.acm.concepts; + +public enum AutomationCompositionOrderedState { + /** + * The automation composition or automation composition element should become uninitialised on participants, it + * should not exist on participants. + */ + UNINITIALISED, + /** + * The automation composition or automation composition element should initialised on the participants and be + * passive, that is, it is not handling automation composition messages yet. + */ + PASSIVE, + /** + * The automation composition or automation composition element should running and is executing automation + * compositions. + */ + RUNNING; + + public boolean equalsAutomationCompositionState(final AutomationCompositionState automationCompositionState) { + return this.name().equals(automationCompositionState.name()); + } + + public AutomationCompositionState asState() { + return AutomationCompositionState.valueOf(this.name()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionState.java new file mode 100644 index 000000000..aa6fcfd1d --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionState.java @@ -0,0 +1,67 @@ +/*- + * ============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.models.acm.concepts; + +public enum AutomationCompositionState { + /** + * The automation composition or automation composition element is not initialised on participants, it does not + * exist on participants. + */ + UNINITIALISED, + /** + * The automation composition or automation composition element is changing from unitialised to passive, it is being + * initialised onto participants. + */ + UNINITIALISED2PASSIVE, + /** + * The automation composition or automation composition element is initialised on the participants but is passive, + * that is, it is not handling automation composition messages yet. + */ + PASSIVE, + /** + * The automation composition or automation composition element is changing from passive to running, the + * participants are preparing to execute automation compositions. + */ + PASSIVE2RUNNING, + /** + * The automation composition or automation composition element is running and is executing automation compositions. + */ + RUNNING, + /** + * The automation composition or automation composition element is completing execution of current automation + * compositions but will not start running any more automation compositions and will become passive. + */ + RUNNING2PASSIVE, + /** + * The automation composition or automation composition element is changing from passive to unitialised, the + * automation composition is being removed from participants. + */ + PASSIVE2UNINITIALISED; + + public boolean equalsAutomationCompositionOrderedState( + final AutomationCompositionOrderedState automationCompositionOrderedState) { + return this.name().equals(automationCompositionOrderedState.name()); + } + + public AutomationCompositionOrderedState asOrderedState() { + return AutomationCompositionOrderedState.valueOf(this.name()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionStatistics.java new file mode 100644 index 000000000..8f73328ad --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionStatistics.java @@ -0,0 +1,50 @@ +/*- + * ============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.models.acm.concepts; + +import java.time.Instant; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@NoArgsConstructor +@Data +@ToString +public class AutomationCompositionStatistics { + + @NonNull + private ToscaConceptIdentifier automationCompositionId; + + @NonNull + private Instant timeStamp; + + @NonNull + private AcElementStatisticsList acElementStatisticsList; + + private long eventCount; + private long lastExecutionTime; + private double averageExecutionTime; + private long upTime; + private long lastEnterTime; + private long lastStart; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java new file mode 100644 index 000000000..1802f814c --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositions.java @@ -0,0 +1,48 @@ +/*- + * ============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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.models.acm.concepts; + +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.models.base.PfUtils; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode +public class AutomationCompositions { + private List automationCompositionList = new ArrayList<>(); + + /** + * Copy constructor, does a deep copy. + * + * @param otherAutomationCompositions the other element to copy from + */ + public AutomationCompositions(final AutomationCompositions otherAutomationCompositions) { + this.automationCompositionList = PfUtils.mapList(automationCompositionList, AutomationComposition::new); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java new file mode 100644 index 000000000..1a8fbc409 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/Participant.java @@ -0,0 +1,77 @@ +/*- + * ============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.models.acm.concepts; + +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; + +/** + * Class to represent details of a running participant instance. + */ +@NoArgsConstructor +@Data +@EqualsAndHashCode(callSuper = true) +public class Participant extends ToscaEntity implements Comparable { + @NonNull + private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey()); + + @NonNull + private ParticipantState participantState = ParticipantState.UNKNOWN; + + @NonNull + private ParticipantHealthStatus healthStatus = ParticipantHealthStatus.UNKNOWN; + + @NonNull + private ToscaConceptIdentifier participantType = new ToscaConceptIdentifier(); + + @Override + public String getType() { + return definition.getName(); + } + + @Override + public String getTypeVersion() { + return definition.getVersion(); + } + + @Override + public int compareTo(final Participant other) { + return compareNameVersion(this, other); + } + + /** + * Copy constructor. + * + * @param otherParticipant the participant to copy from + */ + public Participant(Participant otherParticipant) { + super(otherParticipant); + this.definition = new ToscaConceptIdentifier(otherParticipant.definition); + this.participantState = otherParticipant.participantState; + this.healthStatus = otherParticipant.healthStatus; + this.participantType = otherParticipant.participantType; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java new file mode 100644 index 000000000..949a7c47d --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantDefinition.java @@ -0,0 +1,60 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.ArrayList; +import java.util.List; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a participant definition update instance. + */ +@Getter +@NoArgsConstructor +@Data +@ToString +public class ParticipantDefinition { + + private ToscaConceptIdentifier participantId; + + private ToscaConceptIdentifier participantType; + + // List of AutomationCompositionElementDefinition values for a particular participant + private List automationCompositionElementDefinitionList = new ArrayList<>(); + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param participantDefinition the participant definition to copy from + */ + public ParticipantDefinition(final ParticipantDefinition participantDefinition) { + this.participantId = participantDefinition.participantId; + this.participantType = participantDefinition.participantType; + this.automationCompositionElementDefinitionList = + PfUtils.mapList(participantDefinition.automationCompositionElementDefinitionList, + AutomationCompositionElementDefinition::new); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantHealthStatus.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantHealthStatus.java new file mode 100644 index 000000000..f8cc0a852 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantHealthStatus.java @@ -0,0 +1,52 @@ +/*- + * ============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.models.acm.concepts; + +/** + * Class to hold the possible values for health status of Participant. + */ +public enum ParticipantHealthStatus { + + /** + * Participant is healthy and working fine. + */ + HEALTHY, + + /** + * Participant is not healthy. + */ + NOT_HEALTHY, + + /** + * Participant is currently under test state and performing tests. + */ + TEST_IN_PROGRESS, + + /** + * The health status of the Participant is unknown. + */ + UNKNOWN, + + /** + * The health status of the Participant is off line. + */ + OFF_LINE +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantState.java new file mode 100644 index 000000000..4ab42c697 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantState.java @@ -0,0 +1,60 @@ +/*- + * ============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.models.acm.concepts; + +/** + * Class to hold the possible values for mode of participant. + */ +public enum ParticipantState { + /** + * Participant state is unknown. + */ + UNKNOWN, + + /** + * Participant is passive, automation composition element execution is always rejected. + */ + PASSIVE, + + /** + * Automation composition element execution execution proceeds, but changes to domain state or context are not + * carried out. The participant returns an indication that it is running in SAFE mode together with the action it + * would have performed if it was operating in ACTIVE mode. + */ + SAFE, + + /** + * Automation composition element execution execution proceeds and changes to domain and state are carried out in a + * test environment. The participant returns an indication that it is running in TEST mode together with the action + * it has performed on the test environment. + */ + TEST, + + /** + * Automation composition element execution is executed in the live environment by the participant. + */ + ACTIVE, + + /** + * Automation composition element execution has been terminated. + */ + TERMINATED +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatistics.java new file mode 100644 index 000000000..4d3b96db7 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatistics.java @@ -0,0 +1,52 @@ +/*- + * ============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.models.acm.concepts; + +import java.io.Serializable; +import java.time.Instant; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@NoArgsConstructor +@Data +@ToString +public class ParticipantStatistics implements Serializable { + private static final long serialVersionUID = 744036598792333124L; + + + @NonNull + private ToscaConceptIdentifier participantId; + + @NonNull + private Instant timeStamp; + + private ParticipantState state; + private ParticipantHealthStatus healthStatus; + private long eventCount; + private long lastExecutionTime; + private double averageExecutionTime; + private long upTime; + private long lastEnterTime; + private long lastStart; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsList.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsList.java new file mode 100644 index 000000000..4abdf4a63 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsList.java @@ -0,0 +1,33 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +public class ParticipantStatisticsList { + private List statisticsList; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java new file mode 100644 index 000000000..1872a6144 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUpdates.java @@ -0,0 +1,56 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.ArrayList; +import java.util.List; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a participant definition update instance. + */ +@Getter +@NoArgsConstructor +@Data +@ToString +public class ParticipantUpdates { + + private ToscaConceptIdentifier participantId; + + // List of AutomationCompositionElement values for a particular participant + private List automationCompositionElementList = new ArrayList<>(); + + /** + * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy. + * + * @param participantUpdates the participant with updates to copy from + */ + public ParticipantUpdates(final ParticipantUpdates participantUpdates) { + this.participantId = participantUpdates.participantId; + this.automationCompositionElementList = PfUtils.mapList( + participantUpdates.automationCompositionElementList, AutomationCompositionElement::new); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java new file mode 100644 index 000000000..9d26ce406 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtils.java @@ -0,0 +1,123 @@ +/*- + * ============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.models.acm.concepts; + +import java.util.Map; +import javax.ws.rs.core.Response; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +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.models.base.PfModelRuntimeException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ParticipantUtils { + + private static final Coder CODER = new StandardCoder(); + private static final String AUTOMATION_COMPOSITION_ELEMENT = + "org.onap.policy.clamp.acm.AutomationCompositionElement"; + + /** + * Finds participantType from a map of properties. + * + * @param properties Map of properties + * @return participantType + */ + public static ToscaConceptIdentifier findParticipantType(Map properties) { + var objParticipantType = properties.get("participantType"); + if (objParticipantType != null) { + try { + return CODER.decode(objParticipantType.toString(), ToscaConceptIdentifier.class); + } catch (CoderException e) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e); + } + } + return null; + } + + /** + * Get the First StartPhase. + * + *

This depends on the state of the automation composition and also on all start phases defined in the + * ToscaServiceTemplate. + * + * @param automationComposition the automation composition + * @param toscaServiceTemplate the ToscaServiceTemplate + * @return the First StartPhase + */ + public static int getFirstStartPhase( + AutomationComposition automationComposition, ToscaServiceTemplate toscaServiceTemplate) { + var minStartPhase = 1000; + var maxStartPhase = 0; + for (var element : automationComposition.getElements().values()) { + ToscaNodeTemplate toscaNodeTemplate = toscaServiceTemplate.getToscaTopologyTemplate().getNodeTemplates() + .get(element.getDefinition().getName()); + int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties()); + minStartPhase = Math.min(minStartPhase, startPhase); + maxStartPhase = Math.max(maxStartPhase, startPhase); + } + + return AutomationCompositionState.UNINITIALISED2PASSIVE.equals(automationComposition.getState()) + || AutomationCompositionState.PASSIVE2RUNNING.equals(automationComposition.getState()) ? minStartPhase + : maxStartPhase; + } + + /** + * Finds startPhase from a map of properties. + * + * @param properties Map of properties + * @return startPhase + */ + public static int findStartPhase(Map properties) { + var objParticipantType = properties.get("startPhase"); + if (objParticipantType != null) { + return Integer.valueOf(objParticipantType.toString()); + } + return 0; + } + + /** + * Checks if a NodeTemplate is an AutomationCompositionElement. + * + * @param nodeTemplate the ToscaNodeTemplate + * @param toscaServiceTemplate the ToscaServiceTemplate + * @return true if the NodeTemplate is an AutomationCompositionElement + */ + public static boolean checkIfNodeTemplateIsAutomationCompositionElement(ToscaNodeTemplate nodeTemplate, + ToscaServiceTemplate toscaServiceTemplate) { + if (nodeTemplate.getType().contains(AUTOMATION_COMPOSITION_ELEMENT)) { + return true; + } else { + var nodeType = toscaServiceTemplate.getNodeTypes().get(nodeTemplate.getType()); + if (nodeType != null) { + var derivedFrom = nodeType.getDerivedFrom(); + if (derivedFrom != null) { + return derivedFrom.contains(AUTOMATION_COMPOSITION_ELEMENT); + } + } + } + return false; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotification.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotification.java new file mode 100644 index 000000000..4b898633a --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotification.java @@ -0,0 +1,56 @@ +/*- + * ============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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.models.acm.messages.dmaap.notification; + +import com.google.gson.annotations.SerializedName; +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.collections4.CollectionUtils; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class AutomationCompositionNotification { + + /** + * Status of automation compositions that are being added to participants. + */ + @SerializedName("deployed-automation-compositions") + private List added = new ArrayList<>(); + + /** + * Status of policies that are being deleted from PDPs. + */ + @SerializedName("undeployed-automation-compositions") + private List deleted = new ArrayList<>(); + + + /** + * Determines if the notification is empty (i.e., has no added or delete automation composition + * notifications). + * + * @return {@code true} if the notification is empty, {@code false} otherwise + */ + public boolean isEmpty() { + return (CollectionUtils.isEmpty(added) && CollectionUtils.isEmpty(deleted)); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatus.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatus.java new file mode 100644 index 000000000..f65c6217b --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatus.java @@ -0,0 +1,36 @@ +/*- + * ============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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.models.acm.messages.dmaap.notification; + +import com.google.gson.annotations.SerializedName; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class AutomationCompositionStatus { + @SerializedName("automation-composition-id") + private UUID id; + + private ToscaConceptIdentifier definition; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAck.java new file mode 100644 index 000000000..c0a21d61a --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAck.java @@ -0,0 +1,70 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.function.UnaryOperator; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementAck; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent the AUTOMATION_COMPOSITION_ACK message that a participant sends + * to automation composition runtime as an acknowledgement to either AUTOMATION_COMPOSITION_UPDATE + * or AUTOMATION_COMPOSITION_STATE_CHANGE message. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class AutomationCompositionAck extends ParticipantAckMessage { + + private ToscaConceptIdentifier automationCompositionId; + private Integer startPhase; + + // A map with AutomationCompositionElementID as its key, and a pair of result and message as value per + // AutomationCompositionElement. + private Map automationCompositionResultMap = new LinkedHashMap<>(); + + /** + * Constructor for instantiating ParticipantRegisterAck class with message name. + * + */ + public AutomationCompositionAck(final ParticipantMessageType messageType) { + super(messageType); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public AutomationCompositionAck(final AutomationCompositionAck source) { + super(source); + this.automationCompositionId = source.automationCompositionId; + this.automationCompositionResultMap = + PfUtils.mapMap(source.automationCompositionResultMap, UnaryOperator.identity()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java new file mode 100644 index 000000000..f8daa36a9 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChange.java @@ -0,0 +1,60 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; + +/** + * Class to represent the AUTOMATION_COMPOSITION_STATE_CHANGE message that the automation composition runtime will send + * to participants to change the state of an automation composition they are running. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class AutomationCompositionStateChange extends ParticipantMessage { + private AutomationCompositionOrderedState orderedState; + private AutomationCompositionState currentState; + private Integer startPhase; + + /** + * Constructor for instantiating class with message name. + * + */ + public AutomationCompositionStateChange() { + super(ParticipantMessageType.AUTOMATION_COMPOSITION_STATE_CHANGE); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public AutomationCompositionStateChange(AutomationCompositionStateChange source) { + super(source); + + this.orderedState = source.orderedState; + this.currentState = source.currentState; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdate.java new file mode 100644 index 000000000..55fcc7462 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdate.java @@ -0,0 +1,64 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; +import org.onap.policy.models.base.PfUtils; + +/** + * Class to represent the AUTOMATION_COMPOSITION_UPDATE message that the automation composition runtime sends to a + * participant. When a participant receives this message, it creates the automation composition elements contained in + * the message and sets them to state PASSIVE. subsequent AUTOMATION_COMPOSITION_STATE_CHANGE messages are used to + * activate the automation compositions. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class AutomationCompositionUpdate extends ParticipantMessage { + + // A list of ParticipantUpdates instances which carries details of an updated participant. + private List participantUpdatesList = new ArrayList<>(); + private Integer startPhase = 0; + + /** + * Constructor for instantiating class with message name. + * + */ + public AutomationCompositionUpdate() { + super(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public AutomationCompositionUpdate(AutomationCompositionUpdate source) { + super(source); + + this.participantUpdatesList = PfUtils.mapList(source.participantUpdatesList, ParticipantUpdates::new); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java new file mode 100644 index 000000000..8b33d3172 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessage.java @@ -0,0 +1,115 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import java.util.UUID; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent participant Ack message. + */ +@Getter +@Setter +@ToString +public class ParticipantAckMessage { + + // The responseTo field should match the original request id in the request. + private UUID responseTo; + + // Result: Success/Fail. + private Boolean result; + + // Message indicating reason for failure + private String message; + + private ParticipantMessageType messageType; + + /** + * Participant Type, or {@code null} for messages from participants. + */ + private ToscaConceptIdentifier participantType; + + /** + * Participant ID, or {@code null} for messages from participants. + */ + private ToscaConceptIdentifier participantId; + + /** + * Participant State, or {@code null} for messages from participants. + */ + private ParticipantState state; + + /** + * Constructor for instantiating a participant ack message class. + * + * @param messageType the message type + */ + public ParticipantAckMessage(final ParticipantMessageType messageType) { + this.messageType = messageType; + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantAckMessage(ParticipantAckMessage source) { + this.responseTo = source.responseTo; + this.result = source.result; + this.message = source.message; + this.messageType = source.messageType; + this.participantType = source.participantType; + this.participantId = source.participantId; + this.state = source.state; + } + + /** + * Determines if this message applies to this participant type. + * + * @param participantType type of the participant to match against + * @param participantId id of the participant to match against + * @return {@code true} if this message applies to this participant, {@code false} otherwise + */ + public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, + @NonNull final ToscaConceptIdentifier participantId) { + // Broadcast message to all participants + if (this.participantType == null) { + return true; + } + + if (!participantType.equals(this.participantType)) { + return false; + } + + // Broadcast message to all automation composition elements on this participant + if (this.participantId == null) { + return true; + } + + // Targeted message at this specific participant + return participantId.equals(this.participantId); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregister.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregister.java new file mode 100644 index 000000000..2e7ed8c52 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregister.java @@ -0,0 +1,51 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to represent the PARTICIPANT_DEREGISTER message that all the participants send to the ACM runtime. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantDeregister extends ParticipantMessage { + + /** + * Constructor for instantiating ParticipantDeregister class with message name. + * + */ + public ParticipantDeregister() { + super(ParticipantMessageType.PARTICIPANT_DEREGISTER); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantDeregister(final ParticipantDeregister source) { + super(source); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAck.java new file mode 100644 index 000000000..afa987d65 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAck.java @@ -0,0 +1,51 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to represent the PARTICIPANT_DEREGISTER_ACK message that the ACM runtime sends to the participant. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantDeregisterAck extends ParticipantAckMessage { + + /** + * Constructor for instantiating ParticipantDeregisterAck class with message name. + * + */ + public ParticipantDeregisterAck() { + super(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantDeregisterAck(final ParticipantDeregisterAck source) { + super(source); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java new file mode 100644 index 000000000..c358376b2 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessage.java @@ -0,0 +1,112 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import java.time.Instant; +import java.util.UUID; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent the base class for various messages that will be exchanged between the ACM runtime and + * participants. + */ +@Getter +@Setter +@ToString +public class ParticipantMessage { + @Setter(AccessLevel.NONE) + private ParticipantMessageType messageType; + + private UUID messageId = UUID.randomUUID(); + + /** + * Time-stamp, in milliseconds, when the message was created. Defaults to the current time. + */ + private Instant timestamp = Instant.now(); + + /** + * Participant Type, or {@code null} for messages from participants. + */ + private ToscaConceptIdentifier participantType; + + /** + * Participant ID, or {@code null} for messages from participants. + */ + private ToscaConceptIdentifier participantId; + + /** + * Automation Composition ID, or {@code null} for messages to participants. + */ + private ToscaConceptIdentifier automationCompositionId; + + /** + * Constructor for instantiating a participant message class. + * + * @param messageType the message type + */ + public ParticipantMessage(final ParticipantMessageType messageType) { + this.messageType = messageType; + } + + /** + * Constructs the object, making a deep copy. Does not copy the request id or the time stamp. + * + * @param source source from which to copy + */ + public ParticipantMessage(final ParticipantMessage source) { + this.messageType = source.messageType; + this.participantType = source.participantType; + this.participantId = source.participantId; + this.automationCompositionId = source.automationCompositionId; + } + + /** + * Determines if this message applies to this participant type. + * + * @param participantType type of the participant to match against + * @param participantId id of the participant to match against + * @return {@code true} if this message applies to this participant, {@code false} otherwise + */ + public boolean appliesTo(@NonNull final ToscaConceptIdentifier participantType, + @NonNull final ToscaConceptIdentifier participantId) { + // Broadcast message to all participants + if (this.participantType == null) { + return true; + } + + if (!participantType.equals(this.participantType)) { + return false; + } + + // Broadcast message to all automation composition elements on this participant + if (this.participantId == null) { + return true; + } + + // Targeted message at this specific participant + return participantId.equals(this.participantId); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java new file mode 100644 index 000000000..4f6bcdbf3 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageType.java @@ -0,0 +1,104 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +/** + * Class to hold the possible values for the type of participant messages. + */ +public enum ParticipantMessageType { + + /** + * Used by participants to report status to the automation composition runtime. + */ + PARTICIPANT_STATUS, + + /** + * Used by the acm runtime to change the state of participants, triggers a + * PARTICIPANT_STATUS message with the result of the PARTICIPANT_STATE_CHANGE operation. + */ + PARTICIPANT_STATE_CHANGE, + + /** + * Used by acm runtime to update the automation compositions running on participants, triggers a + * PARTICIPANT_STATUS message with the result of the AUTOMATION_COMPOSITION_UPDATE operation. + */ + AUTOMATION_COMPOSITION_UPDATE, + + /** + * Used by acm runtime to change the state of automation compositions in participants, triggers a + * PARTICIPANT_STATUS message with result of AUTOMATION_COMPOSITION_STATE_CHANGE operation. + */ + AUTOMATION_COMPOSITION_STATE_CHANGE, + + /** + * Used by the automation composition runtime to order a health check on participants, triggers a + * PARTICIPANT_STATUS message with the result of the PARTICIPANT_HEALTH_CHECK operation. + */ + PARTICIPANT_HEALTH_CHECK, + + /** + * Used by participant to register itself with automation composition runtime. + */ + PARTICIPANT_REGISTER, + + /** + * Used by automation composition runtime to respond to participant registration. + */ + PARTICIPANT_REGISTER_ACK, + + /** + * Used by participant to deregister itself with automation composition runtime. + */ + PARTICIPANT_DEREGISTER, + + /** + * Used by automation composition runtime to respond to participant deregistration. + */ + PARTICIPANT_DEREGISTER_ACK, + + /** + * Used by automation composition runtime to send ToscaServiceTemplate to participant. + */ + PARTICIPANT_UPDATE, + + /** + * Used by participant to acknowledge the receipt of PARTICIPANT_UPDATE message + * from automation composition runtime. + */ + PARTICIPANT_UPDATE_ACK, + + /** + * Used by participant to acknowledge the receipt of AUTOMATION_COMPOSITION_UPDATE message + * from automation composition runtime. + */ + AUTOMATION_COMPOSITION_UPDATE_ACK, + + /** + * Used by participant to acknowledge the receipt of AUTOMATION_COMPOSITION_STATE_CHANGE message + * from automation composition runtime. + */ + AUTOMATION_COMPOSITION_STATECHANGE_ACK, + + /** + * Used by automation composition runtime to request for PARTICIPANT_STATUS message immediately. + */ + PARTICIPANT_STATUS_REQ +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java new file mode 100644 index 000000000..7b315dbe0 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegister.java @@ -0,0 +1,51 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to represent the PARTICIPANT_REGISTER message that all the participants send to the ACM runtime. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantRegister extends ParticipantMessage { + + /** + * Constructor for instantiating ParticipantRegister class with message name. + * + */ + public ParticipantRegister() { + super(ParticipantMessageType.PARTICIPANT_REGISTER); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantRegister(final ParticipantRegister source) { + super(source); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAck.java new file mode 100644 index 000000000..60858be4c --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAck.java @@ -0,0 +1,51 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to represent the PARTICIPANT_REGISTER_ACK message that the ACM runtime sends to a registered participant. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantRegisterAck extends ParticipantAckMessage { + + /** + * Constructor for instantiating ParticipantRegisterAck class with message name. + * + */ + public ParticipantRegisterAck() { + super(ParticipantMessageType.PARTICIPANT_REGISTER_ACK); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantRegisterAck(final ParticipantRegisterAck source) { + super(source); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java new file mode 100644 index 000000000..cb0307742 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantResponseStatus.java @@ -0,0 +1,42 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +/** + * Class to hold the possible values for participant response status. + */ +public enum ParticipantResponseStatus { + + /** + * participant operation was successful. + */ + SUCCESS, + + /** + * participant operation failed. + */ + FAIL, + + /** + * periodic response. + */ + PERIODIC +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java new file mode 100644 index 000000000..32b95e11b --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatus.java @@ -0,0 +1,79 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; +import org.onap.policy.models.base.PfUtils; + +/** + * Class to represent the PARTICIPANT_STATUS message that all the participants send to the ACM runtime. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantStatus extends ParticipantMessage { + + // State and health status of the participant + private ParticipantState state; + private ParticipantHealthStatus healthStatus; + + private ParticipantStatistics participantStatistics; + + // A list of ParticipantDefinition updates, returned in response to ParticipantStatusReq only + private List participantDefinitionUpdates = new ArrayList<>(); + + // List of AutomationCompositionInfo types with AutomationCompositionId, its state and statistics + private List automationCompositionInfoList = new ArrayList<>(); + + /** + * Constructor for instantiating ParticipantStatus class with message name. + * + */ + public ParticipantStatus() { + super(ParticipantMessageType.PARTICIPANT_STATUS); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantStatus(final ParticipantStatus source) { + super(source); + + this.state = source.state; + this.healthStatus = source.healthStatus; + this.participantStatistics = (source.participantStatistics == null ? null : new ParticipantStatistics()); + this.participantDefinitionUpdates = + PfUtils.mapList(source.participantDefinitionUpdates, ParticipantDefinition::new); + this.automationCompositionInfoList = + PfUtils.mapList(source.automationCompositionInfoList, AutomationCompositionInfo::new); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReq.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReq.java new file mode 100644 index 000000000..82260ee67 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReq.java @@ -0,0 +1,51 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to represent the PARTICIPANT_STATUS_REQ message that the ACM runtime + * sends to participants for an immediate ParticipantStatus from participants. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantStatusReq extends ParticipantMessage { + + /** + * Constructor for instantiating a participant status request class. + */ + public ParticipantStatusReq() { + super(ParticipantMessageType.PARTICIPANT_STATUS_REQ); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantStatusReq(final ParticipantStatusReq source) { + super(source); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdate.java new file mode 100644 index 000000000..36842a8cf --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdate.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.models.acm.messages.dmaap.participant; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.models.base.PfUtils; + +/** + * Class to represent the PARTICIPANT_UPDATE message that the ACM runtime sends to a participant. + * the ACM Runtime sends automation composition element Definitions and Common Parameter Values to Participants. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantUpdate extends ParticipantMessage { + + // A list of updates to ParticipantDefinitions + private List participantDefinitionUpdates = new ArrayList<>(); + + /** + * Constructor for instantiating ParticipantUpdate class with message name. + * + */ + public ParticipantUpdate() { + super(ParticipantMessageType.PARTICIPANT_UPDATE); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantUpdate(ParticipantUpdate source) { + super(source); + + this.participantDefinitionUpdates = PfUtils.mapList(source.participantDefinitionUpdates, + ParticipantDefinition::new); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAck.java new file mode 100644 index 000000000..2c3a68e22 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAck.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.models.acm.messages.dmaap.participant; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Class to represent the PARTICIPANT_UPDATE_ACK message that registered participant sends to the ACM runtime. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantUpdateAck extends ParticipantAckMessage { + + /** + * Constructor for instantiating ParticipantUpdateAck class with message name. + * + */ + public ParticipantUpdateAck() { + super(ParticipantMessageType.PARTICIPANT_UPDATE_ACK); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantUpdateAck(final ParticipantUpdateAck source) { + super(source); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java new file mode 100644 index 000000000..3e39e970d --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java @@ -0,0 +1,30 @@ +/* + * ============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.models.acm.messages.rest; + +import lombok.Data; + +@Data +public class GenericNameVersion { + + private String name; + + private String version; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/SimpleResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/SimpleResponse.java new file mode 100644 index 000000000..1668652b7 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/SimpleResponse.java @@ -0,0 +1,37 @@ +/* + * ============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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.models.acm.messages.rest; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Response returned when no extra output fields are needed. + */ +@Getter +@Setter +@ToString +public class SimpleResponse { + + /** + * Optional detailed message in error cases. + */ + private String errorDetails; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/TypedSimpleResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/TypedSimpleResponse.java new file mode 100644 index 000000000..871eb3bc2 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/TypedSimpleResponse.java @@ -0,0 +1,35 @@ +/*- + * ============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.models.acm.messages.rest; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * Response returned when no extra output fields are needed. + */ +@Getter +@Setter +@ToString +public class TypedSimpleResponse extends SimpleResponse { + private T response; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/commissioning/CommissioningResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/commissioning/CommissioningResponse.java new file mode 100644 index 000000000..42ce79843 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/commissioning/CommissioningResponse.java @@ -0,0 +1,38 @@ +/*- + * ============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.models.acm.messages.rest.commissioning; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Response to Commissioning requests that affect a change. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class CommissioningResponse extends SimpleResponse { + private List affectedAutomationCompositionDefinitions; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java new file mode 100644 index 000000000..a87433d4c --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java @@ -0,0 +1,43 @@ +/* + * ============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.models.acm.messages.rest.instantiation; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.messages.rest.GenericNameVersion; +import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; + + +/** + * Response to Commissioning requests that affect a change. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class AutomationCompositionOrderStateResponse extends SimpleResponse { + + private AutomationCompositionOrderedState orderedState = AutomationCompositionOrderedState.UNINITIALISED; + + private List automationCompositionIdentifierList = new ArrayList<>(); +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimed.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimed.java new file mode 100644 index 000000000..34556653b --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimed.java @@ -0,0 +1,32 @@ +/* + * ============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.models.acm.messages.rest.instantiation; + +import lombok.Data; + +@Data +public class AutomationCompositionPrimed { + + private String name; + + private String version; + + private boolean primed; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimedResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimedResponse.java new file mode 100644 index 000000000..fa3e8fad7 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionPrimedResponse.java @@ -0,0 +1,39 @@ +/* + * ============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.models.acm.messages.rest.instantiation; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; + + +/** + * Response to provide all primed automation compositions. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class AutomationCompositionPrimedResponse extends SimpleResponse { + + private List primedAutomationCompositionsList = new ArrayList<>(); +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java new file mode 100644 index 000000000..0341d5dae --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java @@ -0,0 +1,38 @@ +/* + * ============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.models.acm.messages.rest.instantiation; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Response to Instance Properties requests that affect a change. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class InstancePropertiesResponse extends SimpleResponse { + private List affectedInstanceProperties = new ArrayList<>(); +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommand.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommand.java new file mode 100644 index 000000000..a3fb70e15 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommand.java @@ -0,0 +1,35 @@ +/*- + * ============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.models.acm.messages.rest.instantiation; + +import java.util.List; +import lombok.Data; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +@Data +public class InstantiationCommand { + // The state to which the automation compositions are to be set + private AutomationCompositionOrderedState orderedState; + + // The list of automation compositions on which the command is to be issued + private List automationCompositionIdentifierList; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java new file mode 100644 index 000000000..e6bdaee9d --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java @@ -0,0 +1,39 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.models.acm.messages.rest.instantiation; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; + +/** + * Response to instantiation OrderState. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class InstantiationOrderStateResponse extends SimpleResponse { + + private AutomationCompositionOrderedState orderedState; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationResponse.java new file mode 100644 index 000000000..e7c346498 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationResponse.java @@ -0,0 +1,38 @@ +/*- + * ============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.models.acm.messages.rest.instantiation; + +import java.util.List; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Response to Commissioning requests that affect a change. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class InstantiationResponse extends SimpleResponse { + private List affectedAutomationCompositions; +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatistics.java new file mode 100644 index 000000000..4a046052e --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatistics.java @@ -0,0 +1,196 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.models.acm.persistence.concepts; + +import java.io.Serializable; +import java.util.List; +import java.util.UUID; +import javax.persistence.AttributeOverride; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.builder.CompareToBuilder; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceTimestampKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent automation composition element statistics in the database. + * + * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) + */ +@Entity +@Table(name = "AcElementStatistics") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class JpaAcElementStatistics extends PfConcept implements PfAuthorative, Serializable { + + private static final long serialVersionUID = 621426717868738629L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfReferenceTimestampKey key = new PfReferenceTimestampKey(); + + + @VerifyKey + @NotNull + // @formatter:off + @AttributeOverride(name = "name", column = @Column(name = "participant_name")) + @AttributeOverride(name = "version", column = @Column(name = "participant_version")) + private PfConceptKey participantId; + // @formatter: on + + @Column + @NotNull + private AutomationCompositionState state; + + @Column + private long acElementUptime; + + + /** + * The Default Constructor creates a {@link JpaAcElementStatistics} object with a null key. + */ + public JpaAcElementStatistics() { + this(new PfReferenceTimestampKey()); + } + + + /** + * The Key Constructor creates a {@link JpaAcElementStatistics} object with the given Reference Timestamp key. + * + * @param key the key + */ + public JpaAcElementStatistics(@NonNull final PfReferenceTimestampKey key) { + this(key, new PfConceptKey(), AutomationCompositionState.PASSIVE, 0L); + } + + /** + * The Key Constructor creates a {@link JpaAcElementStatistics} object with all mandatory fields. + * + * @param key the key + * @param participantId the TOSCA definition of the automation composition element + */ + public JpaAcElementStatistics(@NonNull final PfReferenceTimestampKey key, + @NonNull final PfConceptKey participantId) { + this.key = key; + this.participantId = participantId; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaAcElementStatistics(@NonNull final JpaAcElementStatistics copyConcept) { + super(copyConcept); + this.key = new PfReferenceTimestampKey(copyConcept.key); + this.participantId = new PfConceptKey(copyConcept.participantId); + this.state = copyConcept.state; + this.acElementUptime = copyConcept.acElementUptime; + } + + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaAcElementStatistics(@NonNull final AcElementStatistics authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + + + @Override + public AcElementStatistics toAuthorative() { + var acElementStatistics = new AcElementStatistics(); + acElementStatistics.setId(UUID.fromString(getKey().getReferenceKey().getLocalName())); + acElementStatistics.setTimeStamp(key.getInstant()); + acElementStatistics.setParticipantId(new ToscaConceptIdentifier(participantId)); + acElementStatistics.setState(state); + acElementStatistics.setAcElementUptime(acElementUptime); + + return acElementStatistics; + } + + @Override + public void fromAuthorative(@NonNull AcElementStatistics acElementStatistics) { + // @formatter:off + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfReferenceTimestampKey(acElementStatistics.getParticipantId().getName(), + acElementStatistics.getParticipantId().getVersion(), acElementStatistics.getId().toString(), + acElementStatistics.getTimeStamp())); + } + // @formatter:on + this.setParticipantId(acElementStatistics.getParticipantId().asConceptKey()); + this.setState(acElementStatistics.getState()); + this.setAcElementUptime(acElementStatistics.getAcElementUptime()); + } + + @Override + public List getKeys() { + return getKey().getKeys(); + } + + @Override + public void clean() { + key.clean(); + participantId.clean(); + } + + + @Override + public int compareTo(PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaAcElementStatistics other = (JpaAcElementStatistics) otherConcept; + return new CompareToBuilder().append(this.key, other.key).append(this.state, other.state) + .append(this.acElementUptime, other.acElementUptime).toComparison(); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java new file mode 100644 index 000000000..e5c44d0a2 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationComposition.java @@ -0,0 +1,268 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import javax.persistence.AttributeOverride; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToMany; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.base.PfUtils; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a automation composition in the database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Entity +@Table(name = "AutomationComposition") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaAutomationComposition extends PfConcept implements PfAuthorative { + private static final long serialVersionUID = -4725410933242154805L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfConceptKey key; + + // @formatter:off + @VerifyKey + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "definition_name")) + @AttributeOverride(name = "version", column = @Column(name = "definition_version")) + private PfConceptKey definition; + // @formatter:on + + @Column + @NotNull + private AutomationCompositionState state; + + @Column + @NotNull + private AutomationCompositionOrderedState orderedState; + + @Column + private String description; + + @Column + private Boolean primed; + + @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @NotNull + private Map<@NotNull UUID, @NotNull @Valid JpaAutomationCompositionElement> elements; + // @formatter:on + + /** + * The Default Constructor creates a {@link JpaAutomationComposition} object with a null key. + */ + public JpaAutomationComposition() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaAutomationComposition} object with the given concept key. + * + * @param key the key + */ + public JpaAutomationComposition(@NonNull final PfConceptKey key) { + this(key, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>()); + } + + /** + * The Key Constructor creates a {@link JpaAutomationComposition} object with all mandatory fields. + * + * @param key the key + * @param definition the TOSCA definition of the automation composition + * @param state the state of the automation composition + * @param elements the elements of the automation composition in participants + */ + public JpaAutomationComposition(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, + @NonNull final AutomationCompositionState state, + @NonNull final Map elements) { + this.key = key; + this.definition = definition; + this.state = state; + this.elements = elements; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaAutomationComposition(@NonNull final JpaAutomationComposition copyConcept) { + super(copyConcept); + this.key = new PfConceptKey(copyConcept.key); + this.definition = new PfConceptKey(copyConcept.definition); + this.state = copyConcept.state; + this.orderedState = copyConcept.orderedState; + this.description = copyConcept.description; + this.elements = + PfUtils.mapMap(copyConcept.elements, JpaAutomationCompositionElement::new, new LinkedHashMap<>(0)); + this.primed = copyConcept.primed; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaAutomationComposition(@NonNull final AutomationComposition authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + @Override + public AutomationComposition toAuthorative() { + var automationComposition = new AutomationComposition(); + + automationComposition.setName(getKey().getName()); + automationComposition.setVersion(getKey().getVersion()); + automationComposition.setDefinition(new ToscaConceptIdentifier(definition)); + automationComposition.setState(state); + automationComposition.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); + automationComposition.setDescription(description); + automationComposition.setElements( + PfUtils.mapMap(elements, JpaAutomationCompositionElement::toAuthorative, new LinkedHashMap<>(0))); + automationComposition.setPrimed(primed); + + return automationComposition; + } + + @Override + public void fromAuthorative(@NonNull final AutomationComposition automationComposition) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfConceptKey(automationComposition.getName(), automationComposition.getVersion())); + } + + this.definition = automationComposition.getDefinition().asConceptKey(); + this.state = automationComposition.getState(); + this.orderedState = automationComposition.getOrderedState(); + this.description = automationComposition.getDescription(); + this.primed = automationComposition.getPrimed(); + + this.elements = new LinkedHashMap<>(automationComposition.getElements().size()); + for (Entry elementEntry : automationComposition.getElements().entrySet()) { + var jpaAutomationCompositionElement = new JpaAutomationCompositionElement(); + jpaAutomationCompositionElement + .setKey(new PfReferenceKey(getKey(), elementEntry.getValue().getId().toString())); + jpaAutomationCompositionElement.fromAuthorative(elementEntry.getValue()); + this.elements.put(elementEntry.getKey(), jpaAutomationCompositionElement); + } + } + + @Override + public List getKeys() { + List keyList = getKey().getKeys(); + + keyList.add(definition); + + for (JpaAutomationCompositionElement element : elements.values()) { + keyList.addAll(element.getKeys()); + } + + return keyList; + } + + @Override + public void clean() { + key.clean(); + definition.clean(); + description = (description == null ? null : description.trim()); + + for (JpaAutomationCompositionElement element : elements.values()) { + element.clean(); + } + } + + @Override + public int compareTo(final PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return this.getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaAutomationComposition other = (JpaAutomationComposition) otherConcept; + int result = key.compareTo(other.key); + if (result != 0) { + return result; + } + + result = definition.compareTo(other.definition); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(state, other.state); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(orderedState, other.orderedState); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(description, other.description); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(primed, other.primed); + if (result != 0) { + return result; + } + return PfUtils.compareObjects(elements, other.elements); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java new file mode 100644 index 000000000..08d8ee06b --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java @@ -0,0 +1,253 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.models.acm.persistence.concepts; + +import java.util.List; +import java.util.UUID; +import javax.persistence.AttributeOverride; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a participant automation composition element in the database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Entity +@Table(name = "AutomationCompositionElement") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaAutomationCompositionElement extends PfConcept implements PfAuthorative { + private static final long serialVersionUID = -1791732273187890213L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfReferenceKey key; + + // @formatter:off + @VerifyKey + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "definition_name")) + @AttributeOverride(name = "version", column = @Column(name = "definition_version")) + private PfConceptKey definition; + + @VerifyKey + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "participant_type_name")) + @AttributeOverride(name = "version", column = @Column(name = "participant_type_version")) + private PfConceptKey participantType; + + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "participant_name")) + @AttributeOverride(name = "version", column = @Column(name = "participant_version")) + private PfConceptKey participantId; + // @formatter:on + + @Column + @NotNull + private AutomationCompositionState state; + + @Column + @NotNull + private AutomationCompositionOrderedState orderedState; + + @Column + private String description; + + /** + * The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key. + */ + public JpaAutomationCompositionElement() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with the given concept key. + * + * @param key the key + */ + public JpaAutomationCompositionElement(@NonNull final PfReferenceKey key) { + this(key, new PfConceptKey(), new PfConceptKey(), AutomationCompositionState.UNINITIALISED); + } + + /** + * The Key Constructor creates a {@link JpaAutomationCompositionElement} object with all mandatory fields. + * + * @param key the key + * @param definition the TOSCA definition of the automation composition element + * @param participantType the TOSCA definition of the participant running the automation composition element + * @param state the state of the automation composition + */ + public JpaAutomationCompositionElement(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey definition, + @NonNull final PfConceptKey participantType, @NonNull final AutomationCompositionState state) { + this.key = key; + this.definition = definition; + this.participantType = participantType; + this.state = state; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaAutomationCompositionElement(@NonNull final JpaAutomationCompositionElement copyConcept) { + super(copyConcept); + this.key = new PfReferenceKey(copyConcept.key); + this.definition = new PfConceptKey(copyConcept.definition); + this.participantType = new PfConceptKey(copyConcept.participantType); + this.participantId = new PfConceptKey(copyConcept.participantId); + this.state = copyConcept.state; + this.orderedState = copyConcept.orderedState; + this.description = copyConcept.description; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaAutomationCompositionElement(@NonNull final AutomationCompositionElement authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + @Override + public AutomationCompositionElement toAuthorative() { + var element = new AutomationCompositionElement(); + + element.setId(UUID.fromString(getKey().getLocalName())); + element.setDefinition(new ToscaConceptIdentifier(definition)); + element.setParticipantType(new ToscaConceptIdentifier(participantType)); + element.setParticipantId(new ToscaConceptIdentifier(participantId)); + element.setState(state); + element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState()); + element.setDescription(description); + + return element; + } + + @Override + public void fromAuthorative(@NonNull final AutomationCompositionElement element) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfReferenceKey()); + getKey().setLocalName(element.getId().toString()); + } + + this.definition = element.getDefinition().asConceptKey(); + this.participantType = element.getParticipantType().asConceptKey(); + this.participantId = element.getParticipantId().asConceptKey(); + this.state = element.getState(); + this.orderedState = element.getOrderedState(); + this.description = element.getDescription(); + } + + @Override + public List getKeys() { + List keyList = getKey().getKeys(); + + keyList.add(definition); + keyList.add(participantType); + keyList.add(participantId); + + return keyList; + } + + @Override + public void clean() { + key.clean(); + definition.clean(); + participantType.clean(); + participantId.clean(); + + if (description != null) { + description = description.trim(); + } + } + + @Override + public int compareTo(final PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return this.getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaAutomationCompositionElement other = (JpaAutomationCompositionElement) otherConcept; + int result = key.compareTo(other.key); + if (result != 0) { + return result; + } + + result = definition.compareTo(other.definition); + if (result != 0) { + return result; + } + + result = participantType.compareTo(other.participantType); + if (result != 0) { + return result; + } + + result = participantId.compareTo(other.participantId); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(state, other.state); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(orderedState, other.orderedState); + if (result != 0) { + return result; + } + + return ObjectUtils.compare(description, other.description); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java new file mode 100644 index 000000000..143499c0d --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipant.java @@ -0,0 +1,231 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.AttributeOverride; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.ObjectUtils; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a participant in the database. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Entity +@Table(name = "Participant") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaParticipant extends PfConcept implements PfAuthorative, Serializable { + private static final long serialVersionUID = -4697758484642403483L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfConceptKey key; + + // @formatter:off + @VerifyKey + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "definition_name")) + @AttributeOverride(name = "version", column = @Column(name = "definition_version")) + private PfConceptKey definition; + // @formatter:on + + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "participant_type_name")) + @AttributeOverride(name = "version", column = @Column(name = "participant_type_version")) + private PfConceptKey participantType; + + @Column + @NotNull + private ParticipantState participantState; + + @Column + @NotNull + private ParticipantHealthStatus healthStatus; + + @Column + private String description; + + /** + * The Default Constructor creates a {@link JpaParticipant} object with a null key. + */ + public JpaParticipant() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaParticipant} object with the given concept key. + * + * @param key the key + */ + public JpaParticipant(@NonNull final PfConceptKey key) { + this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.UNKNOWN); + } + + /** + * The Key Constructor creates a {@link JpaParticipant} object with all mandatory fields. + * + * @param key the key + * @param definition the TOSCA definition of the participant + * @param participantState the state of the participant + * @param healthStatus the health state of the participant + */ + public JpaParticipant(@NonNull final PfConceptKey key, @NonNull final PfConceptKey definition, + @NonNull final ParticipantState participantState, @NonNull ParticipantHealthStatus healthStatus) { + this.key = key; + this.definition = definition; + this.participantState = participantState; + this.healthStatus = healthStatus; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaParticipant(@NonNull final JpaParticipant copyConcept) { + super(copyConcept); + this.key = new PfConceptKey(copyConcept.key); + this.definition = new PfConceptKey(copyConcept.definition); + this.participantState = copyConcept.participantState; + this.healthStatus = copyConcept.healthStatus; + this.description = copyConcept.description; + this.participantType = copyConcept.participantType; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaParticipant(@NonNull final Participant authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + @Override + public Participant toAuthorative() { + var participant = new Participant(); + + participant.setName(key.getName()); + participant.setVersion(key.getVersion()); + participant.setDefinition(new ToscaConceptIdentifier(definition)); + participant.setParticipantState(participantState); + participant.setHealthStatus(healthStatus); + participant.setDescription(description); + participant.setParticipantType(new ToscaConceptIdentifier(participantType)); + + return participant; + } + + @Override + public void fromAuthorative(@NonNull final Participant participant) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfConceptKey(participant.getName(), participant.getVersion())); + } + + this.definition = participant.getDefinition().asConceptKey(); + this.setParticipantState(participant.getParticipantState()); + this.setHealthStatus(participant.getHealthStatus()); + this.setDescription(participant.getDescription()); + this.participantType = participant.getParticipantType().asConceptKey(); + } + + @Override + public List getKeys() { + List keyList = getKey().getKeys(); + + keyList.add(definition); + keyList.add(participantType); + + return keyList; + } + + @Override + public void clean() { + key.clean(); + definition.clean(); + description = (description == null ? null : description.trim()); + participantType.clean(); + } + + @Override + public int compareTo(final PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaParticipant other = (JpaParticipant) otherConcept; + int result = key.compareTo(other.key); + if (result != 0) { + return result; + } + + result = definition.compareTo(other.definition); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(participantState, other.participantState); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(healthStatus, other.healthStatus); + if (result != 0) { + return result; + } + + result = ObjectUtils.compare(participantType, other.participantType); + if (result != 0) { + return result; + } + + return ObjectUtils.compare(description, other.description); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatistics.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatistics.java new file mode 100644 index 000000000..a076433bb --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatistics.java @@ -0,0 +1,239 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.models.acm.persistence.concepts; + +import java.io.Serializable; +import java.util.List; +import javax.persistence.AttributeOverride; +import javax.persistence.Column; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import org.apache.commons.lang3.builder.CompareToBuilder; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.base.validation.annotations.VerifyKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Class to represent a participant statistics in the database. + * + * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) + */ +@Entity +@Table(name = "ParticipantStatistics") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@AllArgsConstructor +@EqualsAndHashCode(callSuper = false) +public class JpaParticipantStatistics extends PfConcept implements PfAuthorative, Serializable { + + private static final long serialVersionUID = -5992214428190133190L; + + @EmbeddedId + @VerifyKey + @NotNull + private PfTimestampKey key; + + @VerifyKey + @NotNull + @AttributeOverride(name = "name", column = @Column(name = "participant_name")) + @AttributeOverride(name = "version", column = @Column(name = "participant_version")) + private PfConceptKey participantId; + + @Column + @NotNull + private ParticipantState state; + + @Column + @NotNull + private ParticipantHealthStatus healthStatus; + + @Column + private long eventCount; + + @Column + private long lastExecutionTime; + + @Column + private double averageExecutionTime; + + @Column + private long upTime; + + @Column + private long lastEnterTime; + + @Column + private long lastStart; + + + /** + * The Default Constructor creates a {@link JpaParticipantStatistics} object with a null key. + */ + public JpaParticipantStatistics() { + this(new PfTimestampKey()); + } + + /** + * The Key Constructor creates a {@link JpaParticipantStatistics} object with the given Timestamp key. + * + * @param key the key + */ + public JpaParticipantStatistics(@NonNull final PfTimestampKey key) { + this(key, new PfConceptKey(), ParticipantState.PASSIVE, ParticipantHealthStatus.HEALTHY, 0L, 0L, 0.0d, 0L, 0L, + 0L); + } + + + /** + * The Key Constructor creates a {@link JpaParticipantStatistics} object with all mandatory fields. + * + * @param key the key + * @param participantId the TOSCA definition of the participant + */ + public JpaParticipantStatistics(@NonNull final PfTimestampKey key, @NonNull final PfConceptKey participantId) { + this.key = key; + this.participantId = participantId; + } + + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaParticipantStatistics(@NonNull final JpaParticipantStatistics copyConcept) { + super(copyConcept); + this.key = new PfTimestampKey(copyConcept.key); + this.participantId = new PfConceptKey(copyConcept.participantId); + this.state = copyConcept.state; + this.healthStatus = copyConcept.healthStatus; + this.eventCount = copyConcept.eventCount; + this.lastExecutionTime = copyConcept.lastExecutionTime; + this.averageExecutionTime = copyConcept.averageExecutionTime; + this.upTime = copyConcept.upTime; + this.lastEnterTime = copyConcept.lastEnterTime; + this.lastStart = copyConcept.lastStart; + } + + /** + * Authorative constructor. + * + * @param authorativeConcept the authorative concept to copy from + */ + public JpaParticipantStatistics(@NonNull final ParticipantStatistics authorativeConcept) { + this.fromAuthorative(authorativeConcept); + } + + + @Override + public int compareTo(PfConcept otherConcept) { + if (otherConcept == null) { + return -1; + } + if (this == otherConcept) { + return 0; + } + if (getClass() != otherConcept.getClass()) { + return getClass().getName().compareTo(otherConcept.getClass().getName()); + } + + final JpaParticipantStatistics other = (JpaParticipantStatistics) otherConcept; + // @formatter:off + return new CompareToBuilder() + .append(this.key, other.key) + .append(this.participantId, other.participantId) + .append(this.state, other.state) + .append(this.healthStatus, other.healthStatus) + .append(this.eventCount, other.eventCount) + .append(this.lastExecutionTime, other.lastExecutionTime) + .append(this.averageExecutionTime, other.averageExecutionTime) + .append(this.upTime, other.upTime) + .append(this.lastEnterTime, other.lastEnterTime) + .append(this.lastStart, other.lastStart).toComparison(); + // @formatter:on + } + + @Override + public ParticipantStatistics toAuthorative() { + var participantStatistics = new ParticipantStatistics(); + participantStatistics.setTimeStamp(key.getTimeStamp().toInstant()); + participantStatistics.setParticipantId(new ToscaConceptIdentifier(participantId)); + participantStatistics.setState(state); + participantStatistics.setHealthStatus(healthStatus); + participantStatistics.setAverageExecutionTime(averageExecutionTime); + participantStatistics.setEventCount(eventCount); + participantStatistics.setLastExecutionTime(lastExecutionTime); + participantStatistics.setUpTime(upTime); + participantStatistics.setLastEnterTime(lastEnterTime); + participantStatistics.setLastStart(lastStart); + + return participantStatistics; + } + + @Override + public void fromAuthorative(@NonNull final ParticipantStatistics participantStatistics) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfTimestampKey(participantStatistics.getParticipantId().getName(), + participantStatistics.getParticipantId().getVersion(), participantStatistics.getTimeStamp())); + } + this.setParticipantId(participantStatistics.getParticipantId().asConceptKey()); + this.setState(participantStatistics.getState()); + this.setHealthStatus(participantStatistics.getHealthStatus()); + this.setAverageExecutionTime(participantStatistics.getAverageExecutionTime()); + this.setEventCount(participantStatistics.getEventCount()); + this.setLastExecutionTime(participantStatistics.getLastExecutionTime()); + this.setUpTime(participantStatistics.getUpTime()); + this.setLastEnterTime(participantStatistics.getLastEnterTime()); + this.setLastStart(participantStatistics.getLastStart()); + + } + + @Override + public List getKeys() { + List keyList = getKey().getKeys(); + keyList.addAll(participantId.getKeys()); + return keyList; + } + + @Override + public void clean() { + key.clean(); + participantId.clean(); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProvider.java new file mode 100644 index 000000000..59ddcc2ea --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProvider.java @@ -0,0 +1,139 @@ +/*- + * ============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.models.acm.persistence.provider; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.ws.rs.core.Response.Status; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAcElementStatistics; +import org.onap.policy.clamp.models.acm.persistence.repository.AcElementStatisticsRepository; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfReferenceTimestampKey; +import org.onap.policy.models.dao.PfFilterParameters; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * This class provides the provision of information on automation composition element statistics in the database to + * callers. + * + * @author Ramesh Murugan Iyer (ramesh.murugan.iyer@est.tech) + */ +@Service +@Transactional +@AllArgsConstructor +public class AcElementStatisticsProvider { + + private AcElementStatisticsRepository acElementStatisticsRepository; + + /** + * Creates automation composition element statistics. + * + * @param acElementStatisticsList a specification of the statistics to create + * @return the Element statistics created + * @throws PfModelException on initiation errors + */ + public List createAcElementStatistics( + @NonNull final List acElementStatisticsList) throws PfModelException { + + try { + var jpaAcElementStatisticsList = ProviderUtils.getJpaAndValidateList(acElementStatisticsList, + JpaAcElementStatistics::new, "automation composition element statistics"); + + var jpaAcElementStatisticsSaved = acElementStatisticsRepository.saveAll(jpaAcElementStatisticsList); + + // Return the saved automation composition element statistics + return asAcElementStatisticsList(jpaAcElementStatisticsSaved); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in save automation composition element statistics", + e); + } + } + + /** + * Convert JPA acElement statistics list to acElement statistics list. + * + * @param jpaAcElementStatistics the list to convert + * @return the acElement statistics list + */ + private List asAcElementStatisticsList(List jpaAcElementStatistics) { + return jpaAcElementStatistics.stream().map(JpaAcElementStatistics::toAuthorative).collect(Collectors.toList()); + } + + /** + * Get acElement statistics. + * + * @param name the name of the participant + * @param version version of the participant + * @param id of the automation composition element + * @param timestamp timestamp of the statistics + * @return the acElement statistics found + */ + @Transactional(readOnly = true) + public List getAcElementStatistics(final String name, final String version, final String id, + final Instant timestamp) { + if (name != null && version != null && timestamp != null && id != null) { + return asAcElementStatisticsList(acElementStatisticsRepository + .findAllById(List.of(new PfReferenceTimestampKey(name, version, id, timestamp)))); + } else if (name != null) { + return getFilteredAcElementStatistics(name, version, null, null, null, "DESC", 0); + } + return asAcElementStatisticsList(acElementStatisticsRepository.findAll()); + } + + /** + * Get filtered acElement statistics. + * + * @param name the acElement name for the statistics to get + * @param version the acElement version for the statistics to get + * @param startTimeStamp startTimeStamp to filter statistics + * @param endTimeStamp endTimeStamp to filter statistics + * @param sortOrder sortOrder to query database + * @param getRecordNum Total query count from database + * @param filterMap the filters to apply to the get operation + * @return the acElement statistics found + */ + @Transactional(readOnly = true) + public List getFilteredAcElementStatistics(final String name, final String version, + final Instant startTimeStamp, final Instant endTimeStamp, Map filterMap, final String sortOrder, + final int getRecordNum) { + + // @formatter:off + PfFilterParameters filterParams = PfFilterParameters + .builder() + .name(name) + .version(version) + .startTime(startTimeStamp) + .endTime(endTimeStamp) + .filterMap(filterMap) + .sortOrder(sortOrder) + .recordNum(getRecordNum) + .build(); + // @formatter:on + return asAcElementStatisticsList( + acElementStatisticsRepository.getFiltered(JpaAcElementStatistics.class, filterParams)); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java new file mode 100644 index 000000000..760613026 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java @@ -0,0 +1,287 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. + * ================================================================================ + * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.models.acm.persistence.provider; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import javax.persistence.EntityNotFoundException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; +import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplatesRepository; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * This class provides information on automation composition concepts in the database to callers. + */ +@Service +@Transactional +@AllArgsConstructor +public class AutomationCompositionProvider { + + private final AutomationCompositionRepository automationCompositionRepository; + private final ToscaNodeTemplateRepository toscaNodeTemplateRepository; + private final ToscaNodeTemplatesRepository toscaNodeTemplatesRepository; + + /** + * Get automation composition. + * + * @param automationCompositionId the ID of the automation composition to get + * @return the automation composition found + * @throws PfModelException on errors getting the automation composition + */ + @Transactional(readOnly = true) + public AutomationComposition getAutomationComposition(final ToscaConceptIdentifier automationCompositionId) + throws PfModelException { + try { + return automationCompositionRepository.getById(automationCompositionId.asConceptKey()).toAuthorative(); + } catch (EntityNotFoundException e) { + throw new PfModelException(Status.NOT_FOUND, "AutomationComposition not found", e); + } + } + + /** + * Find automation composition by automationCompositionId. + * + * @param name the name of the automation composition to get, null to get all automation compositions + * @param version the version of the automation composition to get, null to get all automation compositions + * @return the automation composition found + * @throws PfModelException on errors getting the automation composition + */ + @Transactional(readOnly = true) + public Optional findAutomationComposition(@NonNull final String name, + @NonNull final String version) throws PfModelException { + return findAutomationComposition(new PfConceptKey(name, version)); + } + + /** + * Find automation composition by automationCompositionId. + * + * @param automationCompositionId the ID of the automation composition to get + * @return the automation composition found + * @throws PfModelException on errors getting the automation composition + */ + @Transactional(readOnly = true) + public Optional findAutomationComposition( + final ToscaConceptIdentifier automationCompositionId) throws PfModelException { + return findAutomationComposition(automationCompositionId.asConceptKey()); + } + + private Optional findAutomationComposition(@NonNull final PfConceptKey key) + throws PfModelException { + try { + return automationCompositionRepository.findById(key).map(JpaAutomationComposition::toAuthorative); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Not valid parameter", e); + } + } + + /** + * Save automation composition. + * + * @param automationComposition the automation composition to update + * @return the updated automation composition + * @throws PfModelException on errors updating the automation composition + */ + public AutomationComposition saveAutomationComposition(final AutomationComposition automationComposition) + throws PfModelException { + try { + var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition, + JpaAutomationComposition::new, "automation composition")); + + // Return the saved participant + return result.toAuthorative(); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in save automationComposition", e); + } + } + + /** + * Get all automation compositions. + * + * @return all automation compositions found + * @throws PfModelException on errors getting automation compositions + */ + @Transactional(readOnly = true) + public List getAutomationCompositions() throws PfModelException { + + return ProviderUtils.asEntityList(automationCompositionRepository.findAll()); + } + + /** + * Get automation compositions. + * + * @param name the name of the automation composition to get, null to get all automation compositions + * @param version the version of the automation composition to get, null to get all automation compositions + * @return the automation compositions found + * @throws PfModelException on errors getting automation compositions + */ + @Transactional(readOnly = true) + public List getAutomationCompositions(final String name, final String version) + throws PfModelException { + + return ProviderUtils + .asEntityList(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version)); + } + + /** + * Saves automation compositions. + * + * @param automationCompositions a specification of the automation compositions to create + * @return the automation compositions created + * @throws PfModelException on errors creating automation compositions + */ + public List saveAutomationCompositions( + @NonNull final List automationCompositions) throws PfModelException { + try { + var result = + automationCompositionRepository.saveAll(ProviderUtils.getJpaAndValidateList(automationCompositions, + JpaAutomationComposition::new, "automation compositions")); + + // Return the saved participant + return ProviderUtils.asEntityList(result); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in save AutomationCompositions", e); + } + } + + /** + * Saves Instance Properties to the database. + * + * @param serviceTemplate the service template + * @return a Map of tosca node templates + */ + public Map saveInstanceProperties(ToscaServiceTemplate serviceTemplate) { + Map savedNodeTemplates = new HashMap<>(); + + var jpaToscaNodeTemplates = new JpaToscaNodeTemplates(); + jpaToscaNodeTemplates.fromAuthorative(List.of(serviceTemplate.getToscaTopologyTemplate().getNodeTemplates())); + + toscaNodeTemplatesRepository.save(jpaToscaNodeTemplates); + serviceTemplate.getToscaTopologyTemplate().getNodeTemplates().forEach(savedNodeTemplates::put); + + return savedNodeTemplates; + } + + /** + * Delete a automation composition. + * + * @param name the name of the automation composition to delete + * @param version the version of the automation composition to delete + * @return the automation composition deleted + * @throws PfModelException on errors deleting the automation composition + */ + public AutomationComposition deleteAutomationComposition(@NonNull final String name, @NonNull final String version) + throws PfModelException { + + var automationCompositionKey = new PfConceptKey(name, version); + var jpaDeleteAutomationComposition = automationCompositionRepository.findById(automationCompositionKey); + + if (jpaDeleteAutomationComposition.isEmpty()) { + String errorMessage = "delete of automation composition \"" + automationCompositionKey.getId() + + "\" failed, automation composition does not exist"; + throw new PfModelException(Response.Status.BAD_REQUEST, errorMessage); + } + + automationCompositionRepository.deleteById(automationCompositionKey); + + return jpaDeleteAutomationComposition.get().toAuthorative(); + } + + /** + * Deletes Instance Properties on the database. + * + * @param filteredToscaNodeTemplateMap filtered node templates map to delete + * @param filteredToscaNodeTemplateList filtered node template list to delete + */ + public void deleteInstanceProperties(Map filteredToscaNodeTemplateMap, + List filteredToscaNodeTemplateList) { + + var jpaToscaNodeTemplates = new JpaToscaNodeTemplates(); + jpaToscaNodeTemplates.fromAuthorative(List.of(filteredToscaNodeTemplateMap)); + + toscaNodeTemplatesRepository.save(jpaToscaNodeTemplates); + + filteredToscaNodeTemplateList.forEach(template -> { + var jpaToscaNodeTemplate = new JpaToscaNodeTemplate(template); + + toscaNodeTemplateRepository.delete(jpaToscaNodeTemplate); + }); + } + + /** + * Get All Node Templates. + * + * @return the list of node templates found + * @throws PfModelException on errors getting node templates + */ + @Transactional(readOnly = true) + public List getAllNodeTemplates() { + return ProviderUtils.asEntityList(toscaNodeTemplateRepository.findAll()); + } + + /** + * Get Node Templates. + * + * @param name the name of the node template to get, null to get all node templates + * @param version the version of the node template to get, null to get all node templates + * @return the node templates found + * @throws PfModelException on errors getting node templates + */ + @Transactional(readOnly = true) + public List getNodeTemplates(final String name, final String version) { + return ProviderUtils + .asEntityList(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version)); + } + + /** + * Get filtered node templates. + * + * @param filter the filter for the node templates to get + * @return the node templates found + * @throws PfModelException on errors getting node templates + */ + @Transactional(readOnly = true) + public List getFilteredNodeTemplates( + @NonNull final ToscaTypedEntityFilter filter) { + + return filter.filter(ProviderUtils.asEntityList(toscaNodeTemplateRepository + .getFiltered(JpaToscaNodeTemplate.class, filter.getName(), filter.getVersion()))); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java new file mode 100644 index 000000000..1f9e07f8e --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java @@ -0,0 +1,152 @@ +/*- + * ============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.models.acm.persistence.provider; + +import java.util.List; +import java.util.Optional; +import javax.ws.rs.core.Response.Status; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; +import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantRepository; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * This class provides information on participant concepts in the database to callers. + */ +@Service +@Transactional +@AllArgsConstructor +public class ParticipantProvider { + + private ParticipantRepository participantRepository; + + /** + * Get participants. + * + * @param name the name of the participant to get, null to get all participants + * @param version the version of the participant to get, null to get all participants + * @return the participants found + * @throws PfModelException on errors getting participants + */ + @Transactional(readOnly = true) + public List getParticipants(final String name, final String version) throws PfModelException { + + return ProviderUtils.asEntityList(participantRepository.getFiltered(JpaParticipant.class, name, version)); + } + + /** + * Get all participants. + * + * @return the participants found + * @throws PfModelException on errors getting policies + */ + @Transactional(readOnly = true) + public List getParticipants() throws PfModelException { + return ProviderUtils.asEntityList(participantRepository.findAll()); + } + + /** + * Get participant. + * + * @param name the name of the participant to get + * @param version the version of the participant to get + * @return the participant found + * @throws PfModelException on errors getting participant + */ + @Transactional(readOnly = true) + public Optional findParticipant(@NonNull final String name, @NonNull final String version) + throws PfModelException { + try { + return participantRepository.findById(new PfConceptKey(name, version)).map(JpaParticipant::toAuthorative); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in find Participant", e); + } + } + + /** + * Get filtered participants. + * + * @param filter the filter for the participants to get + * @return the participants found + * @throws PfModelException on errors getting policies + */ + @Transactional(readOnly = true) + public List getFilteredParticipants(@NonNull final ToscaTypedEntityFilter filter) + throws PfModelException { + + return filter.filter(ProviderUtils.asEntityList( + participantRepository.getFiltered(JpaParticipant.class, filter.getName(), filter.getVersion()))); + } + + /** + * Saves participant. + * + * @param participant participant to save + * @return the participant created + * @throws PfModelException on errors creating participants + */ + public Participant saveParticipant(@NonNull final Participant participant) throws PfModelException { + try { + var result = participantRepository + .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant")); + + // Return the saved participant + return result.toAuthorative(); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in save Participant", e); + } + } + + /** + * Delete a participant. + * + * @param name the name of the participant to delete + * @param version the version of the participant to get + * @return the participant deleted + * @throws PfModelRuntimeException on errors deleting participants + */ + public Participant deleteParticipant(@NonNull final String name, @NonNull final String version) + throws PfModelException { + try { + var participantKey = new PfConceptKey(name, version); + + var jpaDeleteParticipantOpt = participantRepository.findById(participantKey); + + if (jpaDeleteParticipantOpt.isEmpty()) { + String errorMessage = + "delete of participant \"" + participantKey.getId() + "\" failed, participant does not exist"; + throw new PfModelRuntimeException(Status.BAD_REQUEST, errorMessage); + } + participantRepository.delete(jpaDeleteParticipantOpt.get()); + + return jpaDeleteParticipantOpt.get().toAuthorative(); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in delete Participant", e); + } + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProvider.java new file mode 100644 index 000000000..a5a0ce176 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProvider.java @@ -0,0 +1,138 @@ +/*- + * ============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.models.acm.persistence.provider; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import javax.ws.rs.core.Response.Status; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics; +import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantStatisticsRepository; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.dao.PfFilterParameters; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * This class provides the provision of information on participant statistics in the database to callers. + */ +@Service +@Transactional +@AllArgsConstructor +public class ParticipantStatisticsProvider { + + private ParticipantStatisticsRepository participantStatisticsRepository; + + /** + * Get Participant statistics. + * + * @param name the name of the participant statistics to get, null to get all stats + * @param version the version of the participant statistics to get, null to get all stats for a name + * @param timestamp the time stamp for the stats to get + * @return the participant statistics found + */ + @Transactional(readOnly = true) + public List getParticipantStatistics(final String name, final String version, + final Instant timestamp) { + if (name != null && version != null && timestamp != null) { + return asParticipantStatisticsList( + participantStatisticsRepository.findAllById(List.of(new PfTimestampKey(name, version, timestamp)))); + } else if (name != null) { + return getFilteredParticipantStatistics(name, version, timestamp, null, null, "DESC", 0); + } + return asParticipantStatisticsList(participantStatisticsRepository.findAll()); + } + + /** + * Get filtered participant statistics. + * + * @param name the participant name for the statistics to get + * @param version the participant version for the statistics to get + * @param startTimeStamp startTimeStamp to filter statistics + * @param endTimeStamp endTimeStamp to filter statistics + * @param sortOrder sortOrder to query database + * @param getRecordNum Total query count from database + * @param filterMap the filters to apply to the get operation + * @return the participant statistics found + */ + @Transactional(readOnly = true) + public List getFilteredParticipantStatistics(final String name, final String version, + final Instant startTimeStamp, final Instant endTimeStamp, Map filterMap, + final String sortOrder, final int getRecordNum) { + + // @formatter:off + PfFilterParameters filterParams = PfFilterParameters + .builder() + .name(name) + .version(version) + .startTime(startTimeStamp) + .endTime(endTimeStamp) + .filterMap(filterMap) + .sortOrder(sortOrder) + .recordNum(getRecordNum) + .build(); + // @formatter:on + + return asParticipantStatisticsList( + participantStatisticsRepository.getFiltered(JpaParticipantStatistics.class, filterParams)); + } + + /** + * Creates Participant statistics. + * + * @param participantStatisticsList a specification of the statistics to create + * @return the participant statistics created + * @throws PfModelException on errors creating participant statistics + */ + public List createParticipantStatistics( + @NonNull final List participantStatisticsList) throws PfModelException { + + try { + var jpaParticipantStatisticsList = ProviderUtils.getJpaAndValidateList(participantStatisticsList, + JpaParticipantStatistics::new, "Participant Statistics"); + + var jpaParticipantStatisticsSaved = participantStatisticsRepository.saveAll(jpaParticipantStatisticsList); + + // Return the saved participant statistics + return asParticipantStatisticsList(jpaParticipantStatisticsSaved); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in save participant statistics", e); + } + } + + /** + * Convert JPA participant statistics list to participant statistics list. + * + * @param jpaParticipantStatisticsList the list to convert + * @return the participant statistics list + */ + private List asParticipantStatisticsList( + List jpaParticipantStatisticsList) { + + return jpaParticipantStatisticsList.stream().map(JpaParticipantStatistics::toAuthorative) + .collect(Collectors.toList()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java new file mode 100644 index 000000000..9510e5919 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ProviderUtils.java @@ -0,0 +1,93 @@ +/*- + * ============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.models.acm.persistence.provider; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; +import javax.ws.rs.core.Response; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.models.base.PfAuthorative; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ProviderUtils { + + /** + * Convert a list of concepts to a list of Jpa objects. + * + * @param authorativeConceptList the list of concepts + * @param jpaSupplier the Jpa Supplier + * @param conceptDescription the description used for validation result + * @return the list of Jpa objects + */ + public static > List getJpaAndValidateList( + List authorativeConceptList, Supplier jpaSupplier, String conceptDescription) { + var validationResult = new BeanValidationResult(conceptDescription + " List", authorativeConceptList); + + List jpaConceptList = new ArrayList<>(authorativeConceptList.size()); + + for (A authorativeConcept : authorativeConceptList) { + var jpaConcept = jpaSupplier.get(); + jpaConcept.fromAuthorative(authorativeConcept); + jpaConceptList.add(jpaConcept); + + validationResult.addResult(jpaConcept.validate(conceptDescription)); + } + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + return jpaConceptList; + } + + protected static > J getJpaAndValidate(A authorativeConcept, + Supplier jpaSupplier, String conceptDescription) { + var validationResult = new BeanValidationResult(conceptDescription, authorativeConcept); + + var jpaConcept = jpaSupplier.get(); + jpaConcept.fromAuthorative(authorativeConcept); + + validationResult.addResult(jpaConcept.validate(conceptDescription)); + + if (!validationResult.isValid()) { + throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, validationResult.getResult()); + } + return jpaConcept; + } + + /** + * Convert JPA automation composition list to an authorative automation composition list. + * + * @param the type of TOSCA entity + * @param the type of JPA TOSCA entity + * @param jpaEntityList the list to convert + * @return the authorative list + */ + public static > List asEntityList(List jpaEntityList) { + return jpaEntityList.stream().map(J::toAuthorative).collect(Collectors.toList()); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java new file mode 100644 index 000000000..0de5f480a --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProvider.java @@ -0,0 +1,261 @@ +/*- + * ============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.models.acm.persistence.provider; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import lombok.RequiredArgsConstructor; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaServiceTemplateRepository; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +@RequiredArgsConstructor +public class ServiceTemplateProvider { + + private final ToscaServiceTemplateRepository serviceTemplateRepository; + + /** + * Create service template. + * + * @param serviceTemplate the service template to be created + * @return the created service template + * @throws PfModelException on errors creating the service template + */ + public ToscaServiceTemplate createServiceTemplate(final ToscaServiceTemplate serviceTemplate) + throws PfModelException { + try { + var result = serviceTemplateRepository.save(ProviderUtils.getJpaAndValidate(serviceTemplate, + JpaToscaServiceTemplate::new, "toscaServiceTemplate")); + return result.toAuthorative(); + } catch (IllegalArgumentException e) { + throw new PfModelException(Status.BAD_REQUEST, "Error in save serviceTemplate", e); + } + } + + /** + * Delete service template. + * + * @param name the name of the service template to delete. + * @param version the version of the service template to delete. + * @return the TOSCA service template that was deleted + * @throws PfModelException on errors deleting policy types + */ + public ToscaServiceTemplate deleteServiceTemplate(final String name, final String version) throws PfModelException { + var serviceTemplateKey = new PfConceptKey(name, version); + var jpaDelete = serviceTemplateRepository.findById(serviceTemplateKey); + if (jpaDelete.isEmpty()) { + String errorMessage = "delete of serviceTemplate \"" + serviceTemplateKey.getId() + + "\" failed, serviceTemplate does not exist"; + throw new PfModelException(Response.Status.BAD_REQUEST, errorMessage); + } + serviceTemplateRepository.deleteById(serviceTemplateKey); + return jpaDelete.get().toAuthorative(); + } + + /** + * Get the requested automation composition definitions. + * + * @param name the name of the definition to get, null for all definitions + * @param version the version of the definition to get, null for all definitions + * @return the automation composition definitions + * @throws PfModelException on errors getting automation composition definitions + */ + @Transactional(readOnly = true) + public ToscaServiceTemplate getToscaServiceTemplate(String name, String version) throws PfModelException { + var serviceTemplateKey = new PfConceptKey(name, version); + var jpaServiceTemplates = serviceTemplateRepository.findById(serviceTemplateKey); + if (jpaServiceTemplates.isEmpty()) { + throw new PfModelException(Status.NOT_FOUND, "Automation composition definitions not found"); + } + return jpaServiceTemplates.get().toAuthorative(); + } + + /** + * Get service templates. + * + * @return the topology templates found + * @throws PfModelException on errors getting service templates + */ + @Transactional(readOnly = true) + public List getAllServiceTemplates() throws PfModelException { + var jpaList = serviceTemplateRepository.findAll(); + return ProviderUtils.asEntityList(jpaList); + } + + /** + * Get service templates. + * + * @param name the name of the topology template to get, set to null to get all service templates + * @param version the version of the service template to get, set to null to get all service templates + * @return the topology templates found + * @throws PfModelException on errors getting service templates + */ + @Transactional(readOnly = true) + public List getServiceTemplateList(final String name, final String version) + throws PfModelException { + var jpaList = serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, name, version); + return ProviderUtils.asEntityList(jpaList); + } + + /** + * Get the initial node types with common or instance properties. + * + * @param fullNodeTypes map of all the node types in the specified template + * @param common boolean to indicate whether common or instance properties are required + * @return node types map that only has common properties + * @throws PfModelException on errors getting node type with common properties + */ + private Map getInitialNodeTypesMap(Map fullNodeTypes, + boolean common) { + + var tempNodeTypesMap = new HashMap(); + + fullNodeTypes.forEach((key, nodeType) -> { + var tempToscaNodeType = new ToscaNodeType(); + tempToscaNodeType.setName(key); + + var resultantPropertyMap = findCommonOrInstancePropsInNodeTypes(nodeType, common); + + if (!resultantPropertyMap.isEmpty()) { + tempToscaNodeType.setProperties(resultantPropertyMap); + tempNodeTypesMap.put(key, tempToscaNodeType); + } + }); + return tempNodeTypesMap; + } + + private Map findCommonOrInstancePropsInNodeTypes(ToscaNodeType nodeType, boolean common) { + + var tempCommonPropertyMap = new HashMap(); + var tempInstancePropertyMap = new HashMap(); + + nodeType.getProperties().forEach((propKey, prop) -> { + + if (prop.getMetadata() != null) { + prop.getMetadata().forEach((k, v) -> { + if (k.equals("common") && v.equals("true") && common) { + tempCommonPropertyMap.put(propKey, prop); + } else if (k.equals("common") && v.equals("false") && !common) { + tempInstancePropertyMap.put(propKey, prop); + } + + }); + } else { + tempInstancePropertyMap.put(propKey, prop); + } + }); + + if (tempCommonPropertyMap.isEmpty() && !common) { + return tempInstancePropertyMap; + } else { + return tempCommonPropertyMap; + } + } + + /** + * Get the node types derived from those that have common properties. + * + * @param initialNodeTypes map of all the node types in the specified template + * @param filteredNodeTypes map of all the node types that have common or instance properties + * @return all node types that have common properties including their children + * @throws PfModelException on errors getting node type with common properties + */ + private Map getFinalNodeTypesMap(Map initialNodeTypes, + Map filteredNodeTypes) { + for (var i = 0; i < initialNodeTypes.size(); i++) { + initialNodeTypes.forEach((key, nodeType) -> { + var tempToscaNodeType = new ToscaNodeType(); + tempToscaNodeType.setName(key); + + if (filteredNodeTypes.get(nodeType.getDerivedFrom()) != null) { + tempToscaNodeType.setName(key); + + var finalProps = new HashMap( + filteredNodeTypes.get(nodeType.getDerivedFrom()).getProperties()); + + tempToscaNodeType.setProperties(finalProps); + } else { + return; + } + filteredNodeTypes.putIfAbsent(key, tempToscaNodeType); + + }); + } + return filteredNodeTypes; + } + + /** + * Get the requested node types with common or instance properties. + * + * @param common boolean indicating common or instance properties + * @param serviceTemplate the ToscaServiceTemplate + * @return the node types with common or instance properties + * @throws PfModelException on errors getting node type properties + */ + public Map getCommonOrInstancePropertiesFromNodeTypes(boolean common, + ToscaServiceTemplate serviceTemplate) throws PfModelException { + var tempNodeTypesMap = this.getInitialNodeTypesMap(serviceTemplate.getNodeTypes(), common); + + return this.getFinalNodeTypesMap(serviceTemplate.getNodeTypes(), tempNodeTypesMap); + + } + + /** + * Get node templates with appropriate common or instance properties added. + * + * @param initialNodeTemplates map of all the node templates in the specified template + * @param nodeTypeProps map of all the node types that have common or instance properties including children + * @return all node templates with appropriate common or instance properties added + * @throws PfModelException on errors getting map of node templates with common or instance properties added + */ + public Map getDerivedCommonOrInstanceNodeTemplates( + Map initialNodeTemplates, Map nodeTypeProps) { + + var finalNodeTemplatesMap = new HashMap(); + + initialNodeTemplates.forEach((templateKey, template) -> { + if (nodeTypeProps.containsKey(template.getType())) { + var finalMergedProps = new HashMap(); + + nodeTypeProps.get(template.getType()).getProperties().forEach(finalMergedProps::putIfAbsent); + + template.setProperties(finalMergedProps); + + finalNodeTemplatesMap.put(templateKey, template); + } else { + return; + } + }); + return finalNodeTemplatesMap; + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AcElementStatisticsRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AcElementStatisticsRepository.java new file mode 100644 index 000000000..13001114f --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AcElementStatisticsRepository.java @@ -0,0 +1,32 @@ +/*- + * ============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.models.acm.persistence.repository; + +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAcElementStatistics; +import org.onap.policy.models.base.PfReferenceTimestampKey; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AcElementStatisticsRepository + extends JpaRepository, FilterRepository { + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java new file mode 100644 index 000000000..8eeb77e0d --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java @@ -0,0 +1,31 @@ +/*- + * ============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.models.acm.persistence.repository; + +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; +import org.onap.policy.models.base.PfConceptKey; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface AutomationCompositionRepository + extends JpaRepository, FilterRepository { +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java new file mode 100644 index 000000000..cdedc5eb5 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepository.java @@ -0,0 +1,53 @@ +/*- + * ============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.models.acm.persistence.repository; + +import java.util.List; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.dao.PfFilterParametersIntfc; + +public interface FilterRepository { + + /** + * Get an object from the database, referred to by concept key. + * + * @param the type of the object to get, a subclass of {@link PfConcept} + * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts + * of type T are returned, if name is not null and version is null, all versions of that concept matching the + * name are returned. + * @param filterParams filter parameters + * @return the objects that was retrieved from the database + */ + List getFiltered(Class someClass, PfFilterParametersIntfc filterParams); + + /** + * Get an object from the database, referred to by concept key. + * + * @param the type of the object to get, a subclass of {@link PfConcept} + * @param someClass the class of the object to get, a subclass of {@link PfConcept}, if name is null, all concepts + * of type T are returned, if name is not null and version is null, all versions of that concept matching the + * name are returned. + * @param name the name of the object to get, null returns all objects + * @param version the version the object to get, null returns all objects for a specified name + * @return the objects that was retrieved from the database + */ + List getFiltered(Class someClass, String name, String version); +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java new file mode 100644 index 000000000..d7e81d4da --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImpl.java @@ -0,0 +1,51 @@ +/*- + * ============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.models.acm.persistence.repository; + +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import org.onap.policy.models.base.PfConcept; +import org.onap.policy.models.dao.PfDao; +import org.onap.policy.models.dao.PfFilterParametersIntfc; +import org.onap.policy.models.dao.impl.ProxyDao; +import org.springframework.stereotype.Repository; + +@Repository +public class FilterRepositoryImpl implements FilterRepository { + + @PersistenceContext + private EntityManager entityManager; + + protected PfDao getPfDao() { + return new ProxyDao(entityManager); + } + + @Override + public List getFiltered(Class someClass, PfFilterParametersIntfc filterParams) { + return getPfDao().getFiltered(someClass, filterParams); + } + + @Override + public List getFiltered(Class someClass, String name, String version) { + return getPfDao().getFiltered(someClass, name, version); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java new file mode 100644 index 000000000..2279a75cc --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantRepository.java @@ -0,0 +1,31 @@ +/*- + * ============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.models.acm.persistence.repository; + +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; +import org.onap.policy.models.base.PfConceptKey; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ParticipantRepository extends JpaRepository, FilterRepository { + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantStatisticsRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantStatisticsRepository.java new file mode 100644 index 000000000..9cba62a70 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ParticipantStatisticsRepository.java @@ -0,0 +1,32 @@ +/*- + * ============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.models.acm.persistence.repository; + +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics; +import org.onap.policy.models.base.PfTimestampKey; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ParticipantStatisticsRepository + extends JpaRepository, FilterRepository { + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java new file mode 100644 index 000000000..20d0f0f7e --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplateRepository.java @@ -0,0 +1,30 @@ +/*- + * ============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.models.acm.persistence.repository; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ToscaNodeTemplateRepository + extends JpaRepository, FilterRepository { + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java new file mode 100644 index 000000000..f0ab40bf7 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaNodeTemplatesRepository.java @@ -0,0 +1,29 @@ +/*- + * ============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.models.acm.persistence.repository; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplates; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ToscaNodeTemplatesRepository extends JpaRepository { + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java new file mode 100644 index 000000000..b9190d0a7 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/ToscaServiceTemplateRepository.java @@ -0,0 +1,30 @@ +/*- + * ============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.models.acm.persistence.repository; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ToscaServiceTemplateRepository + extends JpaRepository, FilterRepository { + +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/rest/RestUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/rest/RestUtils.java new file mode 100644 index 000000000..ac19d2a27 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/rest/RestUtils.java @@ -0,0 +1,43 @@ +/*- + * ============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.models.acm.rest; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; +import org.onap.policy.models.errors.concepts.ErrorResponseInfo; +import org.springframework.http.ResponseEntity; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class RestUtils { + + /** + * Convert an ErrorResponseInfo to a ResponseEntity. + * + * @param ex the ErrorResponseInfo + * @return the ResponseEntity + */ + public static ResponseEntity toSimpleResponse(ErrorResponseInfo ex) { + var resp = new SimpleResponse(); + resp.setErrorDetails(ex.getErrorResponse().getErrorMessage()); + return ResponseEntity.status(ex.getErrorResponse().getResponseCode().getStatusCode()).body(resp); + } +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java new file mode 100644 index 000000000..394579aa6 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/utils/AcmUtils.java @@ -0,0 +1,152 @@ +/*- + * ============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.models.acm.utils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; + +/** + * Utility functions used in acm-runtime and participants. + * + */ +public class AcmUtils { + + private AcmUtils() { + throw new IllegalStateException("Utility class"); + } + + /** + * Prepare participant updates map. + * + * @param acElement automation composition element + * @param participantUpdates list of participantUpdates + */ + public static void prepareParticipantUpdate(AutomationCompositionElement acElement, + List participantUpdates) { + if (participantUpdates.isEmpty()) { + participantUpdates.add(getAutomationCompositionElementList(acElement)); + return; + } + + var participantExists = false; + for (ParticipantUpdates participantUpdate : participantUpdates) { + if (participantUpdate.getParticipantId().equals(acElement.getParticipantId())) { + participantUpdate.setAutomationCompositionElementList(List.of(acElement)); + participantExists = true; + } + } + if (!participantExists) { + participantUpdates.add(getAutomationCompositionElementList(acElement)); + } + } + + private static ParticipantUpdates getAutomationCompositionElementList(AutomationCompositionElement acElement) { + var participantUpdate = new ParticipantUpdates(); + participantUpdate.setParticipantId(acElement.getParticipantId()); + participantUpdate.setAutomationCompositionElementList(List.of(acElement)); + return participantUpdate; + } + + /** + * Set the Policy information in the service template for the automation composition element. + * + * @param acElement automation composition element + * @param toscaServiceTemplate ToscaServiceTemplate + */ + public static void setServiceTemplatePolicyInfo(AutomationCompositionElement acElement, + ToscaServiceTemplate toscaServiceTemplate) { + // Pass respective PolicyTypes or Policies as part of toscaServiceTemplateFragment + if (toscaServiceTemplate.getPolicyTypes() == null + && toscaServiceTemplate.getToscaTopologyTemplate().getPolicies() == null) { + return; + } + ToscaServiceTemplate toscaServiceTemplateFragment = new ToscaServiceTemplate(); + toscaServiceTemplateFragment.setPolicyTypes(toscaServiceTemplate.getPolicyTypes()); + ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate(); + toscaTopologyTemplate.setPolicies(toscaServiceTemplate.getToscaTopologyTemplate().getPolicies()); + toscaServiceTemplateFragment.setToscaTopologyTemplate(toscaTopologyTemplate); + toscaServiceTemplateFragment.setDataTypes(toscaServiceTemplate.getDataTypes()); + acElement.setToscaServiceTemplateFragment(toscaServiceTemplateFragment); + } + + /** + * Prepare ParticipantDefinitionUpdate to set in the message. + * + * @param acParticipantType participant type + * @param entryKey key for the entry + * @param entryValue value relates to toscaNodeTemplate + * @param participantDefinitionUpdates list of participantDefinitionUpdates + * @param commonPropertiesMap common properties map + */ + public static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier acParticipantType, String entryKey, + ToscaNodeTemplate entryValue, List participantDefinitionUpdates, + Map commonPropertiesMap) { + + var acDefinition = new AutomationCompositionElementDefinition(); + acDefinition.setAcElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion())); + acDefinition.setAutomationCompositionElementToscaNodeTemplate(entryValue); + if (commonPropertiesMap != null) { + ToscaNodeType nodeType = commonPropertiesMap.get(entryValue.getType()); + if (nodeType != null) { + acDefinition.setCommonPropertiesMap(nodeType.getProperties()); + } + } + + List automationCompositionElementDefinitionList = new ArrayList<>(); + + if (participantDefinitionUpdates.isEmpty()) { + participantDefinitionUpdates.add( + getParticipantDefinition(acDefinition, acParticipantType, automationCompositionElementDefinitionList)); + } else { + var participantExists = false; + for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) { + if (participantDefinitionUpdate.getParticipantType().equals(acParticipantType)) { + participantDefinitionUpdate.getAutomationCompositionElementDefinitionList().add(acDefinition); + participantExists = true; + } + } + if (!participantExists) { + participantDefinitionUpdates.add(getParticipantDefinition(acDefinition, acParticipantType, + automationCompositionElementDefinitionList)); + } + } + } + + private static ParticipantDefinition getParticipantDefinition(AutomationCompositionElementDefinition acDefinition, + ToscaConceptIdentifier acParticipantType, + List automationCompositionElementDefinitionList) { + var participantDefinition = new ParticipantDefinition(); + participantDefinition.setParticipantType(acParticipantType); + automationCompositionElementDefinitionList.add(acDefinition); + participantDefinition.setAutomationCompositionElementDefinitionList(automationCompositionElementDefinitionList); + return participantDefinition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java deleted file mode 100644 index 3bb0050c8..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ClElementStatisticsTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ClElementStatisticsTest { - @Test - void testClElementStatisticsLombok() { - assertNotNull(new ClElementStatistics()); - ClElementStatistics cles0 = new ClElementStatistics(); - - assertThat(cles0.toString()).contains("ClElementStatistics("); - assertThat(cles0.hashCode()).isNotZero(); - assertEquals(true, cles0.equals(cles0)); - assertEquals(false, cles0.equals(null)); - - - ClElementStatistics cles1 = new ClElementStatistics(); - cles1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); - cles1.setTimeStamp(Instant.now()); - - assertThat(cles1.toString()).contains("ClElementStatistics("); - assertEquals(false, cles1.hashCode() == 0); - assertEquals(false, cles1.equals(cles0)); - assertEquals(false, cles1.equals(null)); - - assertNotEquals(cles1, cles0); - - ClElementStatistics cles2 = new ClElementStatistics(); - cles2.setId(UUID.randomUUID()); - - // @formatter:off - assertThatThrownBy(() -> cles2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cles2.setTimeStamp(null)).isInstanceOf(NullPointerException.class); - // @formatter:on - - assertNotEquals(cles2, cles0); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java deleted file mode 100644 index daade4d52..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopConceptPojosTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class ControlLoopConceptPojosTest { - - @Test - void testPojos() { - List pojoClasses = - PojoClassFactory.getPojoClasses(ControlLoopConceptPojosTest.class.getPackageName()); - - // @formatter:off - final Validator validator = ValidatorBuilder - .create() - .with(new SetterMustExistRule()) - .with(new GetterMustExistRule()) - .with(new EqualsAndHashCodeMatchRule()) - .with(new NoPublicFieldsExceptStaticFinalRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .with(new ToStringTester()) - .build(); - - validator.validate(pojoClasses); - // @formatter:on - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java deleted file mode 100644 index ed579febb..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopElementTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopElementTest { - @Test - void testControlLoopElement() { - var cle0 = new ControlLoopElement(); - var cle1 = new ControlLoopElement(cle0); - assertEquals(cle0, cle1); - - cle1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); - cle1.setDescription("Description"); - cle1.setId(UUID.randomUUID()); - cle1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - cle1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); - cle1.setState(ControlLoopState.UNINITIALISED); - - var cle2 = new ControlLoopElement(cle1); - assertEquals(cle1, cle2); - } - - @Test - void testControlLoopState() { - var cle0 = new ControlLoopElement(); - - assertTrue( - cle0.getOrderedState() - .equalsControlLoopState(ControlLoopState.UNINITIALISED)); - - assertTrue( - cle0.getOrderedState().asState() - .equalsControlLoopOrderedState(ControlLoopOrderedState.UNINITIALISED)); - } - - @Test - void testControlLoopElementLombok() { - assertNotNull(new ControlLoopElement()); - var cle0 = new ControlLoopElement(); - - assertThat(cle0.toString()).contains("ControlLoopElement("); - assertThat(cle0.hashCode()).isNotZero(); - assertEquals(true, cle0.equals(cle0)); - assertEquals(false, cle0.equals(null)); - - var cle1 = new ControlLoopElement(); - - cle1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); - cle1.setDescription("Description"); - cle1.setId(UUID.randomUUID()); - cle1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - cle1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); - cle1.setState(ControlLoopState.UNINITIALISED); - - assertThat(cle1.toString()).contains("ControlLoopElement("); - assertEquals(false, cle1.hashCode() == 0); - assertEquals(false, cle1.equals(cle0)); - assertEquals(false, cle1.equals(null)); - - assertNotEquals(cle1, cle0); - - var cle2 = new ControlLoopElement(); - - // @formatter:off - assertThatThrownBy(() -> cle2.setDefinition(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cle2.setId(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cle2.setOrderedState(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cle2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cle2.setState(null)). isInstanceOf(NullPointerException.class); - // @formatter:on - - assertNotEquals(cle2, cle0); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java deleted file mode 100644 index d9c518b53..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ControlLoopTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.time.Instant; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopTest { - @Test - void testControlLoop() { - var cl0 = new ControlLoop(); - cl0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); - assertEquals("dfName", cl0.getType()); - assertEquals("1.2.3", cl0.getTypeVersion()); - - var cl1 = new ControlLoop(cl0); - assertEquals(cl0, cl1); - - assertEquals(0, cl0.compareTo(cl1)); - } - - @Test - void testControlLoopLombok() { - assertNotNull(new ControlLoop()); - var cl0 = new ControlLoop(); - cl0.setElements(new LinkedHashMap<>()); - - assertThat(cl0.toString()).contains("ControlLoop("); - assertThat(cl0.hashCode()).isNotZero(); - assertEquals(true, cl0.equals(cl0)); - assertEquals(false, cl0.equals(null)); - - var cl1 = new ControlLoop(); - - cl1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); - cl1.setDescription("Description"); - cl1.setElements(new LinkedHashMap<>()); - cl1.setName("Name"); - cl1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - cl1.setState(ControlLoopState.UNINITIALISED); - cl1.setVersion("0.0.1"); - - assertThat(cl1.toString()).contains("ControlLoop("); - assertEquals(false, cl1.hashCode() == 0); - assertEquals(false, cl1.equals(cl0)); - assertEquals(false, cl1.equals(null)); - - assertNotEquals(cl1, cl0); - - var cl2 = new ControlLoop(); - cl2.setElements(new LinkedHashMap<>()); - - // @formatter:off - assertThatThrownBy(() -> cl2.setDefinition(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cl2.setOrderedState(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> cl2.setState(null)). isInstanceOf(NullPointerException.class); - // @formatter:on - - assertEquals(cl2, cl0); - - cl1.setCascadedOrderedState(ControlLoopOrderedState.PASSIVE); - assertEquals(ControlLoopOrderedState.PASSIVE, cl1.getOrderedState()); - - cl1.getElements().put(UUID.randomUUID(), new ControlLoopElement()); - cl1.setCascadedOrderedState(ControlLoopOrderedState.RUNNING); - assertEquals(ControlLoopOrderedState.RUNNING, cl1.getOrderedState()); - assertEquals(ControlLoopOrderedState.RUNNING, cl1.getElements().values().iterator().next().getOrderedState()); - - assertNull(cl0.getElements().get(UUID.randomUUID())); - assertNull(cl1.getElements().get(UUID.randomUUID())); - - assertEquals(PfKey.NULL_KEY_NAME, cl0.getDefinition().getName()); - - } - - @Test - void testControlLoopElementStatisticsList() { - var cl = new ControlLoop(); - List emptylist = cl.getControlLoopElementStatisticsList(cl); - assertEquals(List.of(), emptylist); - - var cl1 = getControlLoopTest(); - List list = cl1.getControlLoopElementStatisticsList(cl1); - assertNotNull(list); - assertEquals(2, list.size()); - assertEquals(ControlLoopState.UNINITIALISED, list.get(0).getControlLoopState()); - } - - private ControlLoop getControlLoopTest() { - var cl = new ControlLoop(); - cl.setDefinition(new ToscaConceptIdentifier("defName", "1.2.3")); - cl.setDescription("Description"); - cl.setElements(new LinkedHashMap<>()); - cl.setName("Name"); - cl.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - cl.setState(ControlLoopState.UNINITIALISED); - cl.setVersion("0.0.1"); - - var uuid = UUID.randomUUID(); - var id = new ToscaConceptIdentifier( - "org.onap.policy.controlloop.PolicyControlLoopParticipant", "1.0.1"); - var clElement = getControlLoopElementTest(uuid, id); - - var uuid2 = UUID.randomUUID(); - var id2 = new ToscaConceptIdentifier( - "org.onap.policy.controlloop.PolicyControlLoopParticipantIntermediary", "0.0.1"); - var clElement2 = getControlLoopElementTest(uuid2, id2); - - cl.getElements().put(uuid, clElement); - cl.getElements().put(uuid2, clElement2); - return cl; - } - - private ControlLoopElement getControlLoopElementTest(UUID uuid, ToscaConceptIdentifier id) { - var clElement = new ControlLoopElement(); - clElement.setId(uuid); - clElement.setParticipantId(id); - clElement.setDefinition(id); - clElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - - var clElementStatistics = new ClElementStatistics(); - clElementStatistics.setParticipantId(id); - clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED); - clElementStatistics.setTimeStamp(Instant.now()); - - clElement.setClElementStatistics(clElementStatistics); - - return clElement; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java deleted file mode 100644 index f55f624bf..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantStatisticsTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import java.time.Instant; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantStatisticsTest { - @Test - void testParticipantStatisticsLombok() { - assertNotNull(new ParticipantStatistics()); - ParticipantStatistics ps0 = new ParticipantStatistics(); - - assertThat(ps0.toString()).contains("ParticipantStatistics("); - assertThat(ps0.hashCode()).isNotZero(); - assertEquals(true, ps0.equals(ps0)); - assertEquals(false, ps0.equals(null)); - - - ParticipantStatistics ps1 = new ParticipantStatistics(); - ps1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); - ps1.setTimeStamp(Instant.now()); - - assertThat(ps1.toString()).contains("ParticipantStatistics("); - assertEquals(false, ps1.hashCode() == 0); - assertEquals(false, ps1.equals(ps0)); - assertEquals(false, ps1.equals(null)); - - assertNotEquals(ps1, ps0); - - ParticipantStatistics ps2 = new ParticipantStatistics(); - - // @formatter:off - assertThatThrownBy(() -> ps2.setParticipantId(null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> ps2.setTimeStamp(null)). isInstanceOf(NullPointerException.class); - // @formatter:on - - assertEquals(ps2, ps0); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java deleted file mode 100644 index 5c429b96c..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantTest { - @Test - void testParticipant() { - - Participant p0 = new Participant(); - p0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); - assertEquals("dfName", p0.getType()); - assertEquals("1.2.3", p0.getTypeVersion()); - - Participant p1 = new Participant(p0); - assertEquals(p0, p1); - - assertEquals(0, p0.compareTo(p1)); - } - - @Test - void testParticipantLombok() { - assertNotNull(new Participant()); - Participant p0 = new Participant(); - - assertThat(p0.toString()).contains("Participant("); - assertThat(p0.hashCode()).isNotZero(); - assertEquals(true, p0.equals(p0)); - assertEquals(false, p0.equals(null)); - - - Participant p1 = new Participant(); - - p1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); - p1.setDescription("Description"); - p1.setHealthStatus(ParticipantHealthStatus.HEALTHY); - p1.setName("Name"); - p1.setParticipantState(ParticipantState.ACTIVE); - p1.setVersion("0.0.1"); - - assertThat(p1.toString()).contains("Participant("); - assertEquals(false, p1.hashCode() == 0); - assertEquals(false, p1.equals(p0)); - assertEquals(false, p1.equals(null)); - - assertNotEquals(p1, p0); - - Participant p2 = new Participant(); - - // @formatter:off - assertThatThrownBy(() -> p2.setDefinition(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> p2.setHealthStatus(null)). isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class); - // @formatter:on - - assertEquals(p2, p0); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java deleted file mode 100644 index 3fb8b6d7f..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/concepts/ParticipantUtilsTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============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.models.controlloop.concepts; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Map; -import org.junit.jupiter.api.Test; -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.StandardYamlCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -class ParticipantUtilsTest { - - private static final Coder CODER = new StandardCoder(); - private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml"; - private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json"; - private static final String CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.ControlLoopElement"; - private static final String POLICY_CONTROL_LOOP_ELEMENT = - "org.onap.policy.clamp.controlloop.PolicyControlLoopElement"; - private static final String PARTICIPANT_CONTROL_LOOP_ELEMENT = "org.onap.policy.clamp.controlloop.Participant"; - private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); - - @Test - void testFindParticipantType() throws CoderException { - var identifier = new ToscaConceptIdentifier("Identifier", "1.0.1"); - var result = ParticipantUtils.findParticipantType(Map.of("participantType", CODER.encode(identifier))); - assertThat(result).isEqualTo(identifier); - } - - @Test - void testFindStartPhase() { - var identifier = 13; - var result = ParticipantUtils.findStartPhase(Map.of("startPhase", identifier)); - assertThat(result).isEqualTo(identifier); - } - - @Test - void testGetFirstStartPhase() throws CoderException { - var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), - ToscaServiceTemplate.class); - var controlLoops = CODER.decode(ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON), ControlLoops.class); - var result = ParticipantUtils.getFirstStartPhase(controlLoops.getControlLoopList().get(0), serviceTemplate); - assertThat(result).isZero(); - } - - @Test - void testCheckIfNodeTemplateIsControlLoopElement() throws CoderException { - var serviceTemplate = YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), - ToscaServiceTemplate.class); - var nodeTemplate = new ToscaNodeTemplate(); - nodeTemplate.setType(CONTROL_LOOP_ELEMENT); - assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue(); - - nodeTemplate.setType(POLICY_CONTROL_LOOP_ELEMENT); - assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isTrue(); - - nodeTemplate.setType(PARTICIPANT_CONTROL_LOOP_ELEMENT); - assertThat(ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(nodeTemplate, serviceTemplate)).isFalse(); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java deleted file mode 100644 index 94b0b13c7..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaClElementStatisticsChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -/** - * Test class for {@link JpaClElementStatistics} comparisons. - */ -class DummyJpaClElementStatisticsChild extends JpaClElementStatistics { - private static final long serialVersionUID = -5101743610779424064L; -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java deleted file mode 100644 index 10150cf59..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -/** - * Test class for {@link JpaControlLoop} comparisons. - */ -class DummyJpaControlLoopChild extends JpaControlLoop { - private static final long serialVersionUID = -5101743610779424064L; -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java deleted file mode 100644 index 4bacb9255..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaControlLoopElementChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -/** - * Test class for {@link JpaControlLoopElement} comparisons. - */ -class DummyJpaControlLoopElementChild extends JpaControlLoopElement { - private static final long serialVersionUID = -5101743610779424064L; -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java deleted file mode 100644 index 68dcc319b..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -/** - * Test class for {@link JpaParticipant} comparisons. - */ -class DummyJpaParticipantChild extends JpaParticipant { - private static final long serialVersionUID = -5101743610779424064L; -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java deleted file mode 100644 index 2c1f04ea1..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/DummyJpaParticipantStatisticsChild.java +++ /dev/null @@ -1,28 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -/** - * Test class for {@link JpaParticipantStatistics} comparisons. - */ -class DummyJpaParticipantStatisticsChild extends JpaParticipantStatistics { - private static final long serialVersionUID = -5101743610779424064L; -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java deleted file mode 100644 index 0e6fb8383..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaClElementStatisticsTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfReferenceTimestampKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the {@link JpaClElementStatistics} class. - */ -class JpaClElementStatisticsTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - void testJpaClElementStatisticsConstructor() { - assertThatThrownBy(() -> { - new JpaClElementStatistics((JpaClElementStatistics) null); - }).hasMessageMatching("copyConcept is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaClElementStatistics((PfReferenceTimestampKey) null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaClElementStatistics(null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaClElementStatistics(null, new PfConceptKey()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaClElementStatistics(new PfReferenceTimestampKey(), null); - }).hasMessageMatching("participantId is marked .*ull but is null"); - - assertNotNull(new JpaClElementStatistics()); - assertNotNull(new JpaClElementStatistics((new PfReferenceTimestampKey()))); - assertNotNull(new JpaClElementStatistics(new PfReferenceTimestampKey(), new PfConceptKey())); - } - - @Test - void testJpaClElementStatistics() { - JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance(); - - ClElementStatistics cles = createClElementStatisticsInstance(); - assertEquals(cles, testJpaClElementStatistics.toAuthorative()); - - assertThatThrownBy(() -> { - testJpaClElementStatistics.fromAuthorative(null); - }).hasMessageMatching("clElementStatistics is marked .*ull but is null"); - - assertThatThrownBy(() -> new JpaClElementStatistics((JpaClElementStatistics) null)) - .isInstanceOf(NullPointerException.class); - - JpaClElementStatistics testJpaClElementStatisticsFa = new JpaClElementStatistics(); - testJpaClElementStatisticsFa.setKey(null); - testJpaClElementStatisticsFa.fromAuthorative(cles); - assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); - testJpaClElementStatisticsFa.setKey(PfReferenceTimestampKey.getNullKey()); - testJpaClElementStatisticsFa.fromAuthorative(cles); - assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); - testJpaClElementStatisticsFa.setKey(new PfReferenceTimestampKey("elementName", "0.0.1", - "a95757ba-b34a-4049-a2a8-46773abcbe5e", Instant.ofEpochSecond(123456L))); - testJpaClElementStatisticsFa.fromAuthorative(cles); - assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); - - testJpaClElementStatisticsFa = new JpaClElementStatistics(cles); - assertEquals(testJpaClElementStatistics, testJpaClElementStatisticsFa); - - assertEquals(1, testJpaClElementStatistics.getKeys().size()); - - assertEquals("elementName", testJpaClElementStatistics.getKey().getReferenceKey().getParentKeyName()); - - testJpaClElementStatistics.clean(); - assertEquals("elementName", testJpaClElementStatistics.getKey().getReferenceKey().getParentKeyName()); - - JpaClElementStatistics testJpaClElementStatistics2 = new JpaClElementStatistics(testJpaClElementStatistics); - assertEquals(testJpaClElementStatistics, testJpaClElementStatistics2); - } - - @Test - void testJpaClElementStatisticsValidation() { - JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance(); - - assertThatThrownBy(() -> { - testJpaClElementStatistics.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaClElementStatistics.validate("").isValid()); - } - - @Test - void testJpaClElementStatisticsCompareTo() { - JpaClElementStatistics testJpaClElementStatistics = createJpaClElementStatisticsInstance(); - - JpaClElementStatistics otherJpaClElementStatistics = new JpaClElementStatistics(testJpaClElementStatistics); - assertEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics)); - assertEquals(-1, testJpaClElementStatistics.compareTo(null)); - assertEquals(0, testJpaClElementStatistics.compareTo(testJpaClElementStatistics)); - assertNotEquals(0, testJpaClElementStatistics.compareTo(new DummyJpaClElementStatisticsChild())); - - testJpaClElementStatistics.setState(ControlLoopState.PASSIVE); - assertNotEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics)); - testJpaClElementStatistics.setState(ControlLoopState.UNINITIALISED); - assertEquals(0, testJpaClElementStatistics.compareTo(otherJpaClElementStatistics)); - - assertEquals(testJpaClElementStatistics, new JpaClElementStatistics(testJpaClElementStatistics)); - } - - @Test - void testJpaClElementStatisticsLombok() { - assertNotNull(new Participant()); - JpaClElementStatistics cles0 = new JpaClElementStatistics(); - - assertThat(cles0.toString()).contains("JpaClElementStatistics("); - assertThat(cles0.hashCode()).isNotZero(); - assertEquals(true, cles0.equals(cles0)); - assertEquals(false, cles0.equals(null)); - - - JpaClElementStatistics cles11 = new JpaClElementStatistics(); - - cles11.setState(ControlLoopState.UNINITIALISED); - - assertThat(cles11.toString()).contains("JpaClElementStatistics("); - assertEquals(false, cles11.hashCode() == 0); - assertEquals(false, cles11.equals(cles0)); - assertEquals(false, cles11.equals(null)); - - assertNotEquals(cles11, cles0); - - JpaClElementStatistics cles2 = new JpaClElementStatistics(); - assertEquals(cles2, cles0); - } - - private JpaClElementStatistics createJpaClElementStatisticsInstance() { - ClElementStatistics testCles = createClElementStatisticsInstance(); - JpaClElementStatistics testJpaClElementStatistics = new JpaClElementStatistics(); - testJpaClElementStatistics.setKey(null); - testJpaClElementStatistics.fromAuthorative(testCles); - testJpaClElementStatistics.setKey(PfReferenceTimestampKey.getNullKey()); - testJpaClElementStatistics.fromAuthorative(testCles); - - return testJpaClElementStatistics; - } - - private ClElementStatistics createClElementStatisticsInstance() { - ClElementStatistics clElementStatistics = new ClElementStatistics(); - clElementStatistics.setParticipantId(new ToscaConceptIdentifier("elementName", "0.0.1")); - clElementStatistics.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); - clElementStatistics.setTimeStamp(Instant.ofEpochSecond(123456L)); - clElementStatistics.setControlLoopState(ControlLoopState.UNINITIALISED); - - return clElementStatistics; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java deleted file mode 100644 index 63c5ea3ab..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopElementTest.java +++ /dev/null @@ -1,300 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.UUID; -import org.junit.jupiter.api.Test; -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.controlloop.concepts.Participant; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfKey; -import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the {@link JpaControlLoopElement} class. - */ -class JpaControlLoopElementTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - void testJpaControlLoopElementConstructor() { - assertThatThrownBy(() -> { - new JpaControlLoopElement((JpaControlLoopElement) null); - }).hasMessageMatching("copyConcept is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoopElement((PfReferenceKey) null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, null, null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, null, null, ControlLoopState.UNINITIALISED); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, null, new PfConceptKey("participant", "0.0.1"), null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, null, new PfConceptKey("participant", "0.0.1"), - ControlLoopState.UNINITIALISED); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, new PfConceptKey(), null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, new PfConceptKey(), null, ControlLoopState.UNINITIALISED); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), - ControlLoopState.UNINITIALISED); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(new PfReferenceKey(), null, null, null); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(new PfReferenceKey(), null, null, ControlLoopState.UNINITIALISED); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), null); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), - ControlLoopState.UNINITIALISED); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, null); - }).hasMessageMatching("participantType is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), null, ControlLoopState.UNINITIALISED); - }).hasMessageMatching("participantType is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), - new PfConceptKey("participant", "0.0.1"), null); - }).hasMessageMatching("state is marked .*ull but is null"); - - assertNotNull(new JpaControlLoopElement()); - assertNotNull(new JpaControlLoopElement((new PfReferenceKey()))); - assertNotNull(new JpaControlLoopElement(new PfReferenceKey(), new PfConceptKey(), - new PfConceptKey("participant", "0.0.1"), ControlLoopState.UNINITIALISED)); - } - - @Test - void testJpaControlLoopElement() { - JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); - - ControlLoopElement cle = createControlLoopElementInstance(); - assertEquals(cle, testJpaControlLoopElement.toAuthorative()); - - assertThatThrownBy(() -> { - testJpaControlLoopElement.fromAuthorative(null); - }).hasMessageMatching("element is marked .*ull but is null"); - - assertThatThrownBy(() -> new JpaControlLoopElement((JpaControlLoopElement) null)) - .isInstanceOf(NullPointerException.class); - - JpaControlLoopElement testJpaControlLoopElementFa = new JpaControlLoopElement(); - testJpaControlLoopElementFa.setKey(null); - testJpaControlLoopElementFa.fromAuthorative(cle); - assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa); - testJpaControlLoopElementFa.setKey(PfReferenceKey.getNullKey()); - testJpaControlLoopElementFa.fromAuthorative(cle); - assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa); - testJpaControlLoopElementFa.setKey(new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, - "a95757ba-b34a-4049-a2a8-46773abcbe5e")); - testJpaControlLoopElementFa.fromAuthorative(cle); - assertEquals(testJpaControlLoopElement, testJpaControlLoopElementFa); - - assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", testJpaControlLoopElement.getKey().getLocalName()); - assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", - new JpaControlLoopElement(createControlLoopElementInstance()).getKey().getLocalName()); - assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", - ((PfReferenceKey) new JpaControlLoopElement(createControlLoopElementInstance()).getKeys().get(0)) - .getLocalName()); - - testJpaControlLoopElement.clean(); - assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", testJpaControlLoopElement.getKey().getLocalName()); - - testJpaControlLoopElement.setDescription(" A Message "); - testJpaControlLoopElement.clean(); - assertEquals("A Message", testJpaControlLoopElement.getDescription()); - - JpaControlLoopElement testJpaControlLoopElement2 = new JpaControlLoopElement(testJpaControlLoopElement); - assertEquals(testJpaControlLoopElement, testJpaControlLoopElement2); - } - - @Test - void testJpaControlLoopElementOrderedState() throws CoderException { - ControlLoopElement testControlLoopElement = createControlLoopElementInstance(); - JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); - - testJpaControlLoopElement.setOrderedState(null); - assertEquals(testControlLoopElement, testJpaControlLoopElement.toAuthorative()); - testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - - ControlLoopElement noOrderedStateCle = new StandardCoder().decode( - new File("src/test/resources/json/ControlLoopElementNoOrderedState.json"), ControlLoopElement.class); - - JpaControlLoopElement noOrderedStateJpaCle = new JpaControlLoopElement(noOrderedStateCle); - assertNull(noOrderedStateJpaCle.getOrderedState()); - noOrderedStateCle.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - noOrderedStateJpaCle = new JpaControlLoopElement(noOrderedStateCle); - assertEquals(testJpaControlLoopElement, noOrderedStateJpaCle); - } - - @Test - void testJpaControlLoopElementValidation() { - JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); - - assertThatThrownBy(() -> { - testJpaControlLoopElement.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaControlLoopElement.validate("").isValid()); - } - - @Test - void testJpaControlLoopElementCompareTo() { - JpaControlLoopElement testJpaControlLoopElement = createJpaControlLoopElementInstance(); - - JpaControlLoopElement otherJpaControlLoopElement = new JpaControlLoopElement(testJpaControlLoopElement); - assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - assertEquals(-1, testJpaControlLoopElement.compareTo(null)); - assertEquals(0, testJpaControlLoopElement.compareTo(testJpaControlLoopElement)); - assertNotEquals(0, testJpaControlLoopElement.compareTo(new DummyJpaControlLoopElementChild())); - - testJpaControlLoopElement - .setKey(new PfReferenceKey("BadValue", "0.0.1", "a95757ba-b34a-4049-a2a8-46773abcbe5e")); - assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setKey(new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, - "a95757ba-b34a-4049-a2a8-46773abcbe5e")); - assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - - testJpaControlLoopElement.setDefinition(new PfConceptKey("BadValue", "0.0.1")); - assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setDefinition(new PfConceptKey("cleDef", "0.0.1")); - assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - - testJpaControlLoopElement.setDescription("Description"); - assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setDescription(null); - assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - - testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.PASSIVE); - assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - - testJpaControlLoopElement.setState(ControlLoopState.PASSIVE); - assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setState(ControlLoopState.UNINITIALISED); - assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - - testJpaControlLoopElement.setParticipantType(new PfConceptKey("dummy", "0.0.1")); - assertNotEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - testJpaControlLoopElement.setParticipantType(new PfConceptKey("participantType", "0.0.1")); - assertEquals(0, testJpaControlLoopElement.compareTo(otherJpaControlLoopElement)); - - assertEquals(testJpaControlLoopElement, new JpaControlLoopElement(testJpaControlLoopElement)); - } - - @Test - void testJpaControlLoopElementLombok() { - assertNotNull(new Participant()); - JpaControlLoopElement cle0 = new JpaControlLoopElement(); - - assertThat(cle0.toString()).contains("JpaControlLoopElement("); - assertThat(cle0.hashCode()).isNotZero(); - assertEquals(true, cle0.equals(cle0)); - assertEquals(false, cle0.equals(null)); - - - JpaControlLoopElement cle1 = new JpaControlLoopElement(); - - cle1.setDefinition(new PfConceptKey("defName", "0.0.1")); - cle1.setDescription("Description"); - cle1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - cle1.setState(ControlLoopState.UNINITIALISED); - cle1.setParticipantId(new PfConceptKey("participant", "0.0.1")); - - assertThat(cle1.toString()).contains("ControlLoopElement("); - assertEquals(false, cle1.hashCode() == 0); - assertEquals(false, cle1.equals(cle0)); - assertEquals(false, cle1.equals(null)); - - assertNotEquals(cle1, cle0); - - JpaControlLoopElement cle2 = new JpaControlLoopElement(); - assertEquals(cle2, cle0); - } - - private JpaControlLoopElement createJpaControlLoopElementInstance() { - ControlLoopElement testCle = createControlLoopElementInstance(); - JpaControlLoopElement testJpaControlLoopElement = new JpaControlLoopElement(); - testJpaControlLoopElement.setKey(null); - testJpaControlLoopElement.fromAuthorative(testCle); - testJpaControlLoopElement.setKey(PfReferenceKey.getNullKey()); - testJpaControlLoopElement.fromAuthorative(testCle); - - return testJpaControlLoopElement; - } - - private ControlLoopElement createControlLoopElementInstance() { - ControlLoopElement controlLoopElement = new ControlLoopElement(); - controlLoopElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); - controlLoopElement.setDefinition(new ToscaConceptIdentifier("cleDef", "0.0.1")); - controlLoopElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1")); - - return controlLoopElement; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java deleted file mode 100644 index d705c49b5..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaControlLoopTest.java +++ /dev/null @@ -1,301 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.util.LinkedHashMap; -import org.junit.jupiter.api.Test; -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.ControlLoopState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the {@link JpaControlLoopTest} class. - */ -class JpaControlLoopTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - void testJpaControlLoopConstructor() { - assertThatThrownBy(() -> { - new JpaControlLoop((JpaControlLoop) null); - }).hasMessageMatching("copyConcept is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoop((PfConceptKey) null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, null, null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, null, null, new LinkedHashMap<>()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), null, new LinkedHashMap<>()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(null, new PfConceptKey(), ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, null, null); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, null, new LinkedHashMap<>()); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, null); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), null, ControlLoopState.UNINITIALISED, new LinkedHashMap<>()); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, null); - }).hasMessageMatching("state is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), null, new LinkedHashMap<>()); - }).hasMessageMatching("state is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED, null); - }).hasMessageMatching("elements is marked .*ull but is null"); - - assertNotNull(new JpaControlLoop()); - assertNotNull(new JpaControlLoop((new PfConceptKey()))); - assertNotNull(new JpaControlLoop(new PfConceptKey(), new PfConceptKey(), ControlLoopState.UNINITIALISED, - new LinkedHashMap<>())); - } - - @Test - void testJpaControlLoop() { - JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); - - ControlLoop participant = createControlLoopInstance(); - assertEquals(participant, testJpaControlLoop.toAuthorative()); - - assertThatThrownBy(() -> { - testJpaControlLoop.fromAuthorative(null); - }).hasMessageMatching("controlLoop is marked .*ull but is null"); - - assertThatThrownBy(() -> new JpaControlLoop((JpaControlLoop) null)).isInstanceOf(NullPointerException.class); - - JpaControlLoop testJpaControlLoopFa = new JpaControlLoop(); - testJpaControlLoopFa.setKey(null); - testJpaControlLoopFa.fromAuthorative(participant); - assertEquals(testJpaControlLoop, testJpaControlLoopFa); - testJpaControlLoopFa.setKey(PfConceptKey.getNullKey()); - testJpaControlLoopFa.fromAuthorative(participant); - assertEquals(testJpaControlLoop, testJpaControlLoopFa); - testJpaControlLoopFa.setKey(new PfConceptKey("control-loop", "0.0.1")); - testJpaControlLoopFa.fromAuthorative(participant); - assertEquals(testJpaControlLoop, testJpaControlLoopFa); - - assertEquals("control-loop", testJpaControlLoop.getKey().getName()); - assertEquals("control-loop", new JpaControlLoop(createControlLoopInstance()).getKey().getName()); - assertEquals("control-loop", - ((PfConceptKey) new JpaControlLoop(createControlLoopInstance()).getKeys().get(0)).getName()); - - testJpaControlLoop.clean(); - assertEquals("control-loop", testJpaControlLoop.getKey().getName()); - - testJpaControlLoop.setDescription(" A Message "); - testJpaControlLoop.clean(); - assertEquals("A Message", testJpaControlLoop.getDescription()); - - JpaControlLoop testJpaControlLoop2 = new JpaControlLoop(testJpaControlLoop); - assertEquals(testJpaControlLoop, testJpaControlLoop2); - } - - @Test - void testJpaControlLoopElementOrderedState() throws CoderException { - ControlLoop testControlLoop = createControlLoopInstance(); - JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); - - testJpaControlLoop.setOrderedState(null); - assertEquals(testControlLoop, testJpaControlLoop.toAuthorative()); - testJpaControlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - - ControlLoop noOrderedStateCl = new StandardCoder() - .decode(new File("src/test/resources/json/ControlLoopNoOrderedState.json"), ControlLoop.class); - - JpaControlLoop noOrderedStateJpaCl = new JpaControlLoop(noOrderedStateCl); - assertNull(noOrderedStateJpaCl.getOrderedState()); - noOrderedStateCl.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - noOrderedStateJpaCl = new JpaControlLoop(noOrderedStateCl); - assertEquals(testJpaControlLoop, noOrderedStateJpaCl); - - ControlLoops controlLoopsWithElements = new StandardCoder() - .decode(new File("src/test/resources/providers/TestControlLoops.json"), ControlLoops.class); - - JpaControlLoop jpaControlLoopWithElements = - new JpaControlLoop(controlLoopsWithElements.getControlLoopList().get(0)); - assertEquals(4, jpaControlLoopWithElements.getElements().size()); - assertEquals(18, jpaControlLoopWithElements.getKeys().size()); - assertThatCode(() -> jpaControlLoopWithElements.clean()).doesNotThrowAnyException(); - - assertEquals(controlLoopsWithElements.getControlLoopList().get(0), jpaControlLoopWithElements.toAuthorative()); - } - - @Test - void testJpaControlLoopValidation() { - JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); - - assertThatThrownBy(() -> { - testJpaControlLoop.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaControlLoop.validate("").isValid()); - } - - @Test - void testJpaControlLoopCompareTo() { - JpaControlLoop testJpaControlLoop = createJpaControlLoopInstance(); - - JpaControlLoop otherJpaControlLoop = new JpaControlLoop(testJpaControlLoop); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - assertEquals(-1, testJpaControlLoop.compareTo(null)); - assertEquals(0, testJpaControlLoop.compareTo(testJpaControlLoop)); - assertNotEquals(0, testJpaControlLoop.compareTo(new DummyJpaControlLoopChild())); - - testJpaControlLoop.setKey(new PfConceptKey("BadValue", "0.0.1")); - assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - testJpaControlLoop.setKey(new PfConceptKey("control-loop", "0.0.1")); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - - testJpaControlLoop.setDefinition(new PfConceptKey("BadValue", "0.0.1")); - assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - testJpaControlLoop.setDefinition(new PfConceptKey("controlLoopDefinitionName", "0.0.1")); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - - testJpaControlLoop.setState(ControlLoopState.PASSIVE); - assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - testJpaControlLoop.setState(ControlLoopState.UNINITIALISED); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - - testJpaControlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE); - assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - testJpaControlLoop.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - - testJpaControlLoop.setDescription("A description"); - assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - testJpaControlLoop.setDescription(null); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - - testJpaControlLoop.setPrimed(true); - assertNotEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - testJpaControlLoop.setPrimed(false); - assertEquals(0, testJpaControlLoop.compareTo(otherJpaControlLoop)); - - assertEquals(testJpaControlLoop, new JpaControlLoop(testJpaControlLoop)); - } - - @Test - void testJpaControlLoopLombok() { - assertNotNull(new ControlLoop()); - JpaControlLoop cl0 = new JpaControlLoop(); - - assertThat(cl0.toString()).contains("JpaControlLoop("); - assertThat(cl0.hashCode()).isNotZero(); - assertEquals(true, cl0.equals(cl0)); - assertEquals(false, cl0.equals(null)); - - - JpaControlLoop cl1 = new JpaControlLoop(); - - cl1.setDefinition(new PfConceptKey("defName", "0.0.1")); - cl1.setDescription("Description"); - cl1.setElements(new LinkedHashMap<>()); - cl1.setKey(new PfConceptKey("participant", "0.0.1")); - cl1.setState(ControlLoopState.UNINITIALISED); - - assertThat(cl1.toString()).contains("ControlLoop("); - assertEquals(false, cl1.hashCode() == 0); - assertEquals(false, cl1.equals(cl0)); - assertEquals(false, cl1.equals(null)); - - assertNotEquals(cl1, cl0); - - JpaControlLoop cl2 = new JpaControlLoop(); - assertEquals(cl2, cl0); - } - - private JpaControlLoop createJpaControlLoopInstance() { - ControlLoop testControlLoop = createControlLoopInstance(); - JpaControlLoop testJpaControlLoop = new JpaControlLoop(); - testJpaControlLoop.setKey(null); - testJpaControlLoop.fromAuthorative(testControlLoop); - testJpaControlLoop.setKey(PfConceptKey.getNullKey()); - testJpaControlLoop.fromAuthorative(testControlLoop); - - return testJpaControlLoop; - } - - private ControlLoop createControlLoopInstance() { - ControlLoop testControlLoop = new ControlLoop(); - testControlLoop.setName("control-loop"); - testControlLoop.setVersion("0.0.1"); - testControlLoop.setDefinition(new ToscaConceptIdentifier("controlLoopDefinitionName", "0.0.1")); - testControlLoop.setElements(new LinkedHashMap<>()); - - return testControlLoop; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java deleted file mode 100644 index aff365515..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantStatisticsTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.time.Instant; -import org.junit.jupiter.api.Test; -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.common.parameters.BeanValidationResult; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfTimestampKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the {@link JpaParticipantStatistics} class. - */ -class JpaParticipantStatisticsTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - void testJpaParticipantStatisticsConstructor() { - assertThatThrownBy(() -> { - new JpaParticipantStatistics((JpaParticipantStatistics) null); - }).hasMessageMatching("copyConcept is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics((PfTimestampKey) null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics(null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics(null, new PfConceptKey()); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipantStatistics(new PfTimestampKey(), null); - }).hasMessageMatching("participantId is marked .*ull but is null"); - - assertNotNull(new JpaParticipantStatistics()); - assertNotNull(new JpaParticipantStatistics((new PfTimestampKey()))); - assertNotNull(new JpaParticipantStatistics(new PfTimestampKey(), new PfConceptKey())); - } - - @Test - void testJpaParticipantStatistics() { - JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); - - ParticipantStatistics cles = createParticipantStatisticsInstance(); - assertEquals(cles, testJpaParticipantStatistics.toAuthorative()); - - assertThatThrownBy(() -> { - testJpaParticipantStatistics.fromAuthorative(null); - }).hasMessageMatching("participantStatistics is marked .*ull but is null"); - - assertThatThrownBy(() -> new JpaParticipantStatistics((JpaParticipantStatistics) null)) - .isInstanceOf(NullPointerException.class); - - JpaParticipantStatistics testJpaParticipantStatisticsFa = new JpaParticipantStatistics(); - testJpaParticipantStatisticsFa.setKey(null); - testJpaParticipantStatisticsFa.fromAuthorative(cles); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - testJpaParticipantStatisticsFa.setKey(PfTimestampKey.getNullKey()); - testJpaParticipantStatisticsFa.fromAuthorative(cles); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - testJpaParticipantStatisticsFa - .setKey(new PfTimestampKey("participantName", "0.0.1", Instant.ofEpochMilli(123456L))); - testJpaParticipantStatisticsFa.fromAuthorative(cles); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - - testJpaParticipantStatisticsFa = new JpaParticipantStatistics(cles); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); - - assertEquals(2, testJpaParticipantStatistics.getKeys().size()); - - assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); - - testJpaParticipantStatistics.clean(); - assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); - - JpaParticipantStatistics testJpaParticipantStatistics2 = - new JpaParticipantStatistics(testJpaParticipantStatistics); - assertEquals(testJpaParticipantStatistics, testJpaParticipantStatistics2); - } - - @Test - void testJpaParticipantStatisticsValidation() { - JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); - - assertThatThrownBy(() -> { - testJpaParticipantStatistics.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - BeanValidationResult validationResult = testJpaParticipantStatistics.validate(""); - assertTrue(validationResult.isValid()); - } - - @Test - void testJpaParticipantStatisticsConmpareTo() { - JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); - - JpaParticipantStatistics otherJpaParticipantStatistics = - new JpaParticipantStatistics(testJpaParticipantStatistics); - assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); - assertEquals(-1, testJpaParticipantStatistics.compareTo(null)); - assertEquals(0, testJpaParticipantStatistics.compareTo(testJpaParticipantStatistics)); - assertNotEquals(0, testJpaParticipantStatistics.compareTo(new DummyJpaParticipantStatisticsChild())); - - testJpaParticipantStatistics.setState(ParticipantState.UNKNOWN); - assertNotEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); - testJpaParticipantStatistics.setState(ParticipantState.PASSIVE); - assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); - - assertEquals(testJpaParticipantStatistics, new JpaParticipantStatistics(testJpaParticipantStatistics)); - } - - @Test - void testJpaParticipantStatisticsLombok() { - assertNotNull(new Participant()); - JpaParticipantStatistics ps0 = new JpaParticipantStatistics(); - - assertThat(ps0.toString()).contains("JpaParticipantStatistics("); - assertThat(ps0.hashCode()).isNotZero(); - assertEquals(true, ps0.equals(ps0)); - assertEquals(false, ps0.equals(null)); - - - JpaParticipantStatistics ps1 = new JpaParticipantStatistics(); - - ps1.setState(ParticipantState.UNKNOWN); - - assertThat(ps1.toString()).contains("JpaParticipantStatistics("); - assertEquals(false, ps1.hashCode() == 0); - assertEquals(false, ps1.equals(ps0)); - assertEquals(false, ps1.equals(null)); - - assertNotEquals(ps1, ps0); - - JpaParticipantStatistics ps2 = new JpaParticipantStatistics(); - assertEquals(ps2, ps0); - } - - private JpaParticipantStatistics createJpaParticipantStatisticsInstance() { - ParticipantStatistics testCles = createParticipantStatisticsInstance(); - JpaParticipantStatistics testJpaParticipantStatistics = new JpaParticipantStatistics(); - testJpaParticipantStatistics.setKey(null); - testJpaParticipantStatistics.fromAuthorative(testCles); - testJpaParticipantStatistics.setKey(PfTimestampKey.getNullKey()); - testJpaParticipantStatistics.fromAuthorative(testCles); - - return testJpaParticipantStatistics; - } - - private ParticipantStatistics createParticipantStatisticsInstance() { - ParticipantStatistics participantStatistics = new ParticipantStatistics(); - participantStatistics.setParticipantId(new ToscaConceptIdentifier("participantName", "0.0.1")); - participantStatistics.setTimeStamp(Instant.ofEpochMilli(123456L)); - participantStatistics.setState(ParticipantState.PASSIVE); - participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY); - - return participantStatistics; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java deleted file mode 100644 index 087292354..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/JpaParticipantTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.jupiter.api.Test; -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.models.base.PfConceptKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the {@link JpaParticiant} class. - */ -class JpaParticipantTest { - - private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; - - @Test - void testJpaParticipantConstructor() { - assertThatThrownBy(() -> { - new JpaParticipant((JpaParticipant) null); - }).hasMessageMatching("copyConcept is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipant((PfConceptKey) null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, null, null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, null, null, ParticipantHealthStatus.HEALTHY); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, null, ParticipantState.ACTIVE, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, new PfConceptKey(), null, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, null); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); - }).hasMessageMatching(NULL_KEY_ERROR); - - assertThatThrownBy(() -> { - new JpaParticipant(new PfConceptKey(), null, null, null); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipant(new PfConceptKey(), null, null, ParticipantHealthStatus.HEALTHY); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, null); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); - }).hasMessageMatching("definition is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, null); - }).hasMessageMatching("participantState is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY); - }).hasMessageMatching("participantState is marked .*ull but is null"); - - assertThatThrownBy(() -> { - new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, null); - }).hasMessageMatching("healthStatus is marked .*ull but is null"); - - assertNotNull(new JpaParticipant()); - assertNotNull(new JpaParticipant((new PfConceptKey()))); - assertNotNull(new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, - ParticipantHealthStatus.HEALTHY)); - } - - @Test - void testJpaParticipant() { - JpaParticipant testJpaParticipant = createJpaParticipantInstance(); - - Participant participant = createParticipantInstance(); - assertEquals(participant, testJpaParticipant.toAuthorative()); - - assertThatThrownBy(() -> { - testJpaParticipant.fromAuthorative(null); - }).hasMessageMatching("participant is marked .*ull but is null"); - - assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null)).isInstanceOf(NullPointerException.class); - - JpaParticipant testJpaParticipantFa = new JpaParticipant(); - testJpaParticipantFa.setKey(null); - testJpaParticipantFa.fromAuthorative(participant); - assertEquals(testJpaParticipant, testJpaParticipantFa); - testJpaParticipantFa.setKey(PfConceptKey.getNullKey()); - testJpaParticipantFa.fromAuthorative(participant); - assertEquals(testJpaParticipant, testJpaParticipantFa); - testJpaParticipantFa.setKey(new PfConceptKey("participant", "0.0.1")); - testJpaParticipantFa.fromAuthorative(participant); - assertEquals(testJpaParticipant, testJpaParticipantFa); - - assertEquals("participant", testJpaParticipant.getKey().getName()); - assertEquals("participant", new JpaParticipant(createParticipantInstance()).getKey().getName()); - assertEquals("participant", - ((PfConceptKey) new JpaParticipant(createParticipantInstance()).getKeys().get(0)).getName()); - - testJpaParticipant.clean(); - assertEquals("participant", testJpaParticipant.getKey().getName()); - - testJpaParticipant.setDescription(" A Message "); - testJpaParticipant.clean(); - assertEquals("A Message", testJpaParticipant.getDescription()); - - JpaParticipant testJpaParticipant2 = new JpaParticipant(testJpaParticipant); - assertEquals(testJpaParticipant, testJpaParticipant2); - } - - @Test - void testJpaParticipantValidation() { - JpaParticipant testJpaParticipant = createJpaParticipantInstance(); - - assertThatThrownBy(() -> { - testJpaParticipant.validate(null); - }).hasMessageMatching("fieldName is marked .*ull but is null"); - - assertTrue(testJpaParticipant.validate("").isValid()); - } - - @Test - void testJpaParticipantCompareTo() { - JpaParticipant testJpaParticipant = createJpaParticipantInstance(); - - JpaParticipant otherJpaParticipant = new JpaParticipant(testJpaParticipant); - assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - assertEquals(-1, testJpaParticipant.compareTo(null)); - assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant)); - assertNotEquals(0, testJpaParticipant.compareTo(new DummyJpaParticipantChild())); - - testJpaParticipant.setKey(new PfConceptKey("BadValue", "0.0.1")); - assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - testJpaParticipant.setKey(new PfConceptKey("participant", "0.0.1")); - assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - - testJpaParticipant.setDefinition(new PfConceptKey("BadValue", "0.0.1")); - assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - testJpaParticipant.setDefinition(new PfConceptKey("participantDefinitionName", "0.0.1")); - assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - - testJpaParticipant.setParticipantState(ParticipantState.PASSIVE); - assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - testJpaParticipant.setParticipantState(ParticipantState.UNKNOWN); - assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - - testJpaParticipant.setHealthStatus(ParticipantHealthStatus.NOT_HEALTHY); - assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - testJpaParticipant.setHealthStatus(ParticipantHealthStatus.UNKNOWN); - assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); - - assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant)); - } - - @Test - void testJpaParticipantLombok() { - assertNotNull(new Participant()); - JpaParticipant p0 = new JpaParticipant(); - - assertThat(p0.toString()).contains("JpaParticipant("); - assertThat(p0.hashCode()).isNotZero(); - assertEquals(true, p0.equals(p0)); - assertEquals(false, p0.equals(null)); - - - JpaParticipant p1 = new JpaParticipant(); - - p1.setDefinition(new PfConceptKey("defName", "0.0.1")); - p1.setDescription("Description"); - p1.setHealthStatus(ParticipantHealthStatus.HEALTHY); - p1.setKey(new PfConceptKey("participant", "0.0.1")); - p1.setParticipantState(ParticipantState.ACTIVE); - - assertThat(p1.toString()).contains("Participant("); - assertEquals(false, p1.hashCode() == 0); - assertEquals(false, p1.equals(p0)); - assertEquals(false, p1.equals(null)); - - assertNotEquals(p1, p0); - - JpaParticipant p2 = new JpaParticipant(); - assertEquals(p2, p0); - } - - private JpaParticipant createJpaParticipantInstance() { - Participant testParticipant = createParticipantInstance(); - JpaParticipant testJpaParticipant = new JpaParticipant(); - testJpaParticipant.setKey(null); - testJpaParticipant.fromAuthorative(testParticipant); - testJpaParticipant.setKey(PfConceptKey.getNullKey()); - testJpaParticipant.fromAuthorative(testParticipant); - - return testJpaParticipant; - } - - private Participant createParticipantInstance() { - Participant testParticipant = new Participant(); - testParticipant.setName("participant"); - testParticipant.setVersion("0.0.1"); - testParticipant.setDefinition(new ToscaConceptIdentifier("participantDefinitionName", "0.0.1")); - testParticipant.setParticipantType(new ToscaConceptIdentifier("participantTypeName", "0.0.1")); - - return testParticipant; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java deleted file mode 100644 index c877f9696..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/concepts/PojosTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.concepts; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class PojosTest { - - @Test - void testPojos() { - List pojoClasses = - PojoClassFactory.getPojoClasses(PojosTest.class.getPackageName()); - - // @formatter:off - final Validator validator = ValidatorBuilder - .create() - .with(new SetterMustExistRule()) - .with(new GetterMustExistRule()) - .with(new EqualsAndHashCodeMatchRule()) - .with(new NoPublicFieldsExceptStaticFinalRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .with(new ToStringTester()) - .build(); - - validator.validate(pojoClasses); - // @formatter:on - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java deleted file mode 100644 index 82ce8d789..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ClElementStatisticsProviderTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ClElementStatisticsRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ClElementStatisticsProviderTest { - private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; - private static final Coder CODER = new StandardCoder(); - private static final String CL_ELEMENT_STATS_JSON = "src/test/resources/providers/TestClElementStatistics.json"; - - private ClElementStatisticsProvider clElementStatisticsProvider; - private ClElementStatisticsList inputClElementStats; - private String originalJson = ResourceUtils.getResourceAsString(CL_ELEMENT_STATS_JSON); - - /** - * Set up test ClElement statistics provider. - * - * @throws Exception on errors - */ - @BeforeEach - void beforeSetupDao() throws Exception { - - inputClElementStats = CODER.decode(originalJson, ClElementStatisticsList.class); - var clElementStatisticsRepository = mock(ClElementStatisticsRepository.class); - - var jpaClElementStatisticsList = - ProviderUtils.getJpaAndValidateList(inputClElementStats.getClElementStatistics(), - JpaClElementStatistics::new, "control loop element statistics"); - - for (var clElementStat : jpaClElementStatisticsList) { - when(clElementStatisticsRepository.getById(eq(clElementStat.getKey()))).thenReturn(clElementStat); - when(clElementStatisticsRepository.findAllById(eq(List.of(clElementStat.getKey())))) - .thenReturn(List.of(clElementStat)); - } - - when(clElementStatisticsRepository.saveAll(anyList())).thenReturn(jpaClElementStatisticsList); - - when(clElementStatisticsRepository.getFiltered(eq(JpaClElementStatistics.class), any())) - .thenReturn(List.of(jpaClElementStatisticsList.get(0))); - - clElementStatisticsProvider = new ClElementStatisticsProvider(clElementStatisticsRepository); - } - - @Test - void testClElementStatisticsCreate() throws Exception { - assertThatThrownBy(() -> { - clElementStatisticsProvider.createClElementStatistics(null); - }).hasMessageMatching(LIST_IS_NULL); - - ClElementStatisticsList createdClElementStats = new ClElementStatisticsList(); - createdClElementStats.setClElementStatistics( - clElementStatisticsProvider.createClElementStatistics(inputClElementStats.getClElementStatistics())); - - assertEquals(inputClElementStats.toString().replaceAll("\\s+", ""), - createdClElementStats.toString().replaceAll("\\s+", "")); - } - - @Test - void testGetClElementStatistics() throws Exception { - - List getResponse; - - // Return empty list when no data present in db - getResponse = clElementStatisticsProvider.getClElementStatistics(null, null, null, null); - assertThat(getResponse).isEmpty(); - - clElementStatisticsProvider.createClElementStatistics(inputClElementStats.getClElementStatistics()); - ToscaConceptIdentifier identifier = inputClElementStats.getClElementStatistics().get(0).getParticipantId(); - Instant instant = inputClElementStats.getClElementStatistics().get(0).getTimeStamp(); - String id = inputClElementStats.getClElementStatistics().get(0).getId().toString(); - assertEquals(1, clElementStatisticsProvider - .getClElementStatistics(identifier.getName(), identifier.getVersion(), id, instant).size()); - - assertEquals(1, clElementStatisticsProvider - .getFilteredClElementStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java deleted file mode 100644 index 4b8617b3d..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ControlLoopProviderTest.java +++ /dev/null @@ -1,290 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -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.Optional; -import javax.persistence.EntityNotFoundException; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -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.controlloop.persistence.concepts.JpaControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ControlLoopRepository; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaNodeTemplateRepository; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaNodeTemplatesRepository; -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.base.PfConceptKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; - -class ControlLoopProviderTest { - - private static final String LIST_IS_NULL = "controlLoops is marked .*ull but is null"; - private static final String OBJECT_IS_NULL = "controlLoop is marked non-null but is null"; - - private static final String ID_NAME = "PMSHInstance1"; - private static final String ID_VERSION = "1.0.1"; - private static final String ID_NAME_NOT_EXTST = "not_exist"; - private static final String ID_NAME_NOT_VALID = "not_valid"; - - private static final Coder CODER = new StandardCoder(); - private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json"; - private static final String TOSCA_TEMPLATE_YAML = "examples/controlloop/PMSubscriptionHandling.yaml"; - - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); - - private ControlLoops inputControlLoops; - private List inputControlLoopsJpa; - private String originalJson = ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON); - - @BeforeEach - void beforeSetupDao() throws Exception { - inputControlLoops = CODER.decode(originalJson, ControlLoops.class); - inputControlLoopsJpa = ProviderUtils.getJpaAndValidateList(inputControlLoops.getControlLoopList(), - JpaControlLoop::new, "control loops"); - } - - @Test - void testControlLoopsSave() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoops(null); - }).hasMessageMatching(LIST_IS_NULL); - - when(controlLoopRepository.saveAll(inputControlLoopsJpa)).thenReturn(inputControlLoopsJpa); - - var createdControlLoops = new ControlLoops(); - createdControlLoops - .setControlLoopList(controlLoopProvider.saveControlLoops(inputControlLoops.getControlLoopList())); - - assertEquals(inputControlLoops, createdControlLoops); - - when(controlLoopRepository.saveAll(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoops(inputControlLoops.getControlLoopList()); - }).hasMessageMatching("Error in save ControlLoops"); - } - - @Test - void testControlLoopSave() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoop(null); - }).hasMessageMatching(OBJECT_IS_NULL); - - when(controlLoopRepository.save(inputControlLoopsJpa.get(0))).thenReturn(inputControlLoopsJpa.get(0)); - - var createdControlLoop = controlLoopProvider.saveControlLoop(inputControlLoops.getControlLoopList().get(0)); - - assertEquals(inputControlLoops.getControlLoopList().get(0), createdControlLoop); - - when(controlLoopRepository.save(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.saveControlLoop(inputControlLoops.getControlLoopList().get(0)); - }).hasMessageMatching("Error in save controlLoop"); - } - - @Test - void testGetControlLoops() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - // Return empty list when no data present in db - List getResponse = controlLoopProvider.getControlLoops(); - assertThat(getResponse).isEmpty(); - - controlLoopProvider.saveControlLoops(inputControlLoops.getControlLoopList()); - - var controlLoop0 = inputControlLoops.getControlLoopList().get(1); - var name = controlLoop0.getName(); - var version = controlLoop0.getVersion(); - var controlLoop1 = inputControlLoops.getControlLoopList().get(1); - - when(controlLoopRepository.getFiltered(eq(JpaControlLoop.class), any(), any())) - .thenReturn(List.of(new JpaControlLoop(controlLoop0), new JpaControlLoop(controlLoop1))); - when(controlLoopRepository.findById(controlLoop0.getKey().asIdentifier().asConceptKey())) - .thenReturn(Optional.of(new JpaControlLoop(controlLoop0))); - when(controlLoopRepository.getById(controlLoop0.getKey().asIdentifier().asConceptKey())) - .thenReturn(new JpaControlLoop(controlLoop0)); - when(controlLoopRepository.getFiltered(JpaControlLoop.class, name, version)) - .thenReturn(List.of(new JpaControlLoop(controlLoop0))); - when(controlLoopRepository.findById(controlLoop1.getKey().asIdentifier().asConceptKey())) - .thenReturn(Optional.of(new JpaControlLoop(controlLoop1))); - - assertEquals(1, controlLoopProvider.getControlLoops(name, version).size()); - - var cl = controlLoopProvider.findControlLoop(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)).get(); - assertEquals(inputControlLoops.getControlLoopList().get(1), cl); - - cl = controlLoopProvider.getControlLoop(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)); - assertEquals(inputControlLoops.getControlLoopList().get(1), cl); - - when(controlLoopRepository.getById(any())).thenThrow(EntityNotFoundException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.getControlLoop(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)); - }).hasMessageMatching("ControlLoop not found"); - - cl = controlLoopProvider.findControlLoop(ID_NAME, ID_VERSION).get(); - assertEquals(inputControlLoops.getControlLoopList().get(1), cl); - - assertThat(controlLoopProvider.findControlLoop(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))) - .isEmpty(); - - when(controlLoopRepository.findById(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - controlLoopProvider.findControlLoop(ID_NAME_NOT_VALID, ID_VERSION); - }).hasMessageMatching("Not valid parameter"); - } - - @Test - void testDeleteControlLoop() throws Exception { - var controlLoopRepository = mock(ControlLoopRepository.class); - var controlLoopProvider = new ControlLoopProvider(controlLoopRepository, - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - - assertThatThrownBy(() -> { - controlLoopProvider.deleteControlLoop(ID_NAME_NOT_EXTST, ID_VERSION); - }).hasMessageMatching(".*.failed, control loop does not exist"); - - var controlLoop = inputControlLoops.getControlLoopList().get(0); - var name = controlLoop.getName(); - var version = controlLoop.getVersion(); - - when(controlLoopRepository.findById(new PfConceptKey(name, version))) - .thenReturn(Optional.of(inputControlLoopsJpa.get(0))); - - ControlLoop deletedCl = controlLoopProvider.deleteControlLoop(name, version); - assertEquals(controlLoop, deletedCl); - } - - @Test - void testDeleteAllInstanceProperties() throws Exception { - var controlLoopProvider = new ControlLoopProvider(mock(ControlLoopRepository.class), - mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); - var toscaServiceTemplate = testControlLoopRead(); - controlLoopProvider.deleteInstanceProperties(controlLoopProvider.saveInstanceProperties(toscaServiceTemplate), - controlLoopProvider.getAllNodeTemplates()); - assertThat(controlLoopProvider.getControlLoops()).isEmpty(); - } - - @Test - void testSaveAndDeleteInstanceProperties() throws Exception { - var toscaNodeTemplatesRepository = mock(ToscaNodeTemplatesRepository.class); - var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); - var controlLoopProvider = new ControlLoopProvider(mock(ControlLoopRepository.class), - toscaNodeTemplateRepository, toscaNodeTemplatesRepository); - var toscaServiceTest = testControlLoopRead(); - - controlLoopProvider.saveInstanceProperties(toscaServiceTest); - verify(toscaNodeTemplatesRepository).save(any()); - - var name = "org.onap.policy.controlloop.PolicyControlLoopParticipant"; - var version = "2.3.1"; - var elem = toscaServiceTest.getToscaTopologyTemplate().getNodeTemplates().get(name); - when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version)) - .thenReturn(List.of(new JpaToscaNodeTemplate(elem))); - - var filtered = controlLoopProvider.getNodeTemplates(name, version); - verify(toscaNodeTemplateRepository).getFiltered(JpaToscaNodeTemplate.class, name, version); - - controlLoopProvider.deleteInstanceProperties(controlLoopProvider.saveInstanceProperties(toscaServiceTest), - filtered); - - verify(toscaNodeTemplateRepository).delete(any()); - } - - @Test - void testGetNodeTemplates() throws Exception { - var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); - var controlLoopProvider = new ControlLoopProvider(mock(ControlLoopRepository.class), - toscaNodeTemplateRepository, mock(ToscaNodeTemplatesRepository.class)); - - var toscaNodeTemplate0 = new JpaToscaNodeTemplate(new PfConceptKey(ID_NAME, ID_VERSION)); - var toscaNodeTemplate1 = new JpaToscaNodeTemplate(new PfConceptKey("PMSHInstance2", ID_VERSION)); - - when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, null, null)) - .thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); - when(toscaNodeTemplateRepository.findAll()).thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); - when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, ID_NAME, ID_VERSION)) - .thenReturn(List.of(toscaNodeTemplate0)); - - // Getting all nodes - var listNodes = controlLoopProvider.getAllNodeTemplates(); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(2); - - listNodes = controlLoopProvider.getNodeTemplates(ID_NAME, ID_VERSION); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(1); - - listNodes = controlLoopProvider.getAllNodeTemplates(); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(2); - - var nodeTemplateFilter = - ToscaTypedEntityFilter.builder().name(ID_NAME).version(ID_VERSION).build(); - - listNodes = controlLoopProvider.getFilteredNodeTemplates(nodeTemplateFilter); - assertNotNull(listNodes); - assertThat(listNodes).hasSize(1); - - assertThatThrownBy(() -> { - controlLoopProvider.getFilteredNodeTemplates(null); - }).hasMessageMatching("filter is marked non-null but is null"); - } - - private static ToscaServiceTemplate testControlLoopRead() { - return testControlLoopYamlSerialization(TOSCA_TEMPLATE_YAML); - } - - private static ToscaServiceTemplate testControlLoopYamlSerialization(String controlLoopFilePath) { - var controlLoopString = ResourceUtils.getResourceAsString(controlLoopFilePath); - return yamlTranslator.fromYaml(controlLoopString, ToscaServiceTemplate.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java deleted file mode 100644 index 9b48735f6..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantProviderTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ParticipantRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; - -class ParticipantProviderTest { - - private static final Coder CODER = new StandardCoder(); - private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json"; - private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; - - private List inputParticipants = new ArrayList<>(); - private List jpaParticipantList; - private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON); - - @BeforeEach - void beforeSetupDao() throws Exception { - inputParticipants.add(CODER.decode(originalJson, Participant.class)); - jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant"); - } - - @Test - void testParticipantSave() throws Exception { - var participantRepository = mock(ParticipantRepository.class); - for (var participant : jpaParticipantList) { - when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion()))) - .thenReturn(participant); - } - var participantProvider = new ParticipantProvider(participantRepository); - - assertThatThrownBy(() -> { - participantProvider.saveParticipant(null); - }).hasMessageMatching(LIST_IS_NULL); - - when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0)); - - Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0)); - assertEquals(savedParticipant, inputParticipants.get(0)); - - when(participantRepository.save(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - participantProvider.saveParticipant(inputParticipants.get(0)); - }).hasMessageMatching("Error in save Participant"); - } - - @Test - void testGetControlLoops() throws Exception { - var participantRepository = mock(ParticipantRepository.class); - var participantProvider = new ParticipantProvider(participantRepository); - - // Return empty list when no data present in db - List getResponse = participantProvider.getParticipants(null, null); - assertThat(getResponse).isEmpty(); - - String name = inputParticipants.get(0).getName(); - String version = inputParticipants.get(0).getVersion(); - when(participantRepository.getFiltered(any(), eq(name), eq(version))) - .thenReturn(List.of(jpaParticipantList.get(0))); - assertEquals(1, participantProvider.getParticipants(name, version).size()); - - assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty(); - - assertThat(participantProvider.findParticipant("invalid_name", "1.0.1")).isEmpty(); - - when(participantRepository.findAll()).thenReturn(jpaParticipantList); - assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size()); - - when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); - - assertThatThrownBy(() -> { - participantProvider.findParticipant("notValid", "notValid"); - }).hasMessageMatching("Error in find Participant"); - - assertThatThrownBy(() -> { - participantProvider.getFilteredParticipants(null); - }).hasMessageMatching("filter is marked .*ull but is null"); - - when(participantRepository.getFiltered(eq(JpaParticipant.class), eq(null), eq(null))) - .thenReturn(jpaParticipantList); - - final ToscaTypedEntityFilter filter = ToscaTypedEntityFilter.builder() - .type("org.onap.domain.pmsh.PMSHControlLoopDefinition").build(); - assertEquals(1, participantProvider.getFilteredParticipants(filter).size()); - - } - - @Test - void testDeleteParticipant() throws Exception { - var participantRepository = mock(ParticipantRepository.class); - var participantProvider = new ParticipantProvider(participantRepository); - - assertThatThrownBy(() -> { - participantProvider.deleteParticipant("Invalid_name", "1.0.1"); - }).hasMessageMatching(".*.failed, participant does not exist"); - - String name = inputParticipants.get(0).getName(); - String version = inputParticipants.get(0).getVersion(); - - when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0))); - - Participant deletedParticipant = participantProvider.deleteParticipant(name, version); - assertEquals(inputParticipants.get(0), deletedParticipant); - - when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); - assertThatThrownBy(() -> { - participantProvider.deleteParticipant(name, version); - }).hasMessageMatching("Error in delete Participant"); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java deleted file mode 100644 index 16f4958a9..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ParticipantStatisticsProviderTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.time.Instant; -import java.util.List; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ParticipantStatisticsRepository; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantStatisticsProviderTest { - - private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; - private static final Coder CODER = new StandardCoder(); - private static final String PARTICIPANT_STATS_JSON = "src/test/resources/providers/TestParticipantStatistics.json"; - - private ParticipantStatisticsProvider participantStatisticsProvider; - private ParticipantStatisticsList inputParticipantStatistics; - private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_STATS_JSON); - - @BeforeEach - void beforeSetupDao() throws Exception { - var participantStatisticsRepository = mock(ParticipantStatisticsRepository.class); - participantStatisticsProvider = new ParticipantStatisticsProvider(participantStatisticsRepository); - inputParticipantStatistics = CODER.decode(originalJson, ParticipantStatisticsList.class); - - var jpaParticipantStatisticsList = - ProviderUtils.getJpaAndValidateList(inputParticipantStatistics.getStatisticsList(), - JpaParticipantStatistics::new, "Participant Statistics"); - - for (var participantStat : jpaParticipantStatisticsList) { - when(participantStatisticsRepository.getById(eq(participantStat.getKey()))).thenReturn(participantStat); - when(participantStatisticsRepository.findAllById(eq(List.of(participantStat.getKey())))) - .thenReturn(List.of(participantStat)); - } - - when(participantStatisticsRepository.getFiltered(eq(JpaParticipantStatistics.class), any())) - .thenReturn(List.of(jpaParticipantStatisticsList.get(0))); - - when(participantStatisticsRepository.saveAll(anyList())).thenReturn(jpaParticipantStatisticsList); - } - - @Test - void testParticipantStatisticsCreate() throws Exception { - assertThatThrownBy(() -> { - participantStatisticsProvider.createParticipantStatistics(null); - }).hasMessageMatching(LIST_IS_NULL); - - ParticipantStatisticsList createdStatsList = new ParticipantStatisticsList(); - createdStatsList.setStatisticsList(participantStatisticsProvider - .createParticipantStatistics(inputParticipantStatistics.getStatisticsList())); - - assertEquals(inputParticipantStatistics.toString().replaceAll("\\s+", ""), - createdStatsList.toString().replaceAll("\\s+", "")); - } - - @Test - void testGetControlLoops() throws Exception { - // Return empty list when no data present in db - List getResponse = - participantStatisticsProvider.getParticipantStatistics(null, null, null); - assertThat(getResponse).isEmpty(); - - participantStatisticsProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); - ToscaConceptIdentifier identifier = inputParticipantStatistics.getStatisticsList().get(0).getParticipantId(); - Instant instant = inputParticipantStatistics.getStatisticsList().get(0).getTimeStamp(); - assertEquals(1, participantStatisticsProvider - .getParticipantStatistics(identifier.getName(), identifier.getVersion(), instant).size()); - - assertEquals(1, participantStatisticsProvider - .getFilteredParticipantStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java deleted file mode 100644 index 523a4fb88..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/provider/ServiceTemplateProviderTest.java +++ /dev/null @@ -1,169 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.provider; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.repository.ToscaServiceTemplateRepository; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardYamlCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; - -class ServiceTemplateProviderTest { - - private static final String TOSCA_SERVICE_TEMPLATE_YAML = - "src/test/resources/providers/tosca-for-smoke-testing.yaml"; - - private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); - - private static ToscaServiceTemplate inputServiceTemplate; - - @BeforeAll - static void loadServiceTemplate() { - inputServiceTemplate = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); - } - - @Test - void testGetCommonOrInstancePropertiesFromNodeTypes() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - - var result = serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); - assertNotNull(result); - assertThat(result).hasSize(8); - } - - @Test - void testGetDerivedCommonOrInstanceNodeTemplates() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - - var commonOrInstanceNodeTypeProps = - serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); - - var result = serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates( - inputServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(), commonOrInstanceNodeTypeProps); - - assertNotNull(result); - assertThat(result).hasSize(8); - } - - @Test - void testCreateServiceTemplate() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - when(serviceTemplateRepository.save(jpaServiceTemplate)).thenReturn(jpaServiceTemplate); - - var result = serviceTemplateProvider.createServiceTemplate(inputServiceTemplate); - - assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - @Test - void testDeleteServiceTemplate() throws PfModelException { - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository - .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) - .thenReturn(Optional.of(jpaServiceTemplate)); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - var result = serviceTemplateProvider.deleteServiceTemplate(inputServiceTemplate.getName(), - inputServiceTemplate.getVersion()); - - assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - @Test - void testGetServiceTemplateListEmpty() throws PfModelException { - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository.findById(any())).thenReturn(Optional.empty()); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - assertThatThrownBy(() -> serviceTemplateProvider.getToscaServiceTemplate("Name", "1.0.0")) - .hasMessage("Control Loop definitions not found"); - } - - @Test - void testGetServiceTemplateList() throws PfModelException { - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository - .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) - .thenReturn(Optional.of(jpaServiceTemplate)); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - var result = serviceTemplateProvider.getToscaServiceTemplate(inputServiceTemplate.getName(), - inputServiceTemplate.getVersion()); - - assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - @Test - void testGetServiceTemplate() throws PfModelException { - var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, - "toscaServiceTemplate"); - var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); - when(serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, inputServiceTemplate.getName(), - inputServiceTemplate.getVersion())).thenReturn(List.of(jpaServiceTemplate)); - - var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); - var result = serviceTemplateProvider.getServiceTemplateList(inputServiceTemplate.getName(), - inputServiceTemplate.getVersion()); - - assertThat(result).hasSize(1); - assertThat(result.get(0)).isEqualTo(jpaServiceTemplate.toAuthorative()); - } - - /** - * Get ToscaServiceTemplate from resource. - * - * @param path path of the resource - */ - public static ToscaServiceTemplate getToscaServiceTemplate(String path) { - - try { - return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class); - } catch (CoderException e) { - fail("Cannot read or decode " + path); - return null; - } - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java deleted file mode 100644 index 8b5357457..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/controlloop/persistence/repository/FilterRepositoryImplTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============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.models.controlloop.persistence.repository; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop; -import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ProviderUtils; -import org.onap.policy.common.utils.coder.Coder; -import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.dao.PfDao; -import org.onap.policy.models.dao.PfFilterParameters; -import org.onap.policy.models.provider.PolicyModelsProviderParameters; -import org.onap.policy.models.provider.impl.ModelsProvider; - -class FilterRepositoryImplTest { - private static final String CONTROL_LOOP_JSON = "src/test/resources/providers/TestControlLoops.json"; - private static final Coder CODER = new StandardCoder(); - private static final AtomicInteger dbNameCounter = new AtomicInteger(); - private static final String originalJson = ResourceUtils.getResourceAsString(CONTROL_LOOP_JSON); - private static List jpaControlLoops; - private PfDao pfDao; - - @BeforeEach - void beforeSetupDao() throws Exception { - var parameters = new PolicyModelsProviderParameters(); - parameters.setDatabaseDriver("org.h2.Driver"); - parameters.setName("PolicyProviderParameterGroup"); - parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); - parameters.setDatabaseUrl("jdbc:h2:mem:controlLoopProviderTestDb" + dbNameCounter.getAndDecrement()); - parameters.setDatabaseUser("policy"); - parameters.setDatabasePassword("P01icY"); - parameters.setPersistenceUnit("ToscaConceptTest"); - - pfDao = ModelsProvider.init(parameters); - var inputControlLoops = CODER.decode(originalJson, ControlLoops.class); - jpaControlLoops = ProviderUtils.getJpaAndValidateList(inputControlLoops.getControlLoopList(), - JpaControlLoop::new, "ControlLoops"); - - pfDao.createCollection(jpaControlLoops); - } - - @Test - void testGetPfDao() { - assertThat(new FilterRepositoryImpl().getPfDao()).isNotNull(); - } - - @Test - void testGetFilteredParams() { - var filterRepositoryImpl = new FilterRepositoryImpl() { - @Override - protected PfDao getPfDao() { - return pfDao; - } - }; - var result = filterRepositoryImpl.getFiltered(JpaControlLoop.class, null, null); - assertThat(result).hasSize(2); - - result = filterRepositoryImpl.getFiltered(JpaControlLoop.class, jpaControlLoops.get(0).getName(), null); - assertThat(result).hasSize(1); - } - - @Test - void testGetFiltered() { - var filterRepositoryImpl = new FilterRepositoryImpl() { - @Override - protected PfDao getPfDao() { - return pfDao; - } - }; - - // @formatter:off - PfFilterParameters filterParams = PfFilterParameters - .builder() - .name(jpaControlLoops.get(0).getName()) - .build(); - // @formatter:on - - var result = filterRepositoryImpl.getFiltered(JpaControlLoop.class, filterParams); - assertThat(result).hasSize(1); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java deleted file mode 100644 index bf2e2fa0a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopNotificationTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/*- - * ============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.models.messages.dmaap.notification; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import org.junit.jupiter.api.Test; - -class ControlLoopNotificationTest { - - @Test - void testControlLoopNotification() { - ControlLoopNotification cln0 = new ControlLoopNotification(); - - List addedList = new ArrayList<>(); - addedList.add(new ControlLoopStatus()); - - List deletedList = new ArrayList<>(); - deletedList.add(new ControlLoopStatus()); - - assertEquals(true, cln0.isEmpty()); - - cln0.setAdded(addedList); - assertEquals(false, cln0.isEmpty()); - cln0.setAdded(null); - assertEquals(true, cln0.isEmpty()); - - cln0.setDeleted(deletedList); - assertEquals(false, cln0.isEmpty()); - cln0.setDeleted(null); - assertEquals(true, cln0.isEmpty()); - - cln0.setAdded(addedList); - cln0.setDeleted(deletedList); - assertEquals(false, cln0.isEmpty()); - cln0.setAdded(null); - cln0.setDeleted(null); - assertEquals(true, cln0.isEmpty()); - } - - @Test - void testControlLoopNotificationLombok() { - assertNotNull(new ControlLoopNotification()); - assertNotNull(new ControlLoopNotification(new ArrayList<>(), new ArrayList<>())); - - ControlLoopNotification cln0 = new ControlLoopNotification(); - - assertThat(cln0.toString()).contains("ControlLoopNotification("); - assertEquals(false, cln0.hashCode() == 0); - assertEquals(true, cln0.equals(cln0)); - assertEquals(false, cln0.equals(null)); - - - ControlLoopNotification cln1 = new ControlLoopNotification(); - - assertThat(cln1.toString()).contains("ControlLoopNotification("); - assertEquals(false, cln1.hashCode() == 0); - assertEquals(true, cln1.equals(cln0)); - assertEquals(false, cln1.equals(null)); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java deleted file mode 100644 index cca5e8554..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/ControlLoopStatusTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============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.models.messages.dmaap.notification; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopStatusTest { - - @Test - void testControlLoopStatusLombok() { - assertNotNull(new ControlLoopStatus()); - assertNotNull(new ControlLoopStatus(UUID.randomUUID(), new ToscaConceptIdentifier())); - - ControlLoopStatus cln0 = new ControlLoopStatus(); - - assertThat(cln0.toString()).contains("ControlLoopStatus("); - assertEquals(false, cln0.hashCode() == 0); - assertEquals(true, cln0.equals(cln0)); - assertEquals(false, cln0.equals(null)); - - ControlLoopStatus cln1 = new ControlLoopStatus(); - assertEquals(true, cln1.equals(cln0)); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java deleted file mode 100644 index 1a89a1b3e..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/notification/NotificationPojosTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============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.models.messages.dmaap.notification; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class NotificationPojosTest { - - @Test - void testPojos() { - List pojoClasses = - PojoClassFactory.getPojoClasses(NotificationPojosTest.class.getPackageName()); - - // @formatter:off - final Validator validator = ValidatorBuilder - .create() - .with(new ToStringTester()) - .with(new SetterMustExistRule()) - .with(new GetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - - validator.validate(pojoClasses); - // @formatter:on - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java deleted file mode 100644 index f312c4863..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopAckTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementAck; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ControlLoopAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ControlLoopAck((ControlLoopAck) null)) - .isInstanceOf(NullPointerException.class); - - final var orig = new ControlLoopAck(ParticipantMessageType.CONTROL_LOOP_UPDATE); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopAck(orig).toString())); - - // verify with all values - var id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setParticipantType(id); - var clElementResult = new ControlLoopElementAck(ControlLoopState.UNINITIALISED, - true, "ControlLoopElement result"); - final var controlLoopResultMap = Map.of(UUID.randomUUID(), clElementResult); - orig.setControlLoopResultMap(controlLoopResultMap); - - orig.setResponseTo(UUID.randomUUID()); - orig.setResult(true); - orig.setMessage("Successfully processed ControlLoopUpdate message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopAck(orig).toString())); - - assertSerializable(orig, ControlLoopAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java deleted file mode 100644 index 1bf155e9a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopStateChangeTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the copy constructor and other methods. - */ -class ControlLoopStateChangeTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ControlLoopStateChange(null)).isInstanceOf(NullPointerException.class); - - ControlLoopStateChange orig = new ControlLoopStateChange(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopStateChange(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setMessageId(UUID.randomUUID()); - orig.setOrderedState(ControlLoopOrderedState.RUNNING); - orig.setCurrentState(ControlLoopState.PASSIVE); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ControlLoopStateChange(orig).toString())); - - assertSerializable(orig, ControlLoopStateChange.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java deleted file mode 100644 index ce56d582a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ControlLoopUpdateTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -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.controlloop.concepts.ParticipantUpdates; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; - -/** - * Test the copy constructor. - */ -class ControlLoopUpdateTest { - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ControlLoopUpdate(null)).isInstanceOf(NullPointerException.class); - - ControlLoopUpdate orig = new ControlLoopUpdate(); - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(null); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ControlLoopElement clElement = new ControlLoopElement(); - clElement.setId(UUID.randomUUID()); - clElement.setDefinition(id); - clElement.setDescription("Description"); - clElement.setOrderedState(ControlLoopOrderedState.PASSIVE); - clElement.setState(ControlLoopState.PASSIVE); - clElement.setParticipantId(id); - clElement.setParticipantType(id); - - ToscaProperty property = new ToscaProperty(); - property.setName("test"); - property.setType("testType"); - Map propertiesMap = Map.of("Prop1", property); - clElement.setPropertiesMap(propertiesMap); - - ParticipantUpdates participantUpdates = new ParticipantUpdates(); - participantUpdates.setParticipantId(id); - participantUpdates.setControlLoopElementList(List.of(clElement)); - orig.setParticipantUpdatesList(List.of(participantUpdates)); - - ControlLoopUpdate other = new ControlLoopUpdate(orig); - - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); - assertSerializable(orig, ControlLoopUpdate.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java deleted file mode 100644 index df82ab071..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantAckMessageTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantAckMessageTest { - private ParticipantAckMessage message; - - private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); - private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); - private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); - private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantAckMessage((ParticipantAckMessage) null)) - .isInstanceOf(NullPointerException.class); - - // verify with null values - message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); - ParticipantAckMessage newmsg = new ParticipantAckMessage(message); - newmsg.setResponseTo(message.getResponseTo()); - assertEquals(message.toString(), newmsg.toString()); - - // verify with all values - message = makeMessage(); - newmsg = new ParticipantAckMessage(message); - newmsg.setResponseTo(message.getResponseTo()); - assertEquals(message.toString(), newmsg.toString()); - - assertSerializable(message, ParticipantAckMessage.class); - } - - @Test - void testAppliesTo_NullParticipantId() { - message = makeMessage(); - - assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); - } - - @Test - void testAppliesTo_ParticipantIdMatches() { - message = makeMessage(); - - // ParticipantId matches - assertTrue(message.appliesTo(PTYPE_456, ID_123)); - assertFalse(message.appliesTo(PTYPE_456, ID_124)); - assertFalse(message.appliesTo(PTYPE_457, ID_123)); - } - - @Test - void testAppliesTo_ParticipantIdNoMatch() { - message = makeMessage(); - - // ParticipantId does not match - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id1111"); - id.setVersion("3.2.1"); - assertFalse(message.appliesTo(id, id)); - message.setParticipantType(null); - assertTrue(message.appliesTo(id, id)); - } - - private ParticipantAckMessage makeMessage() { - ParticipantAckMessage msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); - - msg.setParticipantType(PTYPE_456); - msg.setParticipantId(ID_123); - msg.setMessage("Successfull Ack"); - msg.setResult(true); - msg.setResponseTo(UUID.randomUUID()); - - return msg; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java deleted file mode 100644 index f1ae5f709..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterAckTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantDeregisterAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantDeregisterAck(null)).isInstanceOf(NullPointerException.class); - - final ParticipantDeregisterAck orig = new ParticipantDeregisterAck(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregisterAck(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setResponseTo(UUID.randomUUID()); - orig.setMessageType(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); - orig.setResult(true); - orig.setMessage("Successfully processed message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregisterAck(orig).toString())); - - assertSerializable(orig, ParticipantDeregisterAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java deleted file mode 100644 index 89546890a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantDeregisterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantDeregisterTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantDeregister(null)).isInstanceOf(NullPointerException.class); - - final ParticipantDeregister orig = new ParticipantDeregister(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregister(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setParticipantType(id); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantDeregister(orig).toString())); - - assertSerializable(orig, ParticipantDeregister.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java deleted file mode 100644 index 58d3afebc..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantMessageTest { - private ParticipantMessage message; - - private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); - private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); - private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); - private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantMessage((ParticipantMessage) null)) - .isInstanceOf(NullPointerException.class); - - // verify with null values - message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); - ParticipantMessage newmsg = new ParticipantMessage(message); - newmsg.setMessageId(message.getMessageId()); - newmsg.setTimestamp(message.getTimestamp()); - assertEquals(message.toString(), newmsg.toString()); - - // verify with all values - message = makeMessage(); - newmsg = new ParticipantMessage(message); - newmsg.setMessageId(message.getMessageId()); - newmsg.setTimestamp(message.getTimestamp()); - assertEquals(message.toString(), newmsg.toString()); - - assertSerializable(message, ParticipantMessage.class); - } - - @Test - void testAppliesTo_NullParticipantId() { - message = makeMessage(); - - assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); - } - - @Test - void testAppliesTo_ParticipantIdMatches() { - message = makeMessage(); - - // ParticipantId matches - assertTrue(message.appliesTo(PTYPE_456, ID_123)); - assertFalse(message.appliesTo(PTYPE_456, ID_124)); - assertFalse(message.appliesTo(PTYPE_457, ID_123)); - } - - @Test - void testAppliesTo_ParticipantIdNoMatch() { - message = makeMessage(); - - // ParticipantId does not match - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id1111"); - id.setVersion("3.2.1"); - assertFalse(message.appliesTo(id, id)); - message.setParticipantType(null); - assertTrue(message.appliesTo(id, id)); - } - - private ParticipantMessage makeMessage() { - ParticipantMessage msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); - - msg.setParticipantType(PTYPE_456); - msg.setParticipantId(ID_123); - msg.setMessageId(UUID.randomUUID()); - msg.setTimestamp(Instant.ofEpochMilli(3000)); - - return msg; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java deleted file mode 100644 index 78c278f98..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantMessageUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.junit.Assert.assertEquals; - -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.common.utils.coder.StandardCoder; - -/** - * Utility class for tests of ParticipantMessage subclasses. - */ -public class ParticipantMessageUtils { - - private ParticipantMessageUtils() { - - } - - public static String removeVariableFields(String text) { - return text.replaceAll("messageId=[^,]*", "messageId=xxx").replaceAll("timestamp=[^,]*", "timestamp=nnn"); - } - - /** - * Check if object is Serializable. - * - * @param object the Object - * @param clazz the class of the Object - * @throws CoderException if object is not Serializable - */ - public static void assertSerializable(Object object, Class clazz) throws CoderException { - var standardCoder = new StandardCoder(); - var json = standardCoder.encode(object); - var other = standardCoder.decode(json, clazz); - - assertEquals(removeVariableFields(object.toString()), removeVariableFields(other.toString())); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java deleted file mode 100644 index e67fbc143..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantPojosTest.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class ParticipantPojosTest { - - @Test - void testPojos() { - List pojoClasses = - PojoClassFactory.getPojoClasses(ParticipantPojosTest.class.getPackageName()); - - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessage.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessage.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessageTest.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAck.class)); - pojoClasses.remove(PojoClassFactory.getPojoClass(ControlLoopAckTest.class)); - - // @formatter:off - final Validator validator = ValidatorBuilder - .create() - .with(new ToStringTester()) - .with(new SetterMustExistRule()) - .with(new GetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - - validator.validate(pojoClasses); - // @formatter:on - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java deleted file mode 100644 index 886933aba..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterAckTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantRegisterAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantRegisterAck(null)).isInstanceOf(NullPointerException.class); - - final ParticipantRegisterAck orig = new ParticipantRegisterAck(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegisterAck(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setResponseTo(UUID.randomUUID()); - orig.setMessageType(ParticipantMessageType.PARTICIPANT_REGISTER_ACK); - orig.setResult(true); - orig.setMessage("Successfully processed message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegisterAck(orig).toString())); - - assertSerializable(orig, ParticipantRegisterAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java deleted file mode 100644 index e86d9e885..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantRegisterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantRegisterTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantRegister(null)).isInstanceOf(NullPointerException.class); - - final ParticipantRegister orig = new ParticipantRegister(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegister(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setParticipantType(id); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantRegister(orig).toString())); - - assertSerializable(orig, ParticipantRegister.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java deleted file mode 100644 index 98c127107..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusReqTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Test the copy constructor. - */ -class ParticipantStatusReqTest { - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class); - - ParticipantStatusReq orig = new ParticipantStatusReq(); - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setParticipantId(id); - orig.setControlLoopId(null); - orig.setParticipantType(null); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ParticipantStatusReq other = new ParticipantStatusReq(orig); - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); - - assertSerializable(orig, ParticipantStatusReq.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java deleted file mode 100644 index b2bce05cc..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantStatusTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopInfo; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopStatistics; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantHealthStatus; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; - -class ParticipantStatusTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantStatus(null)).isInstanceOf(NullPointerException.class); - - final ParticipantStatus orig = new ParticipantStatus(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantStatus(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4"); - orig.setParticipantType(type); - orig.setMessageId(UUID.randomUUID()); - orig.setState(ParticipantState.ACTIVE); - orig.setHealthStatus(ParticipantHealthStatus.HEALTHY); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ControlLoopInfo clInfo = getControlLoopInfo(id); - orig.setControlLoopInfoList(List.of(clInfo)); - - ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); - participantDefinitionUpdate.setParticipantId(id); - participantDefinitionUpdate.setParticipantType(type); - ControlLoopElementDefinition clDefinition = getClElementDefinition(id); - participantDefinitionUpdate.setControlLoopElementDefinitionList(List.of(clDefinition)); - orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantStatus(orig).toString())); - - assertSerializable(orig, ParticipantStatus.class); - } - - private ControlLoopInfo getControlLoopInfo(ToscaConceptIdentifier id) { - ControlLoopInfo clInfo = new ControlLoopInfo(); - clInfo.setState(ControlLoopState.PASSIVE2RUNNING); - clInfo.setControlLoopId(id); - - ControlLoopStatistics clStatistics = new ControlLoopStatistics(); - clStatistics.setControlLoopId(id); - clStatistics.setAverageExecutionTime(12345); - clStatistics.setEventCount(12345); - clStatistics.setLastEnterTime(12345); - clStatistics.setLastExecutionTime(12345); - clStatistics.setLastStart(12345); - clStatistics.setTimeStamp(Instant.ofEpochMilli(3000)); - clStatistics.setUpTime(12345); - ClElementStatisticsList clElementStatisticsList = new ClElementStatisticsList(); - ClElementStatistics clElementStatistics = new ClElementStatistics(); - clElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); - clElementStatistics.setTimeStamp(Instant.now()); - clElementStatisticsList.setClElementStatistics(List.of(clElementStatistics)); - clStatistics.setClElementStatisticsList(clElementStatisticsList); - - clInfo.setControlLoopStatistics(clStatistics); - return clInfo; - } - - private ControlLoopElementDefinition getClElementDefinition(ToscaConceptIdentifier id) { - ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition(); - clDefinition.setClElementDefinitionId(id); - clDefinition.setControlLoopElementToscaNodeTemplate(toscaNodeTemplate); - - ToscaProperty property = new ToscaProperty(); - property.setName("test"); - property.setType("testType"); - Map commonPropertiesMap = Map.of("Prop1", property); - clDefinition.setCommonPropertiesMap(commonPropertiesMap); - return clDefinition; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java deleted file mode 100644 index d2a191018..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateAckTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantUpdateAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantUpdateAck(null)).isInstanceOf(NullPointerException.class); - - final ParticipantUpdateAck orig = new ParticipantUpdateAck(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantUpdateAck(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setResponseTo(UUID.randomUUID()); - orig.setMessageType(ParticipantMessageType.PARTICIPANT_UPDATE_ACK); - orig.setResult(true); - orig.setMessage("Successfully processed message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantUpdateAck(orig).toString())); - - assertSerializable(orig, ParticipantUpdateAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java deleted file mode 100644 index d7023d0c1..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/dmaap/participant/ParticipantUpdateTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/*- - * ============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.models.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -/** - * Test the copy constructor. - */ -class ParticipantUpdateTest { - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantUpdate(null)).isInstanceOf(NullPointerException.class); - - ParticipantUpdate orig = new ParticipantUpdate(); - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); - orig.setControlLoopId(id); - orig.setParticipantId(id); - orig.setParticipantType(id); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); - toscaServiceTemplate.setName("serviceTemplate"); - toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); - toscaServiceTemplate.setDescription("Description of serviceTemplate"); - toscaServiceTemplate.setVersion("1.2.3"); - - ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); - participantDefinitionUpdate.setParticipantType(id); - ControlLoopElementDefinition clDefinition = getClElementDefinition(id); - participantDefinitionUpdate.setControlLoopElementDefinitionList(List.of(clDefinition)); - orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); - - ParticipantUpdate other = new ParticipantUpdate(orig); - - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); - - assertSerializable(orig, ParticipantUpdate.class); - } - - private ControlLoopElementDefinition getClElementDefinition(ToscaConceptIdentifier id) { - ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - ControlLoopElementDefinition clDefinition = new ControlLoopElementDefinition(); - clDefinition.setClElementDefinitionId(id); - clDefinition.setControlLoopElementToscaNodeTemplate(toscaNodeTemplate); - - ToscaProperty property = new ToscaProperty(); - property.setName("test"); - property.setType("testType"); - Map commonPropertiesMap = Map.of("Prop1", property); - clDefinition.setCommonPropertiesMap(commonPropertiesMap); - return clDefinition; - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java deleted file mode 100644 index 435cce8ef..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/MessagesRestPojosTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.models.messages.rest; - -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.test.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - */ -class MessagesRestPojosTest { - - @Test - void testPojos() { - List pojoClasses = - PojoClassFactory.getPojoClassesRecursively(MessagesRestPojosTest.class.getPackageName(), null); - - - // @formatter:off - final Validator validator = ValidatorBuilder - .create() - .with(new ToStringTester()) - .with(new SetterMustExistRule()) - .with(new GetterMustExistRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .build(); - - validator.validate(pojoClasses); - // @formatter:on - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java deleted file mode 100644 index c9902753f..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationCommandTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============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.models.messages.rest.instantiation; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; - -class InstantiationCommandTest { - @Test - void testInstantiationCommandLombok() { - assertNotNull(new InstantiationCommand()); - InstantiationCommand ic0 = new InstantiationCommand(); - - assertThat(ic0.toString()).contains("InstantiationCommand("); - assertEquals(false, ic0.hashCode() == 0); - assertEquals(true, ic0.equals(ic0)); - assertEquals(false, ic0.equals(null)); - - - InstantiationCommand ic1 = new InstantiationCommand(); - - ic1.setControlLoopIdentifierList(new ArrayList<>()); - ic1.setOrderedState(ControlLoopOrderedState.UNINITIALISED); - - assertThat(ic1.toString()).contains("InstantiationCommand("); - assertEquals(false, ic1.hashCode() == 0); - assertEquals(false, ic1.equals(ic0)); - assertEquals(false, ic1.equals(null)); - - assertNotEquals(ic1, ic0); - - InstantiationCommand ic2 = new InstantiationCommand(); - - assertEquals(ic2, ic0); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java deleted file mode 100644 index 4dedae200..000000000 --- a/models/src/test/java/org/onap/policy/clamp/controlloop/models/rest/RestUtilsTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============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.models.rest; - -import static org.assertj.core.api.Assertions.assertThat; - -import javax.ws.rs.core.Response.Status; -import org.junit.jupiter.api.Test; -import org.onap.policy.models.errors.concepts.ErrorResponse; -import org.onap.policy.models.errors.concepts.ErrorResponseInfo; - -class RestUtilsTest { - - private static final String MESSAGE_ERROR = "Erorr"; - private static final Status STATUS_ERROR = Status.BAD_REQUEST; - - @Test - void testToSimpleResponse() { - var ex = new ErrorResponseInfo() { - - @Override - public ErrorResponse getErrorResponse() { - var er = new ErrorResponse(); - er.setErrorMessage(MESSAGE_ERROR); - er.setResponseCode(STATUS_ERROR); - return er; - } - }; - - var response = RestUtils.toSimpleResponse(ex); - - assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode()); - assertThat(response.getBody()).isNotNull(); - assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java new file mode 100644 index 000000000..ee79b27b7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AcElementStatisticsTest.java @@ -0,0 +1,67 @@ +/*- + * ============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.models.acm.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AcElementStatisticsTest { + @Test + void testAcElementStatisticsLombok() { + assertNotNull(new AcElementStatistics()); + AcElementStatistics aces0 = new AcElementStatistics(); + + assertThat(aces0.toString()).contains("AcElementStatistics("); + assertThat(aces0.hashCode()).isNotZero(); + assertEquals(true, aces0.equals(aces0)); + assertEquals(false, aces0.equals(null)); + + + AcElementStatistics aces1 = new AcElementStatistics(); + aces1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); + aces1.setTimeStamp(Instant.now()); + + assertThat(aces1.toString()).contains("AcElementStatistics("); + assertEquals(false, aces1.hashCode() == 0); + assertEquals(false, aces1.equals(aces0)); + assertEquals(false, aces1.equals(null)); + + assertNotEquals(aces1, aces0); + + AcElementStatistics aces2 = new AcElementStatistics(); + aces2.setId(UUID.randomUUID()); + + // @formatter:off + assertThatThrownBy(() -> aces2.setParticipantId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> aces2.setTimeStamp(null)).isInstanceOf(NullPointerException.class); + // @formatter:on + + assertNotEquals(aces2, aces0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.java new file mode 100644 index 000000000..1d45e5919 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionConceptPojosTest.java @@ -0,0 +1,62 @@ +/*- + * ============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.models.acm.concepts; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class AutomationCompositionConceptPojosTest { + + @Test + void testPojos() { + List pojoClasses = + PojoClassFactory.getPojoClasses(AutomationCompositionConceptPojosTest.class.getPackageName()); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new EqualsAndHashCodeMatchRule()) + .with(new NoPublicFieldsExceptStaticFinalRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java new file mode 100644 index 000000000..4e739db52 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementTest.java @@ -0,0 +1,103 @@ +/*- + * ============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.models.acm.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionElementTest { + @Test + void testAutomationCompositionElement() { + var ace0 = new AutomationCompositionElement(); + var ace1 = new AutomationCompositionElement(ace0); + assertEquals(ace0, ace1); + + ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + ace1.setDescription("Description"); + ace1.setId(UUID.randomUUID()); + ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ace1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); + ace1.setState(AutomationCompositionState.UNINITIALISED); + + var ace2 = new AutomationCompositionElement(ace1); + assertEquals(ace1, ace2); + } + + @Test + void testAutomationCompositionState() { + var ace0 = new AutomationCompositionElement(); + + assertTrue( + ace0.getOrderedState() + .equalsAutomationCompositionState(AutomationCompositionState.UNINITIALISED)); + + assertTrue( + ace0.getOrderedState().asState() + .equalsAutomationCompositionOrderedState(AutomationCompositionOrderedState.UNINITIALISED)); + } + + @Test + void testAutomationCompositionElementLombok() { + assertNotNull(new AutomationCompositionElement()); + var ace0 = new AutomationCompositionElement(); + + assertThat(ace0.toString()).contains("AutomationCompositionElement("); + assertThat(ace0.hashCode()).isNotZero(); + assertEquals(true, ace0.equals(ace0)); + assertEquals(false, ace0.equals(null)); + + var ace1 = new AutomationCompositionElement(); + + ace1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + ace1.setDescription("Description"); + ace1.setId(UUID.randomUUID()); + ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ace1.setParticipantId(new ToscaConceptIdentifier("id", "1.2.3")); + ace1.setState(AutomationCompositionState.UNINITIALISED); + + assertThat(ace1.toString()).contains("AutomationCompositionElement("); + assertEquals(false, ace1.hashCode() == 0); + assertEquals(false, ace1.equals(ace0)); + assertEquals(false, ace1.equals(null)); + + assertNotEquals(ace1, ace0); + + var ace2 = new AutomationCompositionElement(); + + // @formatter:off + assertThatThrownBy(() -> ace2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setId(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setOrderedState(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setParticipantId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ace2.setState(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertNotEquals(ace2, ace0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java new file mode 100644 index 000000000..ad8a1bbea --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java @@ -0,0 +1,160 @@ +/*- + * ============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.models.acm.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.time.Instant; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionTest { + @Test + void testAutomationComposition() { + var ac0 = new AutomationComposition(); + ac0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); + assertEquals("dfName", ac0.getType()); + assertEquals("1.2.3", ac0.getTypeVersion()); + + var ac1 = new AutomationComposition(ac0); + assertEquals(ac0, ac1); + + assertEquals(0, ac0.compareTo(ac1)); + } + + @Test + void testAutomationCompositionLombok() { + assertNotNull(new AutomationComposition()); + var ac0 = new AutomationComposition(); + ac0.setElements(new LinkedHashMap<>()); + + assertThat(ac0.toString()).contains("AutomationComposition("); + assertThat(ac0.hashCode()).isNotZero(); + assertEquals(true, ac0.equals(ac0)); + assertEquals(false, ac0.equals(null)); + + var ac1 = new AutomationComposition(); + + ac1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + ac1.setDescription("Description"); + ac1.setElements(new LinkedHashMap<>()); + ac1.setName("Name"); + ac1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ac1.setState(AutomationCompositionState.UNINITIALISED); + ac1.setVersion("0.0.1"); + + assertThat(ac1.toString()).contains("AutomationComposition("); + assertEquals(false, ac1.hashCode() == 0); + assertEquals(false, ac1.equals(ac0)); + assertEquals(false, ac1.equals(null)); + + assertNotEquals(ac1, ac0); + + var ac2 = new AutomationComposition(); + ac2.setElements(new LinkedHashMap<>()); + + // @formatter:off + assertThatThrownBy(() -> ac2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ac2.setOrderedState(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ac2.setState(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(ac2, ac0); + + ac1.setCascadedOrderedState(AutomationCompositionOrderedState.PASSIVE); + assertEquals(AutomationCompositionOrderedState.PASSIVE, ac1.getOrderedState()); + + ac1.getElements().put(UUID.randomUUID(), new AutomationCompositionElement()); + ac1.setCascadedOrderedState(AutomationCompositionOrderedState.RUNNING); + assertEquals(AutomationCompositionOrderedState.RUNNING, ac1.getOrderedState()); + assertEquals(AutomationCompositionOrderedState.RUNNING, + ac1.getElements().values().iterator().next().getOrderedState()); + + assertNull(ac0.getElements().get(UUID.randomUUID())); + assertNull(ac1.getElements().get(UUID.randomUUID())); + + assertEquals(PfKey.NULL_KEY_NAME, ac0.getDefinition().getName()); + + } + + @Test + void testAutomationCompositionElementStatisticsList() { + var ac = new AutomationComposition(); + List emptylist = ac.getAutomationCompositionElementStatisticsList(ac); + assertEquals(List.of(), emptylist); + + var ac1 = getAutomationCompositionTest(); + List list = ac1.getAutomationCompositionElementStatisticsList(ac1); + assertNotNull(list); + assertEquals(2, list.size()); + assertEquals(AutomationCompositionState.UNINITIALISED, list.get(0).getState()); + } + + private AutomationComposition getAutomationCompositionTest() { + var ac = new AutomationComposition(); + ac.setDefinition(new ToscaConceptIdentifier("defName", "1.2.3")); + ac.setDescription("Description"); + ac.setElements(new LinkedHashMap<>()); + ac.setName("Name"); + ac.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ac.setState(AutomationCompositionState.UNINITIALISED); + ac.setVersion("0.0.1"); + + var uuid = UUID.randomUUID(); + var id = new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "1.0.1"); + var acElement = getAutomationCompositionElementTest(uuid, id); + + var uuid2 = UUID.randomUUID(); + var id2 = new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipantIntermediary", + "0.0.1"); + var acElement2 = getAutomationCompositionElementTest(uuid2, id2); + + ac.getElements().put(uuid, acElement); + ac.getElements().put(uuid2, acElement2); + return ac; + } + + private AutomationCompositionElement getAutomationCompositionElementTest(UUID uuid, ToscaConceptIdentifier id) { + var acElement = new AutomationCompositionElement(); + acElement.setId(uuid); + acElement.setParticipantId(id); + acElement.setDefinition(id); + acElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + + var acElementStatistics = new AcElementStatistics(); + acElementStatistics.setParticipantId(id); + acElementStatistics.setState(AutomationCompositionState.UNINITIALISED); + acElementStatistics.setTimeStamp(Instant.now()); + + acElement.setAcElementStatistics(acElementStatistics); + + return acElement; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java new file mode 100644 index 000000000..de9b884d3 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantStatisticsTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.models.acm.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.time.Instant; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantStatisticsTest { + @Test + void testParticipantStatisticsLombok() { + assertNotNull(new ParticipantStatistics()); + ParticipantStatistics ps0 = new ParticipantStatistics(); + + assertThat(ps0.toString()).contains("ParticipantStatistics("); + assertThat(ps0.hashCode()).isNotZero(); + assertEquals(true, ps0.equals(ps0)); + assertEquals(false, ps0.equals(null)); + + + ParticipantStatistics ps1 = new ParticipantStatistics(); + ps1.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); + ps1.setTimeStamp(Instant.now()); + + assertThat(ps1.toString()).contains("ParticipantStatistics("); + assertEquals(false, ps1.hashCode() == 0); + assertEquals(false, ps1.equals(ps0)); + assertEquals(false, ps1.equals(null)); + + assertNotEquals(ps1, ps0); + + ParticipantStatistics ps2 = new ParticipantStatistics(); + + // @formatter:off + assertThatThrownBy(() -> ps2.setParticipantId(null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> ps2.setTimeStamp(null)). isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(ps2, ps0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java new file mode 100644 index 000000000..164c7c1a0 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java @@ -0,0 +1,84 @@ +/*- + * ============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.models.acm.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantTest { + @Test + void testParticipant() { + + Participant p0 = new Participant(); + p0.setDefinition(new ToscaConceptIdentifier("dfName", "1.2.3")); + assertEquals("dfName", p0.getType()); + assertEquals("1.2.3", p0.getTypeVersion()); + + Participant p1 = new Participant(p0); + assertEquals(p0, p1); + + assertEquals(0, p0.compareTo(p1)); + } + + @Test + void testParticipantLombok() { + assertNotNull(new Participant()); + Participant p0 = new Participant(); + + assertThat(p0.toString()).contains("Participant("); + assertThat(p0.hashCode()).isNotZero(); + assertEquals(true, p0.equals(p0)); + assertEquals(false, p0.equals(null)); + + + Participant p1 = new Participant(); + + p1.setDefinition(new ToscaConceptIdentifier("defName", "0.0.1")); + p1.setDescription("Description"); + p1.setHealthStatus(ParticipantHealthStatus.HEALTHY); + p1.setName("Name"); + p1.setParticipantState(ParticipantState.ACTIVE); + p1.setVersion("0.0.1"); + + assertThat(p1.toString()).contains("Participant("); + assertEquals(false, p1.hashCode() == 0); + assertEquals(false, p1.equals(p0)); + assertEquals(false, p1.equals(null)); + + assertNotEquals(p1, p0); + + Participant p2 = new Participant(); + + // @formatter:off + assertThatThrownBy(() -> p2.setDefinition(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> p2.setHealthStatus(null)). isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> p2.setParticipantState(null)).isInstanceOf(NullPointerException.class); + // @formatter:on + + assertEquals(p2, p0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java new file mode 100644 index 000000000..5252221a8 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantUtilsTest.java @@ -0,0 +1,91 @@ +/*- + * ============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.models.acm.concepts; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Map; +import org.junit.jupiter.api.Test; +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.StandardYamlCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +class ParticipantUtilsTest { + + private static final Coder CODER = new StandardCoder(); + private static final String TOSCA_TEMPLATE_YAML = "examples/acm/PMSubscriptionHandling.yaml"; + private static final String AUTOMATION_COMPOSITION_JSON = + "src/test/resources/providers/TestAutomationCompositions.json"; + private static final String AUTOMATION_COMPOSITION_ELEMENT = + "org.onap.policy.clamp.acm.AutomationCompositionElement"; + private static final String POLICY_AUTOMATION_COMPOSITION_ELEMENT = + "org.onap.policy.clamp.acm.PolicyAutomationCompositionElement"; + private static final String PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT = "org.onap.policy.clamp.acm.Participant"; + private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); + + @Test + void testFindParticipantType() throws CoderException { + var identifier = new ToscaConceptIdentifier("Identifier", "1.0.1"); + var result = ParticipantUtils.findParticipantType(Map.of("participantType", CODER.encode(identifier))); + assertThat(result).isEqualTo(identifier); + } + + @Test + void testFindStartPhase() { + var identifier = 13; + var result = ParticipantUtils.findStartPhase(Map.of("startPhase", identifier)); + assertThat(result).isEqualTo(identifier); + } + + @Test + void testGetFirstStartPhase() throws CoderException { + var serviceTemplate = + YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), ToscaServiceTemplate.class); + var automationCompositions = + CODER.decode(ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON), AutomationCompositions.class); + var result = ParticipantUtils.getFirstStartPhase(automationCompositions.getAutomationCompositionList().get(0), + serviceTemplate); + assertThat(result).isZero(); + } + + @Test + void testCheckIfNodeTemplateIsAutomationCompositionElement() throws CoderException { + var serviceTemplate = + YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(TOSCA_TEMPLATE_YAML), ToscaServiceTemplate.class); + var nodeTemplate = new ToscaNodeTemplate(); + nodeTemplate.setType(AUTOMATION_COMPOSITION_ELEMENT); + assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)) + .isTrue(); + + nodeTemplate.setType(POLICY_AUTOMATION_COMPOSITION_ELEMENT); + assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)) + .isTrue(); + + nodeTemplate.setType(PARTICIPANT_AUTOMATION_COMPOSITION_ELEMENT); + assertThat(ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(nodeTemplate, serviceTemplate)) + .isFalse(); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.java new file mode 100644 index 000000000..49bb719ac --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionNotificationTest.java @@ -0,0 +1,83 @@ +/*- + * ============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.models.acm.messages.dmaap.notification; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; + +class AutomationCompositionNotificationTest { + + @Test + void testAutomationCompositionNotification() { + AutomationCompositionNotification acn0 = new AutomationCompositionNotification(); + + List addedList = new ArrayList<>(); + addedList.add(new AutomationCompositionStatus()); + + List deletedList = new ArrayList<>(); + deletedList.add(new AutomationCompositionStatus()); + + assertEquals(true, acn0.isEmpty()); + + acn0.setAdded(addedList); + assertEquals(false, acn0.isEmpty()); + acn0.setAdded(null); + assertEquals(true, acn0.isEmpty()); + + acn0.setDeleted(deletedList); + assertEquals(false, acn0.isEmpty()); + acn0.setDeleted(null); + assertEquals(true, acn0.isEmpty()); + + acn0.setAdded(addedList); + acn0.setDeleted(deletedList); + assertEquals(false, acn0.isEmpty()); + acn0.setAdded(null); + acn0.setDeleted(null); + assertEquals(true, acn0.isEmpty()); + } + + @Test + void testAutomationCompositionNotificationLombok() { + assertNotNull(new AutomationCompositionNotification()); + assertNotNull(new AutomationCompositionNotification(new ArrayList<>(), new ArrayList<>())); + + AutomationCompositionNotification acn0 = new AutomationCompositionNotification(); + + assertThat(acn0.toString()).contains("AutomationCompositionNotification("); + assertEquals(false, acn0.hashCode() == 0); + assertEquals(true, acn0.equals(acn0)); + assertEquals(false, acn0.equals(null)); + + + AutomationCompositionNotification acn1 = new AutomationCompositionNotification(); + + assertThat(acn1.toString()).contains("AutomationCompositionNotification("); + assertEquals(false, acn1.hashCode() == 0); + assertEquals(true, acn1.equals(acn0)); + assertEquals(false, acn1.equals(null)); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.java new file mode 100644 index 000000000..028566888 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/AutomationCompositionStatusTest.java @@ -0,0 +1,48 @@ +/*- + * ============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.models.acm.messages.dmaap.notification; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionStatusTest { + + @Test + void testAutomationCompositionStatusLombok() { + assertNotNull(new AutomationCompositionStatus()); + assertNotNull(new AutomationCompositionStatus(UUID.randomUUID(), new ToscaConceptIdentifier())); + + AutomationCompositionStatus acn0 = new AutomationCompositionStatus(); + + assertThat(acn0.toString()).contains("AutomationCompositionStatus("); + assertEquals(false, acn0.hashCode() == 0); + assertEquals(true, acn0.equals(acn0)); + assertEquals(false, acn0.equals(null)); + + AutomationCompositionStatus acn1 = new AutomationCompositionStatus(); + assertEquals(true, acn1.equals(acn0)); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/NotificationPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/NotificationPojosTest.java new file mode 100644 index 000000000..494252acc --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/notification/NotificationPojosTest.java @@ -0,0 +1,58 @@ +/*- + * ============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.models.acm.messages.dmaap.notification; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class NotificationPojosTest { + + @Test + void testPojos() { + List pojoClasses = + PojoClassFactory.getPojoClasses(NotificationPojosTest.class.getPackageName()); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java new file mode 100644 index 000000000..383a55115 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionAckTest.java @@ -0,0 +1,68 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementAck; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AutomationCompositionAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new AutomationCompositionAck((AutomationCompositionAck) null)) + .isInstanceOf(NullPointerException.class); + + final var orig = new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionAck(orig).toString())); + + // verify with all values + var id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + var acElementResult = new AutomationCompositionElementAck(AutomationCompositionState.UNINITIALISED, + true, "AutomationCompositionElement result"); + final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult); + orig.setAutomationCompositionResultMap(automationCompositionResultMap); + + orig.setResponseTo(UUID.randomUUID()); + orig.setResult(true); + orig.setMessage("Successfully processed AutomationCompositionUpdate message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionAck(orig).toString())); + + assertSerializable(orig, AutomationCompositionAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java new file mode 100644 index 000000000..6c48afad2 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionStateChangeTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the copy constructor and other methods. + */ +class AutomationCompositionStateChangeTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new AutomationCompositionStateChange(null)).isInstanceOf(NullPointerException.class); + + AutomationCompositionStateChange orig = new AutomationCompositionStateChange(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionStateChange(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setMessageId(UUID.randomUUID()); + orig.setOrderedState(AutomationCompositionOrderedState.RUNNING); + orig.setCurrentState(AutomationCompositionState.PASSIVE); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new AutomationCompositionStateChange(orig).toString())); + + assertSerializable(orig, AutomationCompositionStateChange.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java new file mode 100644 index 000000000..809256d40 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/AutomationCompositionUpdateTest.java @@ -0,0 +1,82 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; + +/** + * Test the copy constructor. + */ +class AutomationCompositionUpdateTest { + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new AutomationCompositionUpdate(null)).isInstanceOf(NullPointerException.class); + + AutomationCompositionUpdate orig = new AutomationCompositionUpdate(); + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(null); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + AutomationCompositionElement acElement = new AutomationCompositionElement(); + acElement.setId(UUID.randomUUID()); + acElement.setDefinition(id); + acElement.setDescription("Description"); + acElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + acElement.setState(AutomationCompositionState.PASSIVE); + acElement.setParticipantId(id); + acElement.setParticipantType(id); + + ToscaProperty property = new ToscaProperty(); + property.setName("test"); + property.setType("testType"); + Map propertiesMap = Map.of("Prop1", property); + acElement.setPropertiesMap(propertiesMap); + + ParticipantUpdates participantUpdates = new ParticipantUpdates(); + participantUpdates.setParticipantId(id); + participantUpdates.setAutomationCompositionElementList(List.of(acElement)); + orig.setParticipantUpdatesList(List.of(participantUpdates)); + + AutomationCompositionUpdate other = new AutomationCompositionUpdate(orig); + + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + assertSerializable(orig, AutomationCompositionUpdate.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java new file mode 100644 index 000000000..89a34e33d --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantAckMessageTest.java @@ -0,0 +1,105 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantAckMessageTest { + private ParticipantAckMessage message; + + private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); + private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); + private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); + private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantAckMessage((ParticipantAckMessage) null)) + .isInstanceOf(NullPointerException.class); + + // verify with null values + message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); + ParticipantAckMessage newmsg = new ParticipantAckMessage(message); + newmsg.setResponseTo(message.getResponseTo()); + assertEquals(message.toString(), newmsg.toString()); + + // verify with all values + message = makeMessage(); + newmsg = new ParticipantAckMessage(message); + newmsg.setResponseTo(message.getResponseTo()); + assertEquals(message.toString(), newmsg.toString()); + + assertSerializable(message, ParticipantAckMessage.class); + } + + @Test + void testAppliesTo_NullParticipantId() { + message = makeMessage(); + + assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); + } + + @Test + void testAppliesTo_ParticipantIdMatches() { + message = makeMessage(); + + // ParticipantId matches + assertTrue(message.appliesTo(PTYPE_456, ID_123)); + assertFalse(message.appliesTo(PTYPE_456, ID_124)); + assertFalse(message.appliesTo(PTYPE_457, ID_123)); + } + + @Test + void testAppliesTo_ParticipantIdNoMatch() { + message = makeMessage(); + + // ParticipantId does not match + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id1111"); + id.setVersion("3.2.1"); + assertFalse(message.appliesTo(id, id)); + message.setParticipantType(null); + assertTrue(message.appliesTo(id, id)); + } + + private ParticipantAckMessage makeMessage() { + ParticipantAckMessage msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); + + msg.setParticipantType(PTYPE_456); + msg.setParticipantId(ID_123); + msg.setMessage("Successfull Ack"); + msg.setResult(true); + msg.setResponseTo(UUID.randomUUID()); + + return msg; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.java new file mode 100644 index 000000000..59a6d826b --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterAckTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantDeregisterAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantDeregisterAck(null)).isInstanceOf(NullPointerException.class); + + final ParticipantDeregisterAck orig = new ParticipantDeregisterAck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregisterAck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setResponseTo(UUID.randomUUID()); + orig.setMessageType(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK); + orig.setResult(true); + orig.setMessage("Successfully processed message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregisterAck(orig).toString())); + + assertSerializable(orig, ParticipantDeregisterAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.java new file mode 100644 index 000000000..873257696 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantDeregisterTest.java @@ -0,0 +1,61 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantDeregisterTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantDeregister(null)).isInstanceOf(NullPointerException.class); + + final ParticipantDeregister orig = new ParticipantDeregister(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregister(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantDeregister(orig).toString())); + + assertSerializable(orig, ParticipantDeregister.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java new file mode 100644 index 000000000..fa16d145d --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageTest.java @@ -0,0 +1,107 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantMessageTest { + private ParticipantMessage message; + + private static final ToscaConceptIdentifier PTYPE_456 = new ToscaConceptIdentifier("PType", "4.5.6"); + private static final ToscaConceptIdentifier PTYPE_457 = new ToscaConceptIdentifier("PType", "4.5.7"); + private static final ToscaConceptIdentifier ID_123 = new ToscaConceptIdentifier("id", "1.2.3"); + private static final ToscaConceptIdentifier ID_124 = new ToscaConceptIdentifier("id", "1.2.4"); + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantMessage((ParticipantMessage) null)) + .isInstanceOf(NullPointerException.class); + + // verify with null values + message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); + ParticipantMessage newmsg = new ParticipantMessage(message); + newmsg.setMessageId(message.getMessageId()); + newmsg.setTimestamp(message.getTimestamp()); + assertEquals(message.toString(), newmsg.toString()); + + // verify with all values + message = makeMessage(); + newmsg = new ParticipantMessage(message); + newmsg.setMessageId(message.getMessageId()); + newmsg.setTimestamp(message.getTimestamp()); + assertEquals(message.toString(), newmsg.toString()); + + assertSerializable(message, ParticipantMessage.class); + } + + @Test + void testAppliesTo_NullParticipantId() { + message = makeMessage(); + + assertThatThrownBy(() -> message.appliesTo(null, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(PTYPE_456, null)).isInstanceOf(NullPointerException.class); + assertThatThrownBy(() -> message.appliesTo(null, ID_123)).isInstanceOf(NullPointerException.class); + } + + @Test + void testAppliesTo_ParticipantIdMatches() { + message = makeMessage(); + + // ParticipantId matches + assertTrue(message.appliesTo(PTYPE_456, ID_123)); + assertFalse(message.appliesTo(PTYPE_456, ID_124)); + assertFalse(message.appliesTo(PTYPE_457, ID_123)); + } + + @Test + void testAppliesTo_ParticipantIdNoMatch() { + message = makeMessage(); + + // ParticipantId does not match + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id1111"); + id.setVersion("3.2.1"); + assertFalse(message.appliesTo(id, id)); + message.setParticipantType(null); + assertTrue(message.appliesTo(id, id)); + } + + private ParticipantMessage makeMessage() { + ParticipantMessage msg = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE); + + msg.setParticipantType(PTYPE_456); + msg.setParticipantId(ID_123); + msg.setMessageId(UUID.randomUUID()); + msg.setTimestamp(Instant.ofEpochMilli(3000)); + + return msg; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java new file mode 100644 index 000000000..4ff4f3b35 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantMessageUtils.java @@ -0,0 +1,55 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.junit.Assert.assertEquals; + +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; + +/** + * Utility class for tests of ParticipantMessage subclasses. + */ +public class ParticipantMessageUtils { + + private ParticipantMessageUtils() { + + } + + public static String removeVariableFields(String text) { + return text.replaceAll("messageId=[^,]*", "messageId=xxx").replaceAll("timestamp=[^,]*", "timestamp=nnn"); + } + + /** + * Check if object is Serializable. + * + * @param object the Object + * @param clazz the class of the Object + * @throws CoderException if object is not Serializable + */ + public static void assertSerializable(Object object, Class clazz) throws CoderException { + var standardCoder = new StandardCoder(); + var json = standardCoder.encode(object); + var other = standardCoder.decode(json, clazz); + + assertEquals(removeVariableFields(object.toString()), removeVariableFields(other.toString())); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.java new file mode 100644 index 000000000..ce23a821f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPojosTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class ParticipantPojosTest { + + @Test + void testPojos() { + List pojoClasses = + PojoClassFactory.getPojoClasses(ParticipantPojosTest.class.getPackageName()); + + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessage.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantMessageTest.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessage.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(ParticipantAckMessageTest.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(AutomationCompositionAck.class)); + pojoClasses.remove(PojoClassFactory.getPojoClass(AutomationCompositionAckTest.class)); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.java new file mode 100644 index 000000000..10200d86f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterAckTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantRegisterAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantRegisterAck(null)).isInstanceOf(NullPointerException.class); + + final ParticipantRegisterAck orig = new ParticipantRegisterAck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegisterAck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setResponseTo(UUID.randomUUID()); + orig.setMessageType(ParticipantMessageType.PARTICIPANT_REGISTER_ACK); + orig.setResult(true); + orig.setMessage("Successfully processed message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegisterAck(orig).toString())); + + assertSerializable(orig, ParticipantRegisterAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.java new file mode 100644 index 000000000..d08acda47 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantRegisterTest.java @@ -0,0 +1,61 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantRegisterTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantRegister(null)).isInstanceOf(NullPointerException.class); + + final ParticipantRegister orig = new ParticipantRegister(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegister(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantRegister(orig).toString())); + + assertSerializable(orig, ParticipantRegister.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java new file mode 100644 index 000000000..92025a707 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusReqTest.java @@ -0,0 +1,56 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the copy constructor. + */ +class ParticipantStatusReqTest { + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantStatusReq(null)).isInstanceOf(NullPointerException.class); + + ParticipantStatusReq orig = new ParticipantStatusReq(); + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setParticipantId(id); + orig.setAutomationCompositionId(null); + orig.setParticipantType(null); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + ParticipantStatusReq other = new ParticipantStatusReq(orig); + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + + assertSerializable(orig, ParticipantStatusReq.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java new file mode 100644 index 000000000..a33c12f2e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantStatusTest.java @@ -0,0 +1,129 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionStatistics; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; + +class ParticipantStatusTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantStatus(null)).isInstanceOf(NullPointerException.class); + + final ParticipantStatus orig = new ParticipantStatus(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantStatus(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + ToscaConceptIdentifier type = new ToscaConceptIdentifier("type", "2.3.4"); + orig.setParticipantType(type); + orig.setMessageId(UUID.randomUUID()); + orig.setState(ParticipantState.ACTIVE); + orig.setHealthStatus(ParticipantHealthStatus.HEALTHY); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + AutomationCompositionInfo acInfo = getAutomationCompositionInfo(id); + orig.setAutomationCompositionInfoList(List.of(acInfo)); + + ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); + participantDefinitionUpdate.setParticipantId(id); + participantDefinitionUpdate.setParticipantType(type); + AutomationCompositionElementDefinition acDefinition = getAcElementDefinition(id); + participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); + orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantStatus(orig).toString())); + + assertSerializable(orig, ParticipantStatus.class); + } + + private AutomationCompositionInfo getAutomationCompositionInfo(ToscaConceptIdentifier id) { + AutomationCompositionInfo acInfo = new AutomationCompositionInfo(); + acInfo.setState(AutomationCompositionState.PASSIVE2RUNNING); + acInfo.setAutomationCompositionId(id); + + AutomationCompositionStatistics acStatistics = new AutomationCompositionStatistics(); + acStatistics.setAutomationCompositionId(id); + acStatistics.setAverageExecutionTime(12345); + acStatistics.setEventCount(12345); + acStatistics.setLastEnterTime(12345); + acStatistics.setLastExecutionTime(12345); + acStatistics.setLastStart(12345); + acStatistics.setTimeStamp(Instant.ofEpochMilli(3000)); + acStatistics.setUpTime(12345); + AcElementStatisticsList acElementStatisticsList = new AcElementStatisticsList(); + AcElementStatistics acElementStatistics = new AcElementStatistics(); + acElementStatistics.setParticipantId(new ToscaConceptIdentifier("defName", "0.0.1")); + acElementStatistics.setTimeStamp(Instant.now()); + acElementStatisticsList.setAcElementStatistics(List.of(acElementStatistics)); + acStatistics.setAcElementStatisticsList(acElementStatisticsList); + + acInfo.setAutomationCompositionStatistics(acStatistics); + return acInfo; + } + + private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { + ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + AutomationCompositionElementDefinition acDefinition = new AutomationCompositionElementDefinition(); + acDefinition.setAcElementDefinitionId(id); + acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + + ToscaProperty property = new ToscaProperty(); + property.setName("test"); + property.setType("testType"); + Map commonPropertiesMap = Map.of("Prop1", property); + acDefinition.setCommonPropertiesMap(commonPropertiesMap); + return acDefinition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java new file mode 100644 index 000000000..9f011a383 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantUpdateAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantUpdateAck(null)).isInstanceOf(NullPointerException.class); + + final ParticipantUpdateAck orig = new ParticipantUpdateAck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantUpdateAck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setResponseTo(UUID.randomUUID()); + orig.setMessageType(ParticipantMessageType.PARTICIPANT_UPDATE_ACK); + orig.setResult(true); + orig.setMessage("Successfully processed message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantUpdateAck(orig).toString())); + + assertSerializable(orig, ParticipantUpdateAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java new file mode 100644 index 000000000..f8aaffe11 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java @@ -0,0 +1,101 @@ +/*- + * ============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.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Test the copy constructor. + */ +class ParticipantUpdateTest { + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantUpdate(null)).isInstanceOf(NullPointerException.class); + + ParticipantUpdate orig = new ParticipantUpdate(); + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3"); + orig.setAutomationCompositionId(id); + orig.setParticipantId(id); + orig.setParticipantType(id); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + ToscaServiceTemplate toscaServiceTemplate = new ToscaServiceTemplate(); + toscaServiceTemplate.setName("serviceTemplate"); + toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); + toscaServiceTemplate.setDescription("Description of serviceTemplate"); + toscaServiceTemplate.setVersion("1.2.3"); + + ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + ParticipantDefinition participantDefinitionUpdate = new ParticipantDefinition(); + participantDefinitionUpdate.setParticipantType(id); + AutomationCompositionElementDefinition acDefinition = getAcElementDefinition(id); + participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); + orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); + + ParticipantUpdate other = new ParticipantUpdate(orig); + + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + + assertSerializable(orig, ParticipantUpdate.class); + } + + private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { + ToscaNodeTemplate toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + AutomationCompositionElementDefinition acDefinition = new AutomationCompositionElementDefinition(); + acDefinition.setAcElementDefinitionId(id); + acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + + ToscaProperty property = new ToscaProperty(); + property.setName("test"); + property.setType("testType"); + Map commonPropertiesMap = Map.of("Prop1", property); + acDefinition.setCommonPropertiesMap(commonPropertiesMap); + return acDefinition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/MessagesRestPojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/MessagesRestPojosTest.java new file mode 100644 index 000000000..4503be783 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/MessagesRestPojosTest.java @@ -0,0 +1,59 @@ +/*- + * ============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.models.acm.messages.rest; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class MessagesRestPojosTest { + + @Test + void testPojos() { + List pojoClasses = + PojoClassFactory.getPojoClassesRecursively(MessagesRestPojosTest.class.getPackageName(), null); + + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new ToStringTester()) + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java new file mode 100644 index 000000000..348359743 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationCommandTest.java @@ -0,0 +1,60 @@ +/*- + * ============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.models.acm.messages.rest.instantiation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; + +class InstantiationCommandTest { + @Test + void testInstantiationCommandLombok() { + assertNotNull(new InstantiationCommand()); + InstantiationCommand ic0 = new InstantiationCommand(); + + assertThat(ic0.toString()).contains("InstantiationCommand("); + assertEquals(false, ic0.hashCode() == 0); + assertEquals(true, ic0.equals(ic0)); + assertEquals(false, ic0.equals(null)); + + + InstantiationCommand ic1 = new InstantiationCommand(); + + ic1.setAutomationCompositionIdentifierList(new ArrayList<>()); + ic1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + + assertThat(ic1.toString()).contains("InstantiationCommand("); + assertEquals(false, ic1.hashCode() == 0); + assertEquals(false, ic1.equals(ic0)); + assertEquals(false, ic1.equals(null)); + + assertNotEquals(ic1, ic0); + + InstantiationCommand ic2 = new InstantiationCommand(); + + assertEquals(ic2, ic0); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java new file mode 100644 index 000000000..ebbaf1d42 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAcElementStatisticsChild.java @@ -0,0 +1,28 @@ +/*- + * ============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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaAcElementStatistics} comparisons. + */ +class DummyJpaAcElementStatisticsChild extends JpaAcElementStatistics { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.java new file mode 100644 index 000000000..c7f4351c7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionChild.java @@ -0,0 +1,28 @@ +/*- + * ============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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaAutomationComposition} comparisons. + */ +class DummyJpaAutomationCompositionChild extends JpaAutomationComposition { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.java new file mode 100644 index 000000000..86723d98f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaAutomationCompositionElementChild.java @@ -0,0 +1,28 @@ +/*- + * ============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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaAutomationCompositionElement} comparisons. + */ +class DummyJpaAutomationCompositionElementChild extends JpaAutomationCompositionElement { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantChild.java new file mode 100644 index 000000000..6b34cc44e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantChild.java @@ -0,0 +1,28 @@ +/*- + * ============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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaParticipant} comparisons. + */ +class DummyJpaParticipantChild extends JpaParticipant { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java new file mode 100644 index 000000000..95082cac7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/DummyJpaParticipantStatisticsChild.java @@ -0,0 +1,28 @@ +/*- + * ============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.models.acm.persistence.concepts; + +/** + * Test class for {@link JpaParticipantStatistics} comparisons. + */ +class DummyJpaParticipantStatisticsChild extends JpaParticipantStatistics { + private static final long serialVersionUID = -5101743610779424064L; +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java new file mode 100644 index 000000000..4cf7b8af0 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAcElementStatisticsTest.java @@ -0,0 +1,189 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfReferenceTimestampKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaAcElementStatistics} class. + */ +class JpaAcElementStatisticsTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaAcElementStatisticsConstructor() { + assertThatThrownBy(() -> { + new JpaAcElementStatistics((JpaAcElementStatistics) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics((PfReferenceTimestampKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics(null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics(null, new PfConceptKey()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAcElementStatistics(new PfReferenceTimestampKey(), null); + }).hasMessageMatching("participantId is marked .*ull but is null"); + + assertNotNull(new JpaAcElementStatistics()); + assertNotNull(new JpaAcElementStatistics((new PfReferenceTimestampKey()))); + assertNotNull(new JpaAcElementStatistics(new PfReferenceTimestampKey(), new PfConceptKey())); + } + + @Test + void testJpaAcElementStatistics() { + JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); + + AcElementStatistics aces = createAcElementStatisticsInstance(); + assertEquals(aces, testJpaAcElementStatistics.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaAcElementStatistics.fromAuthorative(null); + }).hasMessageMatching("acElementStatistics is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaAcElementStatistics((JpaAcElementStatistics) null)) + .isInstanceOf(NullPointerException.class); + + JpaAcElementStatistics testJpaAcElementStatisticsFa = new JpaAcElementStatistics(); + testJpaAcElementStatisticsFa.setKey(null); + testJpaAcElementStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + testJpaAcElementStatisticsFa.setKey(PfReferenceTimestampKey.getNullKey()); + testJpaAcElementStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + testJpaAcElementStatisticsFa.setKey(new PfReferenceTimestampKey("elementName", "0.0.1", + "a95757ba-b34a-4049-a2a8-46773abcbe5e", Instant.ofEpochSecond(123456L))); + testJpaAcElementStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + + testJpaAcElementStatisticsFa = new JpaAcElementStatistics(aces); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatisticsFa); + + assertEquals(1, testJpaAcElementStatistics.getKeys().size()); + + assertEquals("elementName", testJpaAcElementStatistics.getKey().getReferenceKey().getParentKeyName()); + + testJpaAcElementStatistics.clean(); + assertEquals("elementName", testJpaAcElementStatistics.getKey().getReferenceKey().getParentKeyName()); + + JpaAcElementStatistics testJpaAcElementStatistics2 = new JpaAcElementStatistics(testJpaAcElementStatistics); + assertEquals(testJpaAcElementStatistics, testJpaAcElementStatistics2); + } + + @Test + void testJpaAcElementStatisticsValidation() { + JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); + + assertThatThrownBy(() -> { + testJpaAcElementStatistics.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaAcElementStatistics.validate("").isValid()); + } + + @Test + void testJpaAcElementStatisticsCompareTo() { + JpaAcElementStatistics testJpaAcElementStatistics = createJpaAcElementStatisticsInstance(); + + JpaAcElementStatistics otherJpaAcElementStatistics = new JpaAcElementStatistics(testJpaAcElementStatistics); + assertEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); + assertEquals(-1, testJpaAcElementStatistics.compareTo(null)); + assertEquals(0, testJpaAcElementStatistics.compareTo(testJpaAcElementStatistics)); + assertNotEquals(0, testJpaAcElementStatistics.compareTo(new DummyJpaAcElementStatisticsChild())); + + testJpaAcElementStatistics.setState(AutomationCompositionState.PASSIVE); + assertNotEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); + testJpaAcElementStatistics.setState(AutomationCompositionState.UNINITIALISED); + assertEquals(0, testJpaAcElementStatistics.compareTo(otherJpaAcElementStatistics)); + + assertEquals(testJpaAcElementStatistics, new JpaAcElementStatistics(testJpaAcElementStatistics)); + } + + @Test + void testJpaAcElementStatisticsLombok() { + assertNotNull(new Participant()); + JpaAcElementStatistics aces0 = new JpaAcElementStatistics(); + + assertThat(aces0.toString()).contains("JpaAcElementStatistics("); + assertThat(aces0.hashCode()).isNotZero(); + assertEquals(true, aces0.equals(aces0)); + assertEquals(false, aces0.equals(null)); + + + JpaAcElementStatistics aces11 = new JpaAcElementStatistics(); + + aces11.setState(AutomationCompositionState.UNINITIALISED); + + assertThat(aces11.toString()).contains("JpaAcElementStatistics("); + assertEquals(false, aces11.hashCode() == 0); + assertEquals(false, aces11.equals(aces0)); + assertEquals(false, aces11.equals(null)); + + assertNotEquals(aces11, aces0); + + JpaAcElementStatistics aces2 = new JpaAcElementStatistics(); + assertEquals(aces2, aces0); + } + + private JpaAcElementStatistics createJpaAcElementStatisticsInstance() { + AcElementStatistics testAces = createAcElementStatisticsInstance(); + JpaAcElementStatistics testJpaAcElementStatistics = new JpaAcElementStatistics(); + testJpaAcElementStatistics.setKey(null); + testJpaAcElementStatistics.fromAuthorative(testAces); + testJpaAcElementStatistics.setKey(PfReferenceTimestampKey.getNullKey()); + testJpaAcElementStatistics.fromAuthorative(testAces); + + return testJpaAcElementStatistics; + } + + private AcElementStatistics createAcElementStatisticsInstance() { + AcElementStatistics acElementStatistics = new AcElementStatistics(); + acElementStatistics.setParticipantId(new ToscaConceptIdentifier("elementName", "0.0.1")); + acElementStatistics.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); + acElementStatistics.setTimeStamp(Instant.ofEpochSecond(123456L)); + acElementStatistics.setState(AutomationCompositionState.UNINITIALISED); + + return acElementStatistics; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java new file mode 100644 index 000000000..f4257bdd2 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java @@ -0,0 +1,315 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaAutomationCompositionElement} class. + */ +class JpaAutomationCompositionElementTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaAutomationCompositionElementConstructor() { + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement((PfReferenceKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, null, AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, null, new PfConceptKey("participant", "0.0.1"), + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), null, + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), + null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(null, new PfConceptKey(), new PfConceptKey("participant", "0.0.1"), + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, null, + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), + null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), null, new PfConceptKey("participant", "0.0.1"), + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("participantType is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), null, + AutomationCompositionState.UNINITIALISED); + }).hasMessageMatching("participantType is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), + new PfConceptKey("participant", "0.0.1"), null); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertNotNull(new JpaAutomationCompositionElement()); + assertNotNull(new JpaAutomationCompositionElement((new PfReferenceKey()))); + assertNotNull(new JpaAutomationCompositionElement(new PfReferenceKey(), new PfConceptKey(), + new PfConceptKey("participant", "0.0.1"), AutomationCompositionState.UNINITIALISED)); + } + + @Test + void testJpaAutomationCompositionElement() { + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + AutomationCompositionElement ace = createAutomationCompositionElementInstance(); + assertEquals(ace, testJpaAutomationCompositionElement.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaAutomationCompositionElement.fromAuthorative(null); + }).hasMessageMatching("element is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaAutomationCompositionElement((JpaAutomationCompositionElement) null)) + .isInstanceOf(NullPointerException.class); + + JpaAutomationCompositionElement testJpaAutomationCompositionElementFa = new JpaAutomationCompositionElement(); + testJpaAutomationCompositionElementFa.setKey(null); + testJpaAutomationCompositionElementFa.fromAuthorative(ace); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa); + testJpaAutomationCompositionElementFa.setKey(PfReferenceKey.getNullKey()); + testJpaAutomationCompositionElementFa.fromAuthorative(ace); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa); + testJpaAutomationCompositionElementFa.setKey( + new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + testJpaAutomationCompositionElementFa.fromAuthorative(ace); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElementFa); + + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + testJpaAutomationCompositionElement.getKey().getLocalName()); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + new JpaAutomationCompositionElement(createAutomationCompositionElementInstance()).getKey().getLocalName()); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + ((PfReferenceKey) new JpaAutomationCompositionElement(createAutomationCompositionElementInstance()) + .getKeys().get(0)).getLocalName()); + + testJpaAutomationCompositionElement.clean(); + assertEquals("a95757ba-b34a-4049-a2a8-46773abcbe5e", + testJpaAutomationCompositionElement.getKey().getLocalName()); + + testJpaAutomationCompositionElement.setDescription(" A Message "); + testJpaAutomationCompositionElement.clean(); + assertEquals("A Message", testJpaAutomationCompositionElement.getDescription()); + + JpaAutomationCompositionElement testJpaAutomationCompositionElement2 = + new JpaAutomationCompositionElement(testJpaAutomationCompositionElement); + assertEquals(testJpaAutomationCompositionElement, testJpaAutomationCompositionElement2); + } + + @Test + void testJpaAutomationCompositionElementOrderedState() throws CoderException { + AutomationCompositionElement testAutomationCompositionElement = createAutomationCompositionElementInstance(); + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + testJpaAutomationCompositionElement.setOrderedState(null); + assertEquals(testAutomationCompositionElement, testJpaAutomationCompositionElement.toAuthorative()); + testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + + AutomationCompositionElement noOrderedStateAce = new StandardCoder().decode( + new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"), + AutomationCompositionElement.class); + + JpaAutomationCompositionElement noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce); + assertNull(noOrderedStateJpaAce.getOrderedState()); + noOrderedStateAce.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce); + assertEquals(testJpaAutomationCompositionElement, noOrderedStateJpaAce); + } + + @Test + void testJpaAutomationCompositionElementValidation() { + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + assertThatThrownBy(() -> { + testJpaAutomationCompositionElement.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaAutomationCompositionElement.validate("").isValid()); + } + + @Test + void testJpaAutomationCompositionElementCompareTo() { + JpaAutomationCompositionElement testJpaAutomationCompositionElement = + createJpaAutomationCompositionElementInstance(); + + JpaAutomationCompositionElement otherJpaAutomationCompositionElement = + new JpaAutomationCompositionElement(testJpaAutomationCompositionElement); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null)); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement)); + assertNotEquals(0, + testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild())); + + testJpaAutomationCompositionElement + .setKey(new PfReferenceKey("BadValue", "0.0.1", "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setKey( + new PfReferenceKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "a95757ba-b34a-4049-a2a8-46773abcbe5e")); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("aceDef", "0.0.1")); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setDescription("Description"); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setDescription(null); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setState(AutomationCompositionState.PASSIVE); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setState(AutomationCompositionState.UNINITIALISED); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + testJpaAutomationCompositionElement.setParticipantType(new PfConceptKey("dummy", "0.0.1")); + assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + testJpaAutomationCompositionElement.setParticipantType(new PfConceptKey("participantType", "0.0.1")); + assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement)); + + assertEquals(testJpaAutomationCompositionElement, + new JpaAutomationCompositionElement(testJpaAutomationCompositionElement)); + } + + @Test + void testJpaAutomationCompositionElementLombok() { + assertNotNull(new Participant()); + JpaAutomationCompositionElement ace0 = new JpaAutomationCompositionElement(); + + assertThat(ace0.toString()).contains("JpaAutomationCompositionElement("); + assertThat(ace0.hashCode()).isNotZero(); + assertEquals(true, ace0.equals(ace0)); + assertEquals(false, ace0.equals(null)); + + JpaAutomationCompositionElement ace1 = new JpaAutomationCompositionElement(); + + ace1.setDefinition(new PfConceptKey("defName", "0.0.1")); + ace1.setDescription("Description"); + ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + ace1.setState(AutomationCompositionState.UNINITIALISED); + ace1.setParticipantId(new PfConceptKey("participant", "0.0.1")); + + assertThat(ace1.toString()).contains("AutomationCompositionElement("); + assertEquals(false, ace1.hashCode() == 0); + assertEquals(false, ace1.equals(ace0)); + assertEquals(false, ace1.equals(null)); + + assertNotEquals(ace1, ace0); + + JpaAutomationCompositionElement ace2 = new JpaAutomationCompositionElement(); + assertEquals(ace2, ace0); + } + + private JpaAutomationCompositionElement createJpaAutomationCompositionElementInstance() { + AutomationCompositionElement testAce = createAutomationCompositionElementInstance(); + JpaAutomationCompositionElement testJpaAutomationCompositionElement = new JpaAutomationCompositionElement(); + testJpaAutomationCompositionElement.setKey(null); + testJpaAutomationCompositionElement.fromAuthorative(testAce); + testJpaAutomationCompositionElement.setKey(PfReferenceKey.getNullKey()); + testJpaAutomationCompositionElement.fromAuthorative(testAce); + + return testJpaAutomationCompositionElement; + } + + private AutomationCompositionElement createAutomationCompositionElementInstance() { + AutomationCompositionElement automationCompositionElement = new AutomationCompositionElement(); + automationCompositionElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e")); + automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1")); + automationCompositionElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1")); + + return automationCompositionElement; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java new file mode 100644 index 000000000..a016d1202 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java @@ -0,0 +1,310 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.LinkedHashMap; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaAutomationCompositionTest} class. + */ +class JpaAutomationCompositionTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaAutomationCompositionConstructor() { + assertThatThrownBy(() -> { + new JpaAutomationComposition((JpaAutomationComposition) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition((PfConceptKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, null, new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, null, AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), null, new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(null, new PfConceptKey(), AutomationCompositionState.UNINITIALISED, + new LinkedHashMap<>()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, null, new LinkedHashMap<>()); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), null, AutomationCompositionState.UNINITIALISED, + new LinkedHashMap<>()); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), null, new LinkedHashMap<>()); + }).hasMessageMatching("state is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), + AutomationCompositionState.UNINITIALISED, null); + }).hasMessageMatching("elements is marked .*ull but is null"); + + assertNotNull(new JpaAutomationComposition()); + assertNotNull(new JpaAutomationComposition((new PfConceptKey()))); + assertNotNull(new JpaAutomationComposition(new PfConceptKey(), new PfConceptKey(), + AutomationCompositionState.UNINITIALISED, new LinkedHashMap<>())); + } + + @Test + void testJpaAutomationComposition() { + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + AutomationComposition participant = createAutomationCompositionInstance(); + assertEquals(participant, testJpaAutomationComposition.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaAutomationComposition.fromAuthorative(null); + }).hasMessageMatching("automationComposition is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaAutomationComposition((JpaAutomationComposition) null)) + .isInstanceOf(NullPointerException.class); + + JpaAutomationComposition testJpaAutomationCompositionFa = new JpaAutomationComposition(); + testJpaAutomationCompositionFa.setKey(null); + testJpaAutomationCompositionFa.fromAuthorative(participant); + assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + testJpaAutomationCompositionFa.setKey(PfConceptKey.getNullKey()); + testJpaAutomationCompositionFa.fromAuthorative(participant); + assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + testJpaAutomationCompositionFa.setKey(new PfConceptKey("automation-composition", "0.0.1")); + testJpaAutomationCompositionFa.fromAuthorative(participant); + assertEquals(testJpaAutomationComposition, testJpaAutomationCompositionFa); + + assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName()); + assertEquals("automation-composition", + new JpaAutomationComposition(createAutomationCompositionInstance()).getKey().getName()); + assertEquals("automation-composition", + ((PfConceptKey) new JpaAutomationComposition(createAutomationCompositionInstance()).getKeys().get(0)) + .getName()); + + testJpaAutomationComposition.clean(); + assertEquals("automation-composition", testJpaAutomationComposition.getKey().getName()); + + testJpaAutomationComposition.setDescription(" A Message "); + testJpaAutomationComposition.clean(); + assertEquals("A Message", testJpaAutomationComposition.getDescription()); + + JpaAutomationComposition testJpaAutomationComposition2 = + new JpaAutomationComposition(testJpaAutomationComposition); + assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2); + } + + @Test + void testJpaAutomationCompositionElementOrderedState() throws CoderException { + AutomationComposition testAutomationComposition = createAutomationCompositionInstance(); + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + testJpaAutomationComposition.setOrderedState(null); + assertEquals(testAutomationComposition, testJpaAutomationComposition.toAuthorative()); + testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + + AutomationComposition noOrderedStateAc = new StandardCoder().decode( + new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"), AutomationComposition.class); + + JpaAutomationComposition noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc); + assertNull(noOrderedStateJpaAc.getOrderedState()); + noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc); + assertEquals(testJpaAutomationComposition, noOrderedStateJpaAc); + + AutomationCompositions automationCompositionsWithElements = new StandardCoder().decode( + new File("src/test/resources/providers/TestAutomationCompositions.json"), AutomationCompositions.class); + + JpaAutomationComposition jpaAutomationCompositionWithElements = + new JpaAutomationComposition(automationCompositionsWithElements.getAutomationCompositionList().get(0)); + assertEquals(4, jpaAutomationCompositionWithElements.getElements().size()); + assertEquals(18, jpaAutomationCompositionWithElements.getKeys().size()); + assertThatCode(() -> jpaAutomationCompositionWithElements.clean()).doesNotThrowAnyException(); + + assertEquals(automationCompositionsWithElements.getAutomationCompositionList().get(0), + jpaAutomationCompositionWithElements.toAuthorative()); + } + + @Test + void testJpaAutomationCompositionValidation() { + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + assertThatThrownBy(() -> { + testJpaAutomationComposition.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaAutomationComposition.validate("").isValid()); + } + + @Test + void testJpaAutomationCompositionCompareTo() { + JpaAutomationComposition testJpaAutomationComposition = createJpaAutomationCompositionInstance(); + + JpaAutomationComposition otherJpaAutomationComposition = + new JpaAutomationComposition(testJpaAutomationComposition); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + assertEquals(-1, testJpaAutomationComposition.compareTo(null)); + assertEquals(0, testJpaAutomationComposition.compareTo(testJpaAutomationComposition)); + assertNotEquals(0, testJpaAutomationComposition.compareTo(new DummyJpaAutomationCompositionChild())); + + testJpaAutomationComposition.setKey(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setKey(new PfConceptKey("automation-composition", "0.0.1")); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setDefinition(new PfConceptKey("automationCompositionDefinitionName", "0.0.1")); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setState(AutomationCompositionState.PASSIVE); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setState(AutomationCompositionState.UNINITIALISED); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setDescription("A description"); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setDescription(null); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + testJpaAutomationComposition.setPrimed(true); + assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + testJpaAutomationComposition.setPrimed(false); + assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition)); + + assertEquals(testJpaAutomationComposition, new JpaAutomationComposition(testJpaAutomationComposition)); + } + + @Test + void testJpaAutomationCompositionLombok() { + assertNotNull(new AutomationComposition()); + JpaAutomationComposition ac0 = new JpaAutomationComposition(); + + assertThat(ac0.toString()).contains("JpaAutomationComposition("); + assertThat(ac0.hashCode()).isNotZero(); + assertEquals(true, ac0.equals(ac0)); + assertEquals(false, ac0.equals(null)); + + JpaAutomationComposition ac1 = new JpaAutomationComposition(); + + ac1.setDefinition(new PfConceptKey("defName", "0.0.1")); + ac1.setDescription("Description"); + ac1.setElements(new LinkedHashMap<>()); + ac1.setKey(new PfConceptKey("participant", "0.0.1")); + ac1.setState(AutomationCompositionState.UNINITIALISED); + + assertThat(ac1.toString()).contains("AutomationComposition("); + assertEquals(false, ac1.hashCode() == 0); + assertEquals(false, ac1.equals(ac0)); + assertEquals(false, ac1.equals(null)); + + assertNotEquals(ac1, ac0); + + JpaAutomationComposition ac2 = new JpaAutomationComposition(); + assertEquals(ac2, ac0); + } + + private JpaAutomationComposition createJpaAutomationCompositionInstance() { + AutomationComposition testAutomationComposition = createAutomationCompositionInstance(); + JpaAutomationComposition testJpaAutomationComposition = new JpaAutomationComposition(); + testJpaAutomationComposition.setKey(null); + testJpaAutomationComposition.fromAuthorative(testAutomationComposition); + testJpaAutomationComposition.setKey(PfConceptKey.getNullKey()); + testJpaAutomationComposition.fromAuthorative(testAutomationComposition); + + return testJpaAutomationComposition; + } + + private AutomationComposition createAutomationCompositionInstance() { + AutomationComposition testAutomationComposition = new AutomationComposition(); + testAutomationComposition.setName("automation-composition"); + testAutomationComposition.setVersion("0.0.1"); + testAutomationComposition + .setDefinition(new ToscaConceptIdentifier("automationCompositionDefinitionName", "0.0.1")); + testAutomationComposition.setElements(new LinkedHashMap<>()); + + return testAutomationComposition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java new file mode 100644 index 000000000..284d13374 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantStatisticsTest.java @@ -0,0 +1,193 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.time.Instant; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; +import org.onap.policy.common.parameters.BeanValidationResult; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfTimestampKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaParticipantStatistics} class. + */ +class JpaParticipantStatisticsTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaParticipantStatisticsConstructor() { + assertThatThrownBy(() -> { + new JpaParticipantStatistics((JpaParticipantStatistics) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics((PfTimestampKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics(null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics(null, new PfConceptKey()); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipantStatistics(new PfTimestampKey(), null); + }).hasMessageMatching("participantId is marked .*ull but is null"); + + assertNotNull(new JpaParticipantStatistics()); + assertNotNull(new JpaParticipantStatistics((new PfTimestampKey()))); + assertNotNull(new JpaParticipantStatistics(new PfTimestampKey(), new PfConceptKey())); + } + + @Test + void testJpaParticipantStatistics() { + JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); + + ParticipantStatistics aces = createParticipantStatisticsInstance(); + assertEquals(aces, testJpaParticipantStatistics.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaParticipantStatistics.fromAuthorative(null); + }).hasMessageMatching("participantStatistics is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaParticipantStatistics((JpaParticipantStatistics) null)) + .isInstanceOf(NullPointerException.class); + + JpaParticipantStatistics testJpaParticipantStatisticsFa = new JpaParticipantStatistics(); + testJpaParticipantStatisticsFa.setKey(null); + testJpaParticipantStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + testJpaParticipantStatisticsFa.setKey(PfTimestampKey.getNullKey()); + testJpaParticipantStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + testJpaParticipantStatisticsFa + .setKey(new PfTimestampKey("participantName", "0.0.1", Instant.ofEpochMilli(123456L))); + testJpaParticipantStatisticsFa.fromAuthorative(aces); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + + testJpaParticipantStatisticsFa = new JpaParticipantStatistics(aces); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatisticsFa); + + assertEquals(2, testJpaParticipantStatistics.getKeys().size()); + + assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); + + testJpaParticipantStatistics.clean(); + assertEquals("participantName", testJpaParticipantStatistics.getKey().getName()); + + JpaParticipantStatistics testJpaParticipantStatistics2 = + new JpaParticipantStatistics(testJpaParticipantStatistics); + assertEquals(testJpaParticipantStatistics, testJpaParticipantStatistics2); + } + + @Test + void testJpaParticipantStatisticsValidation() { + JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); + + assertThatThrownBy(() -> { + testJpaParticipantStatistics.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + BeanValidationResult validationResult = testJpaParticipantStatistics.validate(""); + assertTrue(validationResult.isValid()); + } + + @Test + void testJpaParticipantStatisticsConmpareTo() { + JpaParticipantStatistics testJpaParticipantStatistics = createJpaParticipantStatisticsInstance(); + + JpaParticipantStatistics otherJpaParticipantStatistics = + new JpaParticipantStatistics(testJpaParticipantStatistics); + assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); + assertEquals(-1, testJpaParticipantStatistics.compareTo(null)); + assertEquals(0, testJpaParticipantStatistics.compareTo(testJpaParticipantStatistics)); + assertNotEquals(0, testJpaParticipantStatistics.compareTo(new DummyJpaParticipantStatisticsChild())); + + testJpaParticipantStatistics.setState(ParticipantState.UNKNOWN); + assertNotEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); + testJpaParticipantStatistics.setState(ParticipantState.PASSIVE); + assertEquals(0, testJpaParticipantStatistics.compareTo(otherJpaParticipantStatistics)); + + assertEquals(testJpaParticipantStatistics, new JpaParticipantStatistics(testJpaParticipantStatistics)); + } + + @Test + void testJpaParticipantStatisticsLombok() { + assertNotNull(new Participant()); + JpaParticipantStatistics ps0 = new JpaParticipantStatistics(); + + assertThat(ps0.toString()).contains("JpaParticipantStatistics("); + assertThat(ps0.hashCode()).isNotZero(); + assertEquals(true, ps0.equals(ps0)); + assertEquals(false, ps0.equals(null)); + + + JpaParticipantStatistics ps1 = new JpaParticipantStatistics(); + + ps1.setState(ParticipantState.UNKNOWN); + + assertThat(ps1.toString()).contains("JpaParticipantStatistics("); + assertEquals(false, ps1.hashCode() == 0); + assertEquals(false, ps1.equals(ps0)); + assertEquals(false, ps1.equals(null)); + + assertNotEquals(ps1, ps0); + + JpaParticipantStatistics ps2 = new JpaParticipantStatistics(); + assertEquals(ps2, ps0); + } + + private JpaParticipantStatistics createJpaParticipantStatisticsInstance() { + ParticipantStatistics testAces = createParticipantStatisticsInstance(); + JpaParticipantStatistics testJpaParticipantStatistics = new JpaParticipantStatistics(); + testJpaParticipantStatistics.setKey(null); + testJpaParticipantStatistics.fromAuthorative(testAces); + testJpaParticipantStatistics.setKey(PfTimestampKey.getNullKey()); + testJpaParticipantStatistics.fromAuthorative(testAces); + + return testJpaParticipantStatistics; + } + + private ParticipantStatistics createParticipantStatisticsInstance() { + ParticipantStatistics participantStatistics = new ParticipantStatistics(); + participantStatistics.setParticipantId(new ToscaConceptIdentifier("participantName", "0.0.1")); + participantStatistics.setTimeStamp(Instant.ofEpochMilli(123456L)); + participantStatistics.setState(ParticipantState.PASSIVE); + participantStatistics.setHealthStatus(ParticipantHealthStatus.HEALTHY); + + return participantStatistics; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java new file mode 100644 index 000000000..776aafa2e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java @@ -0,0 +1,254 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.concepts.ParticipantHealthStatus; +import org.onap.policy.clamp.models.acm.concepts.ParticipantState; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +/** + * Test the {@link JpaParticiant} class. + */ +class JpaParticipantTest { + + private static final String NULL_KEY_ERROR = "key is marked .*ull but is null"; + + @Test + void testJpaParticipantConstructor() { + assertThatThrownBy(() -> { + new JpaParticipant((JpaParticipant) null); + }).hasMessageMatching("copyConcept is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant((PfConceptKey) null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, ParticipantState.ACTIVE, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), null, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, null); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(null, new PfConceptKey(), ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching(NULL_KEY_ERROR); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, null, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, null); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), null, ParticipantState.ACTIVE, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching("definition is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, null); + }).hasMessageMatching("participantState is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), new PfConceptKey(), null, ParticipantHealthStatus.HEALTHY); + }).hasMessageMatching("participantState is marked .*ull but is null"); + + assertThatThrownBy(() -> { + new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, null); + }).hasMessageMatching("healthStatus is marked .*ull but is null"); + + assertNotNull(new JpaParticipant()); + assertNotNull(new JpaParticipant((new PfConceptKey()))); + assertNotNull(new JpaParticipant(new PfConceptKey(), new PfConceptKey(), ParticipantState.ACTIVE, + ParticipantHealthStatus.HEALTHY)); + } + + @Test + void testJpaParticipant() { + JpaParticipant testJpaParticipant = createJpaParticipantInstance(); + + Participant participant = createParticipantInstance(); + assertEquals(participant, testJpaParticipant.toAuthorative()); + + assertThatThrownBy(() -> { + testJpaParticipant.fromAuthorative(null); + }).hasMessageMatching("participant is marked .*ull but is null"); + + assertThatThrownBy(() -> new JpaParticipant((JpaParticipant) null)).isInstanceOf(NullPointerException.class); + + JpaParticipant testJpaParticipantFa = new JpaParticipant(); + testJpaParticipantFa.setKey(null); + testJpaParticipantFa.fromAuthorative(participant); + assertEquals(testJpaParticipant, testJpaParticipantFa); + testJpaParticipantFa.setKey(PfConceptKey.getNullKey()); + testJpaParticipantFa.fromAuthorative(participant); + assertEquals(testJpaParticipant, testJpaParticipantFa); + testJpaParticipantFa.setKey(new PfConceptKey("participant", "0.0.1")); + testJpaParticipantFa.fromAuthorative(participant); + assertEquals(testJpaParticipant, testJpaParticipantFa); + + assertEquals("participant", testJpaParticipant.getKey().getName()); + assertEquals("participant", new JpaParticipant(createParticipantInstance()).getKey().getName()); + assertEquals("participant", + ((PfConceptKey) new JpaParticipant(createParticipantInstance()).getKeys().get(0)).getName()); + + testJpaParticipant.clean(); + assertEquals("participant", testJpaParticipant.getKey().getName()); + + testJpaParticipant.setDescription(" A Message "); + testJpaParticipant.clean(); + assertEquals("A Message", testJpaParticipant.getDescription()); + + JpaParticipant testJpaParticipant2 = new JpaParticipant(testJpaParticipant); + assertEquals(testJpaParticipant, testJpaParticipant2); + } + + @Test + void testJpaParticipantValidation() { + JpaParticipant testJpaParticipant = createJpaParticipantInstance(); + + assertThatThrownBy(() -> { + testJpaParticipant.validate(null); + }).hasMessageMatching("fieldName is marked .*ull but is null"); + + assertTrue(testJpaParticipant.validate("").isValid()); + } + + @Test + void testJpaParticipantCompareTo() { + JpaParticipant testJpaParticipant = createJpaParticipantInstance(); + + JpaParticipant otherJpaParticipant = new JpaParticipant(testJpaParticipant); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + assertEquals(-1, testJpaParticipant.compareTo(null)); + assertEquals(0, testJpaParticipant.compareTo(testJpaParticipant)); + assertNotEquals(0, testJpaParticipant.compareTo(new DummyJpaParticipantChild())); + + testJpaParticipant.setKey(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setKey(new PfConceptKey("participant", "0.0.1")); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + testJpaParticipant.setDefinition(new PfConceptKey("BadValue", "0.0.1")); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setDefinition(new PfConceptKey("participantDefinitionName", "0.0.1")); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + testJpaParticipant.setParticipantState(ParticipantState.PASSIVE); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setParticipantState(ParticipantState.UNKNOWN); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + testJpaParticipant.setHealthStatus(ParticipantHealthStatus.NOT_HEALTHY); + assertNotEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + testJpaParticipant.setHealthStatus(ParticipantHealthStatus.UNKNOWN); + assertEquals(0, testJpaParticipant.compareTo(otherJpaParticipant)); + + assertEquals(testJpaParticipant, new JpaParticipant(testJpaParticipant)); + } + + @Test + void testJpaParticipantLombok() { + assertNotNull(new Participant()); + JpaParticipant p0 = new JpaParticipant(); + + assertThat(p0.toString()).contains("JpaParticipant("); + assertThat(p0.hashCode()).isNotZero(); + assertEquals(true, p0.equals(p0)); + assertEquals(false, p0.equals(null)); + + + JpaParticipant p1 = new JpaParticipant(); + + p1.setDefinition(new PfConceptKey("defName", "0.0.1")); + p1.setDescription("Description"); + p1.setHealthStatus(ParticipantHealthStatus.HEALTHY); + p1.setKey(new PfConceptKey("participant", "0.0.1")); + p1.setParticipantState(ParticipantState.ACTIVE); + + assertThat(p1.toString()).contains("Participant("); + assertEquals(false, p1.hashCode() == 0); + assertEquals(false, p1.equals(p0)); + assertEquals(false, p1.equals(null)); + + assertNotEquals(p1, p0); + + JpaParticipant p2 = new JpaParticipant(); + assertEquals(p2, p0); + } + + private JpaParticipant createJpaParticipantInstance() { + Participant testParticipant = createParticipantInstance(); + JpaParticipant testJpaParticipant = new JpaParticipant(); + testJpaParticipant.setKey(null); + testJpaParticipant.fromAuthorative(testParticipant); + testJpaParticipant.setKey(PfConceptKey.getNullKey()); + testJpaParticipant.fromAuthorative(testParticipant); + + return testJpaParticipant; + } + + private Participant createParticipantInstance() { + Participant testParticipant = new Participant(); + testParticipant.setName("participant"); + testParticipant.setVersion("0.0.1"); + testParticipant.setDefinition(new ToscaConceptIdentifier("participantDefinitionName", "0.0.1")); + testParticipant.setParticipantType(new ToscaConceptIdentifier("participantTypeName", "0.0.1")); + + return testParticipant; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/PojosTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/PojosTest.java new file mode 100644 index 000000000..1f40fae5f --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/PojosTest.java @@ -0,0 +1,62 @@ +/*- + * ============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.models.acm.persistence.concepts; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.impl.PojoClassFactory; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.EqualsAndHashCodeMatchRule; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.NoPublicFieldsExceptStaticFinalRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import java.util.List; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.test.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + */ +class PojosTest { + + @Test + void testPojos() { + List pojoClasses = + PojoClassFactory.getPojoClasses(PojosTest.class.getPackageName()); + + // @formatter:off + final Validator validator = ValidatorBuilder + .create() + .with(new SetterMustExistRule()) + .with(new GetterMustExistRule()) + .with(new EqualsAndHashCodeMatchRule()) + .with(new NoPublicFieldsExceptStaticFinalRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .with(new ToStringTester()) + .build(); + + validator.validate(pojoClasses); + // @formatter:on + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java new file mode 100644 index 000000000..15d1d845d --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AcElementStatisticsProviderTest.java @@ -0,0 +1,116 @@ +/*- + * ============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.models.acm.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.time.Instant; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatistics; +import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAcElementStatistics; +import org.onap.policy.clamp.models.acm.persistence.repository.AcElementStatisticsRepository; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class AcElementStatisticsProviderTest { + private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; + private static final Coder CODER = new StandardCoder(); + private static final String AC_ELEMENT_STATS_JSON = "src/test/resources/providers/TestAcElementStatistics.json"; + + private AcElementStatisticsProvider acElementStatisticsProvider; + private AcElementStatisticsList inputAcElementStats; + private String originalJson = ResourceUtils.getResourceAsString(AC_ELEMENT_STATS_JSON); + + /** + * Set up test AcElement statistics provider. + * + * @throws Exception on errors + */ + @BeforeEach + void beforeSetupDao() throws Exception { + + inputAcElementStats = CODER.decode(originalJson, AcElementStatisticsList.class); + var acElementStatisticsRepository = mock(AcElementStatisticsRepository.class); + + var jpaAcElementStatisticsList = + ProviderUtils.getJpaAndValidateList(inputAcElementStats.getAcElementStatistics(), + JpaAcElementStatistics::new, "automation composition element statistics"); + + for (var acElementStat : jpaAcElementStatisticsList) { + when(acElementStatisticsRepository.getById(eq(acElementStat.getKey()))).thenReturn(acElementStat); + when(acElementStatisticsRepository.findAllById(eq(List.of(acElementStat.getKey())))) + .thenReturn(List.of(acElementStat)); + } + + when(acElementStatisticsRepository.saveAll(anyList())).thenReturn(jpaAcElementStatisticsList); + + when(acElementStatisticsRepository.getFiltered(eq(JpaAcElementStatistics.class), any())) + .thenReturn(List.of(jpaAcElementStatisticsList.get(0))); + + acElementStatisticsProvider = new AcElementStatisticsProvider(acElementStatisticsRepository); + } + + @Test + void testAcElementStatisticsCreate() throws Exception { + assertThatThrownBy(() -> { + acElementStatisticsProvider.createAcElementStatistics(null); + }).hasMessageMatching(LIST_IS_NULL); + + AcElementStatisticsList createdAcElementStats = new AcElementStatisticsList(); + createdAcElementStats.setAcElementStatistics( + acElementStatisticsProvider.createAcElementStatistics(inputAcElementStats.getAcElementStatistics())); + + assertEquals(inputAcElementStats.toString().replaceAll("\\s+", ""), + createdAcElementStats.toString().replaceAll("\\s+", "")); + } + + @Test + void testGetAcElementStatistics() throws Exception { + + List getResponse; + + // Return empty list when no data present in db + getResponse = acElementStatisticsProvider.getAcElementStatistics(null, null, null, null); + assertThat(getResponse).isEmpty(); + + acElementStatisticsProvider.createAcElementStatistics(inputAcElementStats.getAcElementStatistics()); + ToscaConceptIdentifier identifier = inputAcElementStats.getAcElementStatistics().get(0).getParticipantId(); + Instant instant = inputAcElementStats.getAcElementStatistics().get(0).getTimeStamp(); + String id = inputAcElementStats.getAcElementStatistics().get(0).getId().toString(); + assertEquals(1, acElementStatisticsProvider + .getAcElementStatistics(identifier.getName(), identifier.getVersion(), id, instant).size()); + + assertEquals(1, acElementStatisticsProvider + .getFilteredAcElementStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java new file mode 100644 index 000000000..0a367eed8 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProviderTest.java @@ -0,0 +1,305 @@ +/*- + * ============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.models.acm.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +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.Optional; +import javax.persistence.EntityNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; +import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplateRepository; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaNodeTemplatesRepository; +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.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaNodeTemplate; + +class AutomationCompositionProviderTest { + + private static final String LIST_IS_NULL = "automationCompositions is marked .*ull but is null"; + private static final String OBJECT_IS_NULL = "automationComposition is marked non-null but is null"; + + private static final String ID_NAME = "PMSHInstance1"; + private static final String ID_VERSION = "1.0.1"; + private static final String ID_NAME_NOT_EXTST = "not_exist"; + private static final String ID_NAME_NOT_VALID = "not_valid"; + + private static final Coder CODER = new StandardCoder(); + private static final String AUTOMATION_COMPOSITION_JSON = + "src/test/resources/providers/TestAutomationCompositions.json"; + private static final String TOSCA_TEMPLATE_YAML = "examples/acm/PMSubscriptionHandling.yaml"; + + private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); + + private AutomationCompositions inputAutomationCompositions; + private List inputAutomationCompositionsJpa; + private String originalJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON); + + @BeforeEach + void beforeSetupDao() throws Exception { + inputAutomationCompositions = CODER.decode(originalJson, AutomationCompositions.class); + inputAutomationCompositionsJpa = + ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(), + JpaAutomationComposition::new, "automation compositions"); + } + + @Test + void testAutomationCompositionsSave() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + assertThatThrownBy(() -> { + automationCompositionProvider.saveAutomationCompositions(null); + }).hasMessageMatching(LIST_IS_NULL); + + when(automationCompositionRepository.saveAll(inputAutomationCompositionsJpa)) + .thenReturn(inputAutomationCompositionsJpa); + + var createdAutomationCompositions = new AutomationCompositions(); + createdAutomationCompositions.setAutomationCompositionList(automationCompositionProvider + .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList())); + + assertEquals(inputAutomationCompositions, createdAutomationCompositions); + + when(automationCompositionRepository.saveAll(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider + .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()); + }).hasMessageMatching("Error in save AutomationCompositions"); + } + + @Test + void testAutomationCompositionSave() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + assertThatThrownBy(() -> { + automationCompositionProvider.saveAutomationComposition(null); + }).hasMessageMatching(OBJECT_IS_NULL); + + when(automationCompositionRepository.save(inputAutomationCompositionsJpa.get(0))) + .thenReturn(inputAutomationCompositionsJpa.get(0)); + + var createdAutomationComposition = automationCompositionProvider + .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0)); + + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(0), createdAutomationComposition); + + when(automationCompositionRepository.save(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider + .saveAutomationComposition(inputAutomationCompositions.getAutomationCompositionList().get(0)); + }).hasMessageMatching("Error in save automationComposition"); + } + + @Test + void testGetAutomationCompositions() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + // Return empty list when no data present in db + List getResponse = automationCompositionProvider.getAutomationCompositions(); + assertThat(getResponse).isEmpty(); + + automationCompositionProvider + .saveAutomationCompositions(inputAutomationCompositions.getAutomationCompositionList()); + + var automationComposition0 = inputAutomationCompositions.getAutomationCompositionList().get(1); + var name = automationComposition0.getName(); + var version = automationComposition0.getVersion(); + var automationComposition1 = inputAutomationCompositions.getAutomationCompositionList().get(1); + + when(automationCompositionRepository.getFiltered(eq(JpaAutomationComposition.class), any(), any())) + .thenReturn(List.of(new JpaAutomationComposition(automationComposition0), + new JpaAutomationComposition(automationComposition1))); + when(automationCompositionRepository.findById(automationComposition0.getKey().asIdentifier().asConceptKey())) + .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition0))); + when(automationCompositionRepository.getById(automationComposition0.getKey().asIdentifier().asConceptKey())) + .thenReturn(new JpaAutomationComposition(automationComposition0)); + when(automationCompositionRepository.getFiltered(JpaAutomationComposition.class, name, version)) + .thenReturn(List.of(new JpaAutomationComposition(automationComposition0))); + when(automationCompositionRepository.findById(automationComposition1.getKey().asIdentifier().asConceptKey())) + .thenReturn(Optional.of(new JpaAutomationComposition(automationComposition1))); + + assertEquals(1, automationCompositionProvider.getAutomationCompositions(name, version).size()); + + var ac = automationCompositionProvider + .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)).get(); + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac); + + ac = automationCompositionProvider.getAutomationComposition(new ToscaConceptIdentifier(ID_NAME, ID_VERSION)); + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac); + + when(automationCompositionRepository.getById(any())).thenThrow(EntityNotFoundException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider + .getAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION)); + }).hasMessageMatching("AutomationComposition not found"); + + ac = automationCompositionProvider.findAutomationComposition(ID_NAME, ID_VERSION).get(); + assertEquals(inputAutomationCompositions.getAutomationCompositionList().get(1), ac); + + assertThat(automationCompositionProvider + .findAutomationComposition(new ToscaConceptIdentifier(ID_NAME_NOT_EXTST, ID_VERSION))).isEmpty(); + + when(automationCompositionRepository.findById(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + automationCompositionProvider.findAutomationComposition(ID_NAME_NOT_VALID, ID_VERSION); + }).hasMessageMatching("Not valid parameter"); + } + + @Test + void testDeleteAutomationComposition() throws Exception { + var automationCompositionRepository = mock(AutomationCompositionRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository, + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + + assertThatThrownBy(() -> { + automationCompositionProvider.deleteAutomationComposition(ID_NAME_NOT_EXTST, ID_VERSION); + }).hasMessageMatching(".*.failed, automation composition does not exist"); + + var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0); + var name = automationComposition.getName(); + var version = automationComposition.getVersion(); + + when(automationCompositionRepository.findById(new PfConceptKey(name, version))) + .thenReturn(Optional.of(inputAutomationCompositionsJpa.get(0))); + + AutomationComposition deletedAc = automationCompositionProvider.deleteAutomationComposition(name, version); + assertEquals(automationComposition, deletedAc); + } + + @Test + void testDeleteAllInstanceProperties() throws Exception { + var automationCompositionProvider = + new AutomationCompositionProvider(mock(AutomationCompositionRepository.class), + mock(ToscaNodeTemplateRepository.class), mock(ToscaNodeTemplatesRepository.class)); + var toscaServiceTemplate = testAutomationCompositionRead(); + automationCompositionProvider.deleteInstanceProperties( + automationCompositionProvider.saveInstanceProperties(toscaServiceTemplate), + automationCompositionProvider.getAllNodeTemplates()); + assertThat(automationCompositionProvider.getAutomationCompositions()).isEmpty(); + } + + @Test + void testSaveAndDeleteInstanceProperties() throws Exception { + var toscaNodeTemplatesRepository = mock(ToscaNodeTemplatesRepository.class); + var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); + var automationCompositionProvider = new AutomationCompositionProvider( + mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository, toscaNodeTemplatesRepository); + var toscaServiceTest = testAutomationCompositionRead(); + + automationCompositionProvider.saveInstanceProperties(toscaServiceTest); + verify(toscaNodeTemplatesRepository).save(any()); + + var name = "org.onap.policy.acm.PolicyAutomationCompositionParticipant"; + var version = "2.3.1"; + var elem = toscaServiceTest.getToscaTopologyTemplate().getNodeTemplates().get(name); + when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, name, version)) + .thenReturn(List.of(new JpaToscaNodeTemplate(elem))); + + var filtered = automationCompositionProvider.getNodeTemplates(name, version); + verify(toscaNodeTemplateRepository).getFiltered(JpaToscaNodeTemplate.class, name, version); + + automationCompositionProvider + .deleteInstanceProperties(automationCompositionProvider.saveInstanceProperties(toscaServiceTest), filtered); + + verify(toscaNodeTemplateRepository).delete(any()); + } + + @Test + void testGetNodeTemplates() throws Exception { + var toscaNodeTemplateRepository = mock(ToscaNodeTemplateRepository.class); + var automationCompositionProvider = + new AutomationCompositionProvider(mock(AutomationCompositionRepository.class), toscaNodeTemplateRepository, + mock(ToscaNodeTemplatesRepository.class)); + + var toscaNodeTemplate0 = new JpaToscaNodeTemplate(new PfConceptKey(ID_NAME, ID_VERSION)); + var toscaNodeTemplate1 = new JpaToscaNodeTemplate(new PfConceptKey("PMSHInstance2", ID_VERSION)); + + when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, null, null)) + .thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); + when(toscaNodeTemplateRepository.findAll()).thenReturn(List.of(toscaNodeTemplate0, toscaNodeTemplate1)); + when(toscaNodeTemplateRepository.getFiltered(JpaToscaNodeTemplate.class, ID_NAME, ID_VERSION)) + .thenReturn(List.of(toscaNodeTemplate0)); + + // Getting all nodes + var listNodes = automationCompositionProvider.getAllNodeTemplates(); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(2); + + listNodes = automationCompositionProvider.getNodeTemplates(ID_NAME, ID_VERSION); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(1); + + listNodes = automationCompositionProvider.getAllNodeTemplates(); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(2); + + var nodeTemplateFilter = + ToscaTypedEntityFilter.builder().name(ID_NAME).version(ID_VERSION).build(); + + listNodes = automationCompositionProvider.getFilteredNodeTemplates(nodeTemplateFilter); + assertNotNull(listNodes); + assertThat(listNodes).hasSize(1); + + assertThatThrownBy(() -> { + automationCompositionProvider.getFilteredNodeTemplates(null); + }).hasMessageMatching("filter is marked non-null but is null"); + } + + private static ToscaServiceTemplate testAutomationCompositionRead() { + return testAutomationCompositionYamlSerialization(TOSCA_TEMPLATE_YAML); + } + + private static ToscaServiceTemplate testAutomationCompositionYamlSerialization( + String automationCompositionFilePath) { + var automationCompositionString = ResourceUtils.getResourceAsString(automationCompositionFilePath); + return yamlTranslator.fromYaml(automationCompositionString, ToscaServiceTemplate.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java new file mode 100644 index 000000000..f537e2cd7 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java @@ -0,0 +1,149 @@ +/*- + * ============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.models.acm.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant; +import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantRepository; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; + +class ParticipantProviderTest { + + private static final Coder CODER = new StandardCoder(); + private static final String PARTICIPANT_JSON = "src/test/resources/providers/TestParticipant.json"; + private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; + + private List inputParticipants = new ArrayList<>(); + private List jpaParticipantList; + private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON); + + @BeforeEach + void beforeSetupDao() throws Exception { + inputParticipants.add(CODER.decode(originalJson, Participant.class)); + jpaParticipantList = ProviderUtils.getJpaAndValidateList(inputParticipants, JpaParticipant::new, "participant"); + } + + @Test + void testParticipantSave() throws Exception { + var participantRepository = mock(ParticipantRepository.class); + for (var participant : jpaParticipantList) { + when(participantRepository.getById(new PfConceptKey(participant.getName(), participant.getVersion()))) + .thenReturn(participant); + } + var participantProvider = new ParticipantProvider(participantRepository); + + assertThatThrownBy(() -> { + participantProvider.saveParticipant(null); + }).hasMessageMatching(LIST_IS_NULL); + + when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0)); + + Participant savedParticipant = participantProvider.saveParticipant(inputParticipants.get(0)); + assertEquals(savedParticipant, inputParticipants.get(0)); + + when(participantRepository.save(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + participantProvider.saveParticipant(inputParticipants.get(0)); + }).hasMessageMatching("Error in save Participant"); + } + + @Test + void testGetAutomationCompositions() throws Exception { + var participantRepository = mock(ParticipantRepository.class); + var participantProvider = new ParticipantProvider(participantRepository); + + // Return empty list when no data present in db + List getResponse = participantProvider.getParticipants(null, null); + assertThat(getResponse).isEmpty(); + + String name = inputParticipants.get(0).getName(); + String version = inputParticipants.get(0).getVersion(); + when(participantRepository.getFiltered(any(), eq(name), eq(version))) + .thenReturn(List.of(jpaParticipantList.get(0))); + assertEquals(1, participantProvider.getParticipants(name, version).size()); + + assertThat(participantProvider.getParticipants("invalid_name", "1.0.1")).isEmpty(); + + assertThat(participantProvider.findParticipant("invalid_name", "1.0.1")).isEmpty(); + + when(participantRepository.findAll()).thenReturn(jpaParticipantList); + assertThat(participantProvider.getParticipants()).hasSize(inputParticipants.size()); + + when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); + + assertThatThrownBy(() -> { + participantProvider.findParticipant("notValid", "notValid"); + }).hasMessageMatching("Error in find Participant"); + + assertThatThrownBy(() -> { + participantProvider.getFilteredParticipants(null); + }).hasMessageMatching("filter is marked .*ull but is null"); + + when(participantRepository.getFiltered(eq(JpaParticipant.class), eq(null), eq(null))) + .thenReturn(jpaParticipantList); + + final ToscaTypedEntityFilter filter = ToscaTypedEntityFilter.builder() + .type("org.onap.domain.pmsh.PMSHAutomationCompositionDefinition").build(); + assertEquals(1, participantProvider.getFilteredParticipants(filter).size()); + + } + + @Test + void testDeleteParticipant() throws Exception { + var participantRepository = mock(ParticipantRepository.class); + var participantProvider = new ParticipantProvider(participantRepository); + + assertThatThrownBy(() -> { + participantProvider.deleteParticipant("Invalid_name", "1.0.1"); + }).hasMessageMatching(".*.failed, participant does not exist"); + + String name = inputParticipants.get(0).getName(); + String version = inputParticipants.get(0).getVersion(); + + when(participantRepository.findById(any())).thenReturn(Optional.of(jpaParticipantList.get(0))); + + Participant deletedParticipant = participantProvider.deleteParticipant(name, version); + assertEquals(inputParticipants.get(0), deletedParticipant); + + when(participantRepository.findById(any())).thenThrow(IllegalArgumentException.class); + assertThatThrownBy(() -> { + participantProvider.deleteParticipant(name, version); + }).hasMessageMatching("Error in delete Participant"); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java new file mode 100644 index 000000000..3c6b1eb83 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantStatisticsProviderTest.java @@ -0,0 +1,107 @@ +/*- + * ============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.models.acm.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.time.Instant; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics; +import org.onap.policy.clamp.models.acm.concepts.ParticipantStatisticsList; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics; +import org.onap.policy.clamp.models.acm.persistence.repository.ParticipantStatisticsRepository; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantStatisticsProviderTest { + + private static final String LIST_IS_NULL = ".*. is marked .*ull but is null"; + private static final Coder CODER = new StandardCoder(); + private static final String PARTICIPANT_STATS_JSON = "src/test/resources/providers/TestParticipantStatistics.json"; + + private ParticipantStatisticsProvider participantStatisticsProvider; + private ParticipantStatisticsList inputParticipantStatistics; + private String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_STATS_JSON); + + @BeforeEach + void beforeSetupDao() throws Exception { + var participantStatisticsRepository = mock(ParticipantStatisticsRepository.class); + participantStatisticsProvider = new ParticipantStatisticsProvider(participantStatisticsRepository); + inputParticipantStatistics = CODER.decode(originalJson, ParticipantStatisticsList.class); + + var jpaParticipantStatisticsList = + ProviderUtils.getJpaAndValidateList(inputParticipantStatistics.getStatisticsList(), + JpaParticipantStatistics::new, "Participant Statistics"); + + for (var participantStat : jpaParticipantStatisticsList) { + when(participantStatisticsRepository.getById(eq(participantStat.getKey()))).thenReturn(participantStat); + when(participantStatisticsRepository.findAllById(eq(List.of(participantStat.getKey())))) + .thenReturn(List.of(participantStat)); + } + + when(participantStatisticsRepository.getFiltered(eq(JpaParticipantStatistics.class), any())) + .thenReturn(List.of(jpaParticipantStatisticsList.get(0))); + + when(participantStatisticsRepository.saveAll(anyList())).thenReturn(jpaParticipantStatisticsList); + } + + @Test + void testParticipantStatisticsCreate() throws Exception { + assertThatThrownBy(() -> { + participantStatisticsProvider.createParticipantStatistics(null); + }).hasMessageMatching(LIST_IS_NULL); + + ParticipantStatisticsList createdStatsList = new ParticipantStatisticsList(); + createdStatsList.setStatisticsList(participantStatisticsProvider + .createParticipantStatistics(inputParticipantStatistics.getStatisticsList())); + + assertEquals(inputParticipantStatistics.toString().replaceAll("\\s+", ""), + createdStatsList.toString().replaceAll("\\s+", "")); + } + + @Test + void testGetAutomationCompositions() throws Exception { + // Return empty list when no data present in db + List getResponse = + participantStatisticsProvider.getParticipantStatistics(null, null, null); + assertThat(getResponse).isEmpty(); + + participantStatisticsProvider.createParticipantStatistics(inputParticipantStatistics.getStatisticsList()); + ToscaConceptIdentifier identifier = inputParticipantStatistics.getStatisticsList().get(0).getParticipantId(); + Instant instant = inputParticipantStatistics.getStatisticsList().get(0).getTimeStamp(); + assertEquals(1, participantStatisticsProvider + .getParticipantStatistics(identifier.getName(), identifier.getVersion(), instant).size()); + + assertEquals(1, participantStatisticsProvider + .getFilteredParticipantStatistics("name2", "1.0.1", null, null, null, "DESC", 1).size()); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java new file mode 100644 index 000000000..4d998717e --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ServiceTemplateProviderTest.java @@ -0,0 +1,169 @@ +/*- + * ============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.models.acm.persistence.provider; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.persistence.repository.ToscaServiceTemplateRepository; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardYamlCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; + +class ServiceTemplateProviderTest { + + private static final String TOSCA_SERVICE_TEMPLATE_YAML = + "src/test/resources/providers/tosca-for-smoke-testing.yaml"; + + private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder(); + + private static ToscaServiceTemplate inputServiceTemplate; + + @BeforeAll + static void loadServiceTemplate() { + inputServiceTemplate = getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); + } + + @Test + void testGetCommonOrInstancePropertiesFromNodeTypes() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + + var result = serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); + assertNotNull(result); + assertThat(result).hasSize(8); + } + + @Test + void testGetDerivedCommonOrInstanceNodeTemplates() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + + var commonOrInstanceNodeTypeProps = + serviceTemplateProvider.getCommonOrInstancePropertiesFromNodeTypes(true, inputServiceTemplate); + + var result = serviceTemplateProvider.getDerivedCommonOrInstanceNodeTemplates( + inputServiceTemplate.getToscaTopologyTemplate().getNodeTemplates(), commonOrInstanceNodeTypeProps); + + assertNotNull(result); + assertThat(result).hasSize(8); + } + + @Test + void testCreateServiceTemplate() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + when(serviceTemplateRepository.save(jpaServiceTemplate)).thenReturn(jpaServiceTemplate); + + var result = serviceTemplateProvider.createServiceTemplate(inputServiceTemplate); + + assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + @Test + void testDeleteServiceTemplate() throws PfModelException { + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository + .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) + .thenReturn(Optional.of(jpaServiceTemplate)); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + var result = serviceTemplateProvider.deleteServiceTemplate(inputServiceTemplate.getName(), + inputServiceTemplate.getVersion()); + + assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + @Test + void testGetServiceTemplateListEmpty() throws PfModelException { + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository.findById(any())).thenReturn(Optional.empty()); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + assertThatThrownBy(() -> serviceTemplateProvider.getToscaServiceTemplate("Name", "1.0.0")) + .hasMessage("Automation composition definitions not found"); + } + + @Test + void testGetServiceTemplateList() throws PfModelException { + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository + .findById(new PfConceptKey(inputServiceTemplate.getName(), inputServiceTemplate.getVersion()))) + .thenReturn(Optional.of(jpaServiceTemplate)); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + var result = serviceTemplateProvider.getToscaServiceTemplate(inputServiceTemplate.getName(), + inputServiceTemplate.getVersion()); + + assertThat(result).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + @Test + void testGetServiceTemplate() throws PfModelException { + var jpaServiceTemplate = ProviderUtils.getJpaAndValidate(inputServiceTemplate, JpaToscaServiceTemplate::new, + "toscaServiceTemplate"); + var serviceTemplateRepository = mock(ToscaServiceTemplateRepository.class); + when(serviceTemplateRepository.getFiltered(JpaToscaServiceTemplate.class, inputServiceTemplate.getName(), + inputServiceTemplate.getVersion())).thenReturn(List.of(jpaServiceTemplate)); + + var serviceTemplateProvider = new ServiceTemplateProvider(serviceTemplateRepository); + var result = serviceTemplateProvider.getServiceTemplateList(inputServiceTemplate.getName(), + inputServiceTemplate.getVersion()); + + assertThat(result).hasSize(1); + assertThat(result.get(0)).isEqualTo(jpaServiceTemplate.toAuthorative()); + } + + /** + * Get ToscaServiceTemplate from resource. + * + * @param path path of the resource + */ + public static ToscaServiceTemplate getToscaServiceTemplate(String path) { + + try { + return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class); + } catch (CoderException e) { + fail("Cannot read or decode " + path); + return null; + } + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java new file mode 100644 index 000000000..7210a6afd --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/repository/FilterRepositoryImplTest.java @@ -0,0 +1,109 @@ +/*- + * ============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.models.acm.persistence.repository; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; +import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition; +import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.dao.PfDao; +import org.onap.policy.models.dao.PfFilterParameters; +import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.provider.impl.ModelsProvider; + +class FilterRepositoryImplTest { + private static final String AUTOMATION_COMPOSITION_JSON = + "src/test/resources/providers/TestAutomationCompositions.json"; + private static final Coder CODER = new StandardCoder(); + private static final AtomicInteger dbNameCounter = new AtomicInteger(); + private static final String originalJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON); + private static List jpaAutomationCompositions; + private PfDao pfDao; + + @BeforeEach + void beforeSetupDao() throws Exception { + var parameters = new PolicyModelsProviderParameters(); + parameters.setDatabaseDriver("org.h2.Driver"); + parameters.setName("PolicyProviderParameterGroup"); + parameters.setImplementation("org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl"); + parameters.setDatabaseUrl("jdbc:h2:mem:automationCompositionProviderTestDb" + dbNameCounter.getAndDecrement()); + parameters.setDatabaseUser("policy"); + parameters.setDatabasePassword("P01icY"); + parameters.setPersistenceUnit("ToscaConceptTest"); + + pfDao = ModelsProvider.init(parameters); + var inputAutomationCompositions = CODER.decode(originalJson, AutomationCompositions.class); + jpaAutomationCompositions = + ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(), + JpaAutomationComposition::new, "AutomationCompositions"); + + pfDao.createCollection(jpaAutomationCompositions); + } + + @Test + void testGetPfDao() { + assertThat(new FilterRepositoryImpl().getPfDao()).isNotNull(); + } + + @Test + void testGetFilteredParams() { + var filterRepositoryImpl = new FilterRepositoryImpl() { + @Override + protected PfDao getPfDao() { + return pfDao; + } + }; + var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, null, null); + assertThat(result).hasSize(2); + + result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, + jpaAutomationCompositions.get(0).getName(), null); + assertThat(result).hasSize(1); + } + + @Test + void testGetFiltered() { + var filterRepositoryImpl = new FilterRepositoryImpl() { + @Override + protected PfDao getPfDao() { + return pfDao; + } + }; + + // @formatter:off + PfFilterParameters filterParams = PfFilterParameters + .builder() + .name(jpaAutomationCompositions.get(0).getName()) + .build(); + // @formatter:on + + var result = filterRepositoryImpl.getFiltered(JpaAutomationComposition.class, filterParams); + assertThat(result).hasSize(1); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java new file mode 100644 index 000000000..a62f78ba2 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java @@ -0,0 +1,54 @@ +/*- + * ============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.models.acm.rest; + +import static org.assertj.core.api.Assertions.assertThat; + +import javax.ws.rs.core.Response.Status; +import org.junit.jupiter.api.Test; +import org.onap.policy.models.errors.concepts.ErrorResponse; +import org.onap.policy.models.errors.concepts.ErrorResponseInfo; + +class RestUtilsTest { + + private static final String MESSAGE_ERROR = "Erorr"; + private static final Status STATUS_ERROR = Status.BAD_REQUEST; + + @Test + void testToSimpleResponse() { + var ex = new ErrorResponseInfo() { + + @Override + public ErrorResponse getErrorResponse() { + var er = new ErrorResponse(); + er.setErrorMessage(MESSAGE_ERROR); + er.setResponseCode(STATUS_ERROR); + return er; + } + }; + + var response = RestUtils.toSimpleResponse(ex); + + assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode()); + assertThat(response.getBody()).isNotNull(); + assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java new file mode 100644 index 000000000..a5434240a --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/AcmUtilsTest.java @@ -0,0 +1,149 @@ +/*- + * ============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.models.acm.utils; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; + +class AcmUtilsTest { + + private ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.0.0"); + private ToscaConceptIdentifier idNode = + new ToscaConceptIdentifier("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", "0.0.0"); + + @Test + void testCommonUtilsParticipantUpdate() { + var acElement = new AutomationCompositionElement(); + List participantUpdates = new ArrayList<>(); + assertThat(participantUpdates).isEmpty(); + + AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); + assertThat(participantUpdates).isNotEmpty(); + assertEquals(acElement, participantUpdates.get(0).getAutomationCompositionElementList().get(0)); + + AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); + assertNotEquals(id, participantUpdates.get(0).getParticipantId()); + + acElement.setParticipantId(id); + acElement.setParticipantType(id); + AcmUtils.prepareParticipantUpdate(acElement, participantUpdates); + assertEquals(id, participantUpdates.get(1).getParticipantId()); + } + + @Test + void testCommonUtilsServiceTemplate() { + var acElement = new AutomationCompositionElement(); + var toscaServiceTemplate = getDummyToscaServiceTemplate(); + AcmUtils.setServiceTemplatePolicyInfo(acElement, toscaServiceTemplate); + assertEquals(getDummyToscaDataTypeMap(), acElement.getToscaServiceTemplateFragment().getDataTypes()); + } + + @Test + void testCommonUtilsDefinitionUpdate() { + var toscaServiceTemplate = getDummyToscaServiceTemplate(); + List participantDefinitionUpdates = new ArrayList<>(); + assertThat(participantDefinitionUpdates).isEmpty(); + + checkParticipantDefinitionUpdate(toscaServiceTemplate, participantDefinitionUpdates); + assertThat(participantDefinitionUpdates).isNotEmpty(); + assertEquals(id, participantDefinitionUpdates.get(0).getParticipantType()); + + checkParticipantDefinitionUpdate(toscaServiceTemplate, participantDefinitionUpdates); + assertEquals(idNode, participantDefinitionUpdates.get(0).getAutomationCompositionElementDefinitionList().get(0) + .getAcElementDefinitionId()); + } + + private ToscaServiceTemplate getDummyToscaServiceTemplate() { + var toscaServiceTemplate = new ToscaServiceTemplate(); + var policyTypes = getDummyPolicyTypesMap(); + toscaServiceTemplate.setPolicyTypes(policyTypes); + + var dataTypes = getDummyToscaDataTypeMap(); + dataTypes.put("onap.datatypes.ToscaConceptIdentifier", new ToscaDataType()); + toscaServiceTemplate.setDataTypes(dataTypes); + + var toscaTopologyTemplate = new ToscaTopologyTemplate(); + Map policy = new HashMap<>(); + toscaTopologyTemplate.setPolicies(List.of(policy)); + var nodeTemplates = getDummyNodeTemplates(); + toscaTopologyTemplate.setNodeTemplates(nodeTemplates); + + toscaServiceTemplate.setToscaTopologyTemplate(toscaTopologyTemplate); + toscaServiceTemplate.setDerivedFrom("tosca.nodetypes.Root"); + toscaServiceTemplate.setDescription("description"); + toscaServiceTemplate.setMetadata(null); + toscaServiceTemplate.setName("name"); + toscaServiceTemplate.setToscaDefinitionsVersion("1.0.0"); + toscaServiceTemplate.setVersion("1.0.1"); + return toscaServiceTemplate; + } + + private Map getDummyPolicyTypesMap() { + Map policyTypes = new HashMap<>(); + policyTypes.put("onap.policies.Match", new ToscaPolicyType()); + return policyTypes; + } + + private Map getDummyToscaDataTypeMap() { + Map dataTypes = new HashMap<>(); + dataTypes.put("onap.datatypes.ToscaConceptIdentifier", new ToscaDataType()); + return dataTypes; + } + + private Map getDummyNodeTemplates() { + Map nodeTemplates = new HashMap<>(); + var nodeTemplate = new ToscaNodeTemplate(); + nodeTemplate.setType("org.onap.policy.clamp.acm.AutomationCompositionElement"); + nodeTemplates.put("org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", nodeTemplate); + return nodeTemplates; + } + + private void checkParticipantDefinitionUpdate(ToscaServiceTemplate toscaServiceTemplate, + List participantDefinitionUpdates) { + + for (Map.Entry toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate() + .getNodeTemplates().entrySet()) { + if (ParticipantUtils.checkIfNodeTemplateIsAutomationCompositionElement(toscaInputEntry.getValue(), + toscaServiceTemplate)) { + AcmUtils.prepareParticipantDefinitionUpdate(id, toscaInputEntry.getKey(), toscaInputEntry.getValue(), + participantDefinitionUpdates, null); + } + } + } +} diff --git a/models/src/test/resources/META-INF/persistence.xml b/models/src/test/resources/META-INF/persistence.xml index 54495a2fe..9bd136229 100644 --- a/models/src/test/resources/META-INF/persistence.xml +++ b/models/src/test/resources/META-INF/persistence.xml @@ -52,11 +52,11 @@ org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger - org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoop - org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaControlLoopElement - org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipant - org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaParticipantStatistics - org.onap.policy.clamp.controlloop.models.controlloop.persistence.concepts.JpaClElementStatistics + org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition + org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement + org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant + org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipantStatistics + org.onap.policy.clamp.models.acm.persistence.concepts.JpaClElementStatistics diff --git a/models/src/test/resources/examples/acm/PMSubscriptionHandling.yaml b/models/src/test/resources/examples/acm/PMSubscriptionHandling.yaml new file mode 100644 index 000000000..c8796ac49 --- /dev/null +++ b/models/src/test/resources/examples/acm/PMSubscriptionHandling.yaml @@ -0,0 +1,3325 @@ +# ============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========================================================= +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 + org.onap.datatypes.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElementConsulInfo: + name: org.onap.datatypes.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElementConsulInfo + version: 0.0.0 + derived_from: tosca.datatypes.Root + properties: + consulUrl: + name: consulUrl + type: string + typeVersion: 0.0.0 + description: Consul url for this entry + required: true + consul_body: + name: consulBody + type: string + typeVersion: 0.0.0 + description: Body of Consul entry + required: true + 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: {} +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.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: {} +node_types: + org.onap.policy.clamp.acm.Participant: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + required: false + org.onap.policy.clamp.acm.AutomationCompositionElement: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + required: false + participantType: + type: onap.datatypes.ToscaConceptIdentifier + required: true + startPhase: + type: integer + required: false + constraints: + - greater-or-equal: 0 + metadata: + common: true + description: A value indicating the start phase in which this automation composition element will be started, + the first start phase is zero. Automation composition elements are started in their start_phase + order and stopped in reverse start phase order. Automation composition elements with the same start + phase are started and stopped simultaneously + org.onap.policy.clamp.acm.AutomationComposition: + version: 1.0.1 + derived_from: tosca.nodetypes.Root + properties: + provider: + type: string + required: false + elements: + type: list + required: true + entry_schema: + type: onap.datatypes.ToscaConceptIdentifier + org.onap.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement + properties: + dcae_blueprint_id: + type: onap.datatypes.ToscaConceptIdentifier + required: false + dcae_blueprint: + type: onap.dcae.cloudify_blueprint + required: false + consul_info: + type: list + required: false + entry_schema: + type: org.onap.datatypes.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElementConsulInfo + org.onap.policy.clamp.acm.PolicyAutomationCompositionElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement + properties: + policy_type_id: + type: onap.datatypes.ToscaConceptIdentifier + required: true + policy_id: + type: onap.datatypes.ToscaConceptIdentifier + required: false + org.onap.policy.clamp.acm.CDSAutomationCompositionElement: + version: 1.0.1 + derived_from: org.onap.policy.clamp.acm.AutomationCompositionElement + properties: + cds_blueprint_id: + type: onap.datatypes.ToscaConceptIdentifier + required: true +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.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant: + version: 2.3.4 + type: org.onap.policy.clamp.acm.Participant + type_version: 1.0.1 + description: Participant for DCAE microservices + properties: + provider: ONAP + org.onap.policy.acm.PolicyAutomationCompositionParticipant: + version: 2.3.1 + type: org.onap.policy.clamp.acm.Participant + type_version: 1.0.1 + description: Participant for DCAE microservices + properties: + provider: ONAP + org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant: + version: 2.2.1 + type: org.onap.policy.clamp.acm.Participant + type_version: 1.0.1 + description: Participant for DCAE microservices + properties: + provider: ONAP + org.onap.domain.pmsh.PMSH_DCAEMicroservice: + version: 1.2.3 + type: org.onap.policy.clamp.acm.DCAEMicroserviceAutomationCompositionElement + type_version: 1.0.0 + description: Automation composition element for the DCAE microservice for Performance Management Subscription Handling + properties: + provider: Ericsson + participantType: + name: org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant + version: 2.3.4 + dcae_blueprint: + tosca_definitions_version: cloudify_dsl_1_3 + imports: + - https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml + - plugin:k8splugin?version=3.7.0 + - plugin:pgaas?version=1.3.0 + - plugin:clamppolicyplugin?version=1.1.0 + inputs: + tag_version: + type: string + description: Docker image to be used + default: nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.pmsh:1.1.2 + replicas: + type: integer + description: Number of instances + default: 1 + operational_policy_name: + type: string + default: operational.apex.pmcontrol + control_loop_name: + type: string + default: pmsh-control-loop + pmsh_publish_topic_name: + type: string + default: unauthenticated.DCAE_CL_OUTPUT + policy_feedback_topic_name: + type: string + default: unauthenticated.PMSH_CL_INPUT + aai_notification_topic_name: + type: string + default: AAI-EVENT + publisher_client_role: + type: string + description: Client role to request secure access to topic + default: org.onap.dcae.pmPublisher + subscriber_client_role: + type: string + description: Client role to request secure access to topic + default: org.onap.dcae.pmSubscriber + dcae_location: + type: string + description: DCAE location for the subscriber, used to set up routing + default: san-francisco + cpu_limit: + type: string + default: 1000m + cpu_request: + type: string + default: 1000m + memory_limit: + type: string + default: 1024Mi + memory_request: + type: string + default: 1024Mi + pgaas_cluster_name: + type: string + default: dcae-pg-primary.onap + enable_tls: + type: boolean + default: true + protocol: + type: string + description: PMSH protocol. If enable_tls is false, set to http + default: https + policy_model_id: + type: string + default: onap.policies.monitoring.dcae-pm-subscription-handler + policy_id: + type: string + default: MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test + node_templates: + pgaasvm: + type: dcae.nodes.pgaas.database + properties: + writerfqdn: + get_input: pgaas_cluster_name + name: pmsh + pmsh: + type: dcae.nodes.ContainerizedServiceComponentUsingDmaap + interfaces: + cloudify.interfaces.lifecycle: + create: + inputs: + ports: + - '8443:0' + envs: + PMSH_PG_URL: + get_attribute: + - pgaasvm + - admin + - host + PMSH_PG_PASSWORD: + get_attribute: + - pgaasvm + - admin + - password + PMSH_PG_USERNAME: + get_attribute: + - pgaasvm + - admin + - user + PMSH_DB_NAME: + get_attribute: + - pgaasvm + - admin + - database + relationships: + - target: pmsh-policy + type: cloudify.relationships.depends_on + properties: + service_component_type: dcae-pmsh + service_component_name_override: dcae-pmsh + application_config: + enable_tls: + get_input: enable_tls + aaf_identity: dcae@dcae.onap.org + aaf_password: demo123456! + operational_policy_name: + get_input: operational_policy_name + control_loop_name: + get_input: control_loop_name + 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 + streams_publishes: + policy_pm_publisher: + type: message_router + dmaap_info: + topic_url: + concat: + - http://message-router:3904/events/ + - get_input: pmsh_publish_topic_name + streams_subscribes: + policy_pm_subscriber: + type: message_router + dmaap_info: + topic_url: + concat: + - http://message-router:3904/events/ + - get_input: policy_feedback_topic_name + aai_subscriber: + type: message_router + dmaap_info: + topic_url: + concat: + - http://message-router:3904/events/ + - get_input: aai_notification_topic_name + resource_config: + limits: + cpu: + get_input: cpu_limit + memory: + get_input: memory_limit + requests: + cpu: + get_input: cpu_request + memory: + get_input: memory_request + docker_config: + healthcheck: + endpoint: /healthcheck + interval: 15s + timeout: 1s + type: + get_input: protocol + image: + get_input: tag_version + replicas: + get_input: replicas + log_info: + log_directory: /var/log/ONAP/dcaegen2/services/pmsh + tls_info: + cert_directory: /opt/app/pmsh/etc/certs + use_tls: + get_input: enable_tls + pmsh-policy: + type: clamp.nodes.policy + properties: + policy_model_id: + get_input: policy_model_id + policy_id: + get_input: policy_id + consul_info: + - consulUrl: http://consul:31321/v1/kv/dcae-pmsh:policy + consulBody: + subscription: + subscriptionName: subscriptiona + administrativeState: UNLOCKED + fileBasedGP: 15 + fileLocation: /pm/pm.xml + nfFilter: + nfNames: + - ^pnf1.* + modelInvariantIDs: + - 5845y423-g654-6fju-po78-8n53154532k6 + - 7129e420-d396-4efb-af02-6b83499b12f8 + modelVersionIDs: + - e80a6ae3-cafd-4d24-850d-e14c084a5ca9 + measurementGroups: + - measurementGroup: + measurementTypes: + - measurementType: countera + - measurementType: counterb + managedObjectDNsBasic: + - DN: dna + - DN: dnb + - measurementGroup: + measurementTypes: + - measurementType: counterc + - measurementType: counterd + managedObjectDNsBasic: + - DN: dnc + - DN: dnd + org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement: + version: 1.2.3 + type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement + type_version: 1.0.0 + description: Automation composition element for the monitoring policy for Performance Management Subscription Handling + properties: + provider: Ericsson + participantType: + name: org.onap.policy.acm.PolicyAutomationCompositionParticipant + 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_OperationalPolicyAutomationCompositionElement: + version: 1.2.3 + type: org.onap.policy.clamp.acm.PolicyAutomationCompositionElement + type_version: 1.0.0 + description: Automation composition element for the operational policy for Performance Management Subscription Handling + properties: + provider: Ericsson + participantType: + name: org.onap.policy.acm.PolicyAutomationCompositionParticipant + version: 2.2.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.PMSH_CDS_AutomationCompositionElement: + version: 1.2.3 + type: org.onap.policy.clamp.acm.CDSAutomationCompositionElement + type_version: 1.0.0 + description: Automation composition element for CDS for Performance Management Subscription Handling + properties: + provider: Ericsson + participantType: + name: org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant + version: 3.2.1 + cds_blueprint_id: + name: org.onap.ccsdk.cds.PMSHCdsBlueprint + version: 1.0.0 + org.onap.domain.pmsh.PMSHAutomationCompositionDefinition: + version: 1.2.3 + type: org.onap.policy.clamp.acm.AutomationComposition + type_version: 1.0.0 + description: Automation composition for Performance Management Subscription Handling + properties: + provider: Ericsson + elements: + - name: org.onap.domain.pmsh.PMSH_DCAEMicroservice + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement + version: 1.2.3 + - name: org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement + version: 1.2.3 + policies: + - MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test: + type: onap.policies.monitoring.dcae-pm-subscription-handler + type_version: 1.0.0 + name: MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test + version: 1.0.0 + metadata: + policy-id: MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test + policy-version: 1.0.0 + properties: + pmsh_policy: + fileBasedGP: 15 + fileLocation: /pm/pm.xml + subscriptionName: subscriptiona + administrativeState: UNLOCKED + nfFilter: + onap.datatypes.monitoring.nfFilter: + modelVersionIDs: + - e80a6ae3-cafd-4d24-850d-e14c084a5ca9 + modelInvariantIDs: + - 5845y423-g654-6fju-po78-8n53154532k6 + - 7129e420-d396-4efb-af02-6b83499b12f8 + modelNames: [] + nfNames: + - '"^pnf1.*"' + measurementGroups: + - measurementGroup: + onap.datatypes.monitoring.measurementGroup: + measurementTypes: + - measurementType: + onap.datatypes.monitoring.measurementType: + measurementType: countera + - measurementType: + onap.datatypes.monitoring.measurementType: + measurementType: counterb + managedObjectDNsBasic: + - managedObjectDNsBasic: + onap.datatypes.monitoring.managedObjectDNsBasic: + DN: dna + - managedObjectDNsBasic: + onap.datatypes.monitoring.managedObjectDNsBasic: + DN: dnb + - measurementGroup: + onap.datatypes.monitoring.measurementGroup: + measurementTypes: + - measurementType: + onap.datatypes.monitoring.measurementType: + measurementType: counterc + - measurementType: + onap.datatypes.monitoring.measurementType: + measurementType: counterd + managedObjectDNsBasic: + - managedObjectDNsBasic: + onap.datatypes.monitoring.managedObjectDNsBasic: + DN: dnc + - managedObjectDNsBasic: + onap.datatypes.monitoring.managedObjectDNsBasic: + DN: dnd + - operational.apex.pmcontrol: + type: onap.policies.acm.operational.common.Apex + type_version: 1.0.0 + version: 1.0.0 + metadata: + policy-id: operational.apex.pmcontrol + policy-version: 1 + properties: + engineServiceParameters: + name: MyApexEngine + version: 0.0.1 + id: 45 + instanceCount: 2 + deploymentPort: 12561 + policy_type_impl: + apexPolicyModel: + key: + name: PMControlPolicy + version: 0.0.1 + keyInformation: + key: + name: PMControlPolicy_KeyInfo + version: 0.0.1 + keyInfoMap: + entry: + - key: + name: CDSActionIdentifiersType + version: 0.0.1 + value: + key: + name: CDSActionIdentifiersType + version: 0.0.1 + UUID: 6e5fa19b-14df-37e3-a4ae-8c537e861a82 + description: Generated description for concept referred to by key "CDSActionIdentifiersType:0.0.1" + - key: + name: CDSCreateResponseEvent + version: 0.0.1 + value: + key: + name: CDSCreateResponseEvent + version: 0.0.1 + UUID: 14b29e38-ac75-3273-aa4e-8583c0aa7dad + description: Generated description for concept referred to by key "CDSCreateResponseEvent:0.0.1" + - key: + name: CDSCreateResponsePayloadType + version: 0.0.1 + value: + key: + name: CDSCreateResponsePayloadType + version: 0.0.1 + UUID: 04573f8f-e772-30a5-b1d9-d7318d4a1e13 + description: Generated description for concept referred to by key "CDSCreateResponsePayloadType:0.0.1" + - key: + name: CDSCreateResponsePolicy + version: 0.0.1 + value: + key: + name: CDSCreateResponsePolicy + version: 0.0.1 + UUID: e126c965-fc09-3bfe-8f55-70f380a4a49c + description: Generated description for concept referred to by key "CDSCreateResponsePolicy:0.0.1" + - key: + name: CDSCreateResponseTask + version: 0.0.1 + value: + key: + name: CDSCreateResponseTask + version: 0.0.1 + UUID: 6165ee82-afd2-3aab-a517-f00b3f2461d2 + description: Generated description for concept referred to by key "CDSCreateResponseTask:0.0.1" + - key: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + value: + key: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + UUID: 8350ac5e-c157-38b9-9614-a0f93a830e60 + description: Generated description for concept referred to by key "CDSCreateSubscriptionPayloadType:0.0.1" + - key: + name: CDSCreateSubscriptionRequestEvent + version: 0.0.1 + value: + key: + name: CDSCreateSubscriptionRequestEvent + version: 0.0.1 + UUID: cfa325ba-226b-3a31-9183-ec43e2b6e9a2 + description: Generated description for concept referred to by key "CDSCreateSubscriptionRequestEvent:0.0.1" + - key: + name: CDSDeleteResponseEvent + version: 0.0.1 + value: + key: + name: CDSDeleteResponseEvent + version: 0.0.1 + UUID: 8be9c0fa-7437-3841-aff2-b3cec6ae3bd8 + description: Generated description for concept referred to by key "CDSDeleteResponseEvent:0.0.1" + - key: + name: CDSDeleteResponsePayloadType + version: 0.0.1 + value: + key: + name: CDSDeleteResponsePayloadType + version: 0.0.1 + UUID: 3fbfe0c9-152e-34d3-a504-09cd13c058d0 + description: Generated description for concept referred to by key "CDSDeleteResponsePayloadType:0.0.1" + - key: + name: CDSDeleteResponsePolicy + version: 0.0.1 + value: + key: + name: CDSDeleteResponsePolicy + version: 0.0.1 + UUID: a780251c-edd5-3132-b865-04313246b43c + description: Generated description for concept referred to by key "CDSDeleteResponsePolicy:0.0.1" + - key: + name: CDSDeleteResponseTask + version: 0.0.1 + value: + key: + name: CDSDeleteResponseTask + version: 0.0.1 + UUID: afce4555-3aa3-3521-a7d8-ee8cdf0d3efc + description: Generated description for concept referred to by key "CDSDeleteResponseTask:0.0.1" + - key: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + value: + key: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + UUID: 12658406-9147-3c9d-a38c-5ad5e30b092b + description: Generated description for concept referred to by key "CDSDeleteSubscriptionPayloadType:0.0.1" + - key: + name: CDSDeleteSubscriptionRequestEvent + version: 0.0.1 + value: + key: + name: CDSDeleteSubscriptionRequestEvent + version: 0.0.1 + UUID: 24380c95-9289-36e6-8cbf-0edefa15ccd9 + description: Generated description for concept referred to by key "CDSDeleteSubscriptionRequestEvent:0.0.1" + - key: + name: CDSRequestCommonHeaderType + version: 0.0.1 + value: + key: + name: CDSRequestCommonHeaderType + version: 0.0.1 + UUID: 35590ac0-062c-39f1-8786-b4ff716e30b1 + description: Generated description for concept referred to by key "CDSRequestCommonHeaderType:0.0.1" + - key: + name: CDSResponseCommonHeaderType + version: 0.0.1 + value: + key: + name: CDSResponseCommonHeaderType + version: 0.0.1 + UUID: dd7e1805-885a-350b-aaf9-ed541321ae3c + description: Generated description for concept referred to by key "CDSResponseCommonHeaderType:0.0.1" + - key: + name: CDSResponseStatusEvent + version: 0.0.1 + value: + key: + name: CDSResponseStatusEvent + version: 0.0.1 + UUID: 7986e21b-32f7-302e-9554-31f21b673493 + description: Generated description for concept referred to by key "CDSResponseStatusEvent:0.0.1" + - key: + name: CDSResponseStatusType + version: 0.0.1 + value: + key: + name: CDSResponseStatusType + version: 0.0.1 + UUID: 92b8a2cf-344e-3ce1-8cc0-2b7d3cb695fa + description: Generated description for concept referred to by key "CDSResponseStatusType:0.0.1" + - key: + name: CreateSubscriptionPayloadEvent + version: 0.0.1 + value: + key: + name: CreateSubscriptionPayloadEvent + version: 0.0.1 + UUID: 92162397-1a8e-3a3f-a469-d2af7700af4a + description: Generated description for concept referred to by key "CreateSubscriptionPayloadEvent:0.0.1" + - key: + name: CreateSubscriptionPayloadTask + version: 0.0.1 + value: + key: + name: CreateSubscriptionPayloadTask + version: 0.0.1 + UUID: bc0c69f0-52ed-38ea-b468-ae4a6fd1730d + description: Generated description for concept referred to by key "CreateSubscriptionPayloadTask:0.0.1" + - key: + name: CreateSubscriptionRequestTask + version: 0.0.1 + value: + key: + name: CreateSubscriptionRequestTask + version: 0.0.1 + UUID: 89cb75e9-f06c-30d3-b4ff-698d45f63869 + description: Generated description for concept referred to by key "CreateSubscriptionRequestTask:0.0.1" + - key: + name: DeleteSubscriptionPayloadEvent + version: 0.0.1 + value: + key: + name: DeleteSubscriptionPayloadEvent + version: 0.0.1 + UUID: 994fa441-04ab-33bb-832d-1cd12ab5d074 + description: Generated description for concept referred to by key "DeleteSubscriptionPayloadEvent:0.0.1" + - key: + name: DeleteSubscriptionPayloadTask + version: 0.0.1 + value: + key: + name: DeleteSubscriptionPayloadTask + version: 0.0.1 + UUID: 0f519117-5fea-3e4b-941f-8f778100465f + description: Generated description for concept referred to by key "DeleteSubscriptionPayloadTask:0.0.1" + - key: + name: DeleteSubscriptionRequestTask + version: 0.0.1 + value: + key: + name: DeleteSubscriptionRequestTask + version: 0.0.1 + UUID: acb772fe-d442-39e3-98f9-b1080caf4150 + description: Generated description for concept referred to by key "DeleteSubscriptionRequestTask:0.0.1" + - key: + name: MRResponseEvent + version: 0.0.1 + value: + key: + name: MRResponseEvent + version: 0.0.1 + UUID: 13c747a3-6bae-3bcf-9c80-b152e01dc194 + description: Generated description for concept referred to by key "MRResponseEvent:0.0.1" + - key: + name: PMControlPolicy + version: 0.0.1 + value: + key: + name: PMControlPolicy + version: 0.0.1 + UUID: acf1e55c-7bc5-3bd5-975a-0ca54afcd8a4 + description: Generated description for concept referred to by key "PMControlPolicy:0.0.1" + - key: + name: PMControlPolicy_Albums + version: 0.0.1 + value: + key: + name: PMControlPolicy_Albums + version: 0.0.1 + UUID: b38ad204-c2c8-32f4-9b5a-dda0aeb0145b + description: Generated description for concept referred to by key "PMControlPolicy_Albums:0.0.1" + - key: + name: PMControlPolicy_Events + version: 0.0.1 + value: + key: + name: PMControlPolicy_Events + version: 0.0.1 + UUID: be3871a0-c42a-3113-a066-82d192840eca + description: Generated description for concept referred to by key "PMControlPolicy_Events:0.0.1" + - key: + name: PMControlPolicy_KeyInfo + version: 0.0.1 + value: + key: + name: PMControlPolicy_KeyInfo + version: 0.0.1 + UUID: ced37634-28a4-3178-b7f6-2980794927b0 + description: Generated description for concept referred to by key "PMControlPolicy_KeyInfo:0.0.1" + - key: + name: PMControlPolicy_Policies + version: 0.0.1 + value: + key: + name: PMControlPolicy_Policies + version: 0.0.1 + UUID: be3d180d-ef9c-3a75-8e9c-84271a038bed + description: Generated description for concept referred to by key "PMControlPolicy_Policies:0.0.1" + - key: + name: PMControlPolicy_Schemas + version: 0.0.1 + value: + key: + name: PMControlPolicy_Schemas + version: 0.0.1 + UUID: e61973f1-189c-39e5-82f6-0d3afe298a20 + description: Generated description for concept referred to by key "PMControlPolicy_Schemas:0.0.1" + - key: + name: PMControlPolicy_Tasks + version: 0.0.1 + value: + key: + name: PMControlPolicy_Tasks + version: 0.0.1 + UUID: 5658adb3-2962-30a3-a241-fae75bb8eb4a + description: Generated description for concept referred to by key "PMControlPolicy_Tasks:0.0.1" + - key: + name: PMSubscriptionAlbum + version: 0.0.1 + value: + key: + name: PMSubscriptionAlbum + version: 0.0.1 + UUID: c2bd6f0d-6854-317a-9be2-97c08338428c + description: Generated description for concept referred to by key "PMSubscriptionAlbum:0.0.1" + - key: + name: PMSubscriptionOutputEvent + version: 0.0.1 + value: + key: + name: PMSubscriptionOutputEvent + version: 0.0.1 + UUID: 992b7819-9f69-3aa0-bb0f-6e45ea15ce05 + description: Generated description for concept referred to by key "PMSubscriptionOutputEvent:0.0.1" + - key: + name: PMSubscriptionType + version: 0.0.1 + value: + key: + name: PMSubscriptionType + version: 0.0.1 + UUID: 73c1c397-4fc3-357f-93b6-a8ad707fbaae + description: Generated description for concept referred to by key "PMSubscriptionType:0.0.1" + - key: + name: ReceiveEventPolicy + version: 0.0.1 + value: + key: + name: ReceiveEventPolicy + version: 0.0.1 + UUID: 568b7345-9de1-36d3-b6a3-9b857e6809a1 + description: Generated description for concept referred to by key "ReceiveEventPolicy:0.0.1" + - key: + name: ReceiveSubscriptionTask + version: 0.0.1 + value: + key: + name: ReceiveSubscriptionTask + version: 0.0.1 + UUID: f596afc8-100c-35eb-92c8-352355ea457d + description: Generated description for concept referred to by key "ReceiveSubscriptionTask:0.0.1" + - key: + name: SimpleIntType + version: 0.0.1 + value: + key: + name: SimpleIntType + version: 0.0.1 + UUID: 153791fd-ae0a-36a7-88a5-309a7936415d + description: Generated description for concept referred to by key "SimpleIntType:0.0.1" + - key: + name: SimpleStringType + version: 0.0.1 + value: + key: + name: SimpleStringType + version: 0.0.1 + UUID: 8a4957cf-9493-3a76-8c22-a208e23259af + description: Generated description for concept referred to by key "SimpleStringType:0.0.1" + - key: + name: SubscriptionStatusType + version: 0.0.1 + value: + key: + name: SubscriptionStatusType + version: 0.0.1 + UUID: 597643b1-9db1-31ce-85d0-e1c63c43b30b + description: Generated description for concept referred to by key "SubscriptionStatusType:0.0.1" + - key: + name: SubscriptionType + version: 0.0.1 + value: + key: + name: SubscriptionType + version: 0.0.1 + UUID: 184547bb-7d64-3cb2-a273-d7185102c5ce + description: Generated description for concept referred to by key "SubscriptionType:0.0.1" + - key: + name: UUIDType + version: 0.0.1 + value: + key: + name: UUIDType + version: 0.0.1 + UUID: 6a8cc68e-dfc8-3403-9c6d-071c886b319c + description: Generated description for concept referred to by key "UUIDType:0.0.1" + - key: + name: pmsh-operational-policy + version: 0.0.1 + value: + key: + name: pmsh-operational-policy + version: 0.0.1 + UUID: fdf2c9ff-6422-3ea6-b6b6-49b12116265d + description: Generated description for concept referred to by key "pmsh-operational-policy:0.0.1" + policies: + key: + name: PMControlPolicy_Policies + version: 0.0.1 + policyMap: + entry: + - key: + name: CDSCreateResponsePolicy + version: 0.0.1 + value: + policyKey: + name: CDSCreateResponsePolicy + version: 0.0.1 + template: Freestyle + state: + entry: + - key: CDSCreateResponseState + value: + stateKey: + parentKeyName: CDSCreateResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: CDSCreateResponseState + trigger: + name: CDSCreateResponseEvent + version: 0.0.1 + stateOutputs: + entry: + - key: ResponseOutput + value: + key: + parentKeyName: CDSCreateResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: CDSCreateResponseState + localName: ResponseOutput + outgoingEvent: + name: CDSResponseStatusEvent + version: 0.0.1 + nextState: + parentKeyName: 'NULL' + parentKeyVersion: 0.0.0 + parentLocalName: 'NULL' + localName: 'NULL' + contextAlbumReference: [] + taskSelectionLogic: + key: 'NULL' + logicFlavour: UNDEFINED + logic: '' + stateFinalizerLogicMap: + entry: [] + defaultTask: + name: CDSCreateResponseTask + version: 0.0.1 + taskReferences: + entry: + - key: + name: CDSCreateResponseTask + version: 0.0.1 + value: + key: + parentKeyName: CDSCreateResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: CDSCreateResponseState + localName: CDSCreateResponsePolicy + outputType: DIRECT + output: + parentKeyName: CDSCreateResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: CDSCreateResponseState + localName: ResponseOutput + firstState: CDSCreateResponseState + - key: + name: CDSDeleteResponsePolicy + version: 0.0.1 + value: + policyKey: + name: CDSDeleteResponsePolicy + version: 0.0.1 + template: Freestyle + state: + entry: + - key: CDSDeleteResponseState + value: + stateKey: + parentKeyName: CDSDeleteResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: CDSDeleteResponseState + trigger: + name: CDSDeleteResponseEvent + version: 0.0.1 + stateOutputs: + entry: + - key: ResponseOutput + value: + key: + parentKeyName: CDSDeleteResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: CDSDeleteResponseState + localName: ResponseOutput + outgoingEvent: + name: CDSResponseStatusEvent + version: 0.0.1 + nextState: + parentKeyName: 'NULL' + parentKeyVersion: 0.0.0 + parentLocalName: 'NULL' + localName: 'NULL' + contextAlbumReference: [] + taskSelectionLogic: + key: 'NULL' + logicFlavour: UNDEFINED + logic: '' + stateFinalizerLogicMap: + entry: [] + defaultTask: + name: CDSDeleteResponseTask + version: 0.0.1 + taskReferences: + entry: + - key: + name: CDSDeleteResponseTask + version: 0.0.1 + value: + key: + parentKeyName: CDSDeleteResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: CDSDeleteResponseState + localName: CDSDeleteResponsePolicy + outputType: DIRECT + output: + parentKeyName: CDSDeleteResponsePolicy + parentKeyVersion: 0.0.1 + parentLocalName: CDSDeleteResponseState + localName: ResponseOutput + firstState: CDSDeleteResponseState + - key: + name: ReceiveEventPolicy + version: 0.0.1 + value: + policyKey: + name: ReceiveEventPolicy + version: 0.0.1 + template: Freestyle + state: + entry: + - key: CreateOrDeleteState + value: + stateKey: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: CreateOrDeleteState + trigger: + name: PMSubscriptionOutputEvent + version: 0.0.1 + stateOutputs: + entry: + - key: CreateSubscriptionPayload + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateOrDeleteState + localName: CreateSubscriptionPayload + outgoingEvent: + name: CreateSubscriptionPayloadEvent + version: 0.0.1 + nextState: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: CreateSubscription + - key: DeleteSubscriptionPayload + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateOrDeleteState + localName: DeleteSubscriptionPayload + outgoingEvent: + name: DeleteSubscriptionPayloadEvent + version: 0.0.1 + nextState: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: DeleteSubscription + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskSelectionLogic: + key: TaskSelectionLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + + executor.logger.info(executor.subject.id); + + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) + var changeType = pmSubscriptionInfo.get("changeType").toString() + + executor.logger.info("Change Type is " + changeType) + + if ("CREATE".equals(changeType)) { + executor.logger.info("Choosing to create a subscription") + executor.subject.getTaskKey("CreateSubscriptionPayloadTask").copyTo(executor.selectedTask); + } + else if ("DELETE".equals(changeType)) { + executor.logger.info("Choosing to delete a subscription") + executor.subject.getTaskKey("DeleteSubscriptionPayloadTask").copyTo(executor.selectedTask); + } + + //var returnValue = executor.isTrue; + true; + stateFinalizerLogicMap: + entry: [] + defaultTask: + name: CreateSubscriptionPayloadTask + version: 0.0.1 + taskReferences: + entry: + - key: + name: CreateSubscriptionPayloadTask + version: 0.0.1 + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateOrDeleteState + localName: ReceiveEventPolicy + outputType: DIRECT + output: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateOrDeleteState + localName: CreateSubscriptionPayload + - key: + name: DeleteSubscriptionPayloadTask + version: 0.0.1 + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateOrDeleteState + localName: ReceiveEventPolicy + outputType: DIRECT + output: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateOrDeleteState + localName: DeleteSubscriptionPayload + - key: CreateSubscription + value: + stateKey: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: CreateSubscription + trigger: + name: CreateSubscriptionPayloadEvent + version: 0.0.1 + stateOutputs: + entry: + - key: IssueCreateSubscriptionRequestOutput + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateSubscription + localName: IssueCreateSubscriptionRequestOutput + outgoingEvent: + name: CDSCreateSubscriptionRequestEvent + version: 0.0.1 + nextState: + parentKeyName: 'NULL' + parentKeyVersion: 0.0.0 + parentLocalName: 'NULL' + localName: 'NULL' + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskSelectionLogic: + key: 'NULL' + logicFlavour: UNDEFINED + logic: '' + stateFinalizerLogicMap: + entry: [] + defaultTask: + name: CreateSubscriptionRequestTask + version: 0.0.1 + taskReferences: + entry: + - key: + name: CreateSubscriptionRequestTask + version: 0.0.1 + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateSubscription + localName: ReceiveEventPolicy + outputType: DIRECT + output: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: CreateSubscription + localName: IssueCreateSubscriptionRequestOutput + - key: DeleteSubscription + value: + stateKey: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: DeleteSubscription + trigger: + name: DeleteSubscriptionPayloadEvent + version: 0.0.1 + stateOutputs: + entry: + - key: IssueDeleteSubscriptionRequestOutput + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: DeleteSubscription + localName: IssueDeleteSubscriptionRequestOutput + outgoingEvent: + name: CDSDeleteSubscriptionRequestEvent + version: 0.0.1 + nextState: + parentKeyName: 'NULL' + parentKeyVersion: 0.0.0 + parentLocalName: 'NULL' + localName: 'NULL' + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskSelectionLogic: + key: 'NULL' + logicFlavour: UNDEFINED + logic: '' + stateFinalizerLogicMap: + entry: [] + defaultTask: + name: DeleteSubscriptionRequestTask + version: 0.0.1 + taskReferences: + entry: + - key: + name: DeleteSubscriptionRequestTask + version: 0.0.1 + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: DeleteSubscription + localName: ReceiveEventPolicy + outputType: DIRECT + output: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: DeleteSubscription + localName: IssueDeleteSubscriptionRequestOutput + - key: ReceiveSubscriptionState + value: + stateKey: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: ReceiveSubscriptionState + trigger: + name: pmsh-operational-policy + version: 0.0.1 + stateOutputs: + entry: + - key: ReceivePMSubscriptionOutput + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: ReceiveSubscriptionState + localName: ReceivePMSubscriptionOutput + outgoingEvent: + name: PMSubscriptionOutputEvent + version: 0.0.1 + nextState: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: 'NULL' + localName: CreateOrDeleteState + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskSelectionLogic: + key: 'NULL' + logicFlavour: UNDEFINED + logic: '' + stateFinalizerLogicMap: + entry: [] + defaultTask: + name: ReceiveSubscriptionTask + version: 0.0.1 + taskReferences: + entry: + - key: + name: ReceiveSubscriptionTask + version: 0.0.1 + value: + key: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: ReceiveSubscriptionState + localName: ReceiveEventPolicy + outputType: DIRECT + output: + parentKeyName: ReceiveEventPolicy + parentKeyVersion: 0.0.1 + parentLocalName: ReceiveSubscriptionState + localName: ReceivePMSubscriptionOutput + firstState: ReceiveSubscriptionState + tasks: + key: + name: PMControlPolicy_Tasks + version: 0.0.1 + taskMap: + entry: + - key: + name: CDSCreateResponseTask + version: 0.0.1 + value: + key: + name: CDSCreateResponseTask + version: 0.0.1 + inputFields: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSResponseCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSCreateResponsePayloadType + version: 0.0.1 + optional: false + - key: status + value: + key: status + fieldSchemaKey: + name: CDSResponseStatusType + version: 0.0.1 + optional: false + outputFields: + entry: + - key: status + value: + key: status + fieldSchemaKey: + name: SubscriptionStatusType + version: 0.0.1 + optional: false + taskParameters: + entry: [] + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskLogic: + key: TaskLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + + executor.logger.info(executor.subject.id); + + var commonHeader = executor.inFields.get("commonHeader") + var response = executor.inFields.get("payload") + var albumID = commonHeader.get("requestId") + + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString()); + var responseStatus = executor.subject.getOutFieldSchemaHelper("status").createNewInstance(); + + responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) + responseStatus.put("nfName", pmSubscriptionInfo.get("nfName")) + responseStatus.put("changeType", pmSubscriptionInfo.get("changeType")) + + var status = response.get(pmSubscriptionInfo.get("changeType").toLowerCase() + "_DasH_subscription_DasH_response").get("odl_DasH_response").get("status") + + executor.logger.info("RESPONSE STATUS = " + status) + + if(status == "success") { + responseStatus.put("message", "success") + } else { + responseStatus.put("message", "failed") + } + + executor.outFields.put("status", responseStatus) + + //var returnValue = executor.isTrue; + true; + - key: + name: CDSDeleteResponseTask + version: 0.0.1 + value: + key: + name: CDSDeleteResponseTask + version: 0.0.1 + inputFields: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSResponseCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSDeleteResponsePayloadType + version: 0.0.1 + optional: false + - key: status + value: + key: status + fieldSchemaKey: + name: CDSResponseStatusType + version: 0.0.1 + optional: false + outputFields: + entry: + - key: status + value: + key: status + fieldSchemaKey: + name: SubscriptionStatusType + version: 0.0.1 + optional: false + taskParameters: + entry: [] + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskLogic: + key: TaskLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + + executor.logger.info(executor.subject.id); + + var commonHeader = executor.inFields.get("commonHeader") + var response = executor.inFields.get("payload") + var albumID = commonHeader.get("requestId") + + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString()); + var responseStatus = executor.subject.getOutFieldSchemaHelper("status").createNewInstance(); + + responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) + responseStatus.put("nfName", pmSubscriptionInfo.get("nfName")) + responseStatus.put("changeType", pmSubscriptionInfo.get("changeType")) + + var status = response.get(pmSubscriptionInfo.get("changeType").toLowerCase() + "_DasH_subscription_DasH_response").get("odl_DasH_response").get("status") + + executor.logger.info("RESPONSE STATUS = " + status) + + if(status == "success") { + responseStatus.put("message", "success") + } else { + responseStatus.put("message", "failed") + } + + executor.outFields.put("status", responseStatus) + + //var returnValue = executor.isTrue; + true; + - key: + name: CreateSubscriptionPayloadTask + version: 0.0.1 + value: + key: + name: CreateSubscriptionPayloadTask + version: 0.0.1 + inputFields: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + outputFields: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + optional: false + taskParameters: + entry: [] + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskLogic: + key: TaskLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + + executor.logger.info(executor.subject.id); + + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) + + var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() + + var payloadProperties = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance(changeType + "_DasH_subscription_DasH_properties_record"); + + payloadProperties.put("nfName", pmSubscriptionInfo.get("nfName")) + payloadProperties.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) + payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState")) + payloadProperties.put("fileBasedGP", pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString()) + payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation")) + payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups")) + + var payloadEntry = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("CDSRequestPayloadEntry"); + payloadEntry.put(changeType + "_DasH_subscription_DasH_properties", payloadProperties) + + var payload = executor.subject.getOutFieldSchemaHelper("payload").createNewInstance(); + payload.put(changeType + "_DasH_subscription_DasH_request", payloadEntry); + + executor.outFields.put("albumID", executor.inFields.get("albumID")) + executor.outFields.put("payload", payload); + + //var returnValue = executor.isTrue; + true; + - key: + name: CreateSubscriptionRequestTask + version: 0.0.1 + value: + key: + name: CreateSubscriptionRequestTask + version: 0.0.1 + inputFields: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + optional: false + outputFields: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSRequestCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + optional: false + taskParameters: + entry: [] + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskLogic: + key: TaskLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + + executor.logger.info(executor.subject.id); + + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) + + var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() + var blueprintName = pmSubscriptionInfo.get("blueprintName").toLowerCase() + var blueprintVersion = pmSubscriptionInfo.get("blueprintVersion").toLowerCase() + var payload = executor.inFields.get("payload") + var actionName = changeType + "-subscription" + + var commonHeader = executor.subject.getOutFieldSchemaHelper("commonHeader").createNewInstance(); + commonHeader.put("originatorId", "sdnc"); + commonHeader.put("requestId", executor.inFields.get("albumID").toString()); + commonHeader.put("subRequestId", "sub-123456-1000"); + + var actionIdentifiers = executor.subject.getOutFieldSchemaHelper("actionIdentifiers").createNewInstance(); + actionIdentifiers.put("actionName", actionName); + actionIdentifiers.put("blueprintName", blueprintName); + actionIdentifiers.put("blueprintVersion", blueprintVersion); + actionIdentifiers.put("mode", "sync"); + + executor.outFields.put("commonHeader", commonHeader); + executor.outFields.put("actionIdentifiers", actionIdentifiers); + executor.outFields.put("payload", payload); + + //var returnValue = executor.isTrue; + true; + - key: + name: DeleteSubscriptionPayloadTask + version: 0.0.1 + value: + key: + name: DeleteSubscriptionPayloadTask + version: 0.0.1 + inputFields: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + outputFields: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + optional: false + taskParameters: + entry: [] + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskLogic: + key: TaskLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + + executor.logger.info(executor.subject.id); + + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) + + var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() + + var payloadProperties = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance(changeType + "_DasH_subscription_DasH_properties_record"); + + payloadProperties.put("nfName", pmSubscriptionInfo.get("nfName")) + payloadProperties.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) + payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState")) + payloadProperties.put("fileBasedGP", pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString()) + payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation")) + payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups")) + + var payloadEntry = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("CDSRequestPayloadEntry"); + payloadEntry.put(changeType + "_DasH_subscription_DasH_properties", payloadProperties) + + var payload = executor.subject.getOutFieldSchemaHelper("payload").createNewInstance(); + payload.put(changeType + "_DasH_subscription_DasH_request", payloadEntry); + + executor.outFields.put("albumID", executor.inFields.get("albumID")) + executor.outFields.put("payload", payload); + + //var returnValue = executor.isTrue; + true; + - key: + name: DeleteSubscriptionRequestTask + version: 0.0.1 + value: + key: + name: DeleteSubscriptionRequestTask + version: 0.0.1 + inputFields: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + optional: false + outputFields: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSRequestCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + optional: false + taskParameters: + entry: [] + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskLogic: + key: TaskLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + + executor.logger.info(executor.subject.id); + + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) + + var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() + var blueprintName = pmSubscriptionInfo.get("blueprintName").toLowerCase() + var blueprintVersion = pmSubscriptionInfo.get("blueprintVersion").toLowerCase() + var payload = executor.inFields.get("payload") + var actionName = changeType + "-subscription" + + var commonHeader = executor.subject.getOutFieldSchemaHelper("commonHeader").createNewInstance(); + commonHeader.put("originatorId", "sdnc"); + commonHeader.put("requestId", executor.inFields.get("albumID").toString()); + commonHeader.put("subRequestId", "sub-123456-1000"); + + var actionIdentifiers = executor.subject.getOutFieldSchemaHelper("actionIdentifiers").createNewInstance(); + actionIdentifiers.put("actionName", actionName); + actionIdentifiers.put("blueprintName", blueprintName); + actionIdentifiers.put("blueprintVersion", blueprintVersion); + actionIdentifiers.put("mode", "sync"); + + executor.outFields.put("commonHeader", commonHeader); + executor.outFields.put("actionIdentifiers", actionIdentifiers); + executor.outFields.put("payload", payload); + + //var returnValue = executor.isTrue; + true; + - key: + name: ReceiveSubscriptionTask + version: 0.0.1 + value: + key: + name: ReceiveSubscriptionTask + version: 0.0.1 + inputFields: + entry: + - key: blueprintName + value: + key: blueprintName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: blueprintVersion + value: + key: blueprintVersion + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: changeType + value: + key: changeType + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: closedLoopControlName + value: + key: closedLoopControlName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: nfName + value: + key: nfName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: policyName + value: + key: policyName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: subscription + value: + key: subscription + fieldSchemaKey: + name: SubscriptionType + version: 0.0.1 + optional: false + outputFields: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + taskParameters: + entry: [] + contextAlbumReference: + - name: PMSubscriptionAlbum + version: 0.0.1 + taskLogic: + key: TaskLogic + logicFlavour: JAVASCRIPT + logic: |- + /* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + var uuidType = java.util.UUID; + + executor.logger.info(executor.subject.id); + + //albumID will be used to fetch info from our album later + var albumID = uuidType.randomUUID(); + var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").getSchemaHelper().createNewInstance(); + var returnValue = true; + + if(executor.inFields.get("policyName") != null) { + executor.logger.info("nfName in receive sub event " + executor.inFields.get("nfName")); + + var changeType = executor.inFields.get("changeType") + var nfName = executor.inFields.get("nfName") + var policyName = executor.inFields.get("policyName") + var closedLoopControlName = executor.inFields.get("closedLoopControlName") + var subscription = executor.inFields.get("subscription") + var blueprintName = executor.inFields.get("blueprintName") + var blueprintVersion = executor.inFields.get("blueprintVersion") + + pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName")); + pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType")) + pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName")) + pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName")) + pmSubscriptionInfo.put("subscription", subscription) + pmSubscriptionInfo.put("blueprintName", blueprintName) + pmSubscriptionInfo.put("blueprintVersion", blueprintVersion) + + + executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo); + + executor.outFields.put("albumID", albumID) + } else { + executor.message = "Received invalid event" + returnValue = false; + } + + returnValue; + events: + key: + name: PMControlPolicy_Events + version: 0.0.1 + eventMap: + entry: + - key: + name: CDSCreateResponseEvent + version: 0.0.1 + value: + key: + name: CDSCreateResponseEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: CDS + target: APEX + parameter: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSResponseCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSCreateResponsePayloadType + version: 0.0.1 + optional: false + - key: status + value: + key: status + fieldSchemaKey: + name: CDSResponseStatusType + version: 0.0.1 + optional: false + - key: + name: CDSCreateSubscriptionRequestEvent + version: 0.0.1 + value: + key: + name: CDSCreateSubscriptionRequestEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: APEX + target: APEX + parameter: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSRequestCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + optional: false + - key: + name: CDSDeleteResponseEvent + version: 0.0.1 + value: + key: + name: CDSDeleteResponseEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: CDS + target: APEX + parameter: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSResponseCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSDeleteResponsePayloadType + version: 0.0.1 + optional: false + - key: status + value: + key: status + fieldSchemaKey: + name: CDSResponseStatusType + version: 0.0.1 + optional: false + - key: + name: CDSDeleteSubscriptionRequestEvent + version: 0.0.1 + value: + key: + name: CDSDeleteSubscriptionRequestEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: APEX + target: APEX + parameter: + entry: + - key: actionIdentifiers + value: + key: actionIdentifiers + fieldSchemaKey: + name: CDSActionIdentifiersType + version: 0.0.1 + optional: false + - key: commonHeader + value: + key: commonHeader + fieldSchemaKey: + name: CDSRequestCommonHeaderType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + optional: false + - key: + name: CDSResponseStatusEvent + version: 0.0.1 + value: + key: + name: CDSResponseStatusEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: APEX + target: DCAE + parameter: + entry: + - key: status + value: + key: status + fieldSchemaKey: + name: SubscriptionStatusType + version: 0.0.1 + optional: false + - key: + name: CreateSubscriptionPayloadEvent + version: 0.0.1 + value: + key: + name: CreateSubscriptionPayloadEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: APEX + target: APEX + parameter: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + optional: false + - key: + name: DeleteSubscriptionPayloadEvent + version: 0.0.1 + value: + key: + name: DeleteSubscriptionPayloadEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: APEX + target: APEX + parameter: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + - key: payload + value: + key: payload + fieldSchemaKey: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + optional: false + - key: + name: MRResponseEvent + version: 0.0.1 + value: + key: + name: MRResponseEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: DCAE + target: APEX + parameter: + entry: + - key: count + value: + key: count + fieldSchemaKey: + name: SimpleIntType + version: 0.0.1 + optional: false + - key: serverTimeMs + value: + key: serverTimeMs + fieldSchemaKey: + name: SimpleIntType + version: 0.0.1 + optional: false + - key: + name: PMSubscriptionOutputEvent + version: 0.0.1 + value: + key: + name: PMSubscriptionOutputEvent + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: APEX + target: APEX + parameter: + entry: + - key: albumID + value: + key: albumID + fieldSchemaKey: + name: UUIDType + version: 0.0.1 + optional: false + - key: + name: pmsh-operational-policy + version: 0.0.1 + value: + key: + name: pmsh-operational-policy + version: 0.0.1 + nameSpace: org.onap.policy.apex.onap.pmcontrol + source: DCAE + target: APEX + parameter: + entry: + - key: blueprintName + value: + key: blueprintName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: blueprintVersion + value: + key: blueprintVersion + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: changeType + value: + key: changeType + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: closedLoopControlName + value: + key: closedLoopControlName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: nfName + value: + key: nfName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: policyName + value: + key: policyName + fieldSchemaKey: + name: SimpleStringType + version: 0.0.1 + optional: false + - key: subscription + value: + key: subscription + fieldSchemaKey: + name: SubscriptionType + version: 0.0.1 + optional: false + albums: + key: + name: PMControlPolicy_Albums + version: 0.0.1 + albums: + entry: + - key: + name: PMSubscriptionAlbum + version: 0.0.1 + value: + key: + name: PMSubscriptionAlbum + version: 0.0.1 + scope: policy + isWritable: true + itemSchema: + name: PMSubscriptionType + version: 0.0.1 + schemas: + key: + name: PMControlPolicy_Schemas + version: 0.0.1 + schemas: + entry: + - key: + name: CDSActionIdentifiersType + version: 0.0.1 + value: + key: + name: CDSActionIdentifiersType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "type": "record", + "name": "ActionIdentifiers_Type", + "namespace": "org.onap.policy.apex.onap.helloworld", + "fields": [ + { + "name": "actionName", + "type": "string" + }, + { + "name": "blueprintName", + "type": "string" + }, + { + "name": "blueprintVersion", + "type": "string" + }, + { + "name": "mode", + "type": "string" + } + ] + } + - key: + name: CDSCreateResponsePayloadType + version: 0.0.1 + value: + key: + name: CDSCreateResponsePayloadType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "name": "CreateResponsePayloadEntry", + "type": "record", + "namespace": "org.onap.policy.apex.onap.helloworld", + "fields": [ + { + "name": "create_DasH_subscription_DasH_response", + "type": { + "name": "create_DasH_subscription_DasH_response", + "type": "record", + "fields": [ + { + "name": "odl_DasH_response", + "type": { + "name": "odl_DasH_response", + "type": "record", + "fields": [ + { + "name": "status", + "type": "string" + } + ] + } + } + ] + } + } + ] + } + - key: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + value: + key: + name: CDSCreateSubscriptionPayloadType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "type": "map", + "values": { + "type": "record", + "name": "CDSRequestPayloadEntry", + "fields": [ + { + "name": "create_DasH_subscription_DasH_properties", + "type": { + "name": "create_DasH_subscription_DasH_properties_record", + "type": "record", + "fields": [ + { + "name": "nfName", + "type": "string" + }, + { + "name": "subscriptionName", + "type": "string" + }, + { + "name": "administrativeState", + "type": "string" + }, + { + "name": "fileBasedGP", + "type": "string" + }, + { + "name": "fileLocation", + "type": "string" + }, + { + "name": "measurementGroups", + "type": { + "type": "array", + "items": { + "name": "measurementGroups_record", + "type": "record", + "fields": [ + { + "name": "measurementGroup", + "type": { + "name": "measurementGroup", + "type": "record", + "fields": [ + { + "name": "measurementTypes", + "type": { + "type": "array", + "items": { + "name": "measurementTypes_record", + "type": "record", + "fields": [ + { + "name": "measurementType", + "type": "string" + } + ] + } + } + }, + { + "name": "managedObjectDNsBasic", + "type": { + "type": "array", + "items": { + "name": "managedObjectDNsBasic_record", + "type": "record", + "fields": [ + { + "name": "DN", + "type": "string" + } + ] + } + } + } + ] + } + } + ] + } + } + } + ] + } + } + ] + } + } + - key: + name: CDSDeleteResponsePayloadType + version: 0.0.1 + value: + key: + name: CDSDeleteResponsePayloadType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "name": "DeleteResponsePayloadEntry", + "type": "record", + "namespace": "com.acme.avro", + "fields": [ + { + "name": "delete_DasH_subscription_DasH_response", + "type": { + "name": "delete_DasH_subscription_DasH_response", + "type": "record", + "fields": [ + { + "name": "odl_DasH_response", + "type": { + "name": "odl_DasH_response", + "type": "record", + "fields": [ + { + "name": "status", + "type": "string" + } + ] + } + } + ] + } + } + ] + } + - key: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + value: + key: + name: CDSDeleteSubscriptionPayloadType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "type": "map", + "values": { + "type": "record", + "name": "CDSRequestPayloadEntry", + "fields": [ + { + "name": "delete_DasH_subscription_DasH_properties", + "type": { + "name": "delete_DasH_subscription_DasH_properties_record", + "type": "record", + "fields": [ + { + "name": "nfName", + "type": "string" + }, + { + "name": "subscriptionName", + "type": "string" + }, + { + "name": "administrativeState", + "type": "string" + }, + { + "name": "fileBasedGP", + "type": "string" + }, + { + "name": "fileLocation", + "type": "string" + }, + { + "name": "measurementGroups", + "type": { + "type": "array", + "items": { + "name": "measurementGroups_record", + "type": "record", + "fields": [ + { + "name": "measurementGroup", + "type": { + "name": "measurementGroup", + "type": "record", + "fields": [ + { + "name": "measurementTypes", + "type": { + "type": "array", + "items": { + "name": "measurementTypes_record", + "type": "record", + "fields": [ + { + "name": "measurementType", + "type": "string" + } + ] + } + } + }, + { + "name": "managedObjectDNsBasic", + "type": { + "type": "array", + "items": { + "name": "managedObjectDNsBasic_record", + "type": "record", + "fields": [ + { + "name": "DN", + "type": "string" + } + ] + } + } + } + ] + } + } + ] + } + } + } + ] + } + } + ] + } + } + - key: + name: CDSRequestCommonHeaderType + version: 0.0.1 + value: + key: + name: CDSRequestCommonHeaderType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "type": "record", + "name": "RequestCommonHeader_Type", + "namespace": "org.onap.policy.apex.onap.helloworld", + "fields": [ + { + "name": "originatorId", + "type": "string" + }, + { + "name": "requestId", + "type": "string" + }, + { + "name": "subRequestId", + "type": "string" + } + ] + } + - key: + name: CDSResponseCommonHeaderType + version: 0.0.1 + value: + key: + name: CDSResponseCommonHeaderType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "type": "record", + "name": "ResponseCommonHeader_Type", + "namespace": "org.onap.policy.apex.onap.helloworld", + "fields": [ + { + "name": "originatorId", + "type": "string" + }, + { + "name": "requestId", + "type": "string" + }, + { + "name": "subRequestId", + "type": "string" + }, + { + "name": "timestamp", + "type": "string" + }, + { + "name": "flags", + "type": ["null", "string"] + } + ] + } + - key: + name: CDSResponseStatusType + version: 0.0.1 + value: + key: + name: CDSResponseStatusType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "type": "record", + "name": "ResponseStatus_Type", + "namespace": "org.onap.policy.apex.onap.helloworld", + "fields": [ + { + "name": "code", + "type": "int" + }, + { + "name": "eventType", + "type": "string" + }, + { + "name": "timestamp", + "type": "string" + }, + { + "name": "message", + "type": "string" + } + ] + } + - key: + name: PMSubscriptionType + version: 0.0.1 + value: + key: + name: PMSubscriptionType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: "{\n\t\"name\": \"PMSubscription\",\n\t\"type\": \"record\",\n\t\"namespace\": \"\ + org.onap.policy.apex.onap.pmcontrol\",\n\t\"fields\": [\n {\n \"name\": \"nfName\"\ + ,\n \"type\": \"string\"\n },\n\t {\n\t\t\t\"name\": \"changeType\",\n\t\t\t\"\ + type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"closedLoopControlName\",\n\t\t\t\"type\": \"\ + string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"policyName\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\ + {\n\t\t \"name\": \"blueprintName\",\n\t\t \"type\": \"string\"\n\t\t},\n\t\t{\n\t\t \"name\"\ + : \"blueprintVersion\",\n\t\t \"type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"subscription\"\ + ,\n\t\t\t\"type\": {\n\t\t\t\t\"name\": \"subscription\",\n\t\t\t\t\"type\": \"record\",\n\t\t\t\t\ + \"fields\": [{\n\t\t\t\t\t\t\"name\": \"subscriptionName\",\n\t\t\t\t\t\t\"type\": \"string\"\n\t\t\ + \t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"administrativeState\",\n\t\t\t\t\t\t\"type\": \"string\"\ + \n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"fileBasedGP\",\n\t\t\t\t\t\t\"type\": \"int\"\ + \n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"fileLocation\",\n\t\t\t\t\t\t\"type\": \"string\"\ + \n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"measurementGroups\",\n\t\t\t\t\t\t\"type\": {\n\ + \t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\"name\": \"Measurement_Groups_Type\"\ + ,\n\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\"name\"\ + : \"measurementGroup\",\n\t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\t\t\t\t\t\t\"name\": \"Measurement_Group_Type\"\ + ,\n\t\t\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\ + \t\t\t\t\"name\": \"measurementTypes\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\t\t\t\t\t\t\ + \t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"\ + name\": \"Measurement_Types_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\ + \t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"measurementType\",\n\t\ + \t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\ + \t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\ + \t\t\t\t\t\t\t\t\"name\": \"managedObjectDNsBasic\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\ + \t\t\t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\t\ + \t\t\t\t\t\"name\": \"Managed_Object_Dns_Basic_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"record\"\ + ,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"DN\",\n\t\ + \t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\ + \t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\ + \t\t\t\t}\n\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\ + \t}\n\t]\n}" + - key: + name: SimpleIntType + version: 0.0.1 + value: + key: + name: SimpleIntType + version: 0.0.1 + schemaFlavour: Java + schemaDefinition: java.lang.Integer + - key: + name: SimpleStringType + version: 0.0.1 + value: + key: + name: SimpleStringType + version: 0.0.1 + schemaFlavour: Java + schemaDefinition: java.lang.String + - key: + name: SubscriptionStatusType + version: 0.0.1 + value: + key: + name: SubscriptionStatusType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: |- + { + "type": "record", + "name": "ActivateSubscriptionStatus_Type", + "namespace": "org.onap.policy.apex.onap.helloworld", + "fields": [ + { + "name": "subscriptionName", + "type": "string" + }, + { + "name": "nfName", + "type": "string" + }, + { + "name": "changeType", + "type": "string" + }, + { + "name": "message", + "type": "string" + } + ] + } + - key: + name: SubscriptionType + version: 0.0.1 + value: + key: + name: SubscriptionType + version: 0.0.1 + schemaFlavour: Avro + schemaDefinition: "{\n\t\"name\": \"subscription\",\n\t\"type\": \"record\",\n\t\"fields\": [{\n\t\t\ + \t\"name\": \"subscriptionName\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"administrativeState\"\ + ,\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"fileBasedGP\",\n\t\t\t\"type\": \"\ + int\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"fileLocation\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\ + {\n\t\t\t\"name\": \"measurementGroups\",\n\t\t\t\"type\": {\n\t\t\t\t\"type\": \"array\",\n\t\t\t\ + \t\"items\": {\n\t\t\t\t\t\"name\": \"Measurement_Groups_Type\",\n\t\t\t\t\t\"type\": \"record\",\n\ + \t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\"name\": \"measurementGroup\",\n\t\t\t\t\t\t\"type\": {\n\t\ + \t\t\t\t\t\t\"name\": \"Measurement_Group_Type\",\n\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\ + \t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\"name\": \"measurementTypes\",\n\t\t\t\t\t\t\t\t\t\"type\"\ + : {\n\t\t\t\t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\t\ + \t\t\"name\": \"Measurement_Types_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\ + \t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"measurementType\",\n\t\t\t\t\t\t\t\ + \t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ + }\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"name\": \"managedObjectDNsBasic\",\n\ + \t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\"items\"\ + : {\n\t\t\t\t\t\t\t\t\t\t\t\"name\": \"Managed_Object_Dns_Basic_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\"\ + type\": \"record\",\n\t\t\t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"DN\"\ + ,\n\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\t\t}\n\ + \t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}]\n\t\t\t\t}\n\t\ + \t\t}\n\t\t}\n\t]\n}" + - key: + name: UUIDType + version: 0.0.1 + value: + key: + name: UUIDType + version: 0.0.1 + schemaFlavour: Java + schemaDefinition: java.util.UUID + engineParameters: + executorParameters: + JAVASCRIPT: + parameterClassName: org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters + contextParameters: + parameterClassName: org.onap.policy.apex.context.parameters.ContextParameters + schemaParameters: + Avro: + parameterClassName: org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters + Java: + parameterClassName: org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters + jsonAdapters: + Instant: + adaptedClass: java.time.Instant + adaptorClass: org.onap.policy.acm.util.Serialization$GsonInstantAdapter + eventInputParameters: + DCAEConsumer: + carrierTechnologyParameters: + carrierTechnology: RESTCLIENT + parameterClassName: org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters + parameters: + consumerPollTime: '50' + url: https://message-router:3905/events/unauthenticated.DCAE_CL_OUTPUT/cg1/sg1 + eventProtocolParameters: + eventProtocol: JSON + parameters: + nameAlias: policyName + eventName: pmsh-operational-policy + eventNameFilter: pmsh-operational-policy + CDSRequestConsumer: + carrierTechnologyParameters: + carrierTechnology: RESTREQUESTOR + parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters + parameters: + url: http://10.10.10.184:30254/api/v1/execution-service/process + httpMethod: POST + restRequestTimeout: 2000 + httpHeaders: + - - Authorization + - Basic Y2NzZGthcHBzOmNjc2RrYXBwcw== + eventProtocolParameters: + eventProtocol: JSON + eventName: CDSCreateResponseEvent + eventNameFilter: CDSCreateResponseEvent + requestorMode: true + requestorPeer: CDSRequestProducer + requestorTimeout: 500 + CDSDeleteRequestConsumer: + carrierTechnologyParameters: + carrierTechnology: RESTREQUESTOR + parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters + parameters: + url: http://10.10.10.184:30254/api/v1/execution-service/process + httpMethod: POST + restRequestTimeout: 2000 + httpHeaders: + - - Authorization + - Basic Y2NzZGthcHBzOmNjc2RrYXBwcw== + eventProtocolParameters: + eventProtocol: JSON + eventName: CDSDeleteResponseEvent + eventNameFilter: CDSDeleteResponseEvent + requestorMode: true + requestorPeer: CDSDeleteRequestProducer + requestorTimeout: 500 + CDSReplyConsumer: + carrierTechnologyParameters: + carrierTechnology: RESTREQUESTOR + parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters + parameters: + url: https://message-router:3905/events/unauthenticated.PMSH_CL_INPUT + httpMethod: POST + restRequestTimeout: 2000 + eventProtocolParameters: + eventProtocol: JSON + eventName: MRResponseEvent + eventNameFilter: MRResponseEvent + requestorMode: true + requestorPeer: CDSReplyProducer + requestorTimeout: 500 + eventOutputParameters: + logOutputter: + carrierTechnologyParameters: + carrierTechnology: FILE + parameters: + fileName: /tmp/outputevents.log + eventProtocolParameters: + eventProtocol: JSON + StdOutOutputter: + carrierTechnologyParameters: + carrierTechnology: FILE + parameters: + standardIo: true + eventProtocolParameters: + eventProtocol: JSON + CDSRequestProducer: + carrierTechnologyParameters: + carrierTechnology: RESTREQUESTOR + parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters + eventProtocolParameters: + eventProtocol: JSON + eventNameFilter: CDSCreateSubscriptionRequestEvent + requestorMode: true + requestorPeer: CDSRequestConsumer + requestorTimeout: 500 + CDSDeleteRequestProducer: + carrierTechnologyParameters: + carrierTechnology: RESTREQUESTOR + parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters + eventProtocolParameters: + eventProtocol: JSON + eventNameFilter: CDSDeleteSubscriptionRequestEvent + requestorMode: true + requestorPeer: CDSDeleteRequestConsumer + requestorTimeout: 500 + CDSReplyProducer: + carrierTechnologyParameters: + carrierTechnology: RESTREQUESTOR + parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters + eventProtocolParameters: + eventProtocol: JSON + eventNameFilter: CDSResponseStatusEvent + requestorMode: true + requestorPeer: CDSReplyConsumer + requestorTimeout: 500 diff --git a/models/src/test/resources/examples/controlloop/PMSubscriptionHandling.yaml b/models/src/test/resources/examples/controlloop/PMSubscriptionHandling.yaml deleted file mode 100644 index 8e8f3cd39..000000000 --- a/models/src/test/resources/examples/controlloop/PMSubscriptionHandling.yaml +++ /dev/null @@ -1,3325 +0,0 @@ -# ============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========================================================= -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 - org.onap.datatypes.policy.clamp.controlloop.DCAEMicroserviceControlLoopElementConsulInfo: - name: org.onap.datatypes.policy.clamp.controlloop.DCAEMicroserviceControlLoopElementConsulInfo - version: 0.0.0 - derived_from: tosca.datatypes.Root - properties: - consulUrl: - name: consulUrl - type: string - typeVersion: 0.0.0 - description: Consul url for this entry - required: true - consul_body: - name: consulBody - type: string - typeVersion: 0.0.0 - description: Body of Consul entry - required: true - 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: {} -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.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: {} -node_types: - org.onap.policy.clamp.controlloop.Participant: - version: 1.0.1 - derived_from: tosca.nodetypes.Root - properties: - provider: - type: string - required: false - org.onap.policy.clamp.controlloop.ControlLoopElement: - version: 1.0.1 - derived_from: tosca.nodetypes.Root - properties: - provider: - type: string - required: false - participantType: - type: onap.datatypes.ToscaConceptIdentifier - required: true - 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 - org.onap.policy.clamp.controlloop.ControlLoop: - version: 1.0.1 - derived_from: tosca.nodetypes.Root - properties: - provider: - type: string - required: false - elements: - type: list - required: true - entry_schema: - type: onap.datatypes.ToscaConceptIdentifier - org.onap.policy.clamp.controlloop.DCAEMicroserviceControlLoopElement: - version: 1.0.1 - derived_from: org.onap.policy.clamp.controlloop.ControlLoopElement - properties: - dcae_blueprint_id: - type: onap.datatypes.ToscaConceptIdentifier - required: false - dcae_blueprint: - type: onap.dcae.cloudify_blueprint - required: false - consul_info: - type: list - required: false - entry_schema: - type: org.onap.datatypes.policy.clamp.controlloop.DCAEMicroserviceControlLoopElementConsulInfo - 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 - required: true - policy_id: - type: onap.datatypes.ToscaConceptIdentifier - required: 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 - required: true -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.dcae.controlloop.DCAEMicroserviceControlLoopParticipant: - version: 2.3.4 - type: org.onap.policy.clamp.controlloop.Participant - type_version: 1.0.1 - description: Participant for DCAE microservices - properties: - provider: ONAP - 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.ccsdk.cds.controlloop.CdsControlLoopParticipant: - version: 2.2.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_DCAEMicroservice: - version: 1.2.3 - type: org.onap.policy.clamp.controlloop.DCAEMicroserviceControlLoopElement - type_version: 1.0.0 - description: Control loop element for the DCAE microservice for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant - version: 2.3.4 - dcae_blueprint: - tosca_definitions_version: cloudify_dsl_1_3 - imports: - - https://www.getcloudify.org/spec/cloudify/4.5.5/types.yaml - - plugin:k8splugin?version=3.7.0 - - plugin:pgaas?version=1.3.0 - - plugin:clamppolicyplugin?version=1.1.0 - inputs: - tag_version: - type: string - description: Docker image to be used - default: nexus3.onap.org:10001/onap/org.onap.dcaegen2.services.pmsh:1.1.2 - replicas: - type: integer - description: Number of instances - default: 1 - operational_policy_name: - type: string - default: operational.apex.pmcontrol - control_loop_name: - type: string - default: pmsh-control-loop - pmsh_publish_topic_name: - type: string - default: unauthenticated.DCAE_CL_OUTPUT - policy_feedback_topic_name: - type: string - default: unauthenticated.PMSH_CL_INPUT - aai_notification_topic_name: - type: string - default: AAI-EVENT - publisher_client_role: - type: string - description: Client role to request secure access to topic - default: org.onap.dcae.pmPublisher - subscriber_client_role: - type: string - description: Client role to request secure access to topic - default: org.onap.dcae.pmSubscriber - dcae_location: - type: string - description: DCAE location for the subscriber, used to set up routing - default: san-francisco - cpu_limit: - type: string - default: 1000m - cpu_request: - type: string - default: 1000m - memory_limit: - type: string - default: 1024Mi - memory_request: - type: string - default: 1024Mi - pgaas_cluster_name: - type: string - default: dcae-pg-primary.onap - enable_tls: - type: boolean - default: true - protocol: - type: string - description: PMSH protocol. If enable_tls is false, set to http - default: https - policy_model_id: - type: string - default: onap.policies.monitoring.dcae-pm-subscription-handler - policy_id: - type: string - default: MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test - node_templates: - pgaasvm: - type: dcae.nodes.pgaas.database - properties: - writerfqdn: - get_input: pgaas_cluster_name - name: pmsh - pmsh: - type: dcae.nodes.ContainerizedServiceComponentUsingDmaap - interfaces: - cloudify.interfaces.lifecycle: - create: - inputs: - ports: - - '8443:0' - envs: - PMSH_PG_URL: - get_attribute: - - pgaasvm - - admin - - host - PMSH_PG_PASSWORD: - get_attribute: - - pgaasvm - - admin - - password - PMSH_PG_USERNAME: - get_attribute: - - pgaasvm - - admin - - user - PMSH_DB_NAME: - get_attribute: - - pgaasvm - - admin - - database - relationships: - - target: pmsh-policy - type: cloudify.relationships.depends_on - properties: - service_component_type: dcae-pmsh - service_component_name_override: dcae-pmsh - application_config: - enable_tls: - get_input: enable_tls - aaf_identity: dcae@dcae.onap.org - aaf_password: demo123456! - operational_policy_name: - get_input: operational_policy_name - control_loop_name: - get_input: control_loop_name - 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 - streams_publishes: - policy_pm_publisher: - type: message_router - dmaap_info: - topic_url: - concat: - - http://message-router:3904/events/ - - get_input: pmsh_publish_topic_name - streams_subscribes: - policy_pm_subscriber: - type: message_router - dmaap_info: - topic_url: - concat: - - http://message-router:3904/events/ - - get_input: policy_feedback_topic_name - aai_subscriber: - type: message_router - dmaap_info: - topic_url: - concat: - - http://message-router:3904/events/ - - get_input: aai_notification_topic_name - resource_config: - limits: - cpu: - get_input: cpu_limit - memory: - get_input: memory_limit - requests: - cpu: - get_input: cpu_request - memory: - get_input: memory_request - docker_config: - healthcheck: - endpoint: /healthcheck - interval: 15s - timeout: 1s - type: - get_input: protocol - image: - get_input: tag_version - replicas: - get_input: replicas - log_info: - log_directory: /var/log/ONAP/dcaegen2/services/pmsh - tls_info: - cert_directory: /opt/app/pmsh/etc/certs - use_tls: - get_input: enable_tls - pmsh-policy: - type: clamp.nodes.policy - properties: - policy_model_id: - get_input: policy_model_id - policy_id: - get_input: policy_id - consul_info: - - consulUrl: http://consul:31321/v1/kv/dcae-pmsh:policy - consulBody: - subscription: - subscriptionName: subscriptiona - administrativeState: UNLOCKED - fileBasedGP: 15 - fileLocation: /pm/pm.xml - nfFilter: - nfNames: - - ^pnf1.* - modelInvariantIDs: - - 5845y423-g654-6fju-po78-8n53154532k6 - - 7129e420-d396-4efb-af02-6b83499b12f8 - modelVersionIDs: - - e80a6ae3-cafd-4d24-850d-e14c084a5ca9 - measurementGroups: - - measurementGroup: - measurementTypes: - - measurementType: countera - - measurementType: counterb - managedObjectDNsBasic: - - DN: dna - - DN: dnb - - measurementGroup: - measurementTypes: - - measurementType: counterc - - measurementType: counterd - managedObjectDNsBasic: - - DN: dnc - - DN: dnd - 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 - 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 - participantType: - name: org.onap.policy.controlloop.PolicyControlLoopParticipant - version: 2.2.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.PMSH_CDS_ControlLoopElement: - version: 1.2.3 - type: org.onap.policy.clamp.controlloop.CDSControlLoopElement - type_version: 1.0.0 - description: Control loop element for CDS for Performance Management Subscription Handling - properties: - provider: Ericsson - participantType: - name: org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant - version: 3.2.1 - cds_blueprint_id: - name: org.onap.ccsdk.cds.PMSHCdsBlueprint - version: 1.0.0 - org.onap.domain.pmsh.PMSHControlLoopDefinition: - version: 1.2.3 - type: org.onap.policy.clamp.controlloop.ControlLoop - type_version: 1.0.0 - description: Control loop for Performance Management Subscription Handling - properties: - provider: Ericsson - elements: - - name: org.onap.domain.pmsh.PMSH_DCAEMicroservice - 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 - - name: org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement - version: 1.2.3 - policies: - - MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test: - type: onap.policies.monitoring.dcae-pm-subscription-handler - type_version: 1.0.0 - name: MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test - version: 1.0.0 - metadata: - policy-id: MICROSERVICE_vLoadBalancerMS_v1_0_dcae-pm-subscription-handler_1_0_0test - policy-version: 1.0.0 - properties: - pmsh_policy: - fileBasedGP: 15 - fileLocation: /pm/pm.xml - subscriptionName: subscriptiona - administrativeState: UNLOCKED - nfFilter: - onap.datatypes.monitoring.nfFilter: - modelVersionIDs: - - e80a6ae3-cafd-4d24-850d-e14c084a5ca9 - modelInvariantIDs: - - 5845y423-g654-6fju-po78-8n53154532k6 - - 7129e420-d396-4efb-af02-6b83499b12f8 - modelNames: [] - nfNames: - - '"^pnf1.*"' - measurementGroups: - - measurementGroup: - onap.datatypes.monitoring.measurementGroup: - measurementTypes: - - measurementType: - onap.datatypes.monitoring.measurementType: - measurementType: countera - - measurementType: - onap.datatypes.monitoring.measurementType: - measurementType: counterb - managedObjectDNsBasic: - - managedObjectDNsBasic: - onap.datatypes.monitoring.managedObjectDNsBasic: - DN: dna - - managedObjectDNsBasic: - onap.datatypes.monitoring.managedObjectDNsBasic: - DN: dnb - - measurementGroup: - onap.datatypes.monitoring.measurementGroup: - measurementTypes: - - measurementType: - onap.datatypes.monitoring.measurementType: - measurementType: counterc - - measurementType: - onap.datatypes.monitoring.measurementType: - measurementType: counterd - managedObjectDNsBasic: - - managedObjectDNsBasic: - onap.datatypes.monitoring.managedObjectDNsBasic: - DN: dnc - - managedObjectDNsBasic: - onap.datatypes.monitoring.managedObjectDNsBasic: - DN: dnd - - operational.apex.pmcontrol: - type: onap.policies.controlloop.operational.common.Apex - type_version: 1.0.0 - version: 1.0.0 - metadata: - policy-id: operational.apex.pmcontrol - policy-version: 1 - properties: - engineServiceParameters: - name: MyApexEngine - version: 0.0.1 - id: 45 - instanceCount: 2 - deploymentPort: 12561 - policy_type_impl: - apexPolicyModel: - key: - name: PMControlPolicy - version: 0.0.1 - keyInformation: - key: - name: PMControlPolicy_KeyInfo - version: 0.0.1 - keyInfoMap: - entry: - - key: - name: CDSActionIdentifiersType - version: 0.0.1 - value: - key: - name: CDSActionIdentifiersType - version: 0.0.1 - UUID: 6e5fa19b-14df-37e3-a4ae-8c537e861a82 - description: Generated description for concept referred to by key "CDSActionIdentifiersType:0.0.1" - - key: - name: CDSCreateResponseEvent - version: 0.0.1 - value: - key: - name: CDSCreateResponseEvent - version: 0.0.1 - UUID: 14b29e38-ac75-3273-aa4e-8583c0aa7dad - description: Generated description for concept referred to by key "CDSCreateResponseEvent:0.0.1" - - key: - name: CDSCreateResponsePayloadType - version: 0.0.1 - value: - key: - name: CDSCreateResponsePayloadType - version: 0.0.1 - UUID: 04573f8f-e772-30a5-b1d9-d7318d4a1e13 - description: Generated description for concept referred to by key "CDSCreateResponsePayloadType:0.0.1" - - key: - name: CDSCreateResponsePolicy - version: 0.0.1 - value: - key: - name: CDSCreateResponsePolicy - version: 0.0.1 - UUID: e126c965-fc09-3bfe-8f55-70f380a4a49c - description: Generated description for concept referred to by key "CDSCreateResponsePolicy:0.0.1" - - key: - name: CDSCreateResponseTask - version: 0.0.1 - value: - key: - name: CDSCreateResponseTask - version: 0.0.1 - UUID: 6165ee82-afd2-3aab-a517-f00b3f2461d2 - description: Generated description for concept referred to by key "CDSCreateResponseTask:0.0.1" - - key: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - value: - key: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - UUID: 8350ac5e-c157-38b9-9614-a0f93a830e60 - description: Generated description for concept referred to by key "CDSCreateSubscriptionPayloadType:0.0.1" - - key: - name: CDSCreateSubscriptionRequestEvent - version: 0.0.1 - value: - key: - name: CDSCreateSubscriptionRequestEvent - version: 0.0.1 - UUID: cfa325ba-226b-3a31-9183-ec43e2b6e9a2 - description: Generated description for concept referred to by key "CDSCreateSubscriptionRequestEvent:0.0.1" - - key: - name: CDSDeleteResponseEvent - version: 0.0.1 - value: - key: - name: CDSDeleteResponseEvent - version: 0.0.1 - UUID: 8be9c0fa-7437-3841-aff2-b3cec6ae3bd8 - description: Generated description for concept referred to by key "CDSDeleteResponseEvent:0.0.1" - - key: - name: CDSDeleteResponsePayloadType - version: 0.0.1 - value: - key: - name: CDSDeleteResponsePayloadType - version: 0.0.1 - UUID: 3fbfe0c9-152e-34d3-a504-09cd13c058d0 - description: Generated description for concept referred to by key "CDSDeleteResponsePayloadType:0.0.1" - - key: - name: CDSDeleteResponsePolicy - version: 0.0.1 - value: - key: - name: CDSDeleteResponsePolicy - version: 0.0.1 - UUID: a780251c-edd5-3132-b865-04313246b43c - description: Generated description for concept referred to by key "CDSDeleteResponsePolicy:0.0.1" - - key: - name: CDSDeleteResponseTask - version: 0.0.1 - value: - key: - name: CDSDeleteResponseTask - version: 0.0.1 - UUID: afce4555-3aa3-3521-a7d8-ee8cdf0d3efc - description: Generated description for concept referred to by key "CDSDeleteResponseTask:0.0.1" - - key: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - value: - key: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - UUID: 12658406-9147-3c9d-a38c-5ad5e30b092b - description: Generated description for concept referred to by key "CDSDeleteSubscriptionPayloadType:0.0.1" - - key: - name: CDSDeleteSubscriptionRequestEvent - version: 0.0.1 - value: - key: - name: CDSDeleteSubscriptionRequestEvent - version: 0.0.1 - UUID: 24380c95-9289-36e6-8cbf-0edefa15ccd9 - description: Generated description for concept referred to by key "CDSDeleteSubscriptionRequestEvent:0.0.1" - - key: - name: CDSRequestCommonHeaderType - version: 0.0.1 - value: - key: - name: CDSRequestCommonHeaderType - version: 0.0.1 - UUID: 35590ac0-062c-39f1-8786-b4ff716e30b1 - description: Generated description for concept referred to by key "CDSRequestCommonHeaderType:0.0.1" - - key: - name: CDSResponseCommonHeaderType - version: 0.0.1 - value: - key: - name: CDSResponseCommonHeaderType - version: 0.0.1 - UUID: dd7e1805-885a-350b-aaf9-ed541321ae3c - description: Generated description for concept referred to by key "CDSResponseCommonHeaderType:0.0.1" - - key: - name: CDSResponseStatusEvent - version: 0.0.1 - value: - key: - name: CDSResponseStatusEvent - version: 0.0.1 - UUID: 7986e21b-32f7-302e-9554-31f21b673493 - description: Generated description for concept referred to by key "CDSResponseStatusEvent:0.0.1" - - key: - name: CDSResponseStatusType - version: 0.0.1 - value: - key: - name: CDSResponseStatusType - version: 0.0.1 - UUID: 92b8a2cf-344e-3ce1-8cc0-2b7d3cb695fa - description: Generated description for concept referred to by key "CDSResponseStatusType:0.0.1" - - key: - name: CreateSubscriptionPayloadEvent - version: 0.0.1 - value: - key: - name: CreateSubscriptionPayloadEvent - version: 0.0.1 - UUID: 92162397-1a8e-3a3f-a469-d2af7700af4a - description: Generated description for concept referred to by key "CreateSubscriptionPayloadEvent:0.0.1" - - key: - name: CreateSubscriptionPayloadTask - version: 0.0.1 - value: - key: - name: CreateSubscriptionPayloadTask - version: 0.0.1 - UUID: bc0c69f0-52ed-38ea-b468-ae4a6fd1730d - description: Generated description for concept referred to by key "CreateSubscriptionPayloadTask:0.0.1" - - key: - name: CreateSubscriptionRequestTask - version: 0.0.1 - value: - key: - name: CreateSubscriptionRequestTask - version: 0.0.1 - UUID: 89cb75e9-f06c-30d3-b4ff-698d45f63869 - description: Generated description for concept referred to by key "CreateSubscriptionRequestTask:0.0.1" - - key: - name: DeleteSubscriptionPayloadEvent - version: 0.0.1 - value: - key: - name: DeleteSubscriptionPayloadEvent - version: 0.0.1 - UUID: 994fa441-04ab-33bb-832d-1cd12ab5d074 - description: Generated description for concept referred to by key "DeleteSubscriptionPayloadEvent:0.0.1" - - key: - name: DeleteSubscriptionPayloadTask - version: 0.0.1 - value: - key: - name: DeleteSubscriptionPayloadTask - version: 0.0.1 - UUID: 0f519117-5fea-3e4b-941f-8f778100465f - description: Generated description for concept referred to by key "DeleteSubscriptionPayloadTask:0.0.1" - - key: - name: DeleteSubscriptionRequestTask - version: 0.0.1 - value: - key: - name: DeleteSubscriptionRequestTask - version: 0.0.1 - UUID: acb772fe-d442-39e3-98f9-b1080caf4150 - description: Generated description for concept referred to by key "DeleteSubscriptionRequestTask:0.0.1" - - key: - name: MRResponseEvent - version: 0.0.1 - value: - key: - name: MRResponseEvent - version: 0.0.1 - UUID: 13c747a3-6bae-3bcf-9c80-b152e01dc194 - description: Generated description for concept referred to by key "MRResponseEvent:0.0.1" - - key: - name: PMControlPolicy - version: 0.0.1 - value: - key: - name: PMControlPolicy - version: 0.0.1 - UUID: acf1e55c-7bc5-3bd5-975a-0ca54afcd8a4 - description: Generated description for concept referred to by key "PMControlPolicy:0.0.1" - - key: - name: PMControlPolicy_Albums - version: 0.0.1 - value: - key: - name: PMControlPolicy_Albums - version: 0.0.1 - UUID: b38ad204-c2c8-32f4-9b5a-dda0aeb0145b - description: Generated description for concept referred to by key "PMControlPolicy_Albums:0.0.1" - - key: - name: PMControlPolicy_Events - version: 0.0.1 - value: - key: - name: PMControlPolicy_Events - version: 0.0.1 - UUID: be3871a0-c42a-3113-a066-82d192840eca - description: Generated description for concept referred to by key "PMControlPolicy_Events:0.0.1" - - key: - name: PMControlPolicy_KeyInfo - version: 0.0.1 - value: - key: - name: PMControlPolicy_KeyInfo - version: 0.0.1 - UUID: ced37634-28a4-3178-b7f6-2980794927b0 - description: Generated description for concept referred to by key "PMControlPolicy_KeyInfo:0.0.1" - - key: - name: PMControlPolicy_Policies - version: 0.0.1 - value: - key: - name: PMControlPolicy_Policies - version: 0.0.1 - UUID: be3d180d-ef9c-3a75-8e9c-84271a038bed - description: Generated description for concept referred to by key "PMControlPolicy_Policies:0.0.1" - - key: - name: PMControlPolicy_Schemas - version: 0.0.1 - value: - key: - name: PMControlPolicy_Schemas - version: 0.0.1 - UUID: e61973f1-189c-39e5-82f6-0d3afe298a20 - description: Generated description for concept referred to by key "PMControlPolicy_Schemas:0.0.1" - - key: - name: PMControlPolicy_Tasks - version: 0.0.1 - value: - key: - name: PMControlPolicy_Tasks - version: 0.0.1 - UUID: 5658adb3-2962-30a3-a241-fae75bb8eb4a - description: Generated description for concept referred to by key "PMControlPolicy_Tasks:0.0.1" - - key: - name: PMSubscriptionAlbum - version: 0.0.1 - value: - key: - name: PMSubscriptionAlbum - version: 0.0.1 - UUID: c2bd6f0d-6854-317a-9be2-97c08338428c - description: Generated description for concept referred to by key "PMSubscriptionAlbum:0.0.1" - - key: - name: PMSubscriptionOutputEvent - version: 0.0.1 - value: - key: - name: PMSubscriptionOutputEvent - version: 0.0.1 - UUID: 992b7819-9f69-3aa0-bb0f-6e45ea15ce05 - description: Generated description for concept referred to by key "PMSubscriptionOutputEvent:0.0.1" - - key: - name: PMSubscriptionType - version: 0.0.1 - value: - key: - name: PMSubscriptionType - version: 0.0.1 - UUID: 73c1c397-4fc3-357f-93b6-a8ad707fbaae - description: Generated description for concept referred to by key "PMSubscriptionType:0.0.1" - - key: - name: ReceiveEventPolicy - version: 0.0.1 - value: - key: - name: ReceiveEventPolicy - version: 0.0.1 - UUID: 568b7345-9de1-36d3-b6a3-9b857e6809a1 - description: Generated description for concept referred to by key "ReceiveEventPolicy:0.0.1" - - key: - name: ReceiveSubscriptionTask - version: 0.0.1 - value: - key: - name: ReceiveSubscriptionTask - version: 0.0.1 - UUID: f596afc8-100c-35eb-92c8-352355ea457d - description: Generated description for concept referred to by key "ReceiveSubscriptionTask:0.0.1" - - key: - name: SimpleIntType - version: 0.0.1 - value: - key: - name: SimpleIntType - version: 0.0.1 - UUID: 153791fd-ae0a-36a7-88a5-309a7936415d - description: Generated description for concept referred to by key "SimpleIntType:0.0.1" - - key: - name: SimpleStringType - version: 0.0.1 - value: - key: - name: SimpleStringType - version: 0.0.1 - UUID: 8a4957cf-9493-3a76-8c22-a208e23259af - description: Generated description for concept referred to by key "SimpleStringType:0.0.1" - - key: - name: SubscriptionStatusType - version: 0.0.1 - value: - key: - name: SubscriptionStatusType - version: 0.0.1 - UUID: 597643b1-9db1-31ce-85d0-e1c63c43b30b - description: Generated description for concept referred to by key "SubscriptionStatusType:0.0.1" - - key: - name: SubscriptionType - version: 0.0.1 - value: - key: - name: SubscriptionType - version: 0.0.1 - UUID: 184547bb-7d64-3cb2-a273-d7185102c5ce - description: Generated description for concept referred to by key "SubscriptionType:0.0.1" - - key: - name: UUIDType - version: 0.0.1 - value: - key: - name: UUIDType - version: 0.0.1 - UUID: 6a8cc68e-dfc8-3403-9c6d-071c886b319c - description: Generated description for concept referred to by key "UUIDType:0.0.1" - - key: - name: pmsh-operational-policy - version: 0.0.1 - value: - key: - name: pmsh-operational-policy - version: 0.0.1 - UUID: fdf2c9ff-6422-3ea6-b6b6-49b12116265d - description: Generated description for concept referred to by key "pmsh-operational-policy:0.0.1" - policies: - key: - name: PMControlPolicy_Policies - version: 0.0.1 - policyMap: - entry: - - key: - name: CDSCreateResponsePolicy - version: 0.0.1 - value: - policyKey: - name: CDSCreateResponsePolicy - version: 0.0.1 - template: Freestyle - state: - entry: - - key: CDSCreateResponseState - value: - stateKey: - parentKeyName: CDSCreateResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: CDSCreateResponseState - trigger: - name: CDSCreateResponseEvent - version: 0.0.1 - stateOutputs: - entry: - - key: ResponseOutput - value: - key: - parentKeyName: CDSCreateResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: CDSCreateResponseState - localName: ResponseOutput - outgoingEvent: - name: CDSResponseStatusEvent - version: 0.0.1 - nextState: - parentKeyName: 'NULL' - parentKeyVersion: 0.0.0 - parentLocalName: 'NULL' - localName: 'NULL' - contextAlbumReference: [] - taskSelectionLogic: - key: 'NULL' - logicFlavour: UNDEFINED - logic: '' - stateFinalizerLogicMap: - entry: [] - defaultTask: - name: CDSCreateResponseTask - version: 0.0.1 - taskReferences: - entry: - - key: - name: CDSCreateResponseTask - version: 0.0.1 - value: - key: - parentKeyName: CDSCreateResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: CDSCreateResponseState - localName: CDSCreateResponsePolicy - outputType: DIRECT - output: - parentKeyName: CDSCreateResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: CDSCreateResponseState - localName: ResponseOutput - firstState: CDSCreateResponseState - - key: - name: CDSDeleteResponsePolicy - version: 0.0.1 - value: - policyKey: - name: CDSDeleteResponsePolicy - version: 0.0.1 - template: Freestyle - state: - entry: - - key: CDSDeleteResponseState - value: - stateKey: - parentKeyName: CDSDeleteResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: CDSDeleteResponseState - trigger: - name: CDSDeleteResponseEvent - version: 0.0.1 - stateOutputs: - entry: - - key: ResponseOutput - value: - key: - parentKeyName: CDSDeleteResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: CDSDeleteResponseState - localName: ResponseOutput - outgoingEvent: - name: CDSResponseStatusEvent - version: 0.0.1 - nextState: - parentKeyName: 'NULL' - parentKeyVersion: 0.0.0 - parentLocalName: 'NULL' - localName: 'NULL' - contextAlbumReference: [] - taskSelectionLogic: - key: 'NULL' - logicFlavour: UNDEFINED - logic: '' - stateFinalizerLogicMap: - entry: [] - defaultTask: - name: CDSDeleteResponseTask - version: 0.0.1 - taskReferences: - entry: - - key: - name: CDSDeleteResponseTask - version: 0.0.1 - value: - key: - parentKeyName: CDSDeleteResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: CDSDeleteResponseState - localName: CDSDeleteResponsePolicy - outputType: DIRECT - output: - parentKeyName: CDSDeleteResponsePolicy - parentKeyVersion: 0.0.1 - parentLocalName: CDSDeleteResponseState - localName: ResponseOutput - firstState: CDSDeleteResponseState - - key: - name: ReceiveEventPolicy - version: 0.0.1 - value: - policyKey: - name: ReceiveEventPolicy - version: 0.0.1 - template: Freestyle - state: - entry: - - key: CreateOrDeleteState - value: - stateKey: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: CreateOrDeleteState - trigger: - name: PMSubscriptionOutputEvent - version: 0.0.1 - stateOutputs: - entry: - - key: CreateSubscriptionPayload - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateOrDeleteState - localName: CreateSubscriptionPayload - outgoingEvent: - name: CreateSubscriptionPayloadEvent - version: 0.0.1 - nextState: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: CreateSubscription - - key: DeleteSubscriptionPayload - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateOrDeleteState - localName: DeleteSubscriptionPayload - outgoingEvent: - name: DeleteSubscriptionPayloadEvent - version: 0.0.1 - nextState: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: DeleteSubscription - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskSelectionLogic: - key: TaskSelectionLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - - executor.logger.info(executor.subject.id); - - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) - var changeType = pmSubscriptionInfo.get("changeType").toString() - - executor.logger.info("Change Type is " + changeType) - - if ("CREATE".equals(changeType)) { - executor.logger.info("Choosing to create a subscription") - executor.subject.getTaskKey("CreateSubscriptionPayloadTask").copyTo(executor.selectedTask); - } - else if ("DELETE".equals(changeType)) { - executor.logger.info("Choosing to delete a subscription") - executor.subject.getTaskKey("DeleteSubscriptionPayloadTask").copyTo(executor.selectedTask); - } - - //var returnValue = executor.isTrue; - true; - stateFinalizerLogicMap: - entry: [] - defaultTask: - name: CreateSubscriptionPayloadTask - version: 0.0.1 - taskReferences: - entry: - - key: - name: CreateSubscriptionPayloadTask - version: 0.0.1 - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateOrDeleteState - localName: ReceiveEventPolicy - outputType: DIRECT - output: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateOrDeleteState - localName: CreateSubscriptionPayload - - key: - name: DeleteSubscriptionPayloadTask - version: 0.0.1 - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateOrDeleteState - localName: ReceiveEventPolicy - outputType: DIRECT - output: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateOrDeleteState - localName: DeleteSubscriptionPayload - - key: CreateSubscription - value: - stateKey: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: CreateSubscription - trigger: - name: CreateSubscriptionPayloadEvent - version: 0.0.1 - stateOutputs: - entry: - - key: IssueCreateSubscriptionRequestOutput - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateSubscription - localName: IssueCreateSubscriptionRequestOutput - outgoingEvent: - name: CDSCreateSubscriptionRequestEvent - version: 0.0.1 - nextState: - parentKeyName: 'NULL' - parentKeyVersion: 0.0.0 - parentLocalName: 'NULL' - localName: 'NULL' - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskSelectionLogic: - key: 'NULL' - logicFlavour: UNDEFINED - logic: '' - stateFinalizerLogicMap: - entry: [] - defaultTask: - name: CreateSubscriptionRequestTask - version: 0.0.1 - taskReferences: - entry: - - key: - name: CreateSubscriptionRequestTask - version: 0.0.1 - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateSubscription - localName: ReceiveEventPolicy - outputType: DIRECT - output: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: CreateSubscription - localName: IssueCreateSubscriptionRequestOutput - - key: DeleteSubscription - value: - stateKey: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: DeleteSubscription - trigger: - name: DeleteSubscriptionPayloadEvent - version: 0.0.1 - stateOutputs: - entry: - - key: IssueDeleteSubscriptionRequestOutput - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: DeleteSubscription - localName: IssueDeleteSubscriptionRequestOutput - outgoingEvent: - name: CDSDeleteSubscriptionRequestEvent - version: 0.0.1 - nextState: - parentKeyName: 'NULL' - parentKeyVersion: 0.0.0 - parentLocalName: 'NULL' - localName: 'NULL' - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskSelectionLogic: - key: 'NULL' - logicFlavour: UNDEFINED - logic: '' - stateFinalizerLogicMap: - entry: [] - defaultTask: - name: DeleteSubscriptionRequestTask - version: 0.0.1 - taskReferences: - entry: - - key: - name: DeleteSubscriptionRequestTask - version: 0.0.1 - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: DeleteSubscription - localName: ReceiveEventPolicy - outputType: DIRECT - output: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: DeleteSubscription - localName: IssueDeleteSubscriptionRequestOutput - - key: ReceiveSubscriptionState - value: - stateKey: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: ReceiveSubscriptionState - trigger: - name: pmsh-operational-policy - version: 0.0.1 - stateOutputs: - entry: - - key: ReceivePMSubscriptionOutput - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: ReceiveSubscriptionState - localName: ReceivePMSubscriptionOutput - outgoingEvent: - name: PMSubscriptionOutputEvent - version: 0.0.1 - nextState: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: 'NULL' - localName: CreateOrDeleteState - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskSelectionLogic: - key: 'NULL' - logicFlavour: UNDEFINED - logic: '' - stateFinalizerLogicMap: - entry: [] - defaultTask: - name: ReceiveSubscriptionTask - version: 0.0.1 - taskReferences: - entry: - - key: - name: ReceiveSubscriptionTask - version: 0.0.1 - value: - key: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: ReceiveSubscriptionState - localName: ReceiveEventPolicy - outputType: DIRECT - output: - parentKeyName: ReceiveEventPolicy - parentKeyVersion: 0.0.1 - parentLocalName: ReceiveSubscriptionState - localName: ReceivePMSubscriptionOutput - firstState: ReceiveSubscriptionState - tasks: - key: - name: PMControlPolicy_Tasks - version: 0.0.1 - taskMap: - entry: - - key: - name: CDSCreateResponseTask - version: 0.0.1 - value: - key: - name: CDSCreateResponseTask - version: 0.0.1 - inputFields: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSResponseCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSCreateResponsePayloadType - version: 0.0.1 - optional: false - - key: status - value: - key: status - fieldSchemaKey: - name: CDSResponseStatusType - version: 0.0.1 - optional: false - outputFields: - entry: - - key: status - value: - key: status - fieldSchemaKey: - name: SubscriptionStatusType - version: 0.0.1 - optional: false - taskParameters: - entry: [] - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskLogic: - key: TaskLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - - executor.logger.info(executor.subject.id); - - var commonHeader = executor.inFields.get("commonHeader") - var response = executor.inFields.get("payload") - var albumID = commonHeader.get("requestId") - - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString()); - var responseStatus = executor.subject.getOutFieldSchemaHelper("status").createNewInstance(); - - responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) - responseStatus.put("nfName", pmSubscriptionInfo.get("nfName")) - responseStatus.put("changeType", pmSubscriptionInfo.get("changeType")) - - var status = response.get(pmSubscriptionInfo.get("changeType").toLowerCase() + "_DasH_subscription_DasH_response").get("odl_DasH_response").get("status") - - executor.logger.info("RESPONSE STATUS = " + status) - - if(status == "success") { - responseStatus.put("message", "success") - } else { - responseStatus.put("message", "failed") - } - - executor.outFields.put("status", responseStatus) - - //var returnValue = executor.isTrue; - true; - - key: - name: CDSDeleteResponseTask - version: 0.0.1 - value: - key: - name: CDSDeleteResponseTask - version: 0.0.1 - inputFields: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSResponseCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSDeleteResponsePayloadType - version: 0.0.1 - optional: false - - key: status - value: - key: status - fieldSchemaKey: - name: CDSResponseStatusType - version: 0.0.1 - optional: false - outputFields: - entry: - - key: status - value: - key: status - fieldSchemaKey: - name: SubscriptionStatusType - version: 0.0.1 - optional: false - taskParameters: - entry: [] - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskLogic: - key: TaskLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - - executor.logger.info(executor.subject.id); - - var commonHeader = executor.inFields.get("commonHeader") - var response = executor.inFields.get("payload") - var albumID = commonHeader.get("requestId") - - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString()); - var responseStatus = executor.subject.getOutFieldSchemaHelper("status").createNewInstance(); - - responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) - responseStatus.put("nfName", pmSubscriptionInfo.get("nfName")) - responseStatus.put("changeType", pmSubscriptionInfo.get("changeType")) - - var status = response.get(pmSubscriptionInfo.get("changeType").toLowerCase() + "_DasH_subscription_DasH_response").get("odl_DasH_response").get("status") - - executor.logger.info("RESPONSE STATUS = " + status) - - if(status == "success") { - responseStatus.put("message", "success") - } else { - responseStatus.put("message", "failed") - } - - executor.outFields.put("status", responseStatus) - - //var returnValue = executor.isTrue; - true; - - key: - name: CreateSubscriptionPayloadTask - version: 0.0.1 - value: - key: - name: CreateSubscriptionPayloadTask - version: 0.0.1 - inputFields: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - outputFields: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - optional: false - taskParameters: - entry: [] - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskLogic: - key: TaskLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - - executor.logger.info(executor.subject.id); - - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) - - var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() - - var payloadProperties = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance(changeType + "_DasH_subscription_DasH_properties_record"); - - payloadProperties.put("nfName", pmSubscriptionInfo.get("nfName")) - payloadProperties.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) - payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState")) - payloadProperties.put("fileBasedGP", pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString()) - payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation")) - payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups")) - - var payloadEntry = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("CDSRequestPayloadEntry"); - payloadEntry.put(changeType + "_DasH_subscription_DasH_properties", payloadProperties) - - var payload = executor.subject.getOutFieldSchemaHelper("payload").createNewInstance(); - payload.put(changeType + "_DasH_subscription_DasH_request", payloadEntry); - - executor.outFields.put("albumID", executor.inFields.get("albumID")) - executor.outFields.put("payload", payload); - - //var returnValue = executor.isTrue; - true; - - key: - name: CreateSubscriptionRequestTask - version: 0.0.1 - value: - key: - name: CreateSubscriptionRequestTask - version: 0.0.1 - inputFields: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - optional: false - outputFields: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSRequestCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - optional: false - taskParameters: - entry: [] - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskLogic: - key: TaskLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - - executor.logger.info(executor.subject.id); - - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) - - var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() - var blueprintName = pmSubscriptionInfo.get("blueprintName").toLowerCase() - var blueprintVersion = pmSubscriptionInfo.get("blueprintVersion").toLowerCase() - var payload = executor.inFields.get("payload") - var actionName = changeType + "-subscription" - - var commonHeader = executor.subject.getOutFieldSchemaHelper("commonHeader").createNewInstance(); - commonHeader.put("originatorId", "sdnc"); - commonHeader.put("requestId", executor.inFields.get("albumID").toString()); - commonHeader.put("subRequestId", "sub-123456-1000"); - - var actionIdentifiers = executor.subject.getOutFieldSchemaHelper("actionIdentifiers").createNewInstance(); - actionIdentifiers.put("actionName", actionName); - actionIdentifiers.put("blueprintName", blueprintName); - actionIdentifiers.put("blueprintVersion", blueprintVersion); - actionIdentifiers.put("mode", "sync"); - - executor.outFields.put("commonHeader", commonHeader); - executor.outFields.put("actionIdentifiers", actionIdentifiers); - executor.outFields.put("payload", payload); - - //var returnValue = executor.isTrue; - true; - - key: - name: DeleteSubscriptionPayloadTask - version: 0.0.1 - value: - key: - name: DeleteSubscriptionPayloadTask - version: 0.0.1 - inputFields: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - outputFields: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - optional: false - taskParameters: - entry: [] - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskLogic: - key: TaskLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - - executor.logger.info(executor.subject.id); - - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) - - var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() - - var payloadProperties = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance(changeType + "_DasH_subscription_DasH_properties_record"); - - payloadProperties.put("nfName", pmSubscriptionInfo.get("nfName")) - payloadProperties.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) - payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState")) - payloadProperties.put("fileBasedGP", pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString()) - payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation")) - payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups")) - - var payloadEntry = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("CDSRequestPayloadEntry"); - payloadEntry.put(changeType + "_DasH_subscription_DasH_properties", payloadProperties) - - var payload = executor.subject.getOutFieldSchemaHelper("payload").createNewInstance(); - payload.put(changeType + "_DasH_subscription_DasH_request", payloadEntry); - - executor.outFields.put("albumID", executor.inFields.get("albumID")) - executor.outFields.put("payload", payload); - - //var returnValue = executor.isTrue; - true; - - key: - name: DeleteSubscriptionRequestTask - version: 0.0.1 - value: - key: - name: DeleteSubscriptionRequestTask - version: 0.0.1 - inputFields: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - optional: false - outputFields: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSRequestCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - optional: false - taskParameters: - entry: [] - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskLogic: - key: TaskLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - - executor.logger.info(executor.subject.id); - - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) - - var changeType = pmSubscriptionInfo.get("changeType").toLowerCase() - var blueprintName = pmSubscriptionInfo.get("blueprintName").toLowerCase() - var blueprintVersion = pmSubscriptionInfo.get("blueprintVersion").toLowerCase() - var payload = executor.inFields.get("payload") - var actionName = changeType + "-subscription" - - var commonHeader = executor.subject.getOutFieldSchemaHelper("commonHeader").createNewInstance(); - commonHeader.put("originatorId", "sdnc"); - commonHeader.put("requestId", executor.inFields.get("albumID").toString()); - commonHeader.put("subRequestId", "sub-123456-1000"); - - var actionIdentifiers = executor.subject.getOutFieldSchemaHelper("actionIdentifiers").createNewInstance(); - actionIdentifiers.put("actionName", actionName); - actionIdentifiers.put("blueprintName", blueprintName); - actionIdentifiers.put("blueprintVersion", blueprintVersion); - actionIdentifiers.put("mode", "sync"); - - executor.outFields.put("commonHeader", commonHeader); - executor.outFields.put("actionIdentifiers", actionIdentifiers); - executor.outFields.put("payload", payload); - - //var returnValue = executor.isTrue; - true; - - key: - name: ReceiveSubscriptionTask - version: 0.0.1 - value: - key: - name: ReceiveSubscriptionTask - version: 0.0.1 - inputFields: - entry: - - key: blueprintName - value: - key: blueprintName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: blueprintVersion - value: - key: blueprintVersion - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: changeType - value: - key: changeType - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: closedLoopControlName - value: - key: closedLoopControlName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: nfName - value: - key: nfName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: policyName - value: - key: policyName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: subscription - value: - key: subscription - fieldSchemaKey: - name: SubscriptionType - version: 0.0.1 - optional: false - outputFields: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - taskParameters: - entry: [] - contextAlbumReference: - - name: PMSubscriptionAlbum - version: 0.0.1 - taskLogic: - key: TaskLogic - logicFlavour: JAVASCRIPT - logic: |- - /* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - var uuidType = java.util.UUID; - - executor.logger.info(executor.subject.id); - - //albumID will be used to fetch info from our album later - var albumID = uuidType.randomUUID(); - var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").getSchemaHelper().createNewInstance(); - var returnValue = true; - - if(executor.inFields.get("policyName") != null) { - executor.logger.info("nfName in receive sub event " + executor.inFields.get("nfName")); - - var changeType = executor.inFields.get("changeType") - var nfName = executor.inFields.get("nfName") - var policyName = executor.inFields.get("policyName") - var closedLoopControlName = executor.inFields.get("closedLoopControlName") - var subscription = executor.inFields.get("subscription") - var blueprintName = executor.inFields.get("blueprintName") - var blueprintVersion = executor.inFields.get("blueprintVersion") - - pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName")); - pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType")) - pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName")) - pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName")) - pmSubscriptionInfo.put("subscription", subscription) - pmSubscriptionInfo.put("blueprintName", blueprintName) - pmSubscriptionInfo.put("blueprintVersion", blueprintVersion) - - - executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo); - - executor.outFields.put("albumID", albumID) - } else { - executor.message = "Received invalid event" - returnValue = false; - } - - returnValue; - events: - key: - name: PMControlPolicy_Events - version: 0.0.1 - eventMap: - entry: - - key: - name: CDSCreateResponseEvent - version: 0.0.1 - value: - key: - name: CDSCreateResponseEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: CDS - target: APEX - parameter: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSResponseCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSCreateResponsePayloadType - version: 0.0.1 - optional: false - - key: status - value: - key: status - fieldSchemaKey: - name: CDSResponseStatusType - version: 0.0.1 - optional: false - - key: - name: CDSCreateSubscriptionRequestEvent - version: 0.0.1 - value: - key: - name: CDSCreateSubscriptionRequestEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: APEX - target: APEX - parameter: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSRequestCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - optional: false - - key: - name: CDSDeleteResponseEvent - version: 0.0.1 - value: - key: - name: CDSDeleteResponseEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: CDS - target: APEX - parameter: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSResponseCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSDeleteResponsePayloadType - version: 0.0.1 - optional: false - - key: status - value: - key: status - fieldSchemaKey: - name: CDSResponseStatusType - version: 0.0.1 - optional: false - - key: - name: CDSDeleteSubscriptionRequestEvent - version: 0.0.1 - value: - key: - name: CDSDeleteSubscriptionRequestEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: APEX - target: APEX - parameter: - entry: - - key: actionIdentifiers - value: - key: actionIdentifiers - fieldSchemaKey: - name: CDSActionIdentifiersType - version: 0.0.1 - optional: false - - key: commonHeader - value: - key: commonHeader - fieldSchemaKey: - name: CDSRequestCommonHeaderType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - optional: false - - key: - name: CDSResponseStatusEvent - version: 0.0.1 - value: - key: - name: CDSResponseStatusEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: APEX - target: DCAE - parameter: - entry: - - key: status - value: - key: status - fieldSchemaKey: - name: SubscriptionStatusType - version: 0.0.1 - optional: false - - key: - name: CreateSubscriptionPayloadEvent - version: 0.0.1 - value: - key: - name: CreateSubscriptionPayloadEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: APEX - target: APEX - parameter: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - optional: false - - key: - name: DeleteSubscriptionPayloadEvent - version: 0.0.1 - value: - key: - name: DeleteSubscriptionPayloadEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: APEX - target: APEX - parameter: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - - key: payload - value: - key: payload - fieldSchemaKey: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - optional: false - - key: - name: MRResponseEvent - version: 0.0.1 - value: - key: - name: MRResponseEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: DCAE - target: APEX - parameter: - entry: - - key: count - value: - key: count - fieldSchemaKey: - name: SimpleIntType - version: 0.0.1 - optional: false - - key: serverTimeMs - value: - key: serverTimeMs - fieldSchemaKey: - name: SimpleIntType - version: 0.0.1 - optional: false - - key: - name: PMSubscriptionOutputEvent - version: 0.0.1 - value: - key: - name: PMSubscriptionOutputEvent - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: APEX - target: APEX - parameter: - entry: - - key: albumID - value: - key: albumID - fieldSchemaKey: - name: UUIDType - version: 0.0.1 - optional: false - - key: - name: pmsh-operational-policy - version: 0.0.1 - value: - key: - name: pmsh-operational-policy - version: 0.0.1 - nameSpace: org.onap.policy.apex.onap.pmcontrol - source: DCAE - target: APEX - parameter: - entry: - - key: blueprintName - value: - key: blueprintName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: blueprintVersion - value: - key: blueprintVersion - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: changeType - value: - key: changeType - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: closedLoopControlName - value: - key: closedLoopControlName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: nfName - value: - key: nfName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: policyName - value: - key: policyName - fieldSchemaKey: - name: SimpleStringType - version: 0.0.1 - optional: false - - key: subscription - value: - key: subscription - fieldSchemaKey: - name: SubscriptionType - version: 0.0.1 - optional: false - albums: - key: - name: PMControlPolicy_Albums - version: 0.0.1 - albums: - entry: - - key: - name: PMSubscriptionAlbum - version: 0.0.1 - value: - key: - name: PMSubscriptionAlbum - version: 0.0.1 - scope: policy - isWritable: true - itemSchema: - name: PMSubscriptionType - version: 0.0.1 - schemas: - key: - name: PMControlPolicy_Schemas - version: 0.0.1 - schemas: - entry: - - key: - name: CDSActionIdentifiersType - version: 0.0.1 - value: - key: - name: CDSActionIdentifiersType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "type": "record", - "name": "ActionIdentifiers_Type", - "namespace": "org.onap.policy.apex.onap.helloworld", - "fields": [ - { - "name": "actionName", - "type": "string" - }, - { - "name": "blueprintName", - "type": "string" - }, - { - "name": "blueprintVersion", - "type": "string" - }, - { - "name": "mode", - "type": "string" - } - ] - } - - key: - name: CDSCreateResponsePayloadType - version: 0.0.1 - value: - key: - name: CDSCreateResponsePayloadType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "name": "CreateResponsePayloadEntry", - "type": "record", - "namespace": "org.onap.policy.apex.onap.helloworld", - "fields": [ - { - "name": "create_DasH_subscription_DasH_response", - "type": { - "name": "create_DasH_subscription_DasH_response", - "type": "record", - "fields": [ - { - "name": "odl_DasH_response", - "type": { - "name": "odl_DasH_response", - "type": "record", - "fields": [ - { - "name": "status", - "type": "string" - } - ] - } - } - ] - } - } - ] - } - - key: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - value: - key: - name: CDSCreateSubscriptionPayloadType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "type": "map", - "values": { - "type": "record", - "name": "CDSRequestPayloadEntry", - "fields": [ - { - "name": "create_DasH_subscription_DasH_properties", - "type": { - "name": "create_DasH_subscription_DasH_properties_record", - "type": "record", - "fields": [ - { - "name": "nfName", - "type": "string" - }, - { - "name": "subscriptionName", - "type": "string" - }, - { - "name": "administrativeState", - "type": "string" - }, - { - "name": "fileBasedGP", - "type": "string" - }, - { - "name": "fileLocation", - "type": "string" - }, - { - "name": "measurementGroups", - "type": { - "type": "array", - "items": { - "name": "measurementGroups_record", - "type": "record", - "fields": [ - { - "name": "measurementGroup", - "type": { - "name": "measurementGroup", - "type": "record", - "fields": [ - { - "name": "measurementTypes", - "type": { - "type": "array", - "items": { - "name": "measurementTypes_record", - "type": "record", - "fields": [ - { - "name": "measurementType", - "type": "string" - } - ] - } - } - }, - { - "name": "managedObjectDNsBasic", - "type": { - "type": "array", - "items": { - "name": "managedObjectDNsBasic_record", - "type": "record", - "fields": [ - { - "name": "DN", - "type": "string" - } - ] - } - } - } - ] - } - } - ] - } - } - } - ] - } - } - ] - } - } - - key: - name: CDSDeleteResponsePayloadType - version: 0.0.1 - value: - key: - name: CDSDeleteResponsePayloadType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "name": "DeleteResponsePayloadEntry", - "type": "record", - "namespace": "com.acme.avro", - "fields": [ - { - "name": "delete_DasH_subscription_DasH_response", - "type": { - "name": "delete_DasH_subscription_DasH_response", - "type": "record", - "fields": [ - { - "name": "odl_DasH_response", - "type": { - "name": "odl_DasH_response", - "type": "record", - "fields": [ - { - "name": "status", - "type": "string" - } - ] - } - } - ] - } - } - ] - } - - key: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - value: - key: - name: CDSDeleteSubscriptionPayloadType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "type": "map", - "values": { - "type": "record", - "name": "CDSRequestPayloadEntry", - "fields": [ - { - "name": "delete_DasH_subscription_DasH_properties", - "type": { - "name": "delete_DasH_subscription_DasH_properties_record", - "type": "record", - "fields": [ - { - "name": "nfName", - "type": "string" - }, - { - "name": "subscriptionName", - "type": "string" - }, - { - "name": "administrativeState", - "type": "string" - }, - { - "name": "fileBasedGP", - "type": "string" - }, - { - "name": "fileLocation", - "type": "string" - }, - { - "name": "measurementGroups", - "type": { - "type": "array", - "items": { - "name": "measurementGroups_record", - "type": "record", - "fields": [ - { - "name": "measurementGroup", - "type": { - "name": "measurementGroup", - "type": "record", - "fields": [ - { - "name": "measurementTypes", - "type": { - "type": "array", - "items": { - "name": "measurementTypes_record", - "type": "record", - "fields": [ - { - "name": "measurementType", - "type": "string" - } - ] - } - } - }, - { - "name": "managedObjectDNsBasic", - "type": { - "type": "array", - "items": { - "name": "managedObjectDNsBasic_record", - "type": "record", - "fields": [ - { - "name": "DN", - "type": "string" - } - ] - } - } - } - ] - } - } - ] - } - } - } - ] - } - } - ] - } - } - - key: - name: CDSRequestCommonHeaderType - version: 0.0.1 - value: - key: - name: CDSRequestCommonHeaderType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "type": "record", - "name": "RequestCommonHeader_Type", - "namespace": "org.onap.policy.apex.onap.helloworld", - "fields": [ - { - "name": "originatorId", - "type": "string" - }, - { - "name": "requestId", - "type": "string" - }, - { - "name": "subRequestId", - "type": "string" - } - ] - } - - key: - name: CDSResponseCommonHeaderType - version: 0.0.1 - value: - key: - name: CDSResponseCommonHeaderType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "type": "record", - "name": "ResponseCommonHeader_Type", - "namespace": "org.onap.policy.apex.onap.helloworld", - "fields": [ - { - "name": "originatorId", - "type": "string" - }, - { - "name": "requestId", - "type": "string" - }, - { - "name": "subRequestId", - "type": "string" - }, - { - "name": "timestamp", - "type": "string" - }, - { - "name": "flags", - "type": ["null", "string"] - } - ] - } - - key: - name: CDSResponseStatusType - version: 0.0.1 - value: - key: - name: CDSResponseStatusType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "type": "record", - "name": "ResponseStatus_Type", - "namespace": "org.onap.policy.apex.onap.helloworld", - "fields": [ - { - "name": "code", - "type": "int" - }, - { - "name": "eventType", - "type": "string" - }, - { - "name": "timestamp", - "type": "string" - }, - { - "name": "message", - "type": "string" - } - ] - } - - key: - name: PMSubscriptionType - version: 0.0.1 - value: - key: - name: PMSubscriptionType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: "{\n\t\"name\": \"PMSubscription\",\n\t\"type\": \"record\",\n\t\"namespace\": \"\ - org.onap.policy.apex.onap.pmcontrol\",\n\t\"fields\": [\n {\n \"name\": \"nfName\"\ - ,\n \"type\": \"string\"\n },\n\t {\n\t\t\t\"name\": \"changeType\",\n\t\t\t\"\ - type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"closedLoopControlName\",\n\t\t\t\"type\": \"\ - string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"policyName\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\ - {\n\t\t \"name\": \"blueprintName\",\n\t\t \"type\": \"string\"\n\t\t},\n\t\t{\n\t\t \"name\"\ - : \"blueprintVersion\",\n\t\t \"type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"subscription\"\ - ,\n\t\t\t\"type\": {\n\t\t\t\t\"name\": \"subscription\",\n\t\t\t\t\"type\": \"record\",\n\t\t\t\t\ - \"fields\": [{\n\t\t\t\t\t\t\"name\": \"subscriptionName\",\n\t\t\t\t\t\t\"type\": \"string\"\n\t\t\ - \t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"administrativeState\",\n\t\t\t\t\t\t\"type\": \"string\"\ - \n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"fileBasedGP\",\n\t\t\t\t\t\t\"type\": \"int\"\ - \n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"fileLocation\",\n\t\t\t\t\t\t\"type\": \"string\"\ - \n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"name\": \"measurementGroups\",\n\t\t\t\t\t\t\"type\": {\n\ - \t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\"name\": \"Measurement_Groups_Type\"\ - ,\n\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\"name\"\ - : \"measurementGroup\",\n\t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\t\t\t\t\t\t\"name\": \"Measurement_Group_Type\"\ - ,\n\t\t\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\ - \t\t\t\t\"name\": \"measurementTypes\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\t\t\t\t\t\t\ - \t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"\ - name\": \"Measurement_Types_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\ - \t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"measurementType\",\n\t\ - \t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\ - \t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\ - \t\t\t\t\t\t\t\t\"name\": \"managedObjectDNsBasic\",\n\t\t\t\t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\ - \t\t\t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\t\ - \t\t\t\t\t\"name\": \"Managed_Object_Dns_Basic_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"record\"\ - ,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"DN\",\n\t\ - \t\t\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\ - \t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\ - \t\t\t\t}\n\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\ - \t}\n\t]\n}" - - key: - name: SimpleIntType - version: 0.0.1 - value: - key: - name: SimpleIntType - version: 0.0.1 - schemaFlavour: Java - schemaDefinition: java.lang.Integer - - key: - name: SimpleStringType - version: 0.0.1 - value: - key: - name: SimpleStringType - version: 0.0.1 - schemaFlavour: Java - schemaDefinition: java.lang.String - - key: - name: SubscriptionStatusType - version: 0.0.1 - value: - key: - name: SubscriptionStatusType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: |- - { - "type": "record", - "name": "ActivateSubscriptionStatus_Type", - "namespace": "org.onap.policy.apex.onap.helloworld", - "fields": [ - { - "name": "subscriptionName", - "type": "string" - }, - { - "name": "nfName", - "type": "string" - }, - { - "name": "changeType", - "type": "string" - }, - { - "name": "message", - "type": "string" - } - ] - } - - key: - name: SubscriptionType - version: 0.0.1 - value: - key: - name: SubscriptionType - version: 0.0.1 - schemaFlavour: Avro - schemaDefinition: "{\n\t\"name\": \"subscription\",\n\t\"type\": \"record\",\n\t\"fields\": [{\n\t\t\ - \t\"name\": \"subscriptionName\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"administrativeState\"\ - ,\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"fileBasedGP\",\n\t\t\t\"type\": \"\ - int\"\n\t\t},\n\t\t{\n\t\t\t\"name\": \"fileLocation\",\n\t\t\t\"type\": \"string\"\n\t\t},\n\t\t\ - {\n\t\t\t\"name\": \"measurementGroups\",\n\t\t\t\"type\": {\n\t\t\t\t\"type\": \"array\",\n\t\t\t\ - \t\"items\": {\n\t\t\t\t\t\"name\": \"Measurement_Groups_Type\",\n\t\t\t\t\t\"type\": \"record\",\n\ - \t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\"name\": \"measurementGroup\",\n\t\t\t\t\t\t\"type\": {\n\t\ - \t\t\t\t\t\t\"name\": \"Measurement_Group_Type\",\n\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\ - \t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\"name\": \"measurementTypes\",\n\t\t\t\t\t\t\t\t\t\"type\"\ - : {\n\t\t\t\t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\t\t\ - \t\t\"name\": \"Measurement_Types_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\"type\": \"record\",\n\t\t\t\t\t\ - \t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"measurementType\",\n\t\t\t\t\t\t\t\ - \t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ - }\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\"name\": \"managedObjectDNsBasic\",\n\ - \t\t\t\t\t\t\t\t\t\"type\": {\n\t\t\t\t\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\t\t\t\t\"items\"\ - : {\n\t\t\t\t\t\t\t\t\t\t\t\"name\": \"Managed_Object_Dns_Basic_Type\",\n\t\t\t\t\t\t\t\t\t\t\t\"\ - type\": \"record\",\n\t\t\t\t\t\t\t\t\t\t\t\"fields\": [{\n\t\t\t\t\t\t\t\t\t\t\t\t\"name\": \"DN\"\ - ,\n\t\t\t\t\t\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t\t\t\t}\n\ - \t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}]\n\t\t\t\t}\n\t\ - \t\t}\n\t\t}\n\t]\n}" - - key: - name: UUIDType - version: 0.0.1 - value: - key: - name: UUIDType - version: 0.0.1 - schemaFlavour: Java - schemaDefinition: java.util.UUID - engineParameters: - executorParameters: - JAVASCRIPT: - parameterClassName: org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters - contextParameters: - parameterClassName: org.onap.policy.apex.context.parameters.ContextParameters - schemaParameters: - Avro: - parameterClassName: org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters - Java: - parameterClassName: org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters - jsonAdapters: - Instant: - adaptedClass: java.time.Instant - adaptorClass: org.onap.policy.controlloop.util.Serialization$GsonInstantAdapter - eventInputParameters: - DCAEConsumer: - carrierTechnologyParameters: - carrierTechnology: RESTCLIENT - parameterClassName: org.onap.policy.apex.plugins.event.carrier.restclient.RestClientCarrierTechnologyParameters - parameters: - consumerPollTime: '50' - url: https://message-router:3905/events/unauthenticated.DCAE_CL_OUTPUT/cg1/sg1 - eventProtocolParameters: - eventProtocol: JSON - parameters: - nameAlias: policyName - eventName: pmsh-operational-policy - eventNameFilter: pmsh-operational-policy - CDSRequestConsumer: - carrierTechnologyParameters: - carrierTechnology: RESTREQUESTOR - parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters - parameters: - url: http://10.10.10.184:30254/api/v1/execution-service/process - httpMethod: POST - restRequestTimeout: 2000 - httpHeaders: - - - Authorization - - Basic Y2NzZGthcHBzOmNjc2RrYXBwcw== - eventProtocolParameters: - eventProtocol: JSON - eventName: CDSCreateResponseEvent - eventNameFilter: CDSCreateResponseEvent - requestorMode: true - requestorPeer: CDSRequestProducer - requestorTimeout: 500 - CDSDeleteRequestConsumer: - carrierTechnologyParameters: - carrierTechnology: RESTREQUESTOR - parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters - parameters: - url: http://10.10.10.184:30254/api/v1/execution-service/process - httpMethod: POST - restRequestTimeout: 2000 - httpHeaders: - - - Authorization - - Basic Y2NzZGthcHBzOmNjc2RrYXBwcw== - eventProtocolParameters: - eventProtocol: JSON - eventName: CDSDeleteResponseEvent - eventNameFilter: CDSDeleteResponseEvent - requestorMode: true - requestorPeer: CDSDeleteRequestProducer - requestorTimeout: 500 - CDSReplyConsumer: - carrierTechnologyParameters: - carrierTechnology: RESTREQUESTOR - parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters - parameters: - url: https://message-router:3905/events/unauthenticated.PMSH_CL_INPUT - httpMethod: POST - restRequestTimeout: 2000 - eventProtocolParameters: - eventProtocol: JSON - eventName: MRResponseEvent - eventNameFilter: MRResponseEvent - requestorMode: true - requestorPeer: CDSReplyProducer - requestorTimeout: 500 - eventOutputParameters: - logOutputter: - carrierTechnologyParameters: - carrierTechnology: FILE - parameters: - fileName: /tmp/outputevents.log - eventProtocolParameters: - eventProtocol: JSON - StdOutOutputter: - carrierTechnologyParameters: - carrierTechnology: FILE - parameters: - standardIo: true - eventProtocolParameters: - eventProtocol: JSON - CDSRequestProducer: - carrierTechnologyParameters: - carrierTechnology: RESTREQUESTOR - parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters - eventProtocolParameters: - eventProtocol: JSON - eventNameFilter: CDSCreateSubscriptionRequestEvent - requestorMode: true - requestorPeer: CDSRequestConsumer - requestorTimeout: 500 - CDSDeleteRequestProducer: - carrierTechnologyParameters: - carrierTechnology: RESTREQUESTOR - parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters - eventProtocolParameters: - eventProtocol: JSON - eventNameFilter: CDSDeleteSubscriptionRequestEvent - requestorMode: true - requestorPeer: CDSDeleteRequestConsumer - requestorTimeout: 500 - CDSReplyProducer: - carrierTechnologyParameters: - carrierTechnology: RESTREQUESTOR - parameterClassName: org.onap.policy.apex.plugins.event.carrier.restrequestor.RestRequestorCarrierTechnologyParameters - eventProtocolParameters: - eventProtocol: JSON - eventNameFilter: CDSResponseStatusEvent - requestorMode: true - requestorPeer: CDSReplyConsumer - requestorTimeout: 500 diff --git a/models/src/test/resources/json/AutomationCompositionElementNoOrderedState.json b/models/src/test/resources/json/AutomationCompositionElementNoOrderedState.json new file mode 100644 index 000000000..872499abf --- /dev/null +++ b/models/src/test/resources/json/AutomationCompositionElementNoOrderedState.json @@ -0,0 +1,13 @@ +{ + "id": "a95757ba-b34a-4049-a2a8-46773abcbe5e", + "definition": { + "name": "aceDef", + "version": "0.0.1" + }, + "participantType": { + "name": "participantType", + "version": "0.0.1" + }, + "state": "UNINITIALISED", + "orderedState": null +} diff --git a/models/src/test/resources/json/AutomationCompositionNoOrderedState.json b/models/src/test/resources/json/AutomationCompositionNoOrderedState.json new file mode 100644 index 000000000..d61a61117 --- /dev/null +++ b/models/src/test/resources/json/AutomationCompositionNoOrderedState.json @@ -0,0 +1,12 @@ +{ + "definition": { + "name": "automationCompositionDefinitionName", + "version": "0.0.1" + }, + "state": "UNINITIALISED", + "orderedState": null, + "elements": [ + ], + "name": "automation-composition", + "version": "0.0.1" +} diff --git a/models/src/test/resources/json/ControlLoopElementNoOrderedState.json b/models/src/test/resources/json/ControlLoopElementNoOrderedState.json deleted file mode 100644 index 33a63e604..000000000 --- a/models/src/test/resources/json/ControlLoopElementNoOrderedState.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "id": "a95757ba-b34a-4049-a2a8-46773abcbe5e", - "definition": { - "name": "cleDef", - "version": "0.0.1" - }, - "participantType": { - "name": "participantType", - "version": "0.0.1" - }, - "state": "UNINITIALISED", - "orderedState": null -} diff --git a/models/src/test/resources/json/ControlLoopNoOrderedState.json b/models/src/test/resources/json/ControlLoopNoOrderedState.json deleted file mode 100644 index 6bff97580..000000000 --- a/models/src/test/resources/json/ControlLoopNoOrderedState.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "definition": { - "name": "controlLoopDefinitionName", - "version": "0.0.1" - }, - "state": "UNINITIALISED", - "orderedState": null, - "elements": [ - ], - "name": "control-loop", - "version": "0.0.1" -} diff --git a/models/src/test/resources/providers/TestAcElementStatistics.json b/models/src/test/resources/providers/TestAcElementStatistics.json new file mode 100644 index 000000000..cceb91d14 --- /dev/null +++ b/models/src/test/resources/providers/TestAcElementStatistics.json @@ -0,0 +1,24 @@ +{ + "acElementStatistics":[ + { + "participantId":{ + "name":"name1", + "version":"1.001" + }, + "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", + "timeStamp": "2021-01-10T13:45:00.000Z", + "state": "UNINITIALISED", + "acElementUptime":250 + }, + { + "participantId":{ + "name":"name2", + "version":"1.001" + }, + "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", + "timeStamp": "2021-01-10T14:25:00.000Z", + "state": "UNINITIALISED", + "acElementUptime":330 + } + ] +} diff --git a/models/src/test/resources/providers/TestAutomationCompositions.json b/models/src/test/resources/providers/TestAutomationCompositions.json new file mode 100644 index 000000000..906785244 --- /dev/null +++ b/models/src/test/resources/providers/TestAutomationCompositions.json @@ -0,0 +1,142 @@ +{ + "automationCompositionList": [ + { + "definition": { + "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "elements": { + "709c62b3-8918-41b9-a747-e21eb79c6c20": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", + "version": "2.3.4" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "DCAE automation composition element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c21": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", + "version": "2.3.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Monitoring Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c22": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", + "version": "2.3.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Operational Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c23": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant", + "version": "2.2.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "CDS automation composition element for the PMSH instance 0 automation composition" + } + }, + "name": "PMSHInstance0", + "version": "1.0.1", + "description": "PMSH automation composition instance 0" + }, + { + "definition": { + "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition", + "version": "1.0.0" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "elements": { + "709c62b3-8918-41b9-a747-e21eb79c6c24": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c24", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", + "version": "2.3.4" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "DCAE automation composition element for the PMSH instance 1 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c25": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c25", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", + "version": "2.3.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Monitoring Policy element for the PMSH instance 1 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c26": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c26", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", + "version": "2.3.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "Operational Policy element for the PMSH instance 1 automation composition" + }, + "709c62b3-8918-41b9-a747-e21eb79c6c27": { + "id": "709c62b3-8918-41b9-a747-e21eb79c6c27", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant", + "version": "2.2.1" + }, + "state": "UNINITIALISED", + "orderedState": "UNINITIALISED", + "description": "CDS element for the PMSH instance 1 automation composition" + } + }, + "name": "PMSHInstance1", + "version": "1.0.1", + "description": "PMSH automation composition instance 1" + } + ] +} diff --git a/models/src/test/resources/providers/TestClElementStatistics.json b/models/src/test/resources/providers/TestClElementStatistics.json deleted file mode 100644 index ae19e560d..000000000 --- a/models/src/test/resources/providers/TestClElementStatistics.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "clElementStatistics":[ - { - "participantId":{ - "name":"name1", - "version":"1.001" - }, - "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", - "timeStamp": "2021-01-10T13:45:00.000Z", - "controlLoopState": "UNINITIALISED", - "clElementUptime":250 - }, - { - "participantId":{ - "name":"name2", - "version":"1.001" - }, - "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", - "timeStamp": "2021-01-10T14:25:00.000Z", - "controlLoopState": "UNINITIALISED", - "clElementUptime":330 - } - ] -} diff --git a/models/src/test/resources/providers/TestControlLoops.json b/models/src/test/resources/providers/TestControlLoops.json deleted file mode 100644 index fedda9600..000000000 --- a/models/src/test/resources/providers/TestControlLoops.json +++ /dev/null @@ -1,142 +0,0 @@ -{ - "controlLoopList": [ - { - "definition": { - "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", - "version": "1.0.0" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "elements": { - "709c62b3-8918-41b9-a747-e21eb79c6c20": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "DCAE Control Loop Element for the PMSH instance 0 control loop" - }, - "709c62b3-8918-41b9-a747-e21eb79c6c21": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop" - }, - "709c62b3-8918-41b9-a747-e21eb79c6c22": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop" - }, - "709c62b3-8918-41b9-a747-e21eb79c6c23": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", - "version": "2.2.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "CDS Control Loop Element for the PMSH instance 0 control loop" - } - }, - "name": "PMSHInstance0", - "version": "1.0.1", - "description": "PMSH control loop instance 0" - }, - { - "definition": { - "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", - "version": "1.0.0" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "elements": { - "709c62b3-8918-41b9-a747-e21eb79c6c24": { - "id": "709c62b3-8918-41b9-a747-e21eb79c6c24", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version": "2.3.4" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "DCAE Control Loop Element for the PMSH instance 1 control loop" - }, - "709c62b3-8918-41b9-a747-e21eb79c6c25": { - "id": "709c62b3-8918-41b9-a747-e21eb79c6c25", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "Monitoring Policy Control Loop Element for the PMSH instance 1 control loop" - }, - "709c62b3-8918-41b9-a747-e21eb79c6c26": { - "id": "709c62b3-8918-41b9-a747-e21eb79c6c26", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version": "2.3.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "Operational Policy Control Loop Element for the PMSH instance 1 control loop" - }, - "709c62b3-8918-41b9-a747-e21eb79c6c27": { - "id": "709c62b3-8918-41b9-a747-e21eb79c6c27", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", - "version": "2.2.1" - }, - "state": "UNINITIALISED", - "orderedState": "UNINITIALISED", - "description": "CDS Control Loop Element for the PMSH instance 1 control loop" - } - }, - "name": "PMSHInstance1", - "version": "1.0.1", - "description": "PMSH control loop instance 1" - } - ] -} diff --git a/models/src/test/resources/providers/TestParticipant.json b/models/src/test/resources/providers/TestParticipant.json index 4722ead9b..7e4f9540f 100644 --- a/models/src/test/resources/providers/TestParticipant.json +++ b/models/src/test/resources/providers/TestParticipant.json @@ -2,14 +2,14 @@ "name": "dummy_participant1", "version": "1.0.1", "definition":{ - "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", + "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition", "version": "1.0.0" }, "participantState": "PASSIVE", "healthStatus": "HEALTHY", "description": "A dummy PMSH participant1", "participantType":{ - "name": "org.onap.domain.pmsh.PolicyControlLoopDefinition", + "name": "org.onap.domain.pmsh.PolicyAutomationCompositionDefinition", "version": "1.0.0" } } diff --git a/models/src/test/resources/providers/UpdateAutomationCompositions.json b/models/src/test/resources/providers/UpdateAutomationCompositions.json new file mode 100644 index 000000000..f118ea799 --- /dev/null +++ b/models/src/test/resources/providers/UpdateAutomationCompositions.json @@ -0,0 +1,73 @@ +{ + "automationCompositionList": [ + { + "name": "PMSHInstance0", + "version": "1.0.1", + "definition": { + "name": "org.onap.domain.pmsh.PMSHAutomationCompositionDefinition", + "version": "1.0.0" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "PMSH automation composition instance 0", + "elements": { + "709c62b3-8918-41b9-a747-d21eb79c6c20": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.dcae.acm.DCAEMicroserviceAutomationCompositionParticipant", + "version": "2.3.4" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "DCAE element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-d21eb79c6c21": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", + "version": "2.3.1" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "Monitoring Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-d21eb79c6c22": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyAutomationCompositionElement", + "version": "2.3.1" + }, + "participantType": { + "name": "org.onap.policy.acm.PolicyAutomationCompositionParticipant", + "version": "1.0.0" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "Operational Policy element for the PMSH instance 0 automation composition" + }, + "709c62b3-8918-41b9-a747-d21eb79c6c23": { + "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", + "definition": { + "name": "org.onap.domain.pmsh.PMSH_CDS_AutomationCompositionElement", + "version": "1.2.3" + }, + "participantType": { + "name": "org.onap.ccsdk.cds.acm.CdsAutomationCompositionParticipant", + "version": "2.2.1" + }, + "state": "RUNNING", + "orderedState": "RUNNING", + "description": "CDS element for the PMSH instance 0 automation composition" + } + } + } + ] +} diff --git a/models/src/test/resources/providers/UpdateControlLoops.json b/models/src/test/resources/providers/UpdateControlLoops.json deleted file mode 100644 index 2d6bd0753..000000000 --- a/models/src/test/resources/providers/UpdateControlLoops.json +++ /dev/null @@ -1,73 +0,0 @@ -{ - "controlLoopList": [ - { - "name": "PMSHInstance0", - "version": "1.0.1", - "definition": { - "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition", - "version": "1.0.0" - }, - "state": "RUNNING", - "orderedState": "RUNNING", - "description": "PMSH control loop instance 0", - "elements": { - "709c62b3-8918-41b9-a747-d21eb79c6c20": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c20", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", - "version": "2.3.4" - }, - "state": "RUNNING", - "orderedState": "RUNNING", - "description": "DCAE Control Loop Element for the PMSH instance 0 control loop" - }, - "709c62b3-8918-41b9-a747-d21eb79c6c21": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c21", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version": "2.3.1" - }, - "state": "RUNNING", - "orderedState": "RUNNING", - "description": "Monitoring Policy Control Loop Element for the PMSH instance 0 control loop" - }, - "709c62b3-8918-41b9-a747-d21eb79c6c22": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c22", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement", - "version": "2.3.1" - }, - "participantType": { - "name": "org.onap.policy.controlloop.PolicyControlLoopParticipant", - "version": "1.0.0" - }, - "state": "RUNNING", - "orderedState": "RUNNING", - "description": "Operational Policy Control Loop Element for the PMSH instance 0 control loop" - }, - "709c62b3-8918-41b9-a747-d21eb79c6c23": { - "id": "709c62b3-8918-41b9-a747-d21eb79c6c23", - "definition": { - "name": "org.onap.domain.pmsh.PMSH_CDS_ControlLoopElement", - "version": "1.2.3" - }, - "participantType": { - "name": "org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", - "version": "2.2.1" - }, - "state": "RUNNING", - "orderedState": "RUNNING", - "description": "CDS Control Loop Element for the PMSH instance 0 control loop" - } - } - } - ] -} -- cgit 1.2.3-korg