diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-06-20 13:51:35 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-06-20 15:38:56 +0000 |
commit | 8b38d4bbc171247a676b88c57a16ab7a762e07f7 (patch) | |
tree | 31cbfd50092fe7540792211c5192880d1a9e2a3d /participant/participant-intermediary | |
parent | 0460b264c3b02345cdbb46f05125289897d56304 (diff) |
Remove local HashMap in policy participant
Issue-ID: POLICY-5055
Change-Id: Id2495008a28ea3e50a5c17695af529813b1c0c35
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary')
4 files changed, 39 insertions, 9 deletions
diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcLockHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcLockHandler.java index ddf465a2d..89daa5fd2 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcLockHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcLockHandler.java @@ -70,6 +70,9 @@ public class AcLockHandler { private void handleLockState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { + automationComposition.setLockState(LockState.LOCKING); + var serviceTemplateFragment = cacheProvider + .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId()); for (var element : automationComposition.getElements().values()) { var compositionInProperties = cacheProvider .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); @@ -79,7 +82,7 @@ public class AcLockHandler { var compositionElement = cacheProvider.createCompositionElementDto( automationComposition.getCompositionId(), element, compositionInProperties); var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), - null, element.getProperties(), element.getOutProperties()); + serviceTemplateFragment, element.getProperties(), element.getOutProperties()); listener.lock(messageId, compositionElement, instanceElement); } } @@ -87,6 +90,9 @@ public class AcLockHandler { private void handleUnlockState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { + automationComposition.setLockState(LockState.UNLOCKING); + var serviceTemplateFragment = cacheProvider + .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId()); for (var element : automationComposition.getElements().values()) { var compositionInProperties = cacheProvider .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); @@ -96,7 +102,7 @@ public class AcLockHandler { var compositionElement = cacheProvider.createCompositionElementDto( automationComposition.getCompositionId(), element, compositionInProperties); var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), - null, element.getProperties(), element.getOutProperties()); + serviceTemplateFragment, element.getProperties(), element.getOutProperties()); listener.unlock(messageId, compositionElement, instanceElement); } } 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 a3eafd844..b60d6372c 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 @@ -59,7 +59,6 @@ public class AutomationCompositionHandler { private final ParticipantMessagePublisher publisher; private final ThreadHandler listener; - /** * Handle a automation composition state change message. * @@ -116,9 +115,10 @@ public class AutomationCompositionHandler { for (var participantDeploy : updateMsg.getParticipantUpdatesList()) { if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) { - - var acCopy = new AutomationComposition(cacheProvider.getAutomationComposition( - updateMsg.getAutomationCompositionId())); + var automationComposition = cacheProvider.getAutomationComposition( + updateMsg.getAutomationCompositionId()); + automationComposition.setDeployState(DeployState.UPDATING); + var acCopy = new AutomationComposition(automationComposition); updateExistingElementsOnThisParticipant(updateMsg.getAutomationCompositionId(), participantDeploy, DeployState.UPDATING); @@ -154,6 +154,7 @@ public class AutomationCompositionHandler { private void callParticipanDeploy(UUID messageId, List<AcElementDeploy> acElementDeployList, Integer startPhaseMsg, UUID instanceId) { var automationComposition = cacheProvider.getAutomationComposition(instanceId); + automationComposition.setDeployState(DeployState.DEPLOYING); for (var elementDeploy : acElementDeployList) { var element = automationComposition.getElements().get(elementDeploy.getId()); var compositionInProperties = cacheProvider @@ -188,9 +189,11 @@ public class AutomationCompositionHandler { private Map<UUID, InstanceElementDto> getInstanceElementDtoMap(AutomationComposition automationComposition) { Map<UUID, InstanceElementDto> map = new HashMap<>(); + var serviceTemplateFragment = cacheProvider + .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId()); for (var element : automationComposition.getElements().values()) { var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), - null, element.getProperties(), element.getOutProperties()); + serviceTemplateFragment, element.getProperties(), element.getOutProperties()); map.put(element.getId(), instanceElement); } return map; @@ -229,6 +232,9 @@ public class AutomationCompositionHandler { private void handleUndeployState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { automationComposition.setCompositionTargetId(null); + automationComposition.setDeployState(DeployState.UNDEPLOYING); + var serviceTemplateFragment = cacheProvider + .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId()); for (var element : automationComposition.getElements().values()) { var compositionInProperties = cacheProvider .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); @@ -238,7 +244,7 @@ public class AutomationCompositionHandler { var compositionElement = cacheProvider.createCompositionElementDto( automationComposition.getCompositionId(), element, compositionInProperties); var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), - null, element.getProperties(), element.getOutProperties()); + serviceTemplateFragment, element.getProperties(), element.getOutProperties()); listener.undeploy(messageId, compositionElement, instanceElement); } } @@ -246,6 +252,9 @@ public class AutomationCompositionHandler { private void handleDeleteState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { + automationComposition.setDeployState(DeployState.DELETING); + var serviceTemplateFragment = cacheProvider + .getServiceTemplateFragmentMap().get(automationComposition.getCompositionId()); for (var element : automationComposition.getElements().values()) { var compositionInProperties = cacheProvider .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); @@ -255,7 +264,7 @@ public class AutomationCompositionHandler { var compositionElement = cacheProvider.createCompositionElementDto( automationComposition.getCompositionId(), element, compositionInProperties); var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), - null, element.getProperties(), element.getOutProperties()); + serviceTemplateFragment, element.getProperties(), element.getOutProperties()); listener.delete(messageId, compositionElement, instanceElement); } } @@ -279,6 +288,7 @@ public class AutomationCompositionHandler { } var acCopy = new AutomationComposition(automationComposition); automationComposition.setCompositionTargetId(migrationMsg.getCompositionTargetId()); + automationComposition.setDeployState(DeployState.MIGRATING); for (var participantDeploy : migrationMsg.getParticipantUpdatesList()) { if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) { diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java index 7a00e0892..29b77fcb6 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/CacheProvider.java @@ -41,6 +41,7 @@ import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc; import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType; import org.onap.policy.models.base.PfUtils; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.stereotype.Component; @Component @@ -68,6 +69,9 @@ public class CacheProvider { @Getter private final Map<UUID, UUID> msgIdentification = new ConcurrentHashMap<>(); + @Getter + private final Map<UUID, ToscaServiceTemplate> serviceTemplateFragmentMap = new ConcurrentHashMap<>(); + /** * Constructor. * @@ -118,6 +122,7 @@ public class CacheProvider { public void removeElementDefinition(@NonNull UUID compositionId) { acElementsDefinitions.remove(compositionId); + serviceTemplateFragmentMap.remove(compositionId); } /** @@ -171,6 +176,9 @@ public class CacheProvider { acElement.setOutProperties(acElementLast.getOutProperties()); acElement.setOperationalState(acElementLast.getOperationalState()); acElement.setUseState(acElementLast.getUseState()); + if (element.getToscaServiceTemplateFragment() != null) { + serviceTemplateFragmentMap.put(compositionId, element.getToscaServiceTemplateFragment()); + } } acElementMap.put(element.getId(), acElement); } @@ -205,6 +213,9 @@ public class CacheProvider { acElement.setProperties(element.getProperties()); acElement.setOutProperties(element.getOutProperties()); acElementMap.put(element.getId(), acElement); + if (element.getToscaServiceTemplateFragment() != null) { + serviceTemplateFragmentMap.put(compositionId, element.getToscaServiceTemplateFragment()); + } } var automationComposition = new AutomationComposition(); 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 b6b95ba0f..a116f1299 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 @@ -50,6 +50,7 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; 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; /** * Class to hold/create all parameters for test cases. @@ -260,6 +261,7 @@ public class CommonTestData { acElementRestart.setUseState("UseState"); acElementRestart.setProperties(Map.of("key", "value")); acElementRestart.setOutProperties(Map.of("keyOut", "valueOut")); + acElementRestart.setToscaServiceTemplateFragment(new ToscaServiceTemplate()); acElementRestart.setId(UUID.randomUUID()); participantRestartAc.getAcElementList().add(acElementRestart); return participantRestartAc; @@ -281,6 +283,7 @@ public class CommonTestData { acElement.setId(element.getId()); acElement.setDefinition(element.getDefinition()); acElement.setProperties(element.getProperties()); + acElement.setToscaServiceTemplateFragment(new ToscaServiceTemplate()); participantDeploy.getAcElementList().add(acElement); } return participantDeploy; |