diff options
Diffstat (limited to 'participant/participant-intermediary/src')
5 files changed, 186 insertions, 22 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java index da6bccb41..c99241f27 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/AutomationCompositionElementListener.java @@ -47,4 +47,26 @@ public interface AutomationCompositionElementListener { */ public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) throws PfModelException; + + public default void lock(UUID automationCompositionId, UUID automationCompositionElementId) + throws PfModelException { + // default Lock Operation + } + + public default void unlock(UUID automationCompositionId, UUID automationCompositionElementId) + throws PfModelException { + // default Unlock Operation + } + + public default String getUseState(UUID automationCompositionId, UUID automationCompositionElementId) + throws PfModelException { + // default Use State + return ""; + } + + public default String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId) + throws PfModelException { + // default Operational State + return ""; + } } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java index d76700171..1eaf63dcc 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandler.java @@ -111,6 +111,8 @@ public class AutomationCompositionHandler { if (element != null) { element.setDeployState(deployState); element.setLockState(lockState); + element.setUseState(getUseState(automationCompositionId, id)); + element.setOperationalState(getOperationalState(automationCompositionId, id)); } var checkOpt = automationComposition.getElements().values().stream() .filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny(); @@ -133,8 +135,11 @@ public class AutomationCompositionHandler { automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId); acElement.setDeployState(deployState); acElement.setLockState(lockState); + acElement.setUseState(getUseState(automationCompositionId, id)); + acElement.setOperationalState(getOperationalState(automationCompositionId, id)); automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(), - new AcElementDeployAck(deployState, lockState, true, + new AcElementDeployAck(deployState, lockState, + acElement.getOperationalState(), acElement.getUseState(), true, "Automation composition element {} state changed to {}\", id, newState)")); LOGGER.debug("Automation composition element {} state changed to {}", id, deployState); automationCompositionStateChangeAck @@ -408,8 +413,15 @@ public class AutomationCompositionHandler { if (acElementNodeTemplate != null) { int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties()); if (startPhaseMsg.equals(startPhase)) { - updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, - LockState.LOCKED); + for (var acElementListener : listeners) { + try { + acElementListener.lock(instanceId, acElement.getId()); + updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, + LockState.LOCKED); + } catch (PfModelException e) { + LOGGER.error("Automation composition element lock failed {}", instanceId); + } + } } } } @@ -420,8 +432,15 @@ public class AutomationCompositionHandler { if (acElementNodeTemplate != null) { int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties()); if (startPhaseMsg.equals(startPhase)) { - updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, - LockState.UNLOCKED); + for (var acElementListener : listeners) { + try { + acElementListener.unlock(instanceId, acElement.getId()); + updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED, + LockState.UNLOCKED); + } catch (PfModelException e) { + LOGGER.error("Automation composition element unlock failed {}", instanceId); + } + } } } } @@ -436,10 +455,46 @@ public class AutomationCompositionHandler { try { acElementListener.undeploy(instanceId, acElement.getId()); } catch (PfModelException e) { - LOGGER.debug("Automation composition element update failed {}", instanceId); + LOGGER.error("Automation composition element update failed {}", instanceId); } } } } } + + /** + * Get UseState. + * + * @param instanceId the instance Id + * @param acElementId the Automation Composition Element Id + * @return the UseState of the Automation Composition Element + */ + public String getUseState(UUID instanceId, UUID acElementId) { + for (var acElementListener : listeners) { + try { + return acElementListener.getUseState(instanceId, acElementId); + } catch (PfModelException e) { + LOGGER.error("Automation composition element get Use State failed {}", acElementId); + } + } + return null; + } + + /** + * Get OperationalState. + * + * @param instanceId the instance Id + * @param acElementId the Automation Composition Element Id + * @return the OperationalState of the Automation Composition Element + */ + public String getOperationalState(UUID instanceId, UUID acElementId) { + for (var acElementListener : listeners) { + try { + return acElementListener.getOperationalState(instanceId, acElementId); + } catch (PfModelException e) { + LOGGER.error("Automation composition element get Use State failed {}", acElementId); + } + } + return null; + } } 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 5565e0bd0..9e2484c7d 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 @@ -33,6 +33,7 @@ import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessag import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo; import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; @@ -290,6 +291,16 @@ public class ParticipantHandler { acInfo.setAutomationCompositionId(entry.getKey()); acInfo.setDeployState(entry.getValue().getDeployState()); acInfo.setLockState(entry.getValue().getLockState()); + for (var element : entry.getValue().getElements().values()) { + var elementInfo = new AutomationCompositionElementInfo(); + elementInfo.setAutomationCompositionElementId(element.getId()); + elementInfo.setDeployState(element.getDeployState()); + elementInfo.setLockState(element.getLockState()); + elementInfo.setOperationalState( + automationCompositionHandler.getOperationalState(entry.getKey(), element.getId())); + elementInfo.setUseState(automationCompositionHandler.getUseState(entry.getKey(), element.getId())); + acInfo.getElements().add(elementInfo); + } automationCompositionInfoList.add(acInfo); } return automationCompositionInfoList; diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java index 35da039a5..25b1facf5 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AutomationCompositionHandlerTest.java @@ -24,7 +24,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyMap; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import java.util.List; import java.util.UUID; @@ -41,6 +46,7 @@ import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCom import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; +import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -49,6 +55,8 @@ class AutomationCompositionHandlerTest { private final CommonTestData commonTestData = new CommonTestData(); + private static final String STATE_VALUE = "STATE_VALUE"; + @Test void automationCompositionHandlerTest() { var ach = commonTestData.getMockAutomationCompositionHandler(); @@ -116,10 +124,11 @@ class AutomationCompositionHandlerTest { } @Test - void handleAutomationCompositionDeployTest() { + void handleAutomationCompositionDeployTest() throws PfModelException { var acd = new AutomationCompositionElementDefinition(); var definition = CommonTestData.getDefinition(); acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); var updateMsg = new AutomationCompositionDeploy(); updateMsg.setAutomationCompositionId(UUID.randomUUID()); var uuid = UUID.randomUUID(); @@ -130,19 +139,25 @@ class AutomationCompositionHandlerTest { updateMsg.setStartPhase(0); var acElementDefinitions = List.of(acd); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); updateMsg.setFirstStartPhase(false); updateMsg.setStartPhase(1); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); ach.getAutomationCompositionMap().clear(); updateMsg.setFirstStartPhase(true); updateMsg.setStartPhase(0); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); updateMsg.setAutomationCompositionId(UUID.randomUUID()); updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantDeploy.class))); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions)); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(0)).deploy(any(), any(), anyMap()); updateMsg.setStartPhase(1); var participantDeploy = new ParticipantDeploy(); @@ -152,15 +167,13 @@ class AutomationCompositionHandlerTest { participantDeploy.setAcElementList(List.of(element)); updateMsg.setParticipantUpdatesList(List.of(participantDeploy)); - var acd2 = new AutomationCompositionElementDefinition(); - acd2.setAcElementDefinitionId(definition); - acd2.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); - assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, List.of(acd2))); - + updateMsg.setStartPhase(0); + ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions); + verify(listener, times(1)).deploy(any(), any(), anyMap()); } @Test - void acUndeployTest() { + void acUndeployTest() throws PfModelException { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); @@ -171,14 +184,46 @@ class AutomationCompositionHandlerTest { var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); stateChangeUndeploy .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); - ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); + + var acd = new AutomationCompositionElementDefinition(); + acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); + ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of(acd)); + verify(listener, times(1)).undeploy(any(), any()); + stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID()); stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId()); assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of())); } @Test - void automationCompositionStateUnlock() { + void automationCompositionStateLock() throws PfModelException { + var uuid = UUID.randomUUID(); + var partecipantId = CommonTestData.getParticipantId(); + var definition = CommonTestData.getDefinition(); + + var stateChangeLock = + commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.LOCK); + + var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); + stateChangeLock + .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); + var acd = new AutomationCompositionElementDefinition(); + acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); + ach.handleAutomationCompositionStateChange(stateChangeLock, List.of(acd)); + stateChangeLock.setAutomationCompositionId(UUID.randomUUID()); + stateChangeLock.setParticipantId(CommonTestData.getRndParticipantId()); + ach.handleAutomationCompositionStateChange(stateChangeLock, List.of()); + verify(listener, times(1)).lock(any(), any()); + } + + @Test + void automationCompositionStateUnlock() throws PfModelException { var uuid = UUID.randomUUID(); var partecipantId = CommonTestData.getParticipantId(); var definition = CommonTestData.getDefinition(); @@ -187,11 +232,41 @@ class AutomationCompositionHandlerTest { commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK); var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); + var listener = mock(AutomationCompositionElementListener.class); + ach.registerAutomationCompositionElementListener(listener); stateChangeUnlock .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey()); - ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()); + var acd = new AutomationCompositionElementDefinition(); + acd.setAcElementDefinitionId(definition); + acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class)); + ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of(acd)); stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID()); stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId()); - assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of())); + ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()); + verify(listener, times(1)).unlock(any(), any()); + } + + @Test + void testGetUseState() throws PfModelException { + var uuid = UUID.randomUUID(); + var partecipantId = CommonTestData.getParticipantId(); + var definition = CommonTestData.getDefinition(); + var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); + var listener = mock(AutomationCompositionElementListener.class); + when(listener.getUseState(uuid, uuid)).thenReturn(STATE_VALUE); + ach.registerAutomationCompositionElementListener(listener); + assertEquals(STATE_VALUE, ach.getUseState(uuid, uuid)); + } + + @Test + void testGetOperationalState() throws PfModelException { + var uuid = UUID.randomUUID(); + var partecipantId = CommonTestData.getParticipantId(); + var definition = CommonTestData.getDefinition(); + var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId); + var listener = mock(AutomationCompositionElementListener.class); + when(listener.getOperationalState(uuid, uuid)).thenReturn(STATE_VALUE); + ach.registerAutomationCompositionElementListener(listener); + assertEquals(STATE_VALUE, ach.getOperationalState(uuid, uuid)); } } diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java index 4dcfd1428..140fd947a 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/main/parameters/CommonTestData.java @@ -163,7 +163,7 @@ public class CommonTestData { } public static ToscaConceptIdentifier getDefinition() { - return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1"); + return new ToscaConceptIdentifier("org.onap.domain.pmsh.PMSH_DCAEMicroservice", "1.2.3"); } /** @@ -308,6 +308,7 @@ public class CommonTestData { public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid, DeployOrder deployOrder, LockOrder lockOrder) { var stateChange = new AutomationCompositionStateChange(); + stateChange.setStartPhase(0); stateChange.setAutomationCompositionId(UUID.randomUUID()); stateChange.setParticipantId(participantId); stateChange.setMessageId(uuid); |