002b67d192262dab3d95f1c37dfbfd17167fb673
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
22
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;
33
34 /**
35  * Wrapper of AutomationCompositionElementListener.
36  * Valid since 8.1.1 release.
37  */
38 public abstract class AcElementListenerV4 implements AutomationCompositionElementListener {
39     protected final ParticipantIntermediaryApi intermediaryApi;
40
41     protected AcElementListenerV4(ParticipantIntermediaryApi intermediaryApi) {
42         this.intermediaryApi = intermediaryApi;
43     }
44
45     @Override
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");
50     }
51
52     @Override
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");
57     }
58
59     @Override
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");
64     }
65
66     @Override
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");
72
73     }
74
75     @Override
76     public void prime(CompositionDto composition) throws PfModelException {
77         intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.PRIMED,
78             StateChangeResult.NO_ERROR, "Primed");
79     }
80
81     @Override
82     public void deprime(CompositionDto composition) throws PfModelException {
83         intermediaryApi.updateCompositionState(composition.compositionId(), AcTypeState.COMMISSIONED,
84             StateChangeResult.NO_ERROR, "Deprimed");
85     }
86
87     @Override
88     public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
89                         InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate, int stage)
90         throws PfModelException {
91         intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),
92             instanceElementMigrate.elementId(), DeployState.DEPLOYED, null, StateChangeResult.NO_ERROR, "Migrated");
93     }
94
95     @Override
96     public void migratePrecheck(CompositionElementDto compositionElement,
97             CompositionElementDto compositionElementTarget, InstanceElementDto instanceElement,
98             InstanceElementDto instanceElementMigrate) throws PfModelException {
99         intermediaryApi.updateAutomationCompositionElementState(instanceElementMigrate.instanceId(),
100                 instanceElementMigrate.elementId(), DeployState.DEPLOYED, null,
101                 StateChangeResult.NO_ERROR, "Migration Precheck completed");
102     }
103
104     @Override
105     public void review(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
106             throws PfModelException {
107         intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
108                 instanceElement.elementId(), DeployState.DEPLOYED, null,
109                 StateChangeResult.NO_ERROR, "Review completed");
110     }
111
112     @Override
113     public void prepare(CompositionElementDto compositionElement, InstanceElementDto instanceElement, int nextStage)
114             throws PfModelException {
115         intermediaryApi.updateAutomationCompositionElementState(instanceElement.instanceId(),
116                 instanceElement.elementId(), DeployState.UNDEPLOYED, null,
117                 StateChangeResult.NO_ERROR, "Prepare completed");
118     }
119 }