7c0c56a1dc2036a39bd57622de10dc9b1a911bd6
[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.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.TreeMap;
29 import java.util.UUID;
30 import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionElementDto;
31 import org.onap.policy.clamp.acm.participant.intermediary.api.InstanceElementDto;
32 import org.onap.policy.clamp.acm.participant.intermediary.parameters.Topics;
33 import org.onap.policy.clamp.models.acm.concepts.AcElementDeploy;
34 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
35 import org.onap.policy.common.endpoints.parameters.TopicParameters;
36 import org.onap.policy.common.utils.coder.Coder;
37 import org.onap.policy.common.utils.coder.CoderException;
38 import org.onap.policy.common.utils.coder.StandardCoder;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
41
42 public class CommonTestData {
43
44     public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup";
45     public static final String DESCRIPTION = "Participant description";
46     public static final long TIME_INTERVAL = 2000;
47     public static final List<TopicParameters> SINK_TOPIC_PARAMS = List.of(getTopicParams());
48     public static final List<TopicParameters> SOURCE_TOPIC_PARAMS = List.of(getTopicParams(), getSyncTopicParams());
49     public static final Coder CODER = new StandardCoder();
50     private static final UUID AC_ID = UUID.randomUUID();
51     private static final String KEY_NAME =
52             "org.onap.domain.database.HelloWorld_K8SMicroserviceAutomationCompositionElement";
53
54     /**
55      * Get ParticipantK8sParameters.
56      *
57      * @return ParticipantK8sParameters
58      */
59     public ParticipantK8sParameters getParticipantK8sParameters() {
60         try {
61             return CODER.convert(getParticipantK8sParametersMap(PARTICIPANT_GROUP_NAME),
62                 ParticipantK8sParameters.class);
63         } catch (final CoderException e) {
64             throw new RuntimeException("cannot create ParticipantK8sParameters from map", e);
65         }
66     }
67
68     /**
69      * Returns a property map for a ParticipantK8sParameters map for test cases.
70      *
71      * @param name name of the parameters
72      *
73      * @return a property map suitable for constructing an object
74      */
75     public Map<String, Object> getParticipantK8sParametersMap(final String name) {
76         final Map<String, Object> map = new TreeMap<>();
77
78         map.put("name", name);
79         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
80         map.put("localChartDirectory", getLocalChartDir());
81         map.put("infoFileName", getInfoFileName());
82         return map;
83     }
84
85
86     /**
87      * Returns string value of local chart Directory.
88      * @return a string value
89      */
90     public String getLocalChartDir() {
91         return "/var/helm-manager/local-charts";
92     }
93
94     /**
95      * Returns string value of Info file name.
96      * @return string value
97      */
98     public String getInfoFileName() {
99         return "CHART-INFO.json";
100     }
101
102
103
104     /**
105      * Returns a property map for a intermediaryParameters map for test cases.
106      *
107      * @param isEmpty boolean value to represent that object created should be empty or not
108      * @return a property map suitable for constructing an object
109      */
110     public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
111         final Map<String, Object> map = new TreeMap<>();
112         if (!isEmpty) {
113             map.put("name", "Participant parameters");
114             map.put("reportingTimeIntervalMs", TIME_INTERVAL);
115             map.put("description", DESCRIPTION);
116             map.put("participantId", getParticipantId());
117             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
118             map.put("participantSupportedElementTypes", new ArrayList<>());
119             map.put("topics", new Topics("policy-acruntime-participant", "acm-ppnt-sync"));
120         }
121
122         return map;
123     }
124
125     /**
126      * Returns participantId for test cases.
127      *
128      * @return participant Id
129      */
130     public static UUID getParticipantId() {
131         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c02");
132     }
133
134     /**
135      * Returns a property map for a TopicParameters map for test cases.
136      *
137      * @param isEmpty boolean value to represent that object created should be empty or not
138      * @return a property map suitable for constructing an object
139      */
140     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
141         final Map<String, Object> map = new TreeMap<>();
142         if (!isEmpty) {
143             map.put("topicSources", SOURCE_TOPIC_PARAMS);
144             map.put("topicSinks", SINK_TOPIC_PARAMS);
145         }
146         return map;
147     }
148
149     /**
150      * Returns topic parameters for test cases.
151      *
152      * @return topic parameters
153      */
154     public static TopicParameters getTopicParams() {
155         final TopicParameters topicParams = new TopicParameters();
156         topicParams.setTopic("policy-acruntime-participant");
157         topicParams.setTopicCommInfrastructure("NOOP");
158         topicParams.setServers(List.of("localhost"));
159         return topicParams;
160     }
161
162     /**
163      * Returns sync topic parameters for test cases.
164      *
165      * @return topic parameters
166      */
167     public static TopicParameters getSyncTopicParams() {
168         final TopicParameters topicParams = new TopicParameters();
169         topicParams.setTopic("acm-ppnt-sync");
170         topicParams.setTopicCommInfrastructure("NOOP");
171         topicParams.setServers(List.of("localhost"));
172         return topicParams;
173     }
174
175     /**
176      * Get automation composition id.
177      * @return UUID automationCompositionId
178      */
179     public UUID getAutomationCompositionId() {
180         return AC_ID;
181     }
182
183     /**
184      * Create an AcElementDeploy.
185      *
186      * @return an AcElementDeploy
187      */
188     public static AcElementDeploy createAcElementDeploy() {
189         var element = new AcElementDeploy();
190         element.setId(UUID.randomUUID());
191         element.setDefinition(new ToscaConceptIdentifier(KEY_NAME, "1.0.1"));
192         element.setOrderedState(DeployOrder.DEPLOY);
193         return element;
194     }
195
196     /**
197      * Create an InstanceElementDto.
198      *
199      * @return an InstanceElementDto
200      */
201     public InstanceElementDto createInstanceElementDto(Map<String, Object> inProperties) {
202         return new InstanceElementDto(getAutomationCompositionId(), UUID.randomUUID(),
203                 new ToscaServiceTemplate(), inProperties, new HashMap<>());
204     }
205
206
207     /**
208      * Create an compositionElementDto.
209      *
210      * @return an compositionElementDto
211      */
212     public CompositionElementDto createCompositionElementDto() {
213         return new CompositionElementDto(getAutomationCompositionId(), null,
214                 Map.of("uninitializedToPassiveTimeout", 100, "podStatusCheckInterval", "30"), null);
215     }
216 }