3bb6009a8c2cafc0559be51a6626e71b5621789a
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2024 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.clamp.acm.participant.kubernetes.parameters;
23
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.TreeMap;
28 import java.util.UUID;
29 import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
30 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
31 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
32 import org.onap.policy.common.endpoints.parameters.TopicParameters;
33 import org.onap.policy.common.utils.coder.Coder;
34 import org.onap.policy.common.utils.coder.CoderException;
35 import org.onap.policy.common.utils.coder.StandardCoder;
36 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
37
38 public class CommonTestData {
39
40     public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup";
41     public static final String DESCRIPTION = "Participant description";
42     public static final long TIME_INTERVAL = 2000;
43     public static final List<TopicParameters> SINK_TOPIC_PARAMS = List.of(getTopicParams());
44     public static final List<TopicParameters> SOURCE_TOPIC_PARAMS = List.of(getTopicParams(), getSyncTopicParams());
45     public static final Coder CODER = new StandardCoder();
46     private static final UUID AC_ID = UUID.randomUUID();
47     private static final String KEY_NAME =
48             "org.onap.domain.database.HelloWorld_K8SMicroserviceAutomationCompositionElement";
49
50     /**
51      * Get ParticipantK8sParameters.
52      *
53      * @return ParticipantK8sParameters
54      */
55     public ParticipantK8sParameters getParticipantK8sParameters() {
56         try {
57             return CODER.convert(getParticipantK8sParametersMap(PARTICIPANT_GROUP_NAME),
58                 ParticipantK8sParameters.class);
59         } catch (final CoderException e) {
60             throw new RuntimeException("cannot create ParticipantK8sParameters from map", e);
61         }
62     }
63
64     /**
65      * Returns a property map for a ParticipantK8sParameters map for test cases.
66      *
67      * @param name name of the parameters
68      *
69      * @return a property map suitable for constructing an object
70      */
71     public Map<String, Object> getParticipantK8sParametersMap(final String name) {
72         final Map<String, Object> map = new TreeMap<>();
73
74         map.put("name", name);
75         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
76         map.put("localChartDirectory", getLocalChartDir());
77         map.put("infoFileName", getInfoFileName());
78         return map;
79     }
80
81
82     /**
83      * Returns string value of local chart Directory.
84      * @return a string value
85      */
86     public String getLocalChartDir() {
87         return "/var/helm-manager/local-charts";
88     }
89
90     /**
91      * Returns string value of Info file name.
92      * @return string value
93      */
94     public String getInfoFileName() {
95         return "CHART-INFO.json";
96     }
97
98
99
100     /**
101      * Returns a property map for a intermediaryParameters map for test cases.
102      *
103      * @param isEmpty boolean value to represent that object created should be empty or not
104      * @return a property map suitable for constructing an object
105      */
106     public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
107         final Map<String, Object> map = new TreeMap<>();
108         if (!isEmpty) {
109             map.put("name", "Participant parameters");
110             map.put("reportingTimeIntervalMs", TIME_INTERVAL);
111             map.put("description", DESCRIPTION);
112             map.put("participantId", getParticipantId());
113             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
114             map.put("participantSupportedElementTypes", new ArrayList<>());
115             map.put("topics", new Topics("policy-acruntime-participant", "acm-ppnt-sync"));
116         }
117
118         return map;
119     }
120
121     /**
122      * Returns participantId for test cases.
123      *
124      * @return participant Id
125      */
126     public static UUID getParticipantId() {
127         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c02");
128     }
129
130     /**
131      * Returns a property map for a TopicParameters map for test cases.
132      *
133      * @param isEmpty boolean value to represent that object created should be empty or not
134      * @return a property map suitable for constructing an object
135      */
136     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
137         final Map<String, Object> map = new TreeMap<>();
138         if (!isEmpty) {
139             map.put("topicSources", SOURCE_TOPIC_PARAMS);
140             map.put("topicSinks", SINK_TOPIC_PARAMS);
141         }
142         return map;
143     }
144
145     /**
146      * Returns topic parameters for test cases.
147      *
148      * @return topic parameters
149      */
150     public static TopicParameters getTopicParams() {
151         final TopicParameters topicParams = new TopicParameters();
152         topicParams.setTopic("policy-acruntime-participant");
153         topicParams.setTopicCommInfrastructure("NOOP");
154         topicParams.setServers(List.of("localhost"));
155         return topicParams;
156     }
157
158     /**
159      * Returns sync topic parameters for test cases.
160      *
161      * @return topic parameters
162      */
163     public static TopicParameters getSyncTopicParams() {
164         final TopicParameters topicParams = new TopicParameters();
165         topicParams.setTopic("acm-ppnt-sync");
166         topicParams.setTopicCommInfrastructure("NOOP");
167         topicParams.setServers(List.of("localhost"));
168         return topicParams;
169     }
170
171     /**
172      * Get automation composition id.
173      * @return UUID automationCompositionId
174      */
175     public UUID getAutomationCompositionId() {
176         return AC_ID;
177     }
178
179     /**
180      * Create an AcElementDeploy.
181      *
182      * @return an AcElementDeploy
183      */
184     public static AcElementDeploy createAcElementDeploy() {
185         var element = new AcElementDeploy();
186         element.setId(UUID.randomUUID());
187         element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
188         element.setOrderedState(DeployOrder.DEPLOY);
189         return element;
190     }
191 }