3b74066bd073db36a525a6b63439fd4ae580f72d
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021-2023 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.common.endpoints.parameters.TopicParameters;
30 import org.onap.policy.common.utils.coder.Coder;
31 import org.onap.policy.common.utils.coder.CoderException;
32 import org.onap.policy.common.utils.coder.StandardCoder;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
34
35 public class CommonTestData {
36
37     public static final String PARTICIPANT_GROUP_NAME = "AutomationCompositionParticipantGroup";
38     public static final String DESCRIPTION = "Participant description";
39     public static final long TIME_INTERVAL = 2000;
40     public static final List<TopicParameters> TOPIC_PARAMS = List.of(getTopicParams());
41     public static final Coder CODER = new StandardCoder();
42     private static final UUID AC_ID = UUID.randomUUID();
43
44     /**
45      * Get ParticipantK8sParameters.
46      *
47      * @return ParticipantK8sParameters
48      */
49     public ParticipantK8sParameters getParticipantK8sParameters() {
50         try {
51             return CODER.convert(getParticipantK8sParametersMap(PARTICIPANT_GROUP_NAME),
52                 ParticipantK8sParameters.class);
53         } catch (final CoderException e) {
54             throw new RuntimeException("cannot create ParticipantK8sParameters from map", e);
55         }
56     }
57
58     /**
59      * Returns a property map for a ParticipantK8sParameters map for test cases.
60      *
61      * @param name name of the parameters
62      *
63      * @return a property map suitable for constructing an object
64      */
65     public Map<String, Object> getParticipantK8sParametersMap(final String name) {
66         final Map<String, Object> map = new TreeMap<>();
67
68         map.put("name", name);
69         map.put("intermediaryParameters", getIntermediaryParametersMap(false));
70         map.put("localChartDirectory", getLocalChartDir());
71         map.put("infoFileName", getInfoFileName());
72         return map;
73     }
74
75
76     /**
77      * Returns string value of local chart Directory.
78      * @return a string value
79      */
80     public String getLocalChartDir() {
81         return "/var/helm-manager/local-charts";
82     }
83
84     /**
85      * Returns string value of Info file name.
86      * @return string value
87      */
88     public String getInfoFileName() {
89         return "CHART-INFO.json";
90     }
91
92
93
94     /**
95      * Returns a property map for a intermediaryParameters map for test cases.
96      *
97      * @param isEmpty boolean value to represent that object created should be empty or not
98      * @return a property map suitable for constructing an object
99      */
100     public Map<String, Object> getIntermediaryParametersMap(final boolean isEmpty) {
101         final Map<String, Object> map = new TreeMap<>();
102         if (!isEmpty) {
103             map.put("name", "Participant parameters");
104             map.put("reportingTimeIntervalMs", TIME_INTERVAL);
105             map.put("description", DESCRIPTION);
106             map.put("participantId", getParticipantId());
107             map.put("participantType", getParticipantType());
108             map.put("clampAutomationCompositionTopics", getTopicParametersMap(false));
109             map.put("participantSupportedElementTypes", new ArrayList<>());
110         }
111
112         return map;
113     }
114
115     /**
116      * Returns participantType for test cases.
117      *
118      * @return participant Type
119      */
120     public static ToscaConceptIdentifier getParticipantType() {
121         final var participantId = new ToscaConceptIdentifier();
122         participantId.setName("K8sParticipant0");
123         participantId.setVersion("1.0.0");
124         return participantId;
125     }
126
127     /**
128      * Returns participantId for test cases.
129      *
130      * @return participant Id
131      */
132     public static UUID getParticipantId() {
133         return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c02");
134     }
135
136     /**
137      * Returns a property map for a TopicParameters map for test cases.
138      *
139      * @param isEmpty boolean value to represent that object created should be empty or not
140      * @return a property map suitable for constructing an object
141      */
142     public Map<String, Object> getTopicParametersMap(final boolean isEmpty) {
143         final Map<String, Object> map = new TreeMap<>();
144         if (!isEmpty) {
145             map.put("topicSources", TOPIC_PARAMS);
146             map.put("topicSinks", TOPIC_PARAMS);
147         }
148         return map;
149     }
150
151     /**
152      * Returns topic parameters for test cases.
153      *
154      * @return topic parameters
155      */
156     public static TopicParameters getTopicParams() {
157         final TopicParameters topicParams = new TopicParameters();
158         topicParams.setTopic("POLICY-ACRUNTIME-PARTICIPANT");
159         topicParams.setTopicCommInfrastructure("dmaap");
160         topicParams.setServers(List.of("localhost"));
161         return topicParams;
162     }
163
164     /**
165      * Get automation composition id.
166      * @return UUID automationCompositionId
167      */
168     public UUID getAutomationCompositionId() {
169         return AC_ID;
170     }
171 }