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