From 9659c99c9c8b4b7ce33d7f48e61df44a03090186 Mon Sep 17 00:00:00 2001 From: "saul.gill" Date: Thu, 2 Feb 2023 11:40:29 +0000 Subject: Refactor ParticipantUpdate to ParticipantPrime Refactored ParticipantUpdateAck to ParticipantPrimeAck Refactored ParticipantUpdate to ParticipantPrime Refactored all associated tests and code Issue-ID: POLICY-4548 Change-Id: I2265777add4e088173ec465603e26143e3f40070 Signed-off-by: saul.gill --- .../dmaap/participant/ParticipantMessageType.java | 6 +- .../dmaap/participant/ParticipantPrime.java | 63 +++++++++++ .../dmaap/participant/ParticipantPrimeAck.java | 53 +++++++++ .../dmaap/participant/ParticipantUpdate.java | 63 ----------- .../dmaap/participant/ParticipantUpdateAck.java | 53 --------- .../dmaap/participant/ParticipantPrimeAckTest.java | 59 ++++++++++ .../dmaap/participant/ParticipantPrimeTest.java | 92 ++++++++++++++++ .../participant/ParticipantUpdateAckTest.java | 59 ---------- .../dmaap/participant/ParticipantUpdateTest.java | 92 ---------------- .../policy/endtoend/ParticipantMessagesTest.java | 24 ++-- .../policy/main/utils/TestListenerUtils.java | 20 ++-- .../comm/ParticipantMessagePublisher.java | 14 +-- .../comm/ParticipantPrimeListener.java | 47 ++++++++ .../comm/ParticipantUpdateListener.java | 47 -------- .../intermediary/handler/ParticipantHandler.java | 48 ++++---- .../intermediary/comm/ParticipantCommTest.java | 6 +- .../handler/ParticipantHandlerTest.java | 28 ++--- .../commissioning/CommissioningProvider.java | 10 +- .../runtime/supervision/SupervisionHandler.java | 22 ++-- .../comm/ParticipantPrimeAckListener.java | 69 ++++++++++++ .../comm/ParticipantPrimePublisher.java | 122 +++++++++++++++++++++ .../comm/ParticipantUpdateAckListener.java | 69 ------------ .../comm/ParticipantUpdatePublisher.java | 122 --------------------- .../commissioning/CommissioningProviderTest.java | 14 +-- .../supervision/SupervisionHandlerTest.java | 36 +++--- .../supervision/comm/SupervisionMessagesTest.java | 20 ++-- 26 files changed, 629 insertions(+), 629 deletions(-) create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrime.java create mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeAck.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdate.java delete mode 100644 models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAck.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeAckTest.java create mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java delete mode 100644 models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java create mode 100644 participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantPrimeListener.java delete mode 100644 participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantUpdateListener.java create mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimeAckListener.java create mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java delete mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdateAckListener.java delete mode 100644 runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java 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 index 502896188..474bcd36f 100644 --- 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,13 +77,13 @@ public enum ParticipantMessageType { /** * Used by automation composition runtime to send ToscaServiceTemplate to participant. */ - PARTICIPANT_UPDATE, + PARTICIPANT_PRIME, /** * Used by participant to acknowledge the receipt of PARTICIPANT_UPDATE message * from automation composition runtime. */ - PARTICIPANT_UPDATE_ACK, + PARTICIPANT_PRIME_ACK, /** * Used by participant to acknowledge the receipt of AUTOMATION_COMPOSITION_DEPLOY message diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrime.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrime.java new file mode 100644 index 000000000..b9d82a5c8 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrime.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2023 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_PRIME 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 ParticipantPrime extends ParticipantMessage { + + // A list of updates to ParticipantDefinitions + private List participantDefinitionUpdates = new ArrayList<>(); + + /** + * Constructor for instantiating ParticipantPrime class with message name. + * + */ + public ParticipantPrime() { + super(ParticipantMessageType.PARTICIPANT_PRIME); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantPrime(ParticipantPrime 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/ParticipantPrimeAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeAck.java new file mode 100644 index 000000000..156fe919c --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeAck.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2023 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_PRIME_ACK message that registered participant sends to the ACM runtime. + */ +@Getter +@Setter +@ToString(callSuper = true) +public class ParticipantPrimeAck extends ParticipantAckMessage { + + /** + * Constructor for instantiating ParticipantPrimeAck class with message name. + * + */ + public ParticipantPrimeAck() { + super(ParticipantMessageType.PARTICIPANT_PRIME_ACK); + } + + /** + * Constructs the object, making a deep copy. + * + * @param source source from which to copy + */ + public ParticipantPrimeAck(final ParticipantPrimeAck 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 deleted file mode 100644 index 36842a8cf..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/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.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 deleted file mode 100644 index 2c3a68e22..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/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.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/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeAckTest.java new file mode 100644 index 000000000..e4684b8d0 --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeAckTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +class ParticipantPrimeAckTest { + + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantPrimeAck(null)).isInstanceOf(NullPointerException.class); + + final ParticipantPrimeAck orig = new ParticipantPrimeAck(); + + // verify with null values + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantPrimeAck(orig).toString())); + + // verify with all values + ToscaConceptIdentifier id = new ToscaConceptIdentifier(); + id.setName("id"); + id.setVersion("1.2.3"); + orig.setResponseTo(UUID.randomUUID()); + orig.setMessageType(ParticipantMessageType.PARTICIPANT_PRIME_ACK); + orig.setResult(true); + orig.setMessage("Successfully processed message"); + + assertEquals(removeVariableFields(orig.toString()), + removeVariableFields(new ParticipantPrimeAck(orig).toString())); + + assertSerializable(orig, ParticipantPrimeAck.class); + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java new file mode 100644 index 000000000..890fc55ae --- /dev/null +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantPrimeTest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.models.acm.messages.dmaap.participant; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; +import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; + +import java.time.Instant; +import java.util.List; +import java.util.UUID; +import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.utils.CommonTestData; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; + +/** + * Test the copy constructor. + */ +class ParticipantPrimeTest { + @Test + void testCopyConstructor() throws CoderException { + assertThatThrownBy(() -> new ParticipantPrime(null)).isInstanceOf(NullPointerException.class); + + var orig = new ParticipantPrime(); + // verify with all values + orig.setAutomationCompositionId(UUID.randomUUID()); + orig.setParticipantId(CommonTestData.getParticipantId()); + orig.setMessageId(UUID.randomUUID()); + orig.setTimestamp(Instant.ofEpochMilli(3000)); + + var toscaServiceTemplate = new ToscaServiceTemplate(); + toscaServiceTemplate.setName("serviceTemplate"); + toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); + toscaServiceTemplate.setDescription("Description of serviceTemplate"); + toscaServiceTemplate.setVersion("1.2.3"); + + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + var participantDefinitionUpdate = new ParticipantDefinition(); + var type = new ToscaConceptIdentifier("id", "1.2.3"); + var acDefinition = getAcElementDefinition(type); + participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); + orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); + + var other = new ParticipantPrime(orig); + + assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); + + assertSerializable(orig, ParticipantPrime.class); + } + + private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setName("nodeTemplate"); + toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); + toscaNodeTemplate.setDescription("Description of nodeTemplate"); + toscaNodeTemplate.setVersion("1.2.3"); + + var acDefinition = new AutomationCompositionElementDefinition(); + acDefinition.setAcElementDefinitionId(id); + acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + return acDefinition; + } +} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java deleted file mode 100644 index e2c3454a4..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateAckTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============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.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -class ParticipantUpdateAckTest { - - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantUpdateAck(null)).isInstanceOf(NullPointerException.class); - - final ParticipantUpdateAck orig = new ParticipantUpdateAck(); - - // verify with null values - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantUpdateAck(orig).toString())); - - // verify with all values - ToscaConceptIdentifier id = new ToscaConceptIdentifier(); - id.setName("id"); - id.setVersion("1.2.3"); - orig.setResponseTo(UUID.randomUUID()); - orig.setMessageType(ParticipantMessageType.PARTICIPANT_UPDATE_ACK); - orig.setResult(true); - orig.setMessage("Successfully processed message"); - - assertEquals(removeVariableFields(orig.toString()), - removeVariableFields(new ParticipantUpdateAck(orig).toString())); - - assertSerializable(orig, ParticipantUpdateAck.class); - } -} diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java deleted file mode 100644 index ffbd63f1a..000000000 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/dmaap/participant/ParticipantUpdateTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.models.acm.messages.dmaap.participant; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.assertSerializable; -import static org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageUtils.removeVariableFields; - -import java.time.Instant; -import java.util.List; -import java.util.UUID; -import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; -import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; -import org.onap.policy.clamp.models.acm.utils.CommonTestData; -import org.onap.policy.common.utils.coder.CoderException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; - -/** - * Test the copy constructor. - */ -class ParticipantUpdateTest { - @Test - void testCopyConstructor() throws CoderException { - assertThatThrownBy(() -> new ParticipantUpdate(null)).isInstanceOf(NullPointerException.class); - - var orig = new ParticipantUpdate(); - // verify with all values - orig.setAutomationCompositionId(UUID.randomUUID()); - orig.setParticipantId(CommonTestData.getParticipantId()); - orig.setMessageId(UUID.randomUUID()); - orig.setTimestamp(Instant.ofEpochMilli(3000)); - - var toscaServiceTemplate = new ToscaServiceTemplate(); - toscaServiceTemplate.setName("serviceTemplate"); - toscaServiceTemplate.setDerivedFrom("parentServiceTemplate"); - toscaServiceTemplate.setDescription("Description of serviceTemplate"); - toscaServiceTemplate.setVersion("1.2.3"); - - var toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - var participantDefinitionUpdate = new ParticipantDefinition(); - var type = new ToscaConceptIdentifier("id", "1.2.3"); - var acDefinition = getAcElementDefinition(type); - participantDefinitionUpdate.setAutomationCompositionElementDefinitionList(List.of(acDefinition)); - orig.setParticipantDefinitionUpdates(List.of(participantDefinitionUpdate)); - - var other = new ParticipantUpdate(orig); - - assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString())); - - assertSerializable(orig, ParticipantUpdate.class); - } - - private AutomationCompositionElementDefinition getAcElementDefinition(ToscaConceptIdentifier id) { - var toscaNodeTemplate = new ToscaNodeTemplate(); - toscaNodeTemplate.setName("nodeTemplate"); - toscaNodeTemplate.setDerivedFrom("parentNodeTemplate"); - toscaNodeTemplate.setDescription("Description of nodeTemplate"); - toscaNodeTemplate.setVersion("1.2.3"); - - var acDefinition = new AutomationCompositionElementDefinition(); - acDefinition.setAcElementDefinitionId(id); - acDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); - return acDefinition; - } -} diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java index 555183227..5ba598cc8 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/endtoend/ParticipantMessagesTest.java @@ -32,18 +32,18 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantDeregisterAckListener; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; +import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantPrimeListener; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantRegisterAckListener; -import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantUpdateListener; import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; import org.onap.policy.clamp.acm.participant.policy.main.parameters.CommonTestData; import org.onap.policy.clamp.acm.participant.policy.main.utils.TestListenerUtils; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.springframework.beans.factory.annotation.Autowired; @@ -126,11 +126,11 @@ class ParticipantMessagesTest { @Test void testReceiveParticipantUpdateMessage() { - ParticipantUpdate participantUpdateMsg = TestListenerUtils.createParticipantUpdateMsg(); + ParticipantPrime participantPrimeMsg = TestListenerUtils.createParticipantPrimeMsg(); synchronized (lockit) { - ParticipantUpdateListener participantUpdateListener = new ParticipantUpdateListener(participantHandler); - participantUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateMsg); + ParticipantPrimeListener participantPrimeListener = new ParticipantPrimeListener(participantHandler); + participantPrimeListener.onTopicEvent(INFRA, TOPIC, null, participantPrimeMsg); } // Verify the result of GET participants with what is stored @@ -138,16 +138,16 @@ class ParticipantMessagesTest { } @Test - void testSendParticipantUpdateAckMessage() { - final ParticipantUpdateAck participantUpdateAckMsg = new ParticipantUpdateAck(); - participantUpdateAckMsg.setMessage("ParticipantUpdateAck message"); - participantUpdateAckMsg.setResponseTo(UUID.randomUUID()); - participantUpdateAckMsg.setResult(true); + void testSendParticipantPrimeAckMessage() { + final ParticipantPrimeAck participantPrimeAckMsg = new ParticipantPrimeAck(); + participantPrimeAckMsg.setMessage("ParticipantPrimeAck message"); + participantPrimeAckMsg.setResponseTo(UUID.randomUUID()); + participantPrimeAckMsg.setResult(true); synchronized (lockit) { ParticipantMessagePublisher participantMessagePublisher = new ParticipantMessagePublisher(); participantMessagePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); - assertThatCode(() -> participantMessagePublisher.sendParticipantUpdateAck(participantUpdateAckMsg)) + assertThatCode(() -> participantMessagePublisher.sendParticipantPrimeAck(participantPrimeAckMsg)) .doesNotThrowAnyException(); } } diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java index b7058a84f..17d961880 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/TestListenerUtils.java @@ -29,7 +29,7 @@ import java.util.UUID; import lombok.AccessLevel; import lombok.NoArgsConstructor; import org.onap.policy.clamp.acm.participant.policy.main.parameters.CommonTestData; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; @@ -45,23 +45,23 @@ public final class TestListenerUtils { /** * Method to create participantUpdateMsg. * - * @return ParticipantUpdate message + * @return ParticipantPrime message */ - public static ParticipantUpdate createParticipantUpdateMsg() { - final var participantUpdateMsg = new ParticipantUpdate(); + public static ParticipantPrime createParticipantPrimeMsg() { + final var participantPrimeMsg = new ParticipantPrime(); var participantId = CommonTestData.getParticipantId(); - participantUpdateMsg.setParticipantId(participantId); - participantUpdateMsg.setTimestamp(Instant.now()); - participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000)); - participantUpdateMsg.setMessageId(UUID.randomUUID()); + participantPrimeMsg.setParticipantId(participantId); + participantPrimeMsg.setTimestamp(Instant.now()); + participantPrimeMsg.setTimestamp(Instant.ofEpochMilli(3000)); + participantPrimeMsg.setMessageId(UUID.randomUUID()); var toscaServiceTemplate = testAutomationCompositionRead(); // Add policies to the toscaServiceTemplate TestListenerUtils.addPoliciesToToscaServiceTemplate(toscaServiceTemplate); - participantUpdateMsg.setParticipantDefinitionUpdates(new ArrayList<>()); - return participantUpdateMsg; + participantPrimeMsg.setParticipantDefinitionUpdates(new ArrayList<>()); + return participantPrimeMsg; } private static ToscaServiceTemplate testAutomationCompositionRead() { diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java index b18875813..4c885fa26 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantMessagePublisher.java @@ -28,9 +28,9 @@ import org.onap.policy.clamp.acm.participant.intermediary.handler.Publisher; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.client.TopicSinkClient; import org.slf4j.Logger; @@ -100,15 +100,15 @@ public class ParticipantMessagePublisher implements Publisher { } /** - * Method to send Participant Update Ack message to runtime. + * Method to send Participant Prime Ack message to runtime. * - * @param participantUpdateAck the Participant Update Ack + * @param participantPrimeAck the Participant Prime Ack */ - @Timed(value = "publisher.participant_update_ack", description = "PARTICIPANT_UPDATE_ACK messages published") - public void sendParticipantUpdateAck(final ParticipantUpdateAck participantUpdateAck) { + @Timed(value = "publisher.participant_prime_ack", description = "PARTICIPANT_PRIME_ACK messages published") + public void sendParticipantPrimeAck(final ParticipantPrimeAck participantPrimeAck) { validate(); - topicSinkClient.send(participantUpdateAck); - LOGGER.debug("Sent Participant Update Ack message to CLAMP - {}", participantUpdateAck); + topicSinkClient.send(participantPrimeAck); + LOGGER.debug("Sent Participant Prime Ack message to CLAMP - {}", participantPrimeAck); } /** diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantPrimeListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantPrimeListener.java new file mode 100644 index 000000000..e114c74f9 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantPrimeListener.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2023 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.acm.participant.intermediary.comm; + +import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; +import org.springframework.stereotype.Component; + +/** + * Listener for Participant Prime messages sent by runtime. + */ +@Component +public class ParticipantPrimeListener extends ParticipantListener { + + /** + * Constructs the object. + * + * @param participantHandler the handler for managing the state of the participant + */ + public ParticipantPrimeListener(final ParticipantHandler participantHandler) { + super(ParticipantPrime.class, participantHandler, participantHandler::handleParticipantPrime); + } + + @Override + public String getType() { + return ParticipantMessageType.PARTICIPANT_PRIME.name(); + } +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantUpdateListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantUpdateListener.java deleted file mode 100644 index 19eb5fb30..000000000 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantUpdateListener.java +++ /dev/null @@ -1,47 +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.acm.participant.intermediary.comm; - -import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; -import org.springframework.stereotype.Component; - -/** - * Listener for Participant Update messages sent by runtime. - */ -@Component -public class ParticipantUpdateListener extends ParticipantListener { - - /** - * Constructs the object. - * - * @param participantHandler the handler for managing the state of the participant - */ - public ParticipantUpdateListener(final ParticipantHandler participantHandler) { - super(ParticipantUpdate.class, participantHandler, participantHandler::handleParticipantUpdate); - } - - @Override - public String getType() { - return ParticipantMessageType.PARTICIPANT_UPDATE.name(); - } -} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java index 050d66d0b..3aae2c41a 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandler.java @@ -42,12 +42,12 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantAc import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatusReq; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -186,44 +186,44 @@ public class ParticipantHandler { } /** - * Handle a ParticipantUpdate message. + * Handle a ParticipantPrime message. * - * @param participantUpdateMsg the ParticipantUpdate message + * @param participantPrimeMsg the ParticipantPrime message */ - @Timed(value = "listener.participant_update", description = "PARTICIPANT_UPDATE messages received") - public void handleParticipantUpdate(ParticipantUpdate participantUpdateMsg) { - LOGGER.debug("ParticipantUpdate message received for participantId {}", - participantUpdateMsg.getParticipantId()); + @Timed(value = "listener.participant_prime", description = "PARTICIPANT_PRIME messages received") + public void handleParticipantPrime(ParticipantPrime participantPrimeMsg) { + LOGGER.debug("ParticipantPrime message received for participantId {}", + participantPrimeMsg.getParticipantId()); - acElementDefsMap.putIfAbsent(participantUpdateMsg.getCompositionId(), new ArrayList<>()); - if (!participantUpdateMsg.getParticipantDefinitionUpdates().isEmpty()) { + acElementDefsMap.putIfAbsent(participantPrimeMsg.getCompositionId(), new ArrayList<>()); + if (!participantPrimeMsg.getParticipantDefinitionUpdates().isEmpty()) { // This message is to commission the automation composition - for (var participantDefinition : participantUpdateMsg.getParticipantDefinitionUpdates()) { + for (var participantDefinition : participantPrimeMsg.getParticipantDefinitionUpdates()) { if (participantDefinition.getParticipantId().equals(participantId)) { - acElementDefsMap.get(participantUpdateMsg.getCompositionId()) + acElementDefsMap.get(participantPrimeMsg.getCompositionId()) .addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); break; } } } else { // This message is to decommission the automation composition - acElementDefsMap.get(participantUpdateMsg.getCompositionId()).clear(); + acElementDefsMap.get(participantPrimeMsg.getCompositionId()).clear(); } - sendParticipantUpdateAck(participantUpdateMsg.getMessageId(), participantUpdateMsg.getCompositionId()); + sendParticipantPrimeAck(participantPrimeMsg.getMessageId(), participantPrimeMsg.getCompositionId()); } /** - * Method to send ParticipantUpdateAck message to automation composition runtime. + * Method to send ParticipantPrimeAck message to automation composition runtime. */ - public void sendParticipantUpdateAck(UUID messageId, UUID compositionId) { - var participantUpdateAck = new ParticipantUpdateAck(); - participantUpdateAck.setResponseTo(messageId); - participantUpdateAck.setCompositionId(compositionId); - participantUpdateAck.setMessage("Participant Update Ack message"); - participantUpdateAck.setResult(true); - participantUpdateAck.setParticipantId(participantId); - participantUpdateAck.setState(ParticipantState.ON_LINE); - publisher.sendParticipantUpdateAck(participantUpdateAck); + public void sendParticipantPrimeAck(UUID messageId, UUID compositionId) { + var participantPrimeAck = new ParticipantPrimeAck(); + participantPrimeAck.setResponseTo(messageId); + participantPrimeAck.setCompositionId(compositionId); + participantPrimeAck.setMessage("Participant Prime Ack message"); + participantPrimeAck.setResult(true); + participantPrimeAck.setParticipantId(participantId); + participantPrimeAck.setState(ParticipantState.ON_LINE); + publisher.sendParticipantPrimeAck(participantPrimeAck); } /** diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java index d9d99da4e..1540d6e4c 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,8 +56,8 @@ class ParticipantCommTest { assertEquals(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK.name(), participantDeregisterAckListener.getType()); - var participantUpdateListener = new ParticipantUpdateListener(participantHandler); - assertEquals(ParticipantMessageType.PARTICIPANT_UPDATE.name(), participantUpdateListener.getType()); + var participantPrimeListener = new ParticipantPrimeListener(participantHandler); + assertEquals(ParticipantMessageType.PARTICIPANT_PRIME.name(), participantPrimeListener.getType()); var automationCompositionUpdateListener = new AutomationCompositionDeployListener(participantHandler); assertEquals(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY.name(), diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java index 9f1bf29be..7349ab9c0 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ParticipantHandlerTest.java @@ -39,8 +39,8 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantAckMessage; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.common.utils.coder.CoderException; class ParticipantHandlerTest { @@ -54,43 +54,43 @@ class ParticipantHandlerTest { var publisher = new ParticipantMessagePublisher(); var emptyParticipantHandler = new ParticipantHandler(parameters, publisher, automationCompositionHander); - var participantUpdateMsg = new ParticipantUpdate(); + var participantPrimeMsg = new ParticipantPrime(); assertThatThrownBy(() -> - emptyParticipantHandler.handleParticipantUpdate(participantUpdateMsg)) + emptyParticipantHandler.handleParticipantPrime(participantPrimeMsg)) .isInstanceOf(RuntimeException.class); var participantHandler = commonTestData.getMockParticipantHandler(); var participantId = CommonTestData.getParticipantId(); - participantUpdateMsg.setAutomationCompositionId(CommonTestData.AC_ID_1); - participantUpdateMsg.setCompositionId(CommonTestData.AC_ID_1); - participantUpdateMsg.setParticipantId(participantId); - participantUpdateMsg.setMessageId(UUID.randomUUID()); - participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000)); + participantPrimeMsg.setAutomationCompositionId(CommonTestData.AC_ID_1); + participantPrimeMsg.setCompositionId(CommonTestData.AC_ID_1); + participantPrimeMsg.setParticipantId(participantId); + participantPrimeMsg.setMessageId(UUID.randomUUID()); + participantPrimeMsg.setTimestamp(Instant.ofEpochMilli(3000)); var heartbeatF = participantHandler.makeHeartbeat(false); assertEquals(participantId, heartbeatF.getParticipantId()); assertThat(heartbeatF.getAutomationCompositionInfoList()).isEmpty(); - participantHandler.handleParticipantUpdate(participantUpdateMsg); + participantHandler.handleParticipantPrime(participantPrimeMsg); var heartbeatT = participantHandler.makeHeartbeat(true); assertEquals(participantId, heartbeatT.getParticipantId()); assertThat(heartbeatT.getParticipantDefinitionUpdates()).isNotEmpty(); assertEquals(participantId, heartbeatT.getParticipantDefinitionUpdates().get(0).getParticipantId()); - var pum = setListParticipantDefinition(participantUpdateMsg); - participantHandler.handleParticipantUpdate(pum); + var pum = setListParticipantDefinition(participantPrimeMsg); + participantHandler.handleParticipantPrime(pum); var heartbeatTAfterUpdate = participantHandler.makeHeartbeat(true); assertEquals(participantId, heartbeatTAfterUpdate.getParticipantId()); } - private ParticipantUpdate setListParticipantDefinition(ParticipantUpdate participantUpdateMsg) { + private ParticipantPrime setListParticipantDefinition(ParticipantPrime participantPrimeMsg) { var def = new ParticipantDefinition(); def.setParticipantId(CommonTestData.getParticipantId()); - participantUpdateMsg.setParticipantDefinitionUpdates(List.of(def)); - return participantUpdateMsg; + participantPrimeMsg.setParticipantDefinitionUpdates(List.of(def)); + return participantPrimeMsg; } @Test diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java index c273a627a..456e61c20 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java @@ -25,7 +25,7 @@ import java.util.UUID; import java.util.stream.Collectors; import javax.ws.rs.core.Response.Status; import lombok.RequiredArgsConstructor; -import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantUpdatePublisher; +import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantPrimePublisher; 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.messages.rest.commissioning.AcTypeStateUpdate; @@ -53,7 +53,7 @@ public class CommissioningProvider { private final AcDefinitionProvider acDefinitionProvider; private final AutomationCompositionProvider acProvider; private final AcTypeStateResolver acTypeStateResolver; - private final ParticipantUpdatePublisher participantUpdatePublisher; + private final ParticipantPrimePublisher participantPrimePublisher; private CommissioningResponse createCommissioningResponse(UUID compositionId, ToscaServiceTemplate serviceTemplate) { @@ -191,9 +191,9 @@ public class CommissioningProvider { } private void prime(AutomationCompositionDefinition acmDefinition) { - var prearation = participantUpdatePublisher.prepareParticipantPriming(acmDefinition); + var prearation = participantPrimePublisher.prepareParticipantPriming(acmDefinition); acDefinitionProvider.updateAcDefinition(acmDefinition); - participantUpdatePublisher.sendPriming(prearation, acmDefinition.getCompositionId(), null); + participantPrimePublisher.sendPriming(prearation, acmDefinition.getCompositionId(), null); } private void deprime(AutomationCompositionDefinition acmDefinition) { @@ -204,7 +204,7 @@ public class CommissioningProvider { acmDefinition.setState(AcTypeState.DEPRIMING); acDefinitionProvider.updateAcDefinition(acmDefinition); } - participantUpdatePublisher.sendDepriming(acmDefinition.getCompositionId()); + participantPrimePublisher.sendDepriming(acmDefinition.getCompositionId()); } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java index 374df0135..b31a95b18 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandler.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021,2023 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -36,7 +36,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.slf4j.Logger; @@ -85,29 +85,29 @@ public class SupervisionHandler { } /** - * Handle a ParticipantUpdateAck message from a participant. + * Handle a ParticipantPrimeAck message from a participant. * - * @param participantUpdateAckMessage the ParticipantUpdateAck message received from a participant + * @param participantPrimeAckMessage the ParticipantPrimeAck message received from a participant */ - @Timed(value = "listener.participant_update_ack", description = "PARTICIPANT_UPDATE_ACK messages received") - public void handleParticipantMessage(ParticipantUpdateAck participantUpdateAckMessage) { - LOGGER.debug("Participant Update Ack message received {}", participantUpdateAckMessage); - var acDefinitionOpt = acDefinitionProvider.findAcDefinition(participantUpdateAckMessage.getCompositionId()); + @Timed(value = "listener.participant_prime_ack", description = "PARTICIPANT_PRIME_ACK messages received") + public void handleParticipantMessage(ParticipantPrimeAck participantPrimeAckMessage) { + LOGGER.debug("Participant Prime Ack message received {}", participantPrimeAckMessage); + var acDefinitionOpt = acDefinitionProvider.findAcDefinition(participantPrimeAckMessage.getCompositionId()); if (acDefinitionOpt.isEmpty()) { - LOGGER.warn("AC Definition not found in database {}", participantUpdateAckMessage.getCompositionId()); + LOGGER.warn("AC Definition not found in database {}", participantPrimeAckMessage.getCompositionId()); return; } var acDefinition = acDefinitionOpt.get(); if (!AcTypeState.PRIMING.equals(acDefinition.getState()) && !AcTypeState.DEPRIMING.equals(acDefinition.getState())) { LOGGER.warn("AC Definition {} already primed/deprimed with participant {}", - participantUpdateAckMessage.getCompositionId(), participantUpdateAckMessage.getParticipantId()); + participantPrimeAckMessage.getCompositionId(), participantPrimeAckMessage.getParticipantId()); return; } var state = AcTypeState.PRIMING.equals(acDefinition.getState()) ? AcTypeState.PRIMED : AcTypeState.COMMISSIONED; boolean completed = true; for (var element : acDefinition.getElementStateMap().values()) { - if (participantUpdateAckMessage.getParticipantId().equals(element.getParticipantId())) { + if (participantPrimeAckMessage.getParticipantId().equals(element.getParticipantId())) { element.setState(state); } else if (!state.equals(element.getState())) { completed = false; diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimeAckListener.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimeAckListener.java new file mode 100644 index 000000000..163d0708e --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimeAckListener.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2023 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.acm.runtime.supervision.comm; + +import org.onap.policy.clamp.acm.runtime.config.messaging.Listener; +import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; +import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; +import org.onap.policy.common.endpoints.listeners.ScoListener; +import org.onap.policy.common.utils.coder.StandardCoderObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +/** + * Listener for ParticipantPrimeAck messages sent by participants. + */ +@Component +public class ParticipantPrimeAckListener extends ScoListener + implements Listener { + private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantPrimeAckListener.class); + + private final SupervisionHandler supervisionHandler; + + /** + * Constructs the object. + */ + public ParticipantPrimeAckListener(SupervisionHandler supervisionHandler) { + super(ParticipantPrimeAck.class); + this.supervisionHandler = supervisionHandler; + } + + @Override + public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco, + final ParticipantPrimeAck participantPrimeAckMessage) { + LOGGER.debug("ParticipantPrimeAck message received from participant - {}", participantPrimeAckMessage); + supervisionHandler.handleParticipantMessage(participantPrimeAckMessage); + } + + @Override + public String getType() { + return ParticipantMessageType.PARTICIPANT_PRIME_ACK.name(); + } + + @Override + public ScoListener getScoListener() { + return this; + } +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java new file mode 100644 index 000000000..24dcc2382 --- /dev/null +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantPrimePublisher.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021-2023 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.acm.runtime.supervision.comm; + +import io.micrometer.core.annotation.Timed; +import java.time.Instant; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import lombok.AllArgsConstructor; +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.concepts.ParticipantDefinition; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrime; +import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; +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.Component; + +/** + * This class is used to send ParticipantPrime messages to participants on DMaaP. + */ +@Component +@AllArgsConstructor +public class ParticipantPrimePublisher extends AbstractParticipantPublisher { + + private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantPrimePublisher.class); + + private final ParticipantProvider participantProvider; + + /** + * Send ParticipantPrime to Participant + * if participantId is null then message is broadcast. + * + * @param participantDefinitions the list of ParticipantDefinition to send + * @param compositionId the compositionId + * @param participantId the ParticipantId + */ + @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published") + public void sendPriming(List participantDefinitions, UUID compositionId, + UUID participantId) { + var message = new ParticipantPrime(); + message.setCompositionId(compositionId); + message.setParticipantId(participantId); + message.setTimestamp(Instant.now()); + message.setParticipantDefinitionUpdates(participantDefinitions); + LOGGER.debug("Participant Update sent {}", message); + super.send(message); + } + + /** + * Pepare the Priming message creating the list of ParticipantDefinition to send + * and fill the ElementState map of the AC Definition. + * + * @param acmDefinition the AutomationComposition Definition + * @return list of ParticipantDefinition + */ + public List prepareParticipantPriming(AutomationCompositionDefinition acmDefinition) { + acmDefinition.setState(AcTypeState.PRIMING); + var acElements = AcmUtils.extractAcElementsFromServiceTemplate(acmDefinition.getServiceTemplate()); + Map supportedElementMap = new HashMap<>(); + if (AcTypeState.PRIMED.equals(acmDefinition.getState())) { + // scenario Prime again, participants already assigned + for (var elementEntry : acElements) { + var elementState = acmDefinition.getElementStateMap().get(elementEntry.getKey()); + elementState.setState(AcTypeState.PRIMING); + var type = new ToscaConceptIdentifier(elementEntry.getValue().getType(), + elementEntry.getValue().getTypeVersion()); + supportedElementMap.put(type, elementState.getParticipantId()); + } + } else { + // scenario Prime participants not assigned yet + supportedElementMap = participantProvider.getSupportedElementMap(); + for (var elementEntry : acElements) { + var elementState = acmDefinition.getElementStateMap().get(elementEntry.getKey()); + elementState.setState(AcTypeState.PRIMING); + var type = new ToscaConceptIdentifier(elementEntry.getValue().getType(), + elementEntry.getValue().getTypeVersion()); + elementState.setParticipantId(supportedElementMap.get(type)); + } + } + return AcmUtils.prepareParticipantPriming(acElements, supportedElementMap); + } + + /** + * Send ParticipantPrime to Participant after that commissioning has been removed. + */ + @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published") + public void sendDepriming(UUID compositionId) { + var message = new ParticipantPrime(); + message.setCompositionId(compositionId); + message.setTimestamp(Instant.now()); + // DeCommission the automation composition but deleting participantdefinitions on participants + message.setParticipantDefinitionUpdates(null); + + LOGGER.debug("Participant Update sent {}", message); + super.send(message); + } +} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdateAckListener.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdateAckListener.java deleted file mode 100644 index d75de775b..000000000 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdateAckListener.java +++ /dev/null @@ -1,69 +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.acm.runtime.supervision.comm; - -import org.onap.policy.clamp.acm.runtime.config.messaging.Listener; -import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; -import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; -import org.onap.policy.common.endpoints.listeners.ScoListener; -import org.onap.policy.common.utils.coder.StandardCoderObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -/** - * Listener for ParticipantUpdateAck messages sent by participants. - */ -@Component -public class ParticipantUpdateAckListener extends ScoListener - implements Listener { - private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdateAckListener.class); - - private final SupervisionHandler supervisionHandler; - - /** - * Constructs the object. - */ - public ParticipantUpdateAckListener(SupervisionHandler supervisionHandler) { - super(ParticipantUpdateAck.class); - this.supervisionHandler = supervisionHandler; - } - - @Override - public void onTopicEvent(final CommInfrastructure infra, final String topic, final StandardCoderObject sco, - final ParticipantUpdateAck participantUpdateAckMessage) { - LOGGER.debug("ParticipantUpdateAck message received from participant - {}", participantUpdateAckMessage); - supervisionHandler.handleParticipantMessage(participantUpdateAckMessage); - } - - @Override - public String getType() { - return ParticipantMessageType.PARTICIPANT_UPDATE_ACK.name(); - } - - @Override - public ScoListener getScoListener() { - return this; - } -} diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java deleted file mode 100644 index 1915f1b0d..000000000 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantUpdatePublisher.java +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 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.acm.runtime.supervision.comm; - -import io.micrometer.core.annotation.Timed; -import java.time.Instant; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import lombok.AllArgsConstructor; -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.concepts.ParticipantDefinition; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdate; -import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; -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.Component; - -/** - * This class is used to send ParticipantUpdate messages to participants on DMaaP. - */ -@Component -@AllArgsConstructor -public class ParticipantUpdatePublisher extends AbstractParticipantPublisher { - - private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantUpdatePublisher.class); - - private final ParticipantProvider participantProvider; - - /** - * Send ParticipantUpdate to Participant - * if participantId is null then message is broadcast. - * - * @param participantDefinitions the list of ParticipantDefinition to send - * @param compositionId the compositionId - * @param participantId the ParticipantId - */ - @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published") - public void sendPriming(List participantDefinitions, UUID compositionId, - UUID participantId) { - var message = new ParticipantUpdate(); - message.setCompositionId(compositionId); - message.setParticipantId(participantId); - message.setTimestamp(Instant.now()); - message.setParticipantDefinitionUpdates(participantDefinitions); - LOGGER.debug("Participant Update sent {}", message); - super.send(message); - } - - /** - * Pepare the Priming message creating the list of ParticipantDefinition to send - * and fill the ElementState map of the AC Definition. - * - * @param acmDefinition the AutomationComposition Definition - * @return list of ParticipantDefinition - */ - public List prepareParticipantPriming(AutomationCompositionDefinition acmDefinition) { - acmDefinition.setState(AcTypeState.PRIMING); - var acElements = AcmUtils.extractAcElementsFromServiceTemplate(acmDefinition.getServiceTemplate()); - Map supportedElementMap = new HashMap<>(); - if (AcTypeState.PRIMED.equals(acmDefinition.getState())) { - // scenario Prime again, participants already assigned - for (var elementEntry : acElements) { - var elementState = acmDefinition.getElementStateMap().get(elementEntry.getKey()); - elementState.setState(AcTypeState.PRIMING); - var type = new ToscaConceptIdentifier(elementEntry.getValue().getType(), - elementEntry.getValue().getTypeVersion()); - supportedElementMap.put(type, elementState.getParticipantId()); - } - } else { - // scenario Prime participants not assigned yet - supportedElementMap = participantProvider.getSupportedElementMap(); - for (var elementEntry : acElements) { - var elementState = acmDefinition.getElementStateMap().get(elementEntry.getKey()); - elementState.setState(AcTypeState.PRIMING); - var type = new ToscaConceptIdentifier(elementEntry.getValue().getType(), - elementEntry.getValue().getTypeVersion()); - elementState.setParticipantId(supportedElementMap.get(type)); - } - } - return AcmUtils.prepareParticipantPriming(acElements, supportedElementMap); - } - - /** - * Send ParticipantUpdate to Participant after that commissioning has been removed. - */ - @Timed(value = "publisher.participant_update", description = "PARTICIPANT_UPDATE messages published") - public void sendDepriming(UUID compositionId) { - var message = new ParticipantUpdate(); - message.setCompositionId(compositionId); - message.setTimestamp(Instant.now()); - // DeCommission the automation composition but deleting participantdefinitions on participants - message.setParticipantDefinitionUpdates(null); - - LOGGER.debug("Participant Update sent {}", message); - super.send(message); - } -} diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java index 071fc26fd..327d881a1 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java @@ -33,7 +33,7 @@ import java.util.List; 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.supervision.comm.ParticipantUpdatePublisher; +import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantPrimePublisher; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; @@ -154,15 +154,15 @@ class CommissioningProviderTest { var compositionId = acmDefinition.getCompositionId(); when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition); - var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); + var participantPrimePublisher = mock(ParticipantPrimePublisher.class); var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class), - new AcTypeStateResolver(), participantUpdatePublisher); + new AcTypeStateResolver(), participantPrimePublisher); var acTypeStateUpdate = new AcTypeStateUpdate(); acTypeStateUpdate.setPrimeOrder(PrimeOrder.PRIME); provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate); verify(acDefinitionProvider).updateAcDefinition(acmDefinition); - verify(participantUpdatePublisher).sendPriming(any(), any(), any()); + verify(participantPrimePublisher).sendPriming(any(), any(), any()); } @Test @@ -173,13 +173,13 @@ class CommissioningProviderTest { var compositionId = acmDefinition.getCompositionId(); when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition); - var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); + var participantPrimePublisher = mock(ParticipantPrimePublisher.class); var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class), - new AcTypeStateResolver(), participantUpdatePublisher); + new AcTypeStateResolver(), participantPrimePublisher); var acTypeStateUpdate = new AcTypeStateUpdate(); acTypeStateUpdate.setPrimeOrder(PrimeOrder.DEPRIME); provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate); - verify(participantUpdatePublisher).sendDepriming(compositionId); + verify(participantPrimePublisher).sendDepriming(compositionId); } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java index 8ae21ca75..e54cfafa2 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java @@ -48,7 +48,7 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionDeployAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; @@ -240,28 +240,28 @@ class SupervisionHandlerTest { } @Test - void testParticipantUpdateAckNotFound() { - var participantUpdateAckMessage = new ParticipantUpdateAck(); - participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId()); - participantUpdateAckMessage.setState(ParticipantState.ON_LINE); + void testParticipantPrimeAckNotFound() { + var participantPrimeAckMessage = new ParticipantPrimeAck(); + participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId()); + participantPrimeAckMessage.setState(ParticipantState.ON_LINE); var acDefinitionProvider = mock(AcDefinitionProvider.class); var handler = new SupervisionHandler(mock(AutomationCompositionProvider.class), acDefinitionProvider, mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class)); - handler.handleParticipantMessage(participantUpdateAckMessage); + handler.handleParticipantMessage(participantPrimeAckMessage); verify(acDefinitionProvider).findAcDefinition(any()); } @Test - void testParticipantUpdateAckPrimed() { - var participantUpdateAckMessage = new ParticipantUpdateAck(); - participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId()); - participantUpdateAckMessage.setState(ParticipantState.ON_LINE); + void testParticipantPrimeAckPrimed() { + var participantPrimeAckMessage = new ParticipantPrimeAck(); + participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId()); + participantPrimeAckMessage.setState(ParticipantState.ON_LINE); var acDefinition = CommonTestData.createAcDefinition( InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMED); - participantUpdateAckMessage.setCompositionId(acDefinition.getCompositionId()); + participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId()); var acDefinitionProvider = mock(AcDefinitionProvider.class); when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId())) @@ -271,19 +271,19 @@ class SupervisionHandlerTest { mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class)); - handler.handleParticipantMessage(participantUpdateAckMessage); + handler.handleParticipantMessage(participantPrimeAckMessage); verify(acDefinitionProvider).findAcDefinition(any()); } @Test - void testParticipantUpdateAck() { - var participantUpdateAckMessage = new ParticipantUpdateAck(); - participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId()); - participantUpdateAckMessage.setState(ParticipantState.ON_LINE); + void testParticipantPrimeAck() { + var participantPrimeAckMessage = new ParticipantPrimeAck(); + participantPrimeAckMessage.setParticipantId(CommonTestData.getParticipantId()); + participantPrimeAckMessage.setState(ParticipantState.ON_LINE); var acDefinition = CommonTestData.createAcDefinition( InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML), AcTypeState.PRIMING); - participantUpdateAckMessage.setCompositionId(acDefinition.getCompositionId()); + participantPrimeAckMessage.setCompositionId(acDefinition.getCompositionId()); var acDefinitionProvider = mock(AcDefinitionProvider.class); when(acDefinitionProvider.findAcDefinition(acDefinition.getCompositionId())) @@ -293,7 +293,7 @@ class SupervisionHandlerTest { mock(AutomationCompositionDeployPublisher.class), mock(AutomationCompositionStateChangePublisher.class)); - handler.handleParticipantMessage(participantUpdateAckMessage); + handler.handleParticipantMessage(participantPrimeAckMessage); verify(acDefinitionProvider).findAcDefinition(any()); verify(acDefinitionProvider).updateAcDefinition(any()); } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java index 010e8ba38..c2d4e0ff7 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java @@ -46,10 +46,10 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCom import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; +import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantPrimeAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegisterAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; -import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantUpdateAck; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.models.acm.utils.AcmUtils; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; @@ -105,12 +105,12 @@ class SupervisionMessagesTest { } @Test - void testReceiveParticipantUpdateAckMessage() { - final var participantUpdateAckMsg = new ParticipantUpdateAck(); + void testReceiveParticipantPrimeAckMessage() { + final var participantPrimeAckMsg = new ParticipantPrimeAck(); var supervisionHandler = mock(SupervisionHandler.class); - var participantUpdateAckListener = new ParticipantUpdateAckListener(supervisionHandler); - participantUpdateAckListener.onTopicEvent(INFRA, TOPIC, null, participantUpdateAckMsg); - verify(supervisionHandler).handleParticipantMessage(participantUpdateAckMsg); + var participantPrimeAckListener = new ParticipantPrimeAckListener(supervisionHandler); + participantPrimeAckListener.onTopicEvent(INFRA, TOPIC, null, participantPrimeAckMsg); + verify(supervisionHandler).handleParticipantMessage(participantPrimeAckMsg); } @Test @@ -138,8 +138,8 @@ class SupervisionMessagesTest { } @Test - void testParticipantUpdatePublisherDecomisioning() { - var publisher = new ParticipantUpdatePublisher(mock(ParticipantProvider.class)); + void testParticipantPrimePublisherDecommissioning() { + var publisher = new ParticipantPrimePublisher(mock(ParticipantProvider.class)); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); publisher.sendDepriming(UUID.randomUUID()); @@ -147,7 +147,7 @@ class SupervisionMessagesTest { } @Test - void testParticipantUpdatePublisherPriming() { + void testParticipantPrimePublisherPriming() { var participantId = UUID.randomUUID(); Map supportedElementMap = new HashMap<>(); supportedElementMap.put( @@ -160,7 +160,7 @@ class SupervisionMessagesTest { participantId); var participantProvider = mock(ParticipantProvider.class); when(participantProvider.getSupportedElementMap()).thenReturn(supportedElementMap); - var publisher = new ParticipantUpdatePublisher(participantProvider); + var publisher = new ParticipantPrimePublisher(participantProvider); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); -- cgit 1.2.3-korg