diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-02-14 16:30:56 +0000 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-02-15 15:29:53 +0000 |
commit | e0a13196ebb34c84931df27ba00cd1778adbceb9 (patch) | |
tree | 64f1af69d7802ee41a08278ec1e84b21241c1fb5 /participant/participant-intermediary/src/main/java/org | |
parent | 665815fc5c91c3437a0b0459448994789464a391 (diff) |
Add old properties and new properties support
Add old/new properties support in migrate and update,
and add Java code backward compatibility.
Issue-ID: POLICY-4930
Change-Id: I640bc2a858969168b13fe6cdbb557ebf920bafd5
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-intermediary/src/main/java/org')
10 files changed, 873 insertions, 220 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 6e4fca55f..505f515d7 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation. + * Copyright (C) 2021-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. @@ -20,12 +20,7 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.models.base.PfModelException; @@ -35,45 +30,79 @@ import org.onap.policy.models.base.PfModelException; */ public interface AutomationCompositionElementListener { /** - * Handle a automation composition element state change. + * Handle a deploy on a automation composition element. * - * @param automationCompositionElementId the ID of the automation composition element - * @throws PfModelException in case of a model exception + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException from Policy framework */ - void undeploy(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; /** - * Handle an update on a automation composition element. + * Handle an udeploy on a automation composition element. * - * @param automationCompositionId the automationComposition Id - * @param element the information on the automation composition element - * @param properties properties Map - * @throws PfModelException from Policy framework + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception */ - void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException; + void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void lock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + /** + * Handle a lock on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception + */ + void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void unlock(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + /** + * Handle an unlock on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception + */ + void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void delete(UUID automationCompositionId, UUID automationCompositionElementId) throws PfModelException; + /** + * Handle a delete on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @throws PfModelException in case of a model exception + */ + void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) throws PfModelException; - void update(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties) - throws PfModelException; + /** + * Handle an update on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementUpdated the information of the Automation Composition Instance Element updated + * @throws PfModelException from Policy framework + */ + void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException; - void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) - throws PfModelException; + void prime(CompositionDto composition) throws PfModelException; - void deprime(UUID compositionId) throws PfModelException; + void deprime(CompositionDto composition) throws PfModelException; - void handleRestartComposition(UUID compositionId, - List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) - throws PfModelException; + void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException; - void handleRestartInstance(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties, + void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, DeployState deployState, LockState lockState) throws PfModelException; - void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, Map<String, Object> properties) - throws PfModelException; + /** + * Handle an update on a automation composition element. + * + * @param compositionElement the information of the Automation Composition Definition Element + * @param compositionElementTarget the information of the Automation Composition Definition Element Target + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementMigrate the information of the Automation Composition Instance Element updated + * @throws PfModelException from Policy framework + */ + void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException; } diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java new file mode 100644 index 000000000..88f080bc7 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.participant.intermediary.api; + +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public record CompositionDto(UUID compositionId, + Map<ToscaConceptIdentifier, Map<String, Object>> inPropertiesMap, + Map<ToscaConceptIdentifier, Map<String, Object>> outPropertiesMap) { +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionElementDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionElementDto.java new file mode 100644 index 000000000..d203f90cb --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionElementDto.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.participant.intermediary.api; + +import java.util.Map; +import java.util.UUID; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; + +public record CompositionElementDto(UUID compositionId, ToscaConceptIdentifier elementDefinitionId, + Map<String, Object> inProperties, Map<String, Object> outProperties) { +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java new file mode 100644 index 000000000..197d7e46d --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.participant.intermediary.api; + +import java.util.Map; +import java.util.UUID; +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.tosca.authorative.concepts.ToscaServiceTemplate; + +public record InstanceElementDto(UUID instanceId, UUID elementId, ToscaServiceTemplate toscaServiceTemplateFragment, + Map<String, Object> inProperties, Map<String, Object> outProperties) { +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java new file mode 100644 index 000000000..f91a2a180 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV1.java @@ -0,0 +1,260 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.participant.intermediary.api.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; +import org.onap.policy.models.base.PfModelException; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; + +/** + * Wrapper of AutomationCompositionElementListener. + * Valid since 7.1.0 release. + */ +public abstract class AcElementListenerV1 implements AutomationCompositionElementListener { + protected final ParticipantIntermediaryApi intermediaryApi; + + protected AcElementListenerV1(ParticipantIntermediaryApi intermediaryApi) { + this.intermediaryApi = intermediaryApi; + } + + @Override + public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElement.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setToscaServiceTemplateFragment(instanceElement.toscaServiceTemplateFragment()); + element.setProperties(instanceElement.inProperties()); + Map<String, Object> properties = new HashMap<>(instanceElement.inProperties()); + properties.putAll(compositionElement.inProperties()); + deploy(instanceElement.instanceId(), element, properties); + } + + public abstract void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException; + + @Override + public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + undeploy(instanceElement.instanceId(), instanceElement.elementId()); + } + + public abstract void undeploy(UUID instanceId, UUID elementId) throws PfModelException; + + @Override + public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + lock(instanceElement.instanceId(), instanceElement.elementId()); + } + + public void lock(UUID instanceId, UUID elementId) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, + StateChangeResult.NO_ERROR, "Locked"); + } + + @Override + public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + unlock(instanceElement.instanceId(), instanceElement.elementId()); + } + + public void unlock(UUID instanceId, UUID elementId) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, + StateChangeResult.NO_ERROR, "Unlocked"); + } + + @Override + public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + delete(instanceElement.instanceId(), instanceElement.elementId()); + } + + public void delete(UUID instanceId, UUID elementId) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DELETED, null, + StateChangeResult.NO_ERROR, "Deleted"); + } + + @Override + public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElementUpdated.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setProperties(instanceElementUpdated.inProperties()); + update(instanceElementUpdated.instanceId(), element, element.getProperties()); + } + + public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + } + + private List<AutomationCompositionElementDefinition> createAcElementDefinitionList(CompositionDto composition) { + List<AutomationCompositionElementDefinition> elementDefinitionList = new ArrayList<>(); + for (var entry : composition.inPropertiesMap().entrySet()) { + elementDefinitionList.add(createAcElementDefinition(entry.getKey(), entry.getValue(), + composition.outPropertiesMap().get(entry.getKey()))); + } + return elementDefinitionList; + } + + private AutomationCompositionElementDefinition createAcElementDefinition( + ToscaConceptIdentifier toscaConceptIdentifier, Map<String, Object> property, + Map<String, Object> outProperties) { + var acElementDefinition = new AutomationCompositionElementDefinition(); + acElementDefinition.setAcElementDefinitionId(toscaConceptIdentifier); + var toscaNodeTemplate = new ToscaNodeTemplate(); + toscaNodeTemplate.setProperties(property); + acElementDefinition.setAutomationCompositionElementToscaNodeTemplate(toscaNodeTemplate); + acElementDefinition.setOutProperties(outProperties); + return acElementDefinition; + } + + @Override + public void prime(CompositionDto composition) throws PfModelException { + prime(composition.compositionId(), createAcElementDefinitionList(composition)); + } + + public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList) + throws PfModelException { + intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.NO_ERROR, "Primed"); + } + + @Override + public void deprime(CompositionDto composition) throws PfModelException { + deprime(composition.compositionId()); + } + + public void deprime(UUID compositionId) throws PfModelException { + intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.NO_ERROR, + "Deprimed"); + } + + @Override + public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { + handleRestartComposition(composition.compositionId(), createAcElementDefinitionList(composition), state); + } + + /** + * Default implementation of handle Restart Composition. + * + * @param compositionId the composition Id + * @param elementDefinitionList the list of AutomationCompositionElementDefinition + * @param state the current AcTypeState + * @throws PfModelException in case of a model exception + */ + public void handleRestartComposition(UUID compositionId, + List<AutomationCompositionElementDefinition> elementDefinitionList, AcTypeState state) throws PfModelException { + switch (state) { + case PRIMING -> prime(compositionId, elementDefinitionList); + case DEPRIMING -> deprime(compositionId); + default -> + intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.NO_ERROR, "Restarted"); + } + } + + @Override + public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + DeployState deployState, LockState lockState) throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElement.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setProperties(instanceElement.inProperties()); + Map<String, Object> properties = new HashMap<>(instanceElement.inProperties()); + properties.putAll(compositionElement.inProperties()); + handleRestartInstance(instanceElement.instanceId(), element, properties, deployState, lockState); + } + + /** + * Default implementation of handle Restart Instance. + * + * @param instanceId the instance Id + * @param element the AcElementDeploy + * @param properties the in properties + * @param deployState the current deployState + * @param lockState the current lockState + * @throws PfModelException in case of a model exception + */ + public void handleRestartInstance(UUID instanceId, AcElementDeploy element, + Map<String, Object> properties, DeployState deployState, LockState lockState) throws PfModelException { + + if (DeployState.DEPLOYING.equals(deployState)) { + deploy(instanceId, element, properties); + return; + } + if (DeployState.UNDEPLOYING.equals(deployState)) { + undeploy(instanceId, element.getId()); + return; + } + if (DeployState.UPDATING.equals(deployState)) { + update(instanceId, element, properties); + return; + } + if (DeployState.DELETING.equals(deployState)) { + delete(instanceId, element.getId()); + return; + } + if (LockState.LOCKING.equals(lockState)) { + lock(instanceId, element.getId()); + return; + } + if (LockState.UNLOCKING.equals(lockState)) { + unlock(instanceId, element.getId()); + return; + } + intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), + deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); + } + + @Override + public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) throws PfModelException { + var element = new AcElementDeploy(); + element.setId(instanceElement.elementId()); + element.setDefinition(compositionElement.elementDefinitionId()); + element.setProperties(instanceElement.inProperties()); + migrate(instanceElementMigrate.instanceId(), element, compositionElementTarget.compositionId(), + element.getProperties()); + } + + public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, + Map<String, Object> properties) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), + DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); + } +} diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java new file mode 100644 index 000000000..daf9d6e71 --- /dev/null +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/AcElementListenerV2.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.participant.intermediary.api.impl; + +import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; +import org.onap.policy.clamp.models.acm.concepts.AcTypeState; +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.concepts.StateChangeResult; +import org.onap.policy.models.base.PfModelException; + +/** + * Wrapper of AutomationCompositionElementListener. + * Valid since 7.1.1 release. + */ +public abstract class AcElementListenerV2 implements AutomationCompositionElementListener { + protected final ParticipantIntermediaryApi intermediaryApi; + + protected AcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) { + this.intermediaryApi = intermediaryApi; + } + + @Override + public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked"); + } + + @Override + public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked"); + } + + @Override + public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted"); + } + + @Override + public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.NO_ERROR, "Update not supported"); + + } + + @Override + public void prime(CompositionDto composition) throws PfModelException { + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, + StateChangeResult.NO_ERROR, "Primed"); + } + + @Override + public void deprime(CompositionDto composition) throws PfModelException { + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, + StateChangeResult.NO_ERROR, "Deprimed"); + } + + @Override + public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException { + switch (state) { + case PRIMING -> prime(composition); + case DEPRIMING -> deprime(composition); + default -> intermediaryApi + .updateCompositionState(composition.compositionId(), state, StateChangeResult.NO_ERROR, "Restarted"); + } + } + + @Override + public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + DeployState deployState, LockState lockState) throws PfModelException { + + if (DeployState.DEPLOYING.equals(deployState)) { + deploy(compositionElement, instanceElement); + return; + } + if (DeployState.UNDEPLOYING.equals(deployState)) { + undeploy(compositionElement, instanceElement); + return; + } + if (DeployState.UPDATING.equals(deployState)) { + update(compositionElement, instanceElement, instanceElement); + return; + } + if (DeployState.DELETING.equals(deployState)) { + delete(compositionElement, instanceElement); + return; + } + if (LockState.LOCKING.equals(lockState)) { + lock(compositionElement, instanceElement); + return; + } + if (LockState.UNLOCKING.equals(lockState)) { + unlock(compositionElement, instanceElement); + return; + } + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), deployState, lockState, StateChangeResult.NO_ERROR, "Restarted"); + } + + @Override + public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget, + InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate) + throws PfModelException { + intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(), + instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated"); + } +} 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 49b7b731e..fd82c37ba 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 @@ -21,13 +21,20 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.stream.Collectors; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantMessagePublisher; import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; +import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; @@ -195,11 +202,12 @@ public class AutomationCompositionHandler { for (var participantDeploy : updateMsg.getParticipantUpdatesList()) { if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) { + var acCopy = new AutomationComposition(cacheProvider.getAutomationComposition( + updateMsg.getAutomationCompositionId())); updateExistingElementsOnThisParticipant(updateMsg.getAutomationCompositionId(), participantDeploy, DeployState.UPDATING); - callParticipantUpdateProperty(updateMsg.getMessageId(), participantDeploy.getAcElementList(), - updateMsg.getAutomationCompositionId()); + callParticipantUpdateProperty(updateMsg.getMessageId(), participantDeploy.getAcElementList(), acCopy); } } } @@ -228,32 +236,78 @@ public class AutomationCompositionHandler { } } - private void callParticipanDeploy(UUID messageId, List<AcElementDeploy> acElements, Integer startPhaseMsg, - UUID instanceId) { - for (var element : acElements) { - var commonProperties = cacheProvider.getCommonProperties(instanceId, element.getId()); - int startPhase = ParticipantUtils.findStartPhase(commonProperties); + private void callParticipanDeploy(UUID messageId, List<AcElementDeploy> acElementDeployList, + Integer startPhaseMsg, UUID instanceId) { + var automationComposition = cacheProvider.getAutomationComposition(instanceId); + for (var elementDeploy : acElementDeployList) { + var element = automationComposition.getElements().get(elementDeploy.getId()); + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - var map = new HashMap<>(commonProperties); - map.putAll(element.getProperties()); - listener.deploy(messageId, instanceId, element, map); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(instanceId, elementDeploy.getId(), + elementDeploy.getToscaServiceTemplateFragment(), + elementDeploy.getProperties(), element.getOutProperties()); + listener.deploy(messageId, compositionElement, instanceElement); } } } - private void callParticipantUpdateProperty(UUID messageId, List<AcElementDeploy> acElements, UUID instanceId) { - for (var element : acElements) { - listener.update(messageId, instanceId, element, element.getProperties()); + private CompositionElementDto createCompositionElementDto(UUID compositionId, AutomationCompositionElement element, + Map<String, Object> compositionInProperties) { + var compositionOutProperties = cacheProvider.getAcElementsDefinitions() + .get(compositionId).get(element.getDefinition()).getOutProperties(); + return new CompositionElementDto(compositionId, + element.getDefinition(), compositionInProperties, compositionOutProperties); + } + + private Map<UUID, CompositionElementDto> getCompositionElementDtoMap(AutomationComposition automationComposition, + UUID compositionId) { + Map<UUID, CompositionElementDto> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider.getCommonProperties(compositionId, element.getDefinition()); + var compositionElement = createCompositionElementDto(compositionId, element, compositionInProperties); + map.put(element.getId(), compositionElement); + } + return map; + } + + private Map<UUID, CompositionElementDto> getCompositionElementDtoMap(AutomationComposition automationComposition) { + return getCompositionElementDtoMap(automationComposition, automationComposition.getCompositionId()); + } + + private Map<UUID, InstanceElementDto> getInstanceElementDtoMap(AutomationComposition automationComposition) { + Map<UUID, InstanceElementDto> map = new HashMap<>(); + for (var element : automationComposition.getElements().values()) { + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + map.put(element.getId(), instanceElement); + } + return map; + } + + private void callParticipantUpdateProperty(UUID messageId, List<AcElementDeploy> acElements, + AutomationComposition acCopy) { + var instanceElementDtoMap = getInstanceElementDtoMap(acCopy); + var instanceElementDtoMapUpdated = getInstanceElementDtoMap( + cacheProvider.getAutomationComposition(acCopy.getInstanceId())); + var compositionElementDtoMap = getCompositionElementDtoMap(acCopy); + for (var acElement : acElements) { + listener.update(messageId, compositionElementDtoMap.get(acElement.getId()), + instanceElementDtoMap.get(acElement.getId()), instanceElementDtoMapUpdated.get(acElement.getId())); } } private void updateExistingElementsOnThisParticipant(UUID instanceId, ParticipantDeploy participantDeploy, - DeployState deployState) { + DeployState deployState) { var acElementList = cacheProvider.getAutomationComposition(instanceId).getElements(); for (var element : participantDeploy.getAcElementList()) { var acElement = acElementList.get(element.getId()); acElement.getProperties().putAll(element.getProperties()); acElement.setDeployState(deployState); + acElement.setDefinition(element.getDefinition()); } } @@ -267,24 +321,34 @@ public class AutomationCompositionHandler { private void handleUndeployState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { automationComposition.setCompositionTargetId(null); - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setDeployState(DeployState.UNDEPLOYING); - listener.undeploy(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setDeployState(DeployState.UNDEPLOYING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.undeploy(messageId, compositionElement, instanceElement); } } } private void handleDeleteState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setDeployState(DeployState.DELETING); - listener.delete(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setDeployState(DeployState.DELETING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.delete(messageId, compositionElement, instanceElement); } } } @@ -298,12 +362,17 @@ public class AutomationCompositionHandler { */ private void handleLockState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setLockState(LockState.LOCKING); - listener.lock(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setLockState(LockState.LOCKING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.lock(messageId, compositionElement, instanceElement); } } } @@ -317,12 +386,17 @@ public class AutomationCompositionHandler { */ private void handleUnlockState(UUID messageId, final AutomationComposition automationComposition, Integer startPhaseMsg) { - for (var acElement : automationComposition.getElements().values()) { - int startPhase = ParticipantUtils.findStartPhase( - cacheProvider.getCommonProperties(automationComposition.getInstanceId(), acElement.getId())); + for (var element : automationComposition.getElements().values()) { + var compositionInProperties = cacheProvider + .getCommonProperties(automationComposition.getCompositionId(), element.getDefinition()); + int startPhase = ParticipantUtils.findStartPhase(compositionInProperties); if (startPhaseMsg.equals(startPhase)) { - acElement.setLockState(LockState.UNLOCKING); - listener.unlock(messageId, automationComposition.getInstanceId(), acElement.getId()); + element.setLockState(LockState.UNLOCKING); + var compositionElement = createCompositionElementDto(automationComposition.getCompositionId(), + element, compositionInProperties); + var instanceElement = new InstanceElementDto(automationComposition.getInstanceId(), element.getId(), + null, element.getProperties(), element.getOutProperties()); + listener.unlock(messageId, compositionElement, instanceElement); } } } @@ -335,7 +409,13 @@ public class AutomationCompositionHandler { * @param list the list of AutomationCompositionElementDefinition */ public void prime(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list) { - listener.prime(messageId, compositionId, list); + var inPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + el -> el.getAutomationCompositionElementToscaNodeTemplate().getProperties())); + var outPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + AutomationCompositionElementDefinition::getOutProperties)); + listener.prime(messageId, new CompositionDto(compositionId, inPropertiesMap, outPropertiesMap)); } /** @@ -345,7 +425,19 @@ public class AutomationCompositionHandler { * @param compositionId the compositionId */ public void deprime(UUID messageId, UUID compositionId) { - listener.deprime(messageId, compositionId); + var acElementsDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId); + if (acElementsDefinitions == null) { + // this participant does not handle this composition + return; + } + var list = new ArrayList<>(acElementsDefinitions.values()); + var inPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + el -> el.getAutomationCompositionElementToscaNodeTemplate().getProperties())); + var outPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + AutomationCompositionElementDefinition::getOutProperties)); + listener.deprime(messageId, new CompositionDto(compositionId, inPropertiesMap, outPropertiesMap)); } /** @@ -363,7 +455,14 @@ public class AutomationCompositionHandler { for (var automationcomposition : automationCompositionList) { cacheProvider.initializeAutomationComposition(compositionId, automationcomposition); } - listener.restarted(messageId, compositionId, list, state, automationCompositionList); + var inPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + el -> el.getAutomationCompositionElementToscaNodeTemplate().getProperties())); + var outPropertiesMap = list.stream().collect(Collectors.toMap( + AutomationCompositionElementDefinition::getAcElementDefinitionId, + AutomationCompositionElementDefinition::getOutProperties)); + var composition = new CompositionDto(compositionId, inPropertiesMap, outPropertiesMap); + listener.restarted(messageId, composition, state, automationCompositionList); } /** @@ -382,6 +481,7 @@ public class AutomationCompositionHandler { migrationMsg.getAutomationCompositionId()); return; } + var acCopy = new AutomationComposition(automationComposition); automationComposition.setCompositionTargetId(migrationMsg.getCompositionTargetId()); for (var participantDeploy : migrationMsg.getParticipantUpdatesList()) { if (cacheProvider.getParticipantId().equals(participantDeploy.getParticipantId())) { @@ -390,15 +490,23 @@ public class AutomationCompositionHandler { DeployState.MIGRATING); callParticipantMigrate(migrationMsg.getMessageId(), participantDeploy.getAcElementList(), - migrationMsg.getAutomationCompositionId(), migrationMsg.getCompositionTargetId()); + acCopy, migrationMsg.getCompositionTargetId()); } } } - private void callParticipantMigrate(UUID messageId, List<AcElementDeploy> acElements, UUID instanceId, - UUID compositionTargetId) { - for (var element : acElements) { - listener.migrate(messageId, instanceId, element, compositionTargetId, element.getProperties()); + private void callParticipantMigrate(UUID messageId, List<AcElementDeploy> acElements, + AutomationComposition acCopy, UUID compositionTargetId) { + var compositionElementMap = getCompositionElementDtoMap(acCopy); + var instanceElementMap = getInstanceElementDtoMap(acCopy); + var automationComposition = cacheProvider.getAutomationComposition(acCopy.getInstanceId()); + var compositionElementTargetMap = getCompositionElementDtoMap(automationComposition, compositionTargetId); + var instanceElementMigrateMap = getInstanceElementDtoMap(automationComposition); + + for (var acElement : acElements) { + listener.migrate(messageId, compositionElementMap.get(acElement.getId()), + compositionElementTargetMap.get(acElement.getId()), + instanceElementMap.get(acElement.getId()), instanceElementMigrateMap.get(acElement.getId())); } } } 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 cc61c4739..630dfc6ab 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 @@ -125,6 +125,19 @@ public class CacheProvider { } /** + * Get CommonProperties. + * + * @param compositionId the composition Id + * @param definition the AutomationCompositionElementDefinition Id + * @return the common Properties as Map + */ + public Map<String, Object> getCommonProperties(@NonNull UUID compositionId, + @NonNull ToscaConceptIdentifier definition) { + return acElementsDefinitions.get(compositionId).get(definition) + .getAutomationCompositionElementToscaNodeTemplate().getProperties(); + } + + /** * Initialize an AutomationComposition from a ParticipantDeploy. * * @param compositionId the composition Id 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 8c1aed32f..ce0da680b 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 @@ -196,9 +196,11 @@ public class ParticipantHandler { list.addAll(participantDefinition.getAutomationCompositionElementDefinitionList()); } } - cacheProvider.addElementDefinition(participantPrimeMsg.getCompositionId(), list); - automationCompositionHandler.prime(participantPrimeMsg.getMessageId(), + if (!list.isEmpty()) { + cacheProvider.addElementDefinition(participantPrimeMsg.getCompositionId(), list); + automationCompositionHandler.prime(participantPrimeMsg.getMessageId(), participantPrimeMsg.getCompositionId(), list); + } } else { // deprime automationCompositionHandler.deprime(participantPrimeMsg.getMessageId(), diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java index 0aed919e5..9f3e16777 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/ThreadHandler.java @@ -23,7 +23,6 @@ package org.onap.policy.clamp.acm.participant.intermediary.handler; import io.opentelemetry.context.Context; import java.io.Closeable; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; @@ -33,11 +32,11 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto; +import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto; import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy; -import org.onap.policy.clamp.models.acm.concepts.AcElementRestart; import org.onap.policy.clamp.models.acm.concepts.AcTypeState; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.clamp.models.acm.concepts.DeployState; import org.onap.policy.clamp.models.acm.concepts.LockState; import org.onap.policy.clamp.models.acm.concepts.ParticipantRestartAc; @@ -62,149 +61,163 @@ public class ThreadHandler implements Closeable { Context.taskWrapping(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())); /** - * Handle an update on a automation composition element. + * Handle a deploy on a automation composition element. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param element the information on the automation composition element - * @param properties properties Map + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void deploy(UUID messageId, UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { - cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this.deployProcess(instanceId, element, properties)); - executionMap.put(element.getId(), result); + public void deploy(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.deployProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void deployProcess(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { + private void deployProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.deploy(instanceId, element, properties); + listener.deploy(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element deploy failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.UNDEPLOYED, - null, StateChangeResult.FAILED, "Automation composition element deploy failed"); + LOGGER.error("Automation composition element deploy failed {} {}", instanceElement.elementId(), + e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.UNDEPLOYED, null, StateChangeResult.FAILED, + "Automation composition element deploy failed"); } - executionMap.remove(element.getId()); + executionMap.remove(instanceElement.elementId()); } /** - * Handle a automation composition element state change. + * Handle an udeploy on a automation composition element. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void undeploy(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.undeployProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void undeploy(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.undeployProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void undeployProcess(UUID instanceId, UUID elementId) { + private void undeployProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.undeploy(instanceId, elementId); + listener.undeploy(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element undeploy failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.DEPLOYED, null, - StateChangeResult.FAILED, "Automation composition element undeploy failed"); + LOGGER.error( + "Automation composition element undeploy failed {} {}", instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.FAILED, "Automation composition element undeploy failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element lock. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void lock(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.lockProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void lock(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.lockProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void lockProcess(UUID instanceId, UUID elementId) { + private void lockProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.lock(instanceId, elementId); + listener.lock(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element lock failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.UNLOCKED, - StateChangeResult.FAILED, "Automation composition element lock failed"); + LOGGER.error("Automation composition element lock failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.FAILED, + "Automation composition element lock failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element unlock. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void unlock(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.unlockProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void unlock(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.unlockProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void unlockProcess(UUID instanceId, UUID elementId) { + private void unlockProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.unlock(instanceId, elementId); + listener.unlock(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element unlock failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, null, LockState.LOCKED, - StateChangeResult.FAILED, "Automation composition element unlock failed"); + LOGGER.error("Automation composition element unlock failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.FAILED, + "Automation composition element unlock failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element delete. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param elementId the ID of the automation composition element + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element */ - public void delete(UUID messageId, UUID instanceId, UUID elementId) { - cleanExecution(elementId, messageId); - var result = executor.submit(() -> this.deleteProcess(instanceId, elementId)); - executionMap.put(elementId, result); + public void delete(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> this.deleteProcess(compositionElement, instanceElement)); + executionMap.put(instanceElement.elementId(), result); } - private void deleteProcess(UUID instanceId, UUID elementId) { + private void deleteProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement) { try { - listener.delete(instanceId, elementId); + listener.delete(compositionElement, instanceElement); } catch (PfModelException e) { - LOGGER.error("Automation composition element delete failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, elementId, DeployState.UNDEPLOYED, null, - StateChangeResult.FAILED, "Automation composition element delete failed"); + LOGGER.error("Automation composition element delete failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), DeployState.UNDEPLOYED, null, + StateChangeResult.FAILED, "Automation composition element delete failed"); } - executionMap.remove(elementId); + executionMap.remove(instanceElement.elementId()); } /** * Handle a automation composition element properties update. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param element the information on the automation composition element - * @param properties properties Map + * @param compositionElement the information of the Automation Composition Definition Element + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementUpdated the information of the Automation Composition Instance Element updated */ - public void update(UUID messageId, UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { - cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this.updateProcess(instanceId, element, properties)); - executionMap.put(element.getId(), result); + public void update(UUID messageId, CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> + this.updateProcess(compositionElement, instanceElement, instanceElementUpdated)); + executionMap.put(instanceElement.elementId(), result); } - private void updateProcess(UUID instanceId, AcElementDeploy element, Map<String, Object> properties) { + private void updateProcess(CompositionElementDto compositionElement, InstanceElementDto instanceElement, + InstanceElementDto instanceElementUpdated) { try { - listener.update(instanceId, element, properties); + listener.update(compositionElement, instanceElement, instanceElementUpdated); } catch (PfModelException e) { - LOGGER.error("Automation composition element update failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, - null, StateChangeResult.FAILED, "Automation composition element update failed"); + LOGGER.error("Automation composition element update failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(), + instanceElement.elementId(), DeployState.DEPLOYED, null, + StateChangeResult.FAILED, "Automation composition element update failed"); } - executionMap.remove(element.getId()); + executionMap.remove(instanceElement.elementId()); } private void cleanExecution(UUID execIdentificationId, UUID messageId) { @@ -222,23 +235,22 @@ public class ThreadHandler implements Closeable { * Handles prime a Composition Definition. * * @param messageId the messageId - * @param compositionId the compositionId - * @param list the list of AutomationCompositionElementDefinition + * @param composition the composition */ - public void prime(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list) { - cleanExecution(compositionId, messageId); - var result = executor.submit(() -> this.primeProcess(compositionId, list)); - executionMap.put(compositionId, result); + public void prime(UUID messageId, CompositionDto composition) { + cleanExecution(composition.compositionId(), messageId); + var result = executor.submit(() -> this.primeProcess(composition)); + executionMap.put(composition.compositionId(), result); } - private void primeProcess(UUID compositionId, List<AutomationCompositionElementDefinition> list) { + private void primeProcess(CompositionDto composition) { try { - listener.prime(compositionId, list); - executionMap.remove(compositionId); + listener.prime(composition); + executionMap.remove(composition.compositionId()); } catch (PfModelException e) { - LOGGER.error("Composition Defintion prime failed {} {}", compositionId, e.getMessage()); - intermediaryApi.updateCompositionState(compositionId, AcTypeState.COMMISSIONED, StateChangeResult.FAILED, - "Composition Defintion prime failed"); + LOGGER.error("Composition Defintion prime failed {} {}", composition.compositionId(), e.getMessage()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED, + StateChangeResult.FAILED, "Composition Defintion prime failed"); } } @@ -246,22 +258,22 @@ public class ThreadHandler implements Closeable { * Handles deprime a Composition Definition. * * @param messageId the messageId - * @param compositionId the compositionId + * @param composition the composition */ - public void deprime(UUID messageId, UUID compositionId) { - cleanExecution(compositionId, messageId); - var result = executor.submit(() -> this.deprimeProcess(compositionId)); - executionMap.put(compositionId, result); + public void deprime(UUID messageId, CompositionDto composition) { + cleanExecution(composition.compositionId(), messageId); + var result = executor.submit(() -> this.deprimeProcess(composition)); + executionMap.put(composition.compositionId(), result); } - private void deprimeProcess(UUID compositionId) { + private void deprimeProcess(CompositionDto composition) { try { - listener.deprime(compositionId); - executionMap.remove(compositionId); + listener.deprime(composition); + executionMap.remove(composition.compositionId()); } catch (PfModelException e) { - LOGGER.error("Composition Defintion deprime failed {} {}", compositionId, e.getMessage()); - intermediaryApi.updateCompositionState(compositionId, AcTypeState.PRIMED, StateChangeResult.FAILED, - "Composition Defintion deprime failed"); + LOGGER.error("Composition Defintion deprime failed {} {}", composition.compositionId(), e.getMessage()); + intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED, + StateChangeResult.FAILED, "Composition Defintion deprime failed"); } } @@ -269,56 +281,51 @@ public class ThreadHandler implements Closeable { * Handles restarted scenario. * * @param messageId the messageId - * @param compositionId the compositionId - * @param list the list of AutomationCompositionElementDefinition + * @param composition the composition * @param state the state of the composition * @param automationCompositionList list of ParticipantRestartAc */ - public void restarted(UUID messageId, UUID compositionId, List<AutomationCompositionElementDefinition> list, + public void restarted(UUID messageId, CompositionDto composition, AcTypeState state, List<ParticipantRestartAc> automationCompositionList) { try { - listener.handleRestartComposition(compositionId, list, state); + listener.handleRestartComposition(composition, state); } catch (PfModelException e) { - LOGGER.error("Composition Defintion restarted failed {} {}", compositionId, e.getMessage()); - intermediaryApi.updateCompositionState(compositionId, state, StateChangeResult.FAILED, + LOGGER.error("Composition Defintion restarted failed {} {}", composition.compositionId(), e.getMessage()); + intermediaryApi.updateCompositionState(composition.compositionId(), state, StateChangeResult.FAILED, "Composition Defintion restarted failed"); } for (var automationComposition : automationCompositionList) { for (var element : automationComposition.getAcElementList()) { + var compositionElement = new CompositionElementDto(composition.compositionId(), + element.getDefinition(), composition.inPropertiesMap().get(element.getDefinition()), + composition.outPropertiesMap().get(element.getDefinition())); + var instanceElementDto = new InstanceElementDto(automationComposition.getAutomationCompositionId(), + element.getId(), element.getToscaServiceTemplateFragment(), + element.getProperties(), element.getOutProperties()); cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this - .restartedInstanceProcess(automationComposition.getAutomationCompositionId(), element)); + var result = executor.submit(() -> + this.restartedInstanceProcess(compositionElement, instanceElementDto, + element.getDeployState(), element.getLockState())); executionMap.put(element.getId(), result); } } } - private void restartedInstanceProcess(UUID instanceId, AcElementRestart element) { + private void restartedInstanceProcess(CompositionElementDto compositionElement, + InstanceElementDto instanceElementDto, DeployState deployState, LockState lockState) { try { - var map = new HashMap<>(cacheProvider.getCommonProperties(instanceId, element.getId())); - map.putAll(element.getProperties()); - - listener.handleRestartInstance(instanceId, getAcElementDeploy(element), map, element.getDeployState(), - element.getLockState()); - executionMap.remove(element.getId()); + listener.handleRestartInstance(compositionElement, instanceElementDto, deployState, lockState); + executionMap.remove(instanceElementDto.elementId()); } catch (PfModelException e) { - LOGGER.error("Automation composition element deploy failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), - element.getDeployState(), element.getLockState(), StateChangeResult.FAILED, + LOGGER.error("Automation composition element deploy failed {} {}", + instanceElementDto.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState(instanceElementDto.instanceId(), + instanceElementDto.elementId(), deployState, lockState, StateChangeResult.FAILED, "Automation composition element restart failed"); } } - private AcElementDeploy getAcElementDeploy(AcElementRestart element) { - var acElementDeploy = new AcElementDeploy(); - acElementDeploy.setId(element.getId()); - acElementDeploy.setDefinition(element.getDefinition()); - acElementDeploy.setProperties(element.getProperties()); - acElementDeploy.setToscaServiceTemplateFragment(element.getToscaServiceTemplateFragment()); - return acElementDeploy; - } - /** * Closes this stream and releases any system resources associated * with it. If the stream is already closed then invoking this @@ -335,26 +342,32 @@ public class ThreadHandler implements Closeable { * Handles AutomationComposition Migration. * * @param messageId the messageId - * @param instanceId the automationComposition Id - * @param element the information on the automation composition element - * @param compositionTargetId the composition to migrate + * @param compositionElement the information of the Automation Composition Definition Element + * @param compositionElementTarget the information of the Automation Composition Definition Element Target + * @param instanceElement the information of the Automation Composition Instance Element + * @param instanceElementMigrate the information of the Automation Composition Instance Element updated */ - public void migrate(UUID messageId, UUID instanceId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) { - cleanExecution(element.getId(), messageId); - var result = executor.submit(() -> this.migrateProcess(instanceId, element, compositionTargetId, properties)); - executionMap.put(element.getId(), result); + public void migrate(UUID messageId, CompositionElementDto compositionElement, + CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement, + InstanceElementDto instanceElementMigrate) { + cleanExecution(instanceElement.elementId(), messageId); + var result = executor.submit(() -> + this.migrateProcess(compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate)); + executionMap.put(instanceElement.elementId(), result); } - private void migrateProcess(UUID instanceId, AcElementDeploy element, UUID compositionTargetId, - Map<String, Object> properties) { + private void migrateProcess(CompositionElementDto compositionElement, + CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement, + InstanceElementDto instanceElementMigrate) { try { - listener.migrate(instanceId, element, compositionTargetId, properties); + listener.migrate(compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate); } catch (PfModelException e) { - LOGGER.error("Automation composition element migrate failed {} {}", instanceId, e.getMessage()); - intermediaryApi.updateAutomationCompositionElementState(instanceId, element.getId(), DeployState.DEPLOYED, - null, StateChangeResult.FAILED, "Automation composition element migrate failed"); + LOGGER.error("Automation composition element migrate failed {} {}", + instanceElement.elementId(), e.getMessage()); + intermediaryApi.updateAutomationCompositionElementState( + instanceElement.instanceId(), instanceElement.elementId(), DeployState.DEPLOYED, + null, StateChangeResult.FAILED, "Automation composition element migrate failed"); } - executionMap.remove(element.getId()); + executionMap.remove(instanceElement.elementId()); } } |