diff options
41 files changed, 338 insertions, 206 deletions
diff --git a/common/pom.xml b/common/pom.xml index b0b84fea8..49bb5bf13 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021, 2024 Nordix Foundation. + Copyright (C) 2021, 2024-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-common</artifactId> diff --git a/examples/pom.xml b/examples/pom.xml index 43f1dd026..d1e69e12f 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2022-2023 Nordix Foundation. + Copyright (C) 2022-2023, 2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> @@ -56,4 +56,4 @@ </plugins> </build> -</project>
\ No newline at end of file +</project> diff --git a/models/pom.xml b/models/pom.xml index 10ec294d6..a1d3e3c28 100644 --- a/models/pom.xml +++ b/models/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2024 Nordix Foundation. + Copyright (C) 2021-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-models</artifactId> diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProvider.java index c3e5543d9..55da8e6e8 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProvider.java @@ -23,12 +23,15 @@ package org.onap.policy.clamp.models.acm.persistence.provider; import java.sql.Timestamp; import java.time.Instant; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; import lombok.AllArgsConstructor; +import org.hibernate.exception.ConstraintViolationException; +import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.document.concepts.DocMessage; import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantAckMessage; @@ -39,6 +42,9 @@ import org.onap.policy.clamp.models.acm.persistence.concepts.JpaMessageJob; import org.onap.policy.clamp.models.acm.persistence.repository.MessageJobRepository; import org.onap.policy.clamp.models.acm.persistence.repository.MessageRepository; import org.onap.policy.clamp.models.acm.utils.AcmUtils; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -47,6 +53,8 @@ import org.springframework.transaction.annotation.Transactional; @AllArgsConstructor public class MessageProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(MessageProvider.class); + private final MessageRepository messageRepository; private final MessageJobRepository messageJobRepository; @@ -85,20 +93,11 @@ public class MessageProvider { } /** - * Save ParticipantStatus message. + * Save instance OutProperties. * * @param message the ParticipantStatus message */ - public void save(ParticipantStatus message) { - if (!message.getAutomationCompositionInfoList().isEmpty()) { - saveInstanceOutProperties(message); - } - if (!message.getParticipantDefinitionUpdates().isEmpty()) { - saveCompositionOutProperties(message); - } - } - - private void saveInstanceOutProperties(ParticipantStatus message) { + public void saveInstanceOutProperties(ParticipantStatus message) { for (var instance : message.getAutomationCompositionInfoList()) { for (var element : instance.getElements()) { var jpa = new JpaMessage(); @@ -116,17 +115,27 @@ public class MessageProvider { } } - private void saveCompositionOutProperties(ParticipantStatus message) { + /** + * Save composition OutProperties. + * + * @param message the ParticipantStatus message + * @param elementStateMap the NodeTemplateState map + */ + public void saveCompositionOutProperties(ParticipantStatus message, + Map<ToscaConceptIdentifier, NodeTemplateState> elementStateMap) { for (var acDefinition : message.getParticipantDefinitionUpdates()) { for (var element : acDefinition.getAutomationCompositionElementDefinitionList()) { - var jpa = new JpaMessage(); - jpa.setIdentificationId(message.getCompositionId().toString()); - var doc = from(message); - doc.setOutProperties(element.getOutProperties()); - doc.setAcElementDefinitionId(element.getAcElementDefinitionId()); - jpa.fromAuthorative(doc); - ProviderUtils.validate(doc, jpa, "ParticipantStatus composition message"); - messageRepository.save(jpa); + var elementState = elementStateMap.get(element.getAcElementDefinitionId()); + if (elementState != null && elementState.getParticipantId().equals(message.getParticipantId())) { + var jpa = new JpaMessage(); + jpa.setIdentificationId(message.getCompositionId().toString()); + var doc = from(message); + doc.setOutProperties(element.getOutProperties()); + doc.setAcElementDefinitionId(element.getAcElementDefinitionId()); + jpa.fromAuthorative(doc); + ProviderUtils.validate(doc, jpa, "ParticipantStatus composition message"); + messageRepository.save(jpa); + } } } } @@ -223,8 +232,14 @@ public class MessageProvider { return Optional.empty(); } var job = new JpaMessageJob(identificationId.toString()); - var result = messageJobRepository.save(job); - return Optional.of(result.getJobId()); + try { + var result = messageJobRepository.save(job); + return Optional.of(result.getJobId()); + } catch (ConstraintViolationException ex) { + // already exist a job with this identificationId + LOGGER.warn(ex.getMessage()); + } + return Optional.empty(); } /** diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java index d850c54fd..b95ba9582 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/MessageProviderTest.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; +import org.hibernate.exception.ConstraintViolationException; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.models.acm.concepts.AcElementDeployAck; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; @@ -41,6 +42,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInf import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.document.concepts.DocMessage; @@ -95,13 +97,30 @@ class MessageProviderTest { message.setReplicaId(UUID.randomUUID()); var participantDefinition = new ParticipantDefinition(); participantDefinition.setParticipantId(message.getParticipantId()); - var element = CommonTestData.getAcElementDefinition(new ToscaConceptIdentifier("name", "1.0.0")); - element.setOutProperties(Map.of("compositionProperty", "value")); - participantDefinition.setAutomationCompositionElementDefinitionList(List.of(element)); + var element1 = CommonTestData.getAcElementDefinition(new ToscaConceptIdentifier("name1", "1.0.0")); + element1.setOutProperties(Map.of("compositionProperty1", "value")); + var element2 = CommonTestData.getAcElementDefinition(new ToscaConceptIdentifier("name2", "1.0.0")); + element2.setOutProperties(Map.of("compositionProperty2", "value")); + participantDefinition.setAutomationCompositionElementDefinitionList(List.of(element1, element2)); message.setParticipantDefinitionUpdates(List.of(participantDefinition)); + + var nodeTemplateState1 = new NodeTemplateState(); + nodeTemplateState1.setParticipantId(message.getParticipantId()); + nodeTemplateState1.setNodeTemplateId(element1.getAcElementDefinitionId()); + + var nodeTemplateState2 = new NodeTemplateState(); + nodeTemplateState2.setParticipantId(UUID.randomUUID()); + nodeTemplateState2.setNodeTemplateId(element2.getAcElementDefinitionId()); + var messageRepository = mock(MessageRepository.class); var messageProvider = new MessageProvider(messageRepository, mock(MessageJobRepository.class)); - messageProvider.save(message); + + messageProvider.saveCompositionOutProperties(message, Map.of()); + verify(messageRepository, times(0)).save(any()); + + messageProvider.saveCompositionOutProperties(message, + Map.of(nodeTemplateState1.getNodeTemplateId(), nodeTemplateState1, + nodeTemplateState2.getNodeTemplateId(), nodeTemplateState2)); verify(messageRepository).save(any()); } @@ -120,7 +139,7 @@ class MessageProviderTest { message.setAutomationCompositionInfoList(List.of(automationCompositionInfo)); var messageRepository = mock(MessageRepository.class); var messageProvider = new MessageProvider(messageRepository, mock(MessageJobRepository.class)); - messageProvider.save(message); + messageProvider.saveInstanceOutProperties(message); verify(messageRepository).save(any()); } @@ -217,6 +236,16 @@ class MessageProviderTest { } @Test + void testCreateJobFail() { + var messageJobRepository = mock(MessageJobRepository.class); + var identificationId = UUID.randomUUID(); + when(messageJobRepository.save(any())).thenThrow(new ConstraintViolationException("", null, "")); + var messageProvider = new MessageProvider(mock(MessageRepository.class), messageJobRepository); + var opt = messageProvider.createJob(identificationId); + assertThat(opt).isEmpty(); + } + + @Test void testRemoveJob() { var messageJobRepository = mock(MessageJobRepository.class); var messageProvider = new MessageProvider(mock(MessageRepository.class), messageJobRepository); diff --git a/packages/policy-clamp-docker/pom.xml b/packages/policy-clamp-docker/pom.xml index a7a89bf52..aec89472c 100644 --- a/packages/policy-clamp-docker/pom.xml +++ b/packages/policy-clamp-docker/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2023 Nordix Foundation. + Copyright (C) 2021-2023, 2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>clamp-packages</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <packaging>pom</packaging> diff --git a/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile index 965d0a695..a6e40b095 100644 --- a/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/A1pmsParticipant.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/a1pms-participant.tar.gz /packages/ RUN tar xvzf /packages/a1pms-participant.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM A1 PMS Participant" diff --git a/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile b/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile index 61b29ed9a..c50bcaa76 100644 --- a/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/AcmRuntime.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/policy-clamp-runtime-acm.tar.gz /packages/ RUN tar xvzf /packages/policy-clamp-runtime-acm.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM runtime" diff --git a/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile index ec0efece8..abc0624aa 100644 --- a/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/ElementParticipant.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/element-participant.tar.gz /packages RUN tar xvfz /packages/element-participant.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM Element" diff --git a/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile index 50e36a6fe..a8e17cb8e 100644 --- a/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/HttpParticipant.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/http-participant.tar.gz /packages/ RUN tar xvzf /packages/http-participant.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM HTTP Participant" diff --git a/packages/policy-clamp-docker/src/main/docker/KserveParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/KserveParticipant.Dockerfile index 12afb0573..e5d07d5b2 100644 --- a/packages/policy-clamp-docker/src/main/docker/KserveParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/KserveParticipant.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/kserve-participant.tar.gz /packages/ RUN tar xvzf /packages/kserve-participant.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM KSERVE Participant" diff --git a/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile index 289ec6385..b95989ae4 100644 --- a/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/KubernetesParticipant.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/kubernetes-participant.tar.gz /packages/ RUN tar xvzf /packages/kubernetes-participant.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM K8S Participant" diff --git a/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile index b9a5874e9..31972bf0d 100644 --- a/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/PolicyParticipant.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/policy-participant.tar.gz /packages/ RUN tar xvzf /packages/policy-participant.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM Policy Framework Participant" diff --git a/packages/policy-clamp-docker/src/main/docker/SimParticipant.Dockerfile b/packages/policy-clamp-docker/src/main/docker/SimParticipant.Dockerfile index a0f07f378..2a0b5b65f 100644 --- a/packages/policy-clamp-docker/src/main/docker/SimParticipant.Dockerfile +++ b/packages/policy-clamp-docker/src/main/docker/SimParticipant.Dockerfile @@ -23,7 +23,7 @@ RUN mkdir /packages /extracted COPY /maven/lib/sim-participant.tar.gz /packages/ RUN tar xvzf /packages/sim-participant.tar.gz --directory /extracted/ -FROM onap/policy-jre-alpine:4.1.1 +FROM onap/policy-jre-alpine:4.1.2-SNAPSHOT LABEL maintainer="Policy Team" LABEL org.opencontainers.image.title="Policy CLAMP ACM Simulator Participant" diff --git a/packages/policy-clamp-tarball/pom.xml b/packages/policy-clamp-tarball/pom.xml index c5b31aec8..90b7fda6a 100644 --- a/packages/policy-clamp-tarball/pom.xml +++ b/packages/policy-clamp-tarball/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2022 Nordix Foundation. + Copyright (C) 2021-2022, 2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>clamp-packages</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-tarball</artifactId> diff --git a/packages/pom.xml b/packages/pom.xml index 4a2e82d38..fceb363c2 100644 --- a/packages/pom.xml +++ b/packages/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2023 Nordix Foundation. + Copyright (C) 2021-2023, 2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>clamp-packages</artifactId> diff --git a/participant/participant-impl/participant-impl-a1pms/pom.xml b/participant/participant-impl/participant-impl-a1pms/pom.xml index d4b0b75b3..8aea97574 100644 --- a/participant/participant-impl/participant-impl-a1pms/pom.xml +++ b/participant/participant-impl/participant-impl-a1pms/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2022, 2024 Nordix Foundation. + Copyright (C) 2022, 2024-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-a1pms</artifactId> diff --git a/participant/participant-impl/participant-impl-acelement/pom.xml b/participant/participant-impl/participant-impl-acelement/pom.xml index 4495308aa..3a8150bf7 100644 --- a/participant/participant-impl/participant-impl-acelement/pom.xml +++ b/participant/participant-impl/participant-impl-acelement/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2024 Nordix Foundation. + Copyright (C) 2021-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-acm-element-impl</artifactId> diff --git a/participant/participant-impl/participant-impl-cds/pom.xml b/participant/participant-impl/participant-impl-cds/pom.xml index 5dc3214c7..18f4aa27d 100644 --- a/participant/participant-impl/participant-impl-cds/pom.xml +++ b/participant/participant-impl/participant-impl-cds/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021 Nordix Foundation. + Copyright (C) 2021, 2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-cds</artifactId> diff --git a/participant/participant-impl/participant-impl-http/pom.xml b/participant/participant-impl/participant-impl-http/pom.xml index e2275b965..d90f453d2 100644 --- a/participant/participant-impl/participant-impl-http/pom.xml +++ b/participant/participant-impl/participant-impl-http/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021, 2024 Nordix Foundation. + Copyright (C) 2021, 2024-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-http</artifactId> diff --git a/participant/participant-impl/participant-impl-kserve/pom.xml b/participant/participant-impl/participant-impl-kserve/pom.xml index 83022cbcb..499342f4b 100644 --- a/participant/participant-impl/participant-impl-kserve/pom.xml +++ b/participant/participant-impl/participant-impl-kserve/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2023-2024 Nordix Foundation. + Copyright (C) 2023-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-kserve</artifactId> diff --git a/participant/participant-impl/participant-impl-kubernetes/pom.xml b/participant/participant-impl/participant-impl-kubernetes/pom.xml index 01c36ff79..d19ed8045 100644 --- a/participant/participant-impl/participant-impl-kubernetes/pom.xml +++ b/participant/participant-impl/participant-impl-kubernetes/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021, 2023-2024 Nordix Foundation. + Copyright (C) 2021, 2023-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-kubernetes</artifactId> diff --git a/participant/participant-impl/participant-impl-policy/pom.xml b/participant/participant-impl/participant-impl-policy/pom.xml index aa19c576a..517e106e2 100644 --- a/participant/participant-impl/participant-impl-policy/pom.xml +++ b/participant/participant-impl/participant-impl-policy/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021, 2024 Nordix Foundation. + Copyright (C) 2021, 2024-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-policy</artifactId> diff --git a/participant/participant-impl/participant-impl-simulator/pom.xml b/participant/participant-impl/participant-impl-simulator/pom.xml index 9376413e4..67f7fc5ce 100644 --- a/participant/participant-impl/participant-impl-simulator/pom.xml +++ b/participant/participant-impl/participant-impl-simulator/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2023-2024 Nordix Foundation. + Copyright (C) 2023-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant-impl</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl-simulator</artifactId> diff --git a/participant/participant-impl/pom.xml b/participant/participant-impl/pom.xml index 6581bd5d8..a0c58680d 100644 --- a/participant/participant-impl/pom.xml +++ b/participant/participant-impl/pom.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- ============LICENSE_START======================================================= - Copyright (C) 2021-2024 Nordix Foundation. + Copyright (C) 2021-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-impl</artifactId> diff --git a/participant/participant-intermediary/pom.xml b/participant/participant-intermediary/pom.xml index 016381008..ad1d814c2 100644 --- a/participant/participant-intermediary/pom.xml +++ b/participant/participant-intermediary/pom.xml @@ -1,6 +1,6 @@ <!-- ============LICENSE_START======================================================= - Copyright (C) 2021,2024 Nordix Foundation. + Copyright (C) 2021,2024-2025 Nordix Foundation. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ <parent> <groupId>org.onap.policy.clamp.participant</groupId> <artifactId>policy-clamp-participant</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-participant-intermediary</artifactId> diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandler.java index 9e3efce57..d6246773e 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandler.java @@ -30,6 +30,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; 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.ParticipantState; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPrime; @@ -53,12 +54,7 @@ public class AcDefinitionHandler { public void handlePrime(ParticipantPrime participantPrimeMsg) { if (!participantPrimeMsg.getParticipantDefinitionUpdates().isEmpty()) { // prime - List<AutomationCompositionElementDefinition> list = new ArrayList<>(); - for (var participantDefinition : participantPrimeMsg.getParticipantDefinitionUpdates()) { - if (participantDefinition.getParticipantId().equals(cacheProvider.getParticipantId())) { - list.addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); - } - } + var list = collectAcElementDefinition(participantPrimeMsg.getParticipantDefinitionUpdates()); if (!list.isEmpty()) { cacheProvider.addElementDefinition(participantPrimeMsg.getCompositionId(), list); prime(participantPrimeMsg.getMessageId(), participantPrimeMsg.getCompositionId(), list); @@ -69,6 +65,17 @@ public class AcDefinitionHandler { } } + private List<AutomationCompositionElementDefinition> collectAcElementDefinition( + List<ParticipantDefinition> participantDefinitionList) { + List<AutomationCompositionElementDefinition> list = new ArrayList<>(); + for (var participantDefinition : participantDefinitionList) { + if (participantDefinition.getParticipantId().equals(cacheProvider.getParticipantId())) { + list.addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); + } + } + return list; + } + private void prime(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list) { var inPropertiesMap = list.stream().collect(Collectors.toMap( AutomationCompositionElementDefinition::getAcElementDefinitionId, @@ -123,11 +130,10 @@ public class AcDefinitionHandler { listener.cleanExecution(participantSyncMsg.getCompositionId(), participantSyncMsg.getMessageId()); } - List<AutomationCompositionElementDefinition> list = new ArrayList<>(); - for (var participantDefinition : participantSyncMsg.getParticipantDefinitionUpdates()) { - list.addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); + var list = collectAcElementDefinition(participantSyncMsg.getParticipantDefinitionUpdates()); + if (!list.isEmpty()) { + cacheProvider.addElementDefinition(participantSyncMsg.getCompositionId(), list); } - cacheProvider.addElementDefinition(participantSyncMsg.getCompositionId(), list); } for (var automationcomposition : participantSyncMsg.getAutomationcompositionList()) { diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java index d72f5deea..a6fd10386 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java @@ -44,7 +44,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class AcDefinitionHandlerTest { @Test - void handleComposiotPrimeTest() { + void handleCompositionPrimeTest() { var listener = mock(ThreadHandler.class); var cacheProvider = mock(CacheProvider.class); when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId()); @@ -103,6 +103,7 @@ class AcDefinitionHandlerTest { participantSyncMsg.setAutomationcompositionList(List.of(CommonTestData.createParticipantRestartAc())); var cacheProvider = mock(CacheProvider.class); + when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId()); var listener = mock(ThreadHandler.class); var ach = new AcDefinitionHandler(cacheProvider, mock(ParticipantMessagePublisher.class), listener); ach.handleParticipantSync(participantSyncMsg); @@ -122,6 +123,7 @@ class AcDefinitionHandlerTest { participantSyncMsg.setAutomationcompositionList(List.of(participantRestartAc)); var cacheProvider = mock(CacheProvider.class); + when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId()); var listener = mock(ThreadHandler.class); var ach = new AcDefinitionHandler(cacheProvider, mock(ParticipantMessagePublisher.class), listener); ach.handleParticipantSync(participantSyncMsg); diff --git a/participant/pom.xml b/participant/pom.xml index 14915bd72..c26dfd0b3 100644 --- a/participant/pom.xml +++ b/participant/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <groupId>org.onap.policy.clamp.participant</groupId> @@ -25,12 +25,12 @@ <parent> <groupId>org.onap.policy.parent</groupId> <artifactId>integration</artifactId> - <version>5.1.1</version> + <version>5.1.2-SNAPSHOT</version> <relativePath /> </parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> <name>${project.artifactId}</name> <packaging>pom</packaging> <description> @@ -52,8 +52,8 @@ o policy-clamp-participant-impl-kserve: A standard participant for Kserve </description> <properties> - <policy.common.version>3.1.1</policy.common.version> - <policy.models.version>4.1.1</policy.models.version> + <policy.common.version>3.1.2-SNAPSHOT</policy.common.version> + <policy.models.version>4.1.2-SNAPSHOT</policy.models.version> </properties> <modules> <module>common</module> diff --git a/runtime-acm/pom.xml b/runtime-acm/pom.xml index 8852115a1..a44b76743 100644 --- a/runtime-acm/pom.xml +++ b/runtime-acm/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.onap.policy.clamp</groupId> <artifactId>policy-clamp</artifactId> - <version>8.1.1-SNAPSHOT</version> + <version>8.1.2-SNAPSHOT</version> </parent> <artifactId>policy-clamp-runtime-acm</artifactId> diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java index eacd07fc9..0966ab30f 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProvider.java @@ -33,10 +33,12 @@ import org.onap.policy.clamp.acm.runtime.main.utils.EncryptionUtils; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; +import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.concepts.SubState; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate; @@ -201,12 +203,15 @@ public class AutomationCompositionInstantiationProvider { if (!validationResult.isValid()) { throw new PfModelRuntimeException(Status.BAD_REQUEST, validationResult.getResult()); } - // Publish property update event to the participants - supervisionAcHandler.update(acToBeUpdated); + updateAcForProperties(acToBeUpdated); + + var acToPublish = new AutomationComposition(acToBeUpdated); encryptInstanceProperties(acToBeUpdated, acToBeUpdated.getCompositionId()); automationComposition = automationCompositionProvider.updateAutomationComposition(acToBeUpdated); + // Publish property update event to the participants + supervisionAcHandler.update(acToPublish); return createInstantiationResponse(automationComposition); } @@ -245,16 +250,34 @@ public class AutomationCompositionInstantiationProvider { } acToBeUpdated.setCompositionTargetId(automationComposition.getCompositionTargetId()); var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionTargetId()); - // Publish migrate event to the participants - supervisionAcHandler.migrate(acToBeUpdated, acDefinition.getServiceTemplate()); + + updateAcForMigration(acToBeUpdated, acDefinition); + + var acToPublish = new AutomationComposition(acToBeUpdated); encryptInstanceProperties(acToBeUpdated, acToBeUpdated.getCompositionTargetId()); var ac = automationCompositionProvider.updateAutomationComposition(acToBeUpdated); elementsRemoved.forEach(automationCompositionProvider::deleteAutomationCompositionElement); + + // Publish migrate event to the participants + supervisionAcHandler.migrate(acToPublish); return createInstantiationResponse(ac); } + private void updateAcForMigration(AutomationComposition acToBeUpdated, + AutomationCompositionDefinition acDefinition) { + AcmUtils.setCascadedState(acToBeUpdated, DeployState.MIGRATING, LockState.LOCKED); + acToBeUpdated.setStateChangeResult(StateChangeResult.NO_ERROR); + var stage = ParticipantUtils.getFirstStage(acToBeUpdated, acDefinition.getServiceTemplate()); + acToBeUpdated.setPhase(stage); + } + + private void updateAcForProperties(AutomationComposition acToBeUpdated) { + AcmUtils.setCascadedState(acToBeUpdated, DeployState.UPDATING, acToBeUpdated.getLockState()); + acToBeUpdated.setStateChangeResult(StateChangeResult.NO_ERROR); + } + private List<UUID> getElementRemoved(AutomationComposition acFromDb, AutomationComposition acFromMigration) { return acFromDb.getElements().keySet().stream() .filter(id -> acFromMigration.getElements().get(id) == null).toList(); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtils.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtils.java index f7988ea1a..a0226e8a8 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtils.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtils.java @@ -35,9 +35,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.UUID; -import javax.crypto.BadPaddingException; import javax.crypto.Cipher; -import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; @@ -133,13 +131,13 @@ public class EncryptionUtils { var encryptedVal = encrypt(sensitiveStr); elementProperties.put(property.getName(), encryptedVal); LOGGER.debug("Property {} is successfully encrypted", property.getName()); + } } } } catch (Exception e) { - throw new AutomationCompositionRuntimeException(Response.Status.fromStatusCode(500), - "Failed to encrypt instance field ", e); + LOGGER.error("Failed to encrypt instance parameter with error {}", e.getMessage()); } } @@ -149,28 +147,21 @@ public class EncryptionUtils { * @param automationComposition acInstance */ public void findAndDecryptSensitiveData(AutomationComposition automationComposition) { - try { - for (var acInstanceElement: automationComposition.getElements().values()) { - for (var property : acInstanceElement.getProperties().entrySet()) { - var propertyVal = property.getValue(); - if (propertyVal instanceof String propertyValStr && propertyValStr.startsWith(MARKER)) { - var decryptedVal = decrypt(propertyValStr); - acInstanceElement.getProperties().put(property.getKey(), decryptedVal); - LOGGER.debug("Property {} is successfully decrypted", property.getKey()); - } else { - decryptNested(propertyVal); - } + for (var acInstanceElement: automationComposition.getElements().values()) { + for (var property : acInstanceElement.getProperties().entrySet()) { + var propertyVal = property.getValue(); + if (propertyVal instanceof String propertyValStr && propertyValStr.startsWith(MARKER)) { + var decryptedVal = decrypt(propertyValStr); + acInstanceElement.getProperties().put(property.getKey(), decryptedVal); + LOGGER.debug("Property {} is successfully decrypted", property.getKey()); + } else { + decryptNested(propertyVal); } } - } catch (Exception e) { - throw new AutomationCompositionRuntimeException(Response.Status.fromStatusCode(500), - "Failed to decrypt instance field ", e); } } - private void decryptNested(Object propertyVal) throws InvalidAlgorithmParameterException, IllegalBlockSizeException, - NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, InvalidKeySpecException, - InvalidKeyException { + private void decryptNested(Object propertyVal) { if (propertyVal instanceof List<?> listVal) { for (var listEntry : listVal) { if (listEntry instanceof Map<?, ?> tempMap) { @@ -182,9 +173,7 @@ public class EncryptionUtils { } } - private void decryptNestedMap(Map<?, ?> tempMap) throws InvalidAlgorithmParameterException, - IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, - InvalidKeySpecException, InvalidKeyException { + private void decryptNestedMap(Map<?, ?> tempMap) { @SuppressWarnings("unchecked") var nestedMap = (Map<Object, Object>) tempMap; for (var prop : nestedMap.entrySet()) { @@ -196,9 +185,7 @@ public class EncryptionUtils { } } - private void encryptNested(ToscaProperty property, Map<?, ?> properties) - throws InvalidAlgorithmParameterException, IllegalBlockSizeException, NoSuchPaddingException, - BadPaddingException, NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException { + private void encryptNested(ToscaProperty property, Map<?, ?> properties) { // Iterate over nested maps to check if the property exists inside them for (var mapEntry : properties.entrySet()) { if (mapEntry.getValue() instanceof List<?> listVal) { @@ -214,9 +201,7 @@ public class EncryptionUtils { } - private void encryptNestedMaps(ToscaProperty property, Map<?, ?> tempMap) throws InvalidAlgorithmParameterException, - IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, - InvalidKeySpecException, InvalidKeyException { + private void encryptNestedMaps(ToscaProperty property, Map<?, ?> tempMap) { @SuppressWarnings("unchecked") var nestedMap = (Map<Object, Object>) tempMap; var nestedValue = nestedMap.get(property.getName()); @@ -283,32 +268,45 @@ public class EncryptionUtils { return new SecretKeySpec(factory.generateSecret(spec).getEncoded(), "AES"); } - private String encrypt(String input) throws IllegalBlockSizeException, BadPaddingException, - NoSuchAlgorithmException, InvalidKeySpecException, InvalidAlgorithmParameterException, InvalidKeyException, - NoSuchPaddingException { - var iv = generateIV(); + private String encrypt(String input) { + try { + var iv = generateIV(); + var cipher = getCipher(iv, Cipher.ENCRYPT_MODE); + var cipherText = cipher.doFinal(input.getBytes()); + var cipherByte = ByteBuffer.allocate(iv.length + cipherText.length).put(iv).put(cipherText).array(); + return MARKER + Base64.getEncoder().encodeToString(cipherByte); + + } catch (Exception e) { + LOGGER.error("Failed to encrypt instance field with error {}", e.getMessage()); + } + return input; + } + + protected Cipher getCipher(byte[] iv, int mode) throws NoSuchPaddingException, NoSuchAlgorithmException, + InvalidKeySpecException, InvalidAlgorithmParameterException, InvalidKeyException { var parameterSpec = new GCMParameterSpec(GCM_TAG, iv); var cipher = Cipher.getInstance(ALGORITHM); - cipher.init(Cipher.ENCRYPT_MODE, getSecretKey(), parameterSpec); - var cipherText = cipher.doFinal(input.getBytes()); - var cipherByte = ByteBuffer.allocate(iv.length + cipherText.length).put(iv).put(cipherText).array(); - return MARKER + Base64.getEncoder().encodeToString(cipherByte); + cipher.init(mode, getSecretKey(), parameterSpec); + return cipher; } - private String decrypt(String cipherText) throws IllegalBlockSizeException, BadPaddingException, - NoSuchAlgorithmException, InvalidKeySpecException, - InvalidAlgorithmParameterException, InvalidKeyException, NoSuchPaddingException { - var decodedText = Base64.getDecoder().decode(cipherText.substring(MARKER.length()).getBytes()); - var byteBuffer = ByteBuffer.wrap(decodedText); - var iv = new byte[IV_LENGTH]; - byteBuffer.get(iv); - var encryptedByte = new byte[byteBuffer.remaining()]; - byteBuffer.get(encryptedByte); + private String decrypt(String cipherText) { + try { + var decodedText = Base64.getDecoder().decode(cipherText.substring(MARKER.length()).getBytes()); + var byteBuffer = ByteBuffer.wrap(decodedText); + var iv = new byte[IV_LENGTH]; + byteBuffer.get(iv); + var encryptedByte = new byte[byteBuffer.remaining()]; + byteBuffer.get(encryptedByte); + + var cipher = getCipher(iv, Cipher.DECRYPT_MODE); + var plainText = cipher.doFinal(encryptedByte); + return new String(plainText); + + } catch (Exception e) { + throw new AutomationCompositionRuntimeException(Response.Status.fromStatusCode(500), + "Failed to decrypt instance field ", e); + } - var parameterSpec = new GCMParameterSpec(GCM_TAG, iv); - var cipher = Cipher.getInstance(ALGORITHM); - cipher.init(Cipher.DECRYPT_MODE, getSecretKey(), parameterSpec); - var plainText = cipher.doFinal(encryptedByte); - return new String(plainText); } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java index 126ffafd0..f436eb287 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandler.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import lombok.AllArgsConstructor; +import org.onap.policy.clamp.acm.runtime.main.utils.EncryptionUtils; import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AcPreparePublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher; @@ -44,7 +45,6 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCom import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.MessageProvider; import org.onap.policy.clamp.models.acm.utils.AcmUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -67,6 +67,7 @@ public class SupervisionAcHandler { private final AutomationCompositionMigrationPublisher acCompositionMigrationPublisher; private final AcPreparePublisher acPreparePublisher; private final MessageProvider messageProvider; + private final EncryptionUtils encryptionUtils; private final ExecutorService executor = Context.taskWrapping(Executors.newFixedThreadPool(1)); @@ -93,7 +94,11 @@ public class SupervisionAcHandler { automationComposition.setPhase(startPhase); automationCompositionProvider.updateAutomationComposition(automationComposition); executor.execute( - () -> automationCompositionDeployPublisher.send(automationComposition, startPhase, true)); + () -> { + var acToSend = new AutomationComposition(automationComposition); + decryptInstanceProperties(acToSend); + automationCompositionDeployPublisher.send(acToSend, startPhase, true); + }); } /** @@ -156,7 +161,11 @@ public class SupervisionAcHandler { AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE, SubState.PREPARING); automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); automationCompositionProvider.updateAutomationComposition(automationComposition); - executor.execute(() -> acPreparePublisher.sendPrepare(automationComposition)); + executor.execute(() -> { + var acToSend = new AutomationComposition(automationComposition); + decryptInstanceProperties(acToSend); + acPreparePublisher.sendPrepare(acToSend); + }); } /** @@ -202,10 +211,11 @@ public class SupervisionAcHandler { * @param automationComposition the AutomationComposition */ public void update(AutomationComposition automationComposition) { - AcmUtils.setCascadedState(automationComposition, DeployState.UPDATING, automationComposition.getLockState()); - automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); executor.execute( - () -> acElementPropertiesPublisher.send(automationComposition)); + () -> { + decryptInstanceProperties(automationComposition); + acElementPropertiesPublisher.send(automationComposition); + }); } /** @@ -318,14 +328,12 @@ public class SupervisionAcHandler { * Handle Migration of an AutomationComposition instance to other ACM Definition. * * @param automationComposition the AutomationComposition - * @param serviceTemplate the ServiceTemplate */ - public void migrate(AutomationComposition automationComposition, ToscaServiceTemplate serviceTemplate) { - AcmUtils.setCascadedState(automationComposition, DeployState.MIGRATING, LockState.LOCKED); - var stage = ParticipantUtils.getFirstStage(automationComposition, serviceTemplate); - automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); - automationComposition.setPhase(stage); - executor.execute(() -> acCompositionMigrationPublisher.send(automationComposition, stage)); + public void migrate(AutomationComposition automationComposition) { + executor.execute(() -> { + decryptInstanceProperties(automationComposition); + acCompositionMigrationPublisher.send(automationComposition, automationComposition.getPhase()); + }); } /** @@ -336,4 +344,10 @@ public class SupervisionAcHandler { public void migratePrecheck(AutomationComposition automationComposition) { executor.execute(() -> acCompositionMigrationPublisher.send(automationComposition, 0)); } + + private void decryptInstanceProperties(AutomationComposition automationComposition) { + if (encryptionUtils.encryptionEnabled()) { + encryptionUtils.findAndDecryptSensitiveData(automationComposition); + } + } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java index d0b7b62b6..5627bead2 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java @@ -25,6 +25,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; import lombok.AllArgsConstructor; import org.apache.commons.collections4.MapUtils; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher; @@ -33,6 +35,7 @@ import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantSyncPublish import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; +import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState; import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; @@ -109,11 +112,19 @@ public class SupervisionParticipantHandler { participantStatusMsg.getParticipantSupportedElementType(), false); if (!participantStatusMsg.getAutomationCompositionInfoList().isEmpty()) { - messageProvider.save(participantStatusMsg); + messageProvider.saveInstanceOutProperties(participantStatusMsg); } if (!participantStatusMsg.getParticipantDefinitionUpdates().isEmpty() && participantStatusMsg.getCompositionId() != null) { - messageProvider.save(participantStatusMsg); + var acDefinition = acDefinitionProvider.findAcDefinition(participantStatusMsg.getCompositionId()); + if (acDefinition.isPresent()) { + var map = acDefinition.get().getElementStateMap() + .values().stream().collect(Collectors.toMap(NodeTemplateState::getNodeTemplateId, + UnaryOperator.identity())); + messageProvider.saveCompositionOutProperties(participantStatusMsg, map); + } else { + LOGGER.error("Not valid ParticipantStatus message"); + } } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java index d53f700f6..a3d11b5f3 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java @@ -187,6 +187,7 @@ class AutomationCompositionInstantiationProviderTest { var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, new AcInstanceStateResolver(), supervisionAcHandler, participantProvider, CommonTestData.getTestParamaterGroup(), encryptionUtils); + var instantiationResponse = instantiationProvider.updateAutomationComposition( automationCompositionUpdate.getCompositionId(), automationCompositionUpdate); @@ -200,9 +201,12 @@ class AutomationCompositionInstantiationProviderTest { element.setId(UUID.randomUUID()); automationCompositionUpdate.getElements().put(element.getId(), element); } + acmFromDb.getElements().values().forEach(element -> element.setDeployState(DeployState.DEPLOYED)); + acmFromDb.setDeployState(DeployState.DEPLOYED); assertThatThrownBy( - () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) - .hasMessageStartingWith("Element id not present "); + () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) + .hasMessageStartingWith("Element id not present "); + } @Test @@ -302,7 +306,7 @@ class AutomationCompositionInstantiationProviderTest { var instantiationResponse = instantiationProvider.updateAutomationComposition(compositionId, automationCompositionTarget); - verify(supervisionAcHandler).migrate(any(), any()); + verify(supervisionAcHandler).migrate(any()); InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationCompositionTarget); } @@ -373,7 +377,7 @@ class AutomationCompositionInstantiationProviderTest { var instantiationResponse = instantiationProvider .updateAutomationComposition(automationComposition.getCompositionId(), automationComposition); - verify(supervisionAcHandler).migrate(any(), any()); + verify(supervisionAcHandler).migrate(any()); verify(acProvider).updateAutomationComposition(automationComposition); InstantiationUtils.assertInstantiationResponse(instantiationResponse, automationComposition); } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtilTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtilTest.java index 7ad8b7169..f4fffdb4d 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtilTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/utils/EncryptionUtilTest.java @@ -21,12 +21,17 @@ package org.onap.policy.clamp.acm.runtime.main.utils; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.security.InvalidAlgorithmParameterException; +import javax.crypto.Cipher; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; +import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils; @@ -61,11 +66,41 @@ class EncryptionUtilTest { encryptionUtils.findAndEncryptSensitiveData(acDefinition, automationComposition); }); + assert automationComposition != null; + automationComposition.getElements().values().forEach(element -> { + assertTrue(element.getProperties().get("secret").toString().startsWith("ENCRYPTED:")); + assertTrue(element.getProperties().get("password").toString().startsWith("ENCRYPTED:")); + }); + var encryptionUtil2 = new EncryptionUtils(CommonTestData.getEncryptionParameterGroup()); assertDoesNotThrow(() -> { - assert automationComposition != null; encryptionUtil2.findAndDecryptSensitiveData(automationComposition); }); + automationComposition.getElements().values().forEach(element -> { + assertEquals("mysecret", element.getProperties().get("secret").toString()); + assertEquals("mypass", element.getProperties().get("password").toString()); + }); + } + + @Test + void testErrorScenario() { + var encryptionUtils = new EncryptionUtils(CommonTestData.getEncryptionParameterGroup()) { + @Override + protected Cipher getCipher(byte[] iv, int mode) throws InvalidAlgorithmParameterException { + throw new InvalidAlgorithmParameterException(); + } + }; + var automationComposition = + InstantiationUtils.getAutomationCompositionFromResource(INSTANTIATE_JSON, "Crud"); + assertDoesNotThrow(() -> encryptionUtils.findAndEncryptSensitiveData(acDefinition, null)); + + var encryptionUtils2 = new EncryptionUtils(CommonTestData.getEncryptionParameterGroup()); + encryptionUtils2.findAndEncryptSensitiveData(acDefinition, automationComposition); + + assert automationComposition != null; + assertThrows(AutomationCompositionRuntimeException.class, + () -> encryptionUtils.findAndDecryptSensitiveData(automationComposition)); + } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java index 448a96b21..e3baa6f63 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAcHandlerTest.java @@ -35,6 +35,7 @@ import java.util.Optional; import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; +import org.onap.policy.clamp.acm.runtime.main.utils.EncryptionUtils; import org.onap.policy.clamp.acm.runtime.supervision.comm.AcElementPropertiesPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AcPreparePublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionDeployPublisher; @@ -63,7 +64,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), messageProvider); + mock(AcPreparePublisher.class), messageProvider, mock(EncryptionUtils.class)); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); @@ -111,7 +112,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), messageProvider); + mock(AcPreparePublisher.class), messageProvider, mock(EncryptionUtils.class)); var automationCompositionAckMessage = getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK, @@ -135,7 +136,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), messageProvider); + mock(AcPreparePublisher.class), messageProvider, mock(EncryptionUtils.class)); var automationCompositionAckMessage = getAutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK, @@ -177,7 +178,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), messageProvider); + mock(AcPreparePublisher.class), messageProvider, mock(EncryptionUtils.class)); handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); @@ -216,7 +217,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), automationCompositionStateChangePublisher, mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), messageProvider); + mock(AcPreparePublisher.class), messageProvider, mock(EncryptionUtils.class)); handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); @@ -230,7 +231,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, automationCompositionDeployPublisher, mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); @@ -249,7 +250,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -267,7 +268,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); @@ -288,7 +289,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -306,7 +307,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -326,7 +327,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -344,7 +345,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), acStateChangePublisher, mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); var automationComposition = @@ -377,7 +378,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), messageProvider); + mock(AcPreparePublisher.class), messageProvider, mock(EncryptionUtils.class)); handler.handleAutomationCompositionUpdateAckMessage(automationCompositionAckMessage); @@ -391,7 +392,7 @@ class SupervisionAcHandlerTest { mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), acElementPropertiesPublisher, mock(AutomationCompositionMigrationPublisher.class), - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Lock"); handler.update(automationComposition); @@ -405,11 +406,12 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), acCompositionMigrationPublisher, - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate"); - var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); - handler.migrate(automationComposition, serviceTemplate); + assert automationComposition != null; + automationComposition.setPhase(0); + handler.migrate(automationComposition); verify(acCompositionMigrationPublisher, timeout(1000)).send(any(AutomationComposition.class), anyInt()); } @@ -420,7 +422,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), acCompositionMigrationPublisher, - mock(AcPreparePublisher.class), mock(MessageProvider.class)); + mock(AcPreparePublisher.class), mock(MessageProvider.class), mock(EncryptionUtils.class)); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate"); handler.migratePrecheck(automationComposition); @@ -434,7 +436,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - acPreparePublisher, mock(MessageProvider.class)); + acPreparePublisher, mock(MessageProvider.class), mock(EncryptionUtils.class)); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate"); handler.prepare(automationComposition); @@ -448,7 +450,7 @@ class SupervisionAcHandlerTest { var handler = new SupervisionAcHandler(automationCompositionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class), mock(AcElementPropertiesPublisher.class), mock(AutomationCompositionMigrationPublisher.class), - acPreparePublisher, mock(MessageProvider.class)); + acPreparePublisher, mock(MessageProvider.class), mock(EncryptionUtils.class)); var automationComposition = InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Migrate"); handler.review(automationComposition); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java index 315fb8c48..2cdcf210a 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java @@ -169,16 +169,11 @@ class SupervisionParticipantHandlerTest { } @Test - void testHandleParticipantStatus() { + void testHandleParticipantStatusWithInstanceOutProperties() { var participantStatusMessage = createParticipantStatus(); participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo())); participantStatusMessage.setCompositionId(UUID.randomUUID()); - var acDefinitionProvider = mock(AcDefinitionProvider.class); - var acDefinition = new AutomationCompositionDefinition(); - acDefinition.setCompositionId(participantStatusMessage.getCompositionId()); - when(acDefinitionProvider.getAcDefinition(acDefinition.getCompositionId())).thenReturn(acDefinition); - var participantProvider = mock(ParticipantProvider.class); var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); when(participantProvider.findParticipant(CommonTestData.getParticipantId())) @@ -190,17 +185,18 @@ class SupervisionParticipantHandlerTest { var automationCompositionProvider = mock(AutomationCompositionProvider.class); var messageProvider = mock(MessageProvider.class); + var acDefinitionProvider = mock(AcDefinitionProvider.class); var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, acDefinitionProvider, mock(ParticipantSyncPublisher.class), messageProvider); handler.handleParticipantMessage(participantStatusMessage); - verify(messageProvider).save(any(ParticipantStatus.class)); + verify(messageProvider).saveInstanceOutProperties(any(ParticipantStatus.class)); } @Test - void testAcDefinitionOutProperties() { + void testHandleParticipantStatusWithCompositionOutProperties() { var participantStatusMessage = createParticipantStatus(); var participantDefinition = new ParticipantDefinition(); participantStatusMessage.setParticipantDefinitionUpdates(List.of(participantDefinition)); @@ -228,31 +224,30 @@ class SupervisionParticipantHandlerTest { mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionProvider.class), acDefinitionProvider, mock(ParticipantSyncPublisher.class), messageProvider); handler.handleParticipantMessage(participantStatusMessage); - verify(messageProvider).save(participantStatusMessage); + verify(messageProvider).saveCompositionOutProperties(any(), any()); } @Test - void testAcOutProperties() { + void testAcOutPropertiesNotValid() { var participantStatusMessage = createParticipantStatus(); - participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo())); + var participantDefinition = new ParticipantDefinition(); + participantStatusMessage.setParticipantDefinitionUpdates(List.of(participantDefinition)); + participantDefinition.setParticipantId(participantStatusMessage.getParticipantId()); + var acElementDefinition = new AutomationCompositionElementDefinition(); + acElementDefinition.setAcElementDefinitionId(new ToscaConceptIdentifier("code", "1.0.0")); + participantDefinition.setAutomationCompositionElementDefinitionList(List.of(acElementDefinition)); var compositionId = UUID.randomUUID(); participantStatusMessage.setCompositionId(compositionId); - var acDefinition = new AutomationCompositionDefinition(); - acDefinition.setState(AcTypeState.COMMISSIONED); - acDefinition.setCompositionId(compositionId); var acDefinitionProvider = mock(AcDefinitionProvider.class); var messageProvider = mock(MessageProvider.class); - when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); - when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition); - var participantProvider = mock(ParticipantProvider.class); var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionProvider.class), acDefinitionProvider, mock(ParticipantSyncPublisher.class), messageProvider); handler.handleParticipantMessage(participantStatusMessage); - verify(messageProvider).save(participantStatusMessage); + verify(messageProvider, times(0)).saveCompositionOutProperties(any(), any()); } @Test @@ -275,7 +270,6 @@ class SupervisionParticipantHandlerTest { @Test void testHandleParticipantStatusCheckOnline() { var participantStatusMessage = createParticipantStatus(); - participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo())); participantStatusMessage.setCompositionId(UUID.randomUUID()); var acDefinitionProvider = mock(AcDefinitionProvider.class); @@ -296,7 +290,6 @@ class SupervisionParticipantHandlerTest { handler.handleParticipantMessage(participantStatusMessage); verify(participantProvider).saveParticipant(any()); - verify(messageProvider).save(any(ParticipantStatus.class)); } private ParticipantStatus createParticipantStatus() { diff --git a/runtime-acm/src/test/resources/providers/AcInstantiateEncryptTest.json b/runtime-acm/src/test/resources/providers/AcInstantiateEncryptTest.json index 896a8b6c9..4a0de52ba 100644 --- a/runtime-acm/src/test/resources/providers/AcInstantiateEncryptTest.json +++ b/runtime-acm/src/test/resources/providers/AcInstantiateEncryptTest.json @@ -12,8 +12,8 @@ }, "description": "Starter Automation Composition Element for the Demo", "properties": { - "secret": "mysecret1", - "password": "mypass1", + "secret": "mysecret", + "password": "mypass", "baseUrl": "http://address:30800", "httpHeaders": { "Content-Type": "application/json", @@ -57,8 +57,8 @@ "description": "Bridge Automation Composition Element for the Demo", "properties": { "baseUrl": "http://address:30801", - "password": "mypass2", - "secret": "secret2", + "password": "mypass", + "secret": "mysecret", "httpHeaders": { "Content-Type": "application/json", "Authorization": "Basic YWNtVXNlcjp6YiFYenRHMzQ=" diff --git a/version.properties b/version.properties index 5f2883325..d6f6425c3 100644 --- a/version.properties +++ b/version.properties @@ -27,7 +27,7 @@ major=8 minor=1 -patch=1 +patch=2 base_version=${major}.${minor}.${patch} |