diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-09-05 09:08:15 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-09-05 09:39:43 +0000 |
commit | abe1caac52206d5fb5d6861bd0f55bb6407b15dc (patch) | |
tree | 6f2e5ffb969090acb2f65aadf056266858dc2247 /runtime-acm | |
parent | 7c5744fecbc2067e800cd3bc90acac0e44318ada (diff) |
Remove restart reference in ACM-runtime
Restart has been replaced in ACM by sync messages, and
there are still some java code that should be removed
around the old restart scenario implementation.
Issue-ID: POLICY-5125
Change-Id: Iffbd228fb352f1d53a2e9de24b061bccbc9dfea9
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
12 files changed, 25 insertions, 341 deletions
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 8a56fbb1e..48b139495 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 @@ -188,10 +188,6 @@ public class CommissioningProvider { throw new PfModelRuntimeException(Status.BAD_REQUEST, "There are instances, Priming/Depriming not allowed"); } var acmDefinition = acDefinitionProvider.getAcDefinition(compositionId); - if (acmDefinition.getRestarting() != null) { - throw new PfModelRuntimeException(Status.BAD_REQUEST, - "There is a restarting process, Priming/Depriming not allowed"); - } var stateOrdered = acTypeStateResolver.resolve(acTypeStateUpdate.getPrimeOrder(), acmDefinition.getState(), acmDefinition.getStateChangeResult()); switch (stateOrdered) { 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 867148d8b..42af70596 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 @@ -144,10 +144,6 @@ public class AutomationCompositionInstantiationProvider { } - if (automationComposition.getRestarting() != null) { - throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Update not allowed"); - } - var deployOrder = DeployOrder.UPDATE; var subOrder = SubOrder.NONE; @@ -336,12 +332,6 @@ public class AutomationCompositionInstantiationProvider { ValidationStatus.INVALID, "Commissioned automation composition definition not primed")); return result; } - if (acDefinitionOpt.get().getRestarting() != null) { - result.addResult( - new ObjectValidationResult("ServiceTemplate.restarting", acDefinitionOpt.get().getRestarting(), - ValidationStatus.INVALID, "There is a restarting process in composition")); - return result; - } var participantIds = acDefinitionOpt.get().getElementStateMap().values().stream() .map(NodeTemplateState::getParticipantId).collect(Collectors.toSet()); @@ -405,9 +395,6 @@ public class AutomationCompositionInstantiationProvider { throw new PfModelRuntimeException(Status.BAD_REQUEST, "Automation composition state is still " + automationComposition.getDeployState()); } - if (automationComposition.getRestarting() != null) { - throw new PfModelRuntimeException(Status.BAD_REQUEST, "There is a restarting process, Delete not allowed"); - } var acDefinition = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionId()); var participantIds = acDefinition.getElementStateMap().values().stream() .map(NodeTemplateState::getParticipantId).collect(Collectors.toSet()); 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 95294285e..f13f5da2c 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 @@ -114,7 +114,7 @@ public class SupervisionHandler { } if (toUpdate) { acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(), - acDefinition.getStateChangeResult(), null); + acDefinition.getStateChangeResult()); if (!participantPrimeAckMessage.getParticipantId().equals(participantPrimeAckMessage.getReplicaId())) { participantSyncPublisher.sendSync(acDefinition, participantPrimeAckMessage.getReplicaId()); } 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 3c93a3571..ea3ef0ff7 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 @@ -30,7 +30,6 @@ import org.apache.commons.collections4.MapUtils; import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher; -import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRestartPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantSyncPublisher; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; @@ -40,7 +39,6 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; -import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRegister; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus; @@ -65,7 +63,6 @@ public class SupervisionParticipantHandler { private final ParticipantDeregisterAckPublisher participantDeregisterAckPublisher; private final AutomationCompositionProvider automationCompositionProvider; private final AcDefinitionProvider acDefinitionProvider; - private final ParticipantRestartPublisher participantRestartPublisher; private final ParticipantSyncPublisher participantSyncPublisher; private final AcRuntimeParameterGroup acRuntimeParameterGroup; @@ -183,61 +180,11 @@ public class SupervisionParticipantHandler { private void handleRestart(UUID participantId, UUID replicaId) { var compositionIds = participantProvider.getCompositionIds(participantId); - var oldParticipant = participantId.equals(replicaId); for (var compositionId : compositionIds) { var acDefinition = acDefinitionProvider.getAcDefinition(compositionId); LOGGER.debug("Scan Composition {} for restart", acDefinition.getCompositionId()); - if (oldParticipant) { - handleRestart(participantId, acDefinition); - } else { - handleSyncRestart(participantId, replicaId, acDefinition); - } - } - } - - private void handleRestart(final UUID participantId, AutomationCompositionDefinition acDefinition) { - if (AcTypeState.COMMISSIONED.equals(acDefinition.getState())) { - LOGGER.debug("Composition {} COMMISSIONED", acDefinition.getCompositionId()); - return; - } - LOGGER.debug("Composition to be send in Restart message {}", acDefinition.getCompositionId()); - for (var elementState : acDefinition.getElementStateMap().values()) { - if (participantId.equals(elementState.getParticipantId())) { - elementState.setRestarting(true); - } - } - // expected final state - if (StateChangeResult.TIMEOUT.equals(acDefinition.getStateChangeResult())) { - acDefinition.setStateChangeResult(StateChangeResult.NO_ERROR); - } - acDefinition.setRestarting(true); - acDefinitionProvider.updateAcDefinition(acDefinition, - acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName()); - - var automationCompositionList = - automationCompositionProvider.getAcInstancesByCompositionId(acDefinition.getCompositionId()); - var automationCompositions = automationCompositionList.stream() - .filter(ac -> isAcToBeRestarted(participantId, ac)).toList(); - participantRestartPublisher.send(participantId, acDefinition, automationCompositions); - } - - private boolean isAcToBeRestarted(UUID participantId, AutomationComposition automationComposition) { - boolean toAdd = false; - for (var element : automationComposition.getElements().values()) { - if (participantId.equals(element.getParticipantId())) { - element.setRestarting(true); - toAdd = true; - } - } - if (toAdd) { - automationComposition.setRestarting(true); - // expected final state - if (StateChangeResult.TIMEOUT.equals(automationComposition.getStateChangeResult())) { - automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR); - } - automationCompositionProvider.updateAutomationComposition(automationComposition); + handleSyncRestart(participantId, replicaId, acDefinition); } - return toAdd; } private void handleSyncRestart(final UUID participantId, UUID replicaId, diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java index d746b331f..c4cebb430 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScanner.java @@ -126,7 +126,7 @@ public class SupervisionScanner { } if (completed) { acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), finalState, - StateChangeResult.NO_ERROR, null); + StateChangeResult.NO_ERROR); participantSyncPublisher.sendSync(acDefinition, null); } else { handleTimeout(acDefinition); @@ -299,7 +299,7 @@ public class SupervisionScanner { LOGGER.debug("Report timeout for the ac definition {}", acDefinition.getCompositionId()); acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT); acDefinitionProvider.updateAcDefinitionState(acDefinition.getCompositionId(), - acDefinition.getState(), acDefinition.getStateChangeResult(), acDefinition.getRestarting()); + acDefinition.getState(), acDefinition.getStateChangeResult()); } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java deleted file mode 100644 index 540cf62be..000000000 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/ParticipantRestartPublisher.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2023-2024 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License 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.List; -import java.util.UUID; -import lombok.AllArgsConstructor; -import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; -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.messages.kafka.participant.ParticipantRestart; -import org.onap.policy.clamp.models.acm.utils.AcmUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -@Component -@AllArgsConstructor -public class ParticipantRestartPublisher extends AbstractParticipantPublisher<ParticipantRestart> { - - private static final Logger LOGGER = LoggerFactory.getLogger(ParticipantRestartPublisher.class); - private final AcRuntimeParameterGroup acRuntimeParameterGroup; - - /** - * Send Restart to Participant. - * - * @param participantId the ParticipantId - * @param acmDefinition the AutomationComposition Definition - * @param automationCompositions the list of automationCompositions - */ - @Timed(value = "publisher.participant_restart", description = "Participant Restart published") - public void send(UUID participantId, AutomationCompositionDefinition acmDefinition, - List<AutomationComposition> automationCompositions) { - - var message = new ParticipantRestart(); - message.setParticipantId(participantId); - message.setCompositionId(acmDefinition.getCompositionId()); - message.setMessageId(UUID.randomUUID()); - message.setTimestamp(Instant.now()); - message.setState(acmDefinition.getState()); - message.setParticipantDefinitionUpdates( - AcmUtils.prepareParticipantRestarting(participantId, acmDefinition, - acRuntimeParameterGroup.getAcmParameters().getToscaElementName())); - var toscaServiceTemplateFragment = AcmUtils.getToscaServiceTemplateFragment(acmDefinition.getServiceTemplate()); - - for (var automationComposition : automationCompositions) { - var restartAc = AcmUtils - .createAcRestart(automationComposition, participantId, toscaServiceTemplateFragment); - message.getAutomationcompositionList().add(restartAc); - } - - LOGGER.debug("Participant Restart sent {}", message.getMessageId()); - 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 e001d91bc..8c76baef7 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 @@ -233,22 +233,4 @@ class CommissioningProviderTest { assertThatThrownBy(() -> provider.deleteAutomationCompositionDefinition(compositionId)) .hasMessageMatching("ACM not in COMMISSIONED state, Delete of ACM Definition not allowed"); } - - @Test - void testPrimingBadRequest() { - var acDefinitionProvider = mock(AcDefinitionProvider.class); - var toscaServiceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); - var acmDefinition = CommonTestData.createAcDefinition(toscaServiceTemplate, AcTypeState.PRIMED); - acmDefinition.setRestarting(true); - var compositionId = acmDefinition.getCompositionId(); - when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acmDefinition); - - var provider = new CommissioningProvider(acDefinitionProvider, mock(AutomationCompositionProvider.class), - mock(ParticipantProvider.class), new AcTypeStateResolver(), mock(ParticipantPrimePublisher.class), - mock(AcRuntimeParameterGroup.class)); - - var acTypeStateUpdate = new AcTypeStateUpdate(); - assertThatThrownBy(() -> provider.compositionDefinitionPriming(compositionId, acTypeStateUpdate)) - .hasMessageMatching("There is a restarting process, Priming/Depriming not allowed"); - } } 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 90633e706..21ad2f616 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 @@ -231,75 +231,6 @@ class AutomationCompositionInstantiationProviderTest { } @Test - void testUpdateRestartedBadRequest() { - var automationCompositionUpdate = - InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); - automationCompositionUpdate.setDeployState(DeployState.DEPLOYED); - automationCompositionUpdate.setLockState(LockState.LOCKED); - automationCompositionUpdate.setRestarting(true); - var acProvider = mock(AutomationCompositionProvider.class); - when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())) - .thenReturn(automationCompositionUpdate); - - var instantiationProvider = - new AutomationCompositionInstantiationProvider(acProvider, mock(AcDefinitionProvider.class), null, - mock(SupervisionAcHandler.class), mock(ParticipantProvider.class), - mock(AcRuntimeParameterGroup.class)); - - var compositionId = automationCompositionUpdate.getCompositionId(); - assertThatThrownBy( - () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) - .hasMessageMatching("There is a restarting process, Update not allowed"); - - automationCompositionUpdate.setCompositionTargetId(UUID.randomUUID()); - assertThatThrownBy( - () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) - .hasMessageMatching("There is a restarting process, Update not allowed"); - - automationCompositionUpdate.setDeployState(DeployState.UNDEPLOYED); - automationCompositionUpdate.setLockState(LockState.NONE); - - var instanceId = automationCompositionUpdate.getInstanceId(); - assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(compositionId, instanceId)) - .hasMessageMatching("There is a restarting process, Delete not allowed"); - } - - @Test - void testUpdateCompositionRestartedBadRequest() { - var acDefinitionProvider = mock(AcDefinitionProvider.class); - var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); - acDefinition.setRestarting(true); - var compositionId = acDefinition.getCompositionId(); - when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition)); - - var automationCompositionUpdate = - InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); - automationCompositionUpdate.setCompositionId(compositionId); - automationCompositionUpdate.setDeployState(DeployState.DEPLOYED); - automationCompositionUpdate.setLockState(LockState.LOCKED); - var acProvider = mock(AutomationCompositionProvider.class); - when(acProvider.getAutomationComposition(automationCompositionUpdate.getInstanceId())) - .thenReturn(automationCompositionUpdate); - when(acProvider.updateAutomationComposition(automationCompositionUpdate)) - .thenReturn(automationCompositionUpdate); - - var supervisionAcHandler = mock(SupervisionAcHandler.class); - var participantProvider = mock(ParticipantProvider.class); - var instantiationProvider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, - new AcInstanceStateResolver(), supervisionAcHandler, participantProvider, - mock(AcRuntimeParameterGroup.class)); - var message = - """ - "AutomationComposition" INVALID, item has status INVALID - item "ServiceTemplate.restarting" value "true" INVALID, There is a restarting process in composition - """; - - assertThatThrownBy( - () -> instantiationProvider.updateAutomationComposition(compositionId, automationCompositionUpdate)) - .hasMessageMatching(message); - } - - @Test void testMigrationAddRemoveElements() { var acDefinitionProvider = mock(AcDefinitionProvider.class); var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.PRIMED); 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 e689e6467..09a79d890 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 @@ -130,7 +130,7 @@ class SupervisionHandlerTest { verify(acDefinitionProvider, times(acDefinition.getElementStateMap().size())) .updateAcDefinitionElement(any(), any()); verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), AcTypeState.PRIMED, - StateChangeResult.NO_ERROR, null); + StateChangeResult.NO_ERROR); } @Test @@ -156,6 +156,6 @@ class SupervisionHandlerTest { verify(acDefinitionProvider).findAcDefinition(any()); verify(acDefinitionProvider).updateAcDefinitionElement(any(), any()); verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), AcTypeState.PRIMING, - StateChangeResult.FAILED, null); + StateChangeResult.FAILED); } } 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 932529d79..aab1a1ceb 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 @@ -37,7 +37,6 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher; -import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRestartPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantSyncPublisher; import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; @@ -77,8 +76,8 @@ class SupervisionParticipantHandlerTest { var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher, mock(AutomationCompositionProvider.class), - mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class), - mock(ParticipantSyncPublisher.class), mock(AcRuntimeParameterGroup.class)); + mock(AcDefinitionProvider.class), mock(ParticipantSyncPublisher.class), + mock(AcRuntimeParameterGroup.class)); handler.handleParticipantMessage(participantDeregisterMessage); @@ -98,8 +97,8 @@ class SupervisionParticipantHandlerTest { var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class); var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher, mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionProvider.class), - mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class), - mock(ParticipantSyncPublisher.class), mock(AcRuntimeParameterGroup.class)); + mock(AcDefinitionProvider.class), mock(ParticipantSyncPublisher.class), + mock(AcRuntimeParameterGroup.class)); handler.handleParticipantMessage(participantRegisterMessage); verify(participantProvider).saveParticipant(any()); @@ -108,64 +107,6 @@ class SupervisionParticipantHandlerTest { } @Test - void testHandleParticipantRestart() { - var participantRegisterMessage = new ParticipantRegister(); - participantRegisterMessage.setMessageId(UUID.randomUUID()); - var participantId = CommonTestData.getParticipantId(); - participantRegisterMessage.setParticipantId(participantId); - participantRegisterMessage.setReplicaId(participantId); - var supportedElementType = CommonTestData.createParticipantSupportedElementType(); - participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType)); - - var participant = new Participant(); - var replica = new ParticipantReplica(); - replica.setReplicaId(participantId); - participant.setParticipantId(participantId); - participant.getReplicas().put(replica.getReplicaId(), replica); - var participantProvider = mock(ParticipantProvider.class); - when(participantProvider.findParticipant(participantId)).thenReturn(Optional.of(participant)); - when(participantProvider.findParticipantReplica(participantId)).thenReturn(Optional.of(replica)); - var compositionId = UUID.randomUUID(); - var composition2Id = UUID.randomUUID(); - when(participantProvider.getCompositionIds(participantId)).thenReturn(Set.of(compositionId, composition2Id)); - - var acDefinitionProvider = mock(AcDefinitionProvider.class); - var acDefinition = new AutomationCompositionDefinition(); - acDefinition.setState(AcTypeState.COMMISSIONED); - acDefinition.setCompositionId(composition2Id); - when(acDefinitionProvider.getAcDefinition(composition2Id)).thenReturn(acDefinition); - - acDefinition = new AutomationCompositionDefinition(); - acDefinition.setCompositionId(compositionId); - acDefinition.setState(AcTypeState.PRIMED); - var nodeTemplateState = new NodeTemplateState(); - nodeTemplateState.setParticipantId(participantId); - acDefinition.setElementStateMap(Map.of("code", nodeTemplateState)); - when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition); - - var automationComposition = - InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud"); - automationComposition.getElements().values().iterator().next().setParticipantId(participantId); - var automationCompositionProvider = mock(AutomationCompositionProvider.class); - when(automationCompositionProvider.getAcInstancesByCompositionId(compositionId)) - .thenReturn(List.of(automationComposition)); - - var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class); - var participantRestartPublisher = mock(ParticipantRestartPublisher.class); - var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher, - mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, acDefinitionProvider, - participantRestartPublisher, mock(ParticipantSyncPublisher.class), - CommonTestData.getTestParamaterGroup()); - handler.handleParticipantMessage(participantRegisterMessage); - - verify(participantRegisterAckPublisher) - .send(participantRegisterMessage.getMessageId(), participantId, participantId); - verify(acDefinitionProvider).updateAcDefinition(any(AutomationCompositionDefinition.class), - eq(CommonTestData.TOSCA_COMP_NAME)); - verify(participantRestartPublisher).send(any(), any(AutomationCompositionDefinition.class), any()); - } - - @Test void testHandleParticipantSyncRestart() { var participantRegisterMessage = new ParticipantRegister(); participantRegisterMessage.setMessageId(UUID.randomUUID()); @@ -213,8 +154,7 @@ class SupervisionParticipantHandlerTest { var participantSyncPublisher = mock(ParticipantSyncPublisher.class); var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher, mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, acDefinitionProvider, - mock(ParticipantRestartPublisher.class), participantSyncPublisher, - CommonTestData.getTestParamaterGroup()); + participantSyncPublisher, CommonTestData.getTestParamaterGroup()); handler.handleParticipantMessage(participantRegisterMessage); verify(participantRegisterAckPublisher) @@ -235,8 +175,8 @@ class SupervisionParticipantHandlerTest { var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, - mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class), - mock(ParticipantSyncPublisher.class), mock(AcRuntimeParameterGroup.class)); + mock(AcDefinitionProvider.class), mock(ParticipantSyncPublisher.class), + mock(AcRuntimeParameterGroup.class)); var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); when(participantProvider.findParticipant(CommonTestData.getParticipantId())) .thenReturn(Optional.of(participant)); @@ -271,8 +211,8 @@ class SupervisionParticipantHandlerTest { var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), mock(AutomationCompositionProvider.class), - acDefinitionProvider, mock(ParticipantRestartPublisher.class), - mock(ParticipantSyncPublisher.class), CommonTestData.getTestParamaterGroup()); + acDefinitionProvider, mock(ParticipantSyncPublisher.class), + CommonTestData.getTestParamaterGroup()); handler.handleParticipantMessage(participantStatusMessage); verify(acDefinitionProvider).updateAcDefinition(acDefinition, CommonTestData.TOSCA_COMP_NAME); @@ -288,8 +228,8 @@ class SupervisionParticipantHandlerTest { var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, - mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class), - mock(ParticipantSyncPublisher.class), mock(AcRuntimeParameterGroup.class)); + mock(AcDefinitionProvider.class), mock(ParticipantSyncPublisher.class), + mock(AcRuntimeParameterGroup.class)); handler.handleParticipantMessage(participantStatusMessage); verify(participantProvider).saveParticipant(any()); @@ -306,8 +246,8 @@ class SupervisionParticipantHandlerTest { var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider, - mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class), - mock(ParticipantSyncPublisher.class), mock(AcRuntimeParameterGroup.class)); + mock(AcDefinitionProvider.class), mock(ParticipantSyncPublisher.class), + mock(AcRuntimeParameterGroup.class)); var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId()); when(participantProvider.findParticipant(CommonTestData.getParticipantId())) .thenReturn(Optional.of(participant)); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java index 1e3c89091..5cefd5f09 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java @@ -108,7 +108,7 @@ class SupervisionScannerTest { mock(AutomationCompositionStateChangePublisher.class), mock(AutomationCompositionDeployPublisher.class), mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup); supervisionScanner.run(); - verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any()); + verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any()); } @Test @@ -121,7 +121,7 @@ class SupervisionScannerTest { mock(ParticipantSyncPublisher.class), null, acRuntimeParameterGroup); supervisionScanner.run(); // Ac Definition in Priming state - verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any()); + verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any()); acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); supervisionScanner = new SupervisionScanner(mock(AutomationCompositionProvider.class), acDefinitionProvider, @@ -130,13 +130,13 @@ class SupervisionScannerTest { supervisionScanner.run(); // set Timeout verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(), - StateChangeResult.TIMEOUT, null); + StateChangeResult.TIMEOUT); clearInvocations(acDefinitionProvider); acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT); supervisionScanner.run(); // already in Timeout - verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any(), any()); + verify(acDefinitionProvider, times(0)).updateAcDefinitionState(any(), any(), any()); clearInvocations(acDefinitionProvider); // retry by the user @@ -144,7 +144,7 @@ class SupervisionScannerTest { supervisionScanner.run(); // set Timeout verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), acDefinition.getState(), - StateChangeResult.TIMEOUT, null); + StateChangeResult.TIMEOUT); clearInvocations(acDefinitionProvider); for (var element : acDefinition.getElementStateMap().values()) { @@ -153,7 +153,7 @@ class SupervisionScannerTest { supervisionScanner.run(); // completed verify(acDefinitionProvider).updateAcDefinitionState(acDefinition.getCompositionId(), AcTypeState.PRIMED, - StateChangeResult.NO_ERROR, null); + StateChangeResult.NO_ERROR); } @Test 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 7fd0aa2e2..a1ef9b4e2 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 @@ -258,30 +258,6 @@ class SupervisionMessagesTest { } @Test - void testParticipantRestartPublisher() { - var publisher = new ParticipantRestartPublisher(CommonTestData.getTestParamaterGroup()); - var topicSink = mock(TopicSink.class); - publisher.active(topicSink); - - var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML); - var acmDefinition = new AutomationCompositionDefinition(); - acmDefinition.setCompositionId(UUID.randomUUID()); - acmDefinition.setServiceTemplate(serviceTemplate); - var acElements = AcmUtils - .extractAcElementsFromServiceTemplate(serviceTemplate, ""); - acmDefinition.setElementStateMap(AcmUtils.createElementStateMap(acElements, AcTypeState.PRIMED)); - - var automationComposition = - InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_UPDATE_JSON, "Crud"); - - var participantId = automationComposition.getElements().values().iterator().next().getParticipantId(); - acmDefinition.getElementStateMap().values().iterator().next().setParticipantId(participantId); - - publisher.send(participantId, acmDefinition, List.of(automationComposition)); - verify(topicSink).send(anyString()); - } - - @Test void testParticipantSyncPublisherAutomationComposition() { var publisher = new ParticipantSyncPublisher(CommonTestData.getTestParamaterGroup()); var topicSink = mock(TopicSink.class); |