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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.clamp.acm.participant.kubernetes.parameters;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
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.parameters.topic.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;
42 public class CommonTestData {
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";
55 * Get ParticipantK8sParameters.
57 * @return ParticipantK8sParameters
59 public ParticipantK8sParameters getParticipantK8sParameters() {
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);
69 * Returns a property map for a ParticipantK8sParameters map for test cases.
71 * @param name name of the parameters
73 * @return a property map suitable for constructing an object
75 public Map<String, Object> getParticipantK8sParametersMap(final String name) {
76 final Map<String, Object> map = new TreeMap<>();
78 map.put("name", name);
79 map.put("intermediaryParameters", getIntermediaryParametersMap(false));
80 map.put("localChartDirectory", getLocalChartDir());
81 map.put("infoFileName", getInfoFileName());
87 * Returns string value of local chart Directory.
88 * @return a string value
90 public String getLocalChartDir() {
91 return "/var/helm-manager/local-charts";
95 * Returns string value of Info file name.
96 * @return string value
98 public String getInfoFileName() {
99 return "CHART-INFO.json";
105 * Returns a property map for a intermediaryParameters map for test cases.
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
110 public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
111 final Map<String, Object> map = new TreeMap<>();
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"));
126 * Returns participantId for test cases.
128 * @return participant Id
130 public static UUID getParticipantId() {
131 return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c02");
135 * Returns a property map for a TopicParameters map for test cases.
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
140 public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
141 final Map<String, Object> map = new TreeMap<>();
143 map.put("topicSources", SOURCE_TOPIC_PARAMS);
144 map.put("topicSinks", SINK_TOPIC_PARAMS);
150 * Returns topic parameters for test cases.
152 * @return topic parameters
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"));
163 * Returns sync topic parameters for test cases.
165 * @return topic parameters
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"));
176 * Get automation composition id.
177 * @return UUID automationCompositionId
179 public UUID getAutomationCompositionId() {
184 * Create an AcElementDeploy.
186 * @return an AcElementDeploy
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);
197 * Create an InstanceElementDto.
199 * @return an InstanceElementDto
201 public InstanceElementDto createInstanceElementDto(Map<String, Object> inProperties) {
202 return new InstanceElementDto(getAutomationCompositionId(), UUID.randomUUID(),
203 new ToscaServiceTemplate(), inProperties, new HashMap<>());
208 * Create an compositionElementDto.
210 * @return an compositionElementDto
212 public CompositionElementDto createCompositionElementDto() {
213 return new CompositionElementDto(getAutomationCompositionId(), null,
214 Map.of("uninitializedToPassiveTimeout", 100, "podStatusCheckInterval", "30"), null);