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 +++++++++++ 137 files changed, 5459 insertions(+), 5278 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 (limited to 'models/src/main') 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; + } +} -- cgit 1.2.3-korg