2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
23 import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
24 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
25 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
26 import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
27 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
28 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
29 import org.onap.policy.clamp.models.acm.concepts.DeployState;
30 import org.onap.policy.clamp.models.acm.concepts.LockState;
31 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
32 import org.onap.policy.models.base.PfModelException;
35 * Wrapper of AutomationCompositionElementListener.
36 * Valid since 7.1.1 release.
38 public abstract class AcElementListenerV2 implements AutomationCompositionElementListener {
39 protected final ParticipantIntermediaryApi intermediaryApi;
41 protected AcElementListenerV2(ParticipantIntermediaryApi intermediaryApi) {
42 this.intermediaryApi = intermediaryApi;
46 public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
47 throws PfModelException {
48 intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
49 instanceElement.elementId(), null, LockState.LOCKED, StateChangeResult.NO_ERROR, "Locked");
53 public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
54 throws PfModelException {
55 intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
56 instanceElement.elementId(), null, LockState.UNLOCKED, StateChangeResult.NO_ERROR, "Unlocked");
60 public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
61 throws PfModelException {
62 intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
63 instanceElement.elementId(), DeployState.DELETED, null, StateChangeResult.NO_ERROR, "Deleted");
67 public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
68 InstanceElementDto instanceElementUpdated) throws PfModelException {
69 intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
70 instanceElement.elementId(), DeployState.DEPLOYED, null,
71 StateChangeResult.NO_ERROR, "Update not supported");
76 public void prime(CompositionDto composition) throws PfModelException {
77 intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED,
78 StateChangeResult.NO_ERROR, "Primed");
82 public void deprime(CompositionDto composition) throws PfModelException {
83 intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED,
84 StateChangeResult.NO_ERROR, "Deprimed");
88 public void handleRestartComposition(CompositionDto composition, AcTypeState state) throws PfModelException {
90 case PRIMING -> prime(composition);
91 case DEPRIMING -> deprime(composition);
92 default -> intermediaryApi
93 .updateCompositionState(composition.compositionId(), state, StateChangeResult.NO_ERROR, "Restarted");
98 public void handleRestartInstance(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
99 DeployState deployState, LockState lockState) throws PfModelException {
101 if (DeployState.DEPLOYING.equals(deployState)) {
102 deploy(compositionElement, instanceElement);
105 if (DeployState.UNDEPLOYING.equals(deployState)) {
106 undeploy(compositionElement, instanceElement);
109 if (DeployState.UPDATING.equals(deployState)) {
110 update(compositionElement, instanceElement, instanceElement);
113 if (DeployState.DELETING.equals(deployState)) {
114 delete(compositionElement, instanceElement);
117 if (LockState.LOCKING.equals(lockState)) {
118 lock(compositionElement, instanceElement);
121 if (LockState.UNLOCKING.equals(lockState)) {
122 unlock(compositionElement, instanceElement);
125 intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
126 instanceElement.elementId(), deployState, lockState, StateChangeResult.NO_ERROR, "Restarted");
130 public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
131 InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate)
132 throws PfModelException {
133 intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),
134 instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");