28bade22f040a284c692b14b4717c40ed5215125
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023-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
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.sim.main.handler;
22
23 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
24 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
25 import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
26 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
27 import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV2;
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.clamp.models.acm.utils.AcmUtils;
33 import org.onap.policy.models.base.PfModelException;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
37 import org.springframework.stereotype.Component;
38
39 /**
40  * This class handles implementation of automationCompositionElement updates.
41  */
42 @ConditionalOnExpression("'${element.handler:AcElementHandlerV2}' == 'AcElementHandlerV2'")
43 @Component
44 public class AutomationCompositionElementHandlerV2 extends AcElementListenerV2 {
45
46     private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandlerV2.class);
47
48     private final SimulatorService simulatorService;
49
50     public AutomationCompositionElementHandlerV2(ParticipantIntermediaryApi intermediaryApi,
51         SimulatorService simulatorService) {
52         super(intermediaryApi);
53         this.simulatorService = simulatorService;
54     }
55
56     /**
57      * Handle a deploy on a automation composition element.
58      *
59      * @param compositionElement the information of the Automation Composition Definition Element
60      * @param instanceElement the information of the Automation Composition Instance Element
61      * @throws PfModelException from Policy framework
62      */
63     @Override
64     public void deploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
65             throws PfModelException {
66         LOGGER.debug("deploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
67         simulatorService.deploy(instanceElement.instanceId(), instanceElement.elementId());
68     }
69
70     /**
71      * Handle a automation composition element state change.
72      *
73      * @param compositionElement the information of the Automation Composition Definition Element
74      * @param instanceElement the information of the Automation Composition Instance Element
75      * @throws PfModelException from Policy framework
76      */
77     @Override
78     public void undeploy(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
79             throws PfModelException {
80         LOGGER.debug("undeploy call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
81         simulatorService.undeploy(instanceElement.instanceId(), instanceElement.elementId());
82     }
83
84     @Override
85     public void lock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
86             throws PfModelException {
87         LOGGER.debug("lock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
88         simulatorService.lock(instanceElement.instanceId(), instanceElement.elementId());
89     }
90
91     @Override
92     public void unlock(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
93             throws PfModelException {
94         LOGGER.debug("unlock call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
95         simulatorService.unlock(instanceElement.instanceId(), instanceElement.elementId());
96     }
97
98     @Override
99     public void delete(CompositionElementDto compositionElement, InstanceElementDto instanceElement)
100             throws PfModelException {
101         LOGGER.debug("delete call compositionElement: {}, instanceElement: {}", compositionElement, instanceElement);
102         simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
103     }
104
105     @Override
106     public void update(CompositionElementDto compositionElement, InstanceElementDto instanceElement,
107                        InstanceElementDto instanceElementUpdated) throws PfModelException {
108         LOGGER.debug("update call compositionElement: {}, instanceElement: {}, instanceElementUpdated: {}",
109                 compositionElement, instanceElement, instanceElementUpdated);
110         simulatorService.update(instanceElement.instanceId(), instanceElement.elementId());
111     }
112
113     @Override
114     public void prime(CompositionDto composition) throws PfModelException {
115         LOGGER.debug("prime call composition: {}", composition);
116         simulatorService.prime(composition.compositionId());
117     }
118
119     @Override
120     public void deprime(CompositionDto composition) throws PfModelException {
121         LOGGER.debug("deprime call composition: {}", composition);
122         simulatorService.deprime(composition.compositionId());
123     }
124
125     @Override
126     public void migrate(CompositionElementDto compositionElement, CompositionElementDto compositionElementTarget,
127                         InstanceElementDto instanceElement, InstanceElementDto instanceElementMigrate)
128             throws PfModelException {
129         LOGGER.debug("migrate call compositionElement: {}, compositionElementTarget: {}, instanceElement: {},"
130                         + " instanceElementMigrate: {}",
131                 compositionElement, compositionElementTarget, instanceElement, instanceElementMigrate);
132         simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId());
133     }
134 }