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