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