03a0517e0736027d78411df0ab22d5294959b17e
[policy/clamp.git] /
1 /*-
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
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 java.util.List;
24 import java.util.Map;
25 import java.util.UUID;
26 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
27 import org.onap.policy.clamp.acm.participant.intermediary.api.impl.AcElementListenerV1;
28 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
29 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
30 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
31 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
32 import org.onap.policy.models.base.PfModelException;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
36 import org.springframework.stereotype.Component;
37
38 @ConditionalOnExpression("'${element.handler}'=='AcElementHandlerV1'")
39 @Component
40 public class AutomationCompositionElementHandlerV1 extends AcElementListenerV1 {
41
42     private static final Logger LOGGER = LoggerFactory.getLogger(AutomationCompositionElementHandlerV1.class);
43
44     private final SimulatorService simulatorService;
45
46     public AutomationCompositionElementHandlerV1(ParticipantIntermediaryApi intermediaryApi,
47         SimulatorService simulatorService) {
48         super(intermediaryApi);
49         this.simulatorService = simulatorService;
50     }
51
52     @Override
53     public void deploy(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
54             throws PfModelException {
55         LOGGER.debug("deploy call instanceId: {}, element: {}, properties: {}", instanceId, element, properties);
56         simulatorService.deploy(instanceId, element.getId());
57     }
58
59     @Override
60     public void undeploy(UUID instanceId, UUID elementId) throws PfModelException {
61         LOGGER.debug("undeploy call instanceId: {}, elementId: {}", instanceId, elementId);
62         simulatorService.undeploy(instanceId, elementId);
63     }
64
65     @Override
66     public void lock(UUID instanceId, UUID elementId) throws PfModelException {
67         LOGGER.debug("lock call instanceId: {}, elementId: {}", instanceId, elementId);
68         simulatorService.lock(instanceId, elementId);
69     }
70
71     @Override
72     public void unlock(UUID instanceId, UUID elementId) throws PfModelException {
73         LOGGER.debug("unlock call instanceId: {}, elementId: {}", instanceId, elementId);
74         simulatorService.unlock(instanceId, elementId);
75     }
76
77     @Override
78     public void delete(UUID instanceId, UUID elementId) throws PfModelException {
79         LOGGER.debug("delete call instanceId: {}, elementId: {}", instanceId, elementId);
80         simulatorService.delete(instanceId, elementId);
81     }
82
83     @Override
84     public void update(UUID instanceId, AcElementDeploy element, Map<String, Object> properties)
85             throws PfModelException {
86         LOGGER.debug("update call instanceId: {}, element: {}, properties: {}", instanceId, element, properties);
87         simulatorService.update(instanceId, element.getId());
88     }
89
90     @Override
91     public void prime(UUID compositionId, List<AutomationCompositionElementDefinition> elementDefinitionList)
92             throws PfModelException {
93         LOGGER.debug("prime call compositionId: {}, elementDefinitionList: {}", compositionId, elementDefinitionList);
94         simulatorService.prime(compositionId);
95     }
96
97     @Override
98     public void deprime(UUID compositionId) throws PfModelException {
99         LOGGER.debug("deprime call compositionId: {}", compositionId);
100         simulatorService.deprime(compositionId);
101     }
102
103     @Override
104     public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTargetId,
105         Map<String, Object> properties) throws PfModelException {
106         LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}",
107                 instanceId, element, compositionTargetId, properties);
108         simulatorService.migrate(instanceId, element.getId());
109     }
110 }