summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/blueprint/Properties.java
blob: 9aa53547c88ed97a4efa5bae412c8ffa45ef84da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*============LICENSE_START=======================================================
 org.onap.dcae
 ================================================================================
 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
 Copyright (c) 2020 Nokia. All rights reserved.
 ================================================================================
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 ============LICENSE_END=========================================================
 */

package org.onap.blueprintgenerator.models.blueprint;

import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createBooleanInput;
import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createIntegerInput;
import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.createStringInput;
import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType;
import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType;
import static org.onap.blueprintgenerator.models.blueprint.tls.TlsConstants.USE_EXTERNAL_TLS_FIELD;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.TreeMap;
import lombok.Getter;
import lombok.Setter;
import org.onap.blueprintgenerator.models.blueprint.tls.ExternalCertificateParametersFactory;
import org.onap.blueprintgenerator.models.blueprint.tls.ExternalTlsInfoFactory;
import org.onap.blueprintgenerator.models.blueprint.tls.TlsInfo;
import org.onap.blueprintgenerator.models.blueprint.tls.impl.ExternalTlsInfo;
import org.onap.blueprintgenerator.models.componentspec.Auxilary;
import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
import org.onap.blueprintgenerator.models.componentspec.Publishes;
import org.onap.blueprintgenerator.models.componentspec.Subscribes;
import org.onap.blueprintgenerator.models.dmaapbp.DmaapStreams;


@Getter
@Setter
@JsonInclude(value = Include.NON_NULL)
public class Properties {

    private static final String EMPTY_VALUE = "";

    ArrayList<DmaapStreams> streams_publishes;
    ArrayList<DmaapStreams> streams_subscribes;
    private Appconfig application_config;
    private Auxilary docker_config;
    private Object image;
    private GetInput location_id;
    private String service_component_type;
    private TreeMap<String, Object> log_info;
    private String dns_name;
    private Object replicas;
    private String name;
    private GetInput topic_name;
    private GetInput feed_name;
    private TlsInfo tls_info;
    private ExternalTlsInfo external_cert;
    private ResourceConfig resource_config;
    private GetInput always_pull_image;
    private Boolean useExisting;
    @JsonIgnore
    private ExternalTlsInfoFactory externalCertFactory;

    public Properties() {
        ExternalCertificateParametersFactory externalCertificateDataFactory = new ExternalCertificateParametersFactory();
        externalCertFactory = new ExternalTlsInfoFactory(externalCertificateDataFactory);
    }

    public TreeMap<String, LinkedHashMap<String, Object>> createOnapProperties(
        TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec componentSpec, String override) {
        TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;

        //set the image
        GetInput image = new GetInput();
        image.setBpInputName("image");
        this.setImage(image);
        retInputs.put("image", createStringInput(componentSpec.getImageUri()));

        //set the location id
        GetInput location = new GetInput();
        location.setBpInputName("location_id");
        this.setLocation_id(location);
        retInputs.put("location_id", createStringInput(EMPTY_VALUE));

        //set the log info
        this.setLog_info(componentSpec.getAuxilary().getLog_info());

        //set the replicas
        GetInput replica = new GetInput();
        replica.setBpInputName("replicas");
        this.setReplicas(replica);
        LinkedHashMap<String, Object> rep = createIntegerInput("number of instances", 1);
        retInputs.put("replicas", rep);

        //set the dns name
        //this.setDns_name(cs.getSelf().getName());

        //set the name
        //this.setName(cs.getSelf().getName());

        //set the docker config
        Auxilary aux = componentSpec.getAuxilary();
//		if(aux.getPorts() != null) {
//			retInputs = aux.createPorts(retInputs);
//		}
        this.setDocker_config(aux);

        //set the app config
        Appconfig app = new Appconfig();
        retInputs = app.createAppconfig(retInputs, componentSpec, override, false);
        this.setApplication_config(app);

        // set always_pull_image
        this.always_pull_image = new GetInput();
        this.always_pull_image.setBpInputName("always_pull_image");
        LinkedHashMap<String, Object> inputAlwaysPullImage = createBooleanInput(
            "Set to true if the image should always be pulled",
            true);
        retInputs.put("always_pull_image", inputAlwaysPullImage);

        //set service component type
        String serviceComponentType = componentSpec.getSelfName().replace('.', '-');
        this.setService_component_type(serviceComponentType);

        //set the tls info for internal and external communication
        TreeMap<String, Object> tls_info = componentSpec.getAuxilary().getTls_info();
        if (tls_info != null) {
            addTlsInfo(componentSpec, retInputs);
            if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
                retInputs.putAll(addExternalTlsInfo(componentSpec));
            }
        }

        //set the reource config
        ResourceConfig resource = new ResourceConfig();
        retInputs = resource.createResourceConfig(retInputs, componentSpec.getSelf().getName());
        this.setResource_config(resource);

        return retInputs;
    }

    public TreeMap<String, LinkedHashMap<String, Object>> createDmaapProperties(
        TreeMap<String, LinkedHashMap<String, Object>> inps, ComponentSpec componentSpec, String override) {
        TreeMap<String, LinkedHashMap<String, Object>> retInputs = inps;

        //set the image
        GetInput image = new GetInput();
        image.setBpInputName("tag_version");
        this.setImage(image);
        retInputs.put("tag_version", createStringInput(componentSpec.getImageUri()));

        //set the location id
        GetInput location = new GetInput();
        location.setBpInputName("location_id");
        this.setLocation_id(location);
        retInputs.put("location_id", createStringInput(EMPTY_VALUE));

        //set the log info
        this.setLog_info(componentSpec.getAuxilary().getLog_info());

        //set service component type
        String serviceComponentType = componentSpec.getSelfName().replace('.', '-');
        this.setService_component_type(serviceComponentType);

        //set the tls info for internal and external communication
        TreeMap<String, Object> tls_info = componentSpec.getAuxilary().getTls_info();
        if (tls_info != null) {
            addTlsInfo(componentSpec, retInputs);
            if (tls_info.get(USE_EXTERNAL_TLS_FIELD) != null) {
                retInputs.putAll(addExternalTlsInfo(componentSpec));
            }
        }

        //set the replicas
        GetInput replica = new GetInput();
        replica.setBpInputName("replicas");
        this.setReplicas(replica);
        LinkedHashMap<String, Object> rep = createIntegerInput("number of instances", 1);
        retInputs.put("replicas", rep);

//		//set the dns name
//		this.setDns_name(cs.getSelf().getName());

//		//set the name
//		this.setName(cs.getSelf().getName());

        //set the docker config
        Auxilary aux = componentSpec.getAuxilary();
//		if(aux.getPorts() != null) {
//			retInputs = aux.createPorts(retInputs);
//		}
        this.setDocker_config(aux);

        //set the appconfig
        Appconfig app = new Appconfig();
        retInputs = app.createAppconfig(retInputs, componentSpec, override, true);
        this.setApplication_config(app);

        //set the stream publishes
        ArrayList<DmaapStreams> pubStreams = new ArrayList<>();
        if (componentSpec.getStreams().getPublishes() != null) {
            for (Publishes publishes : componentSpec.getStreams().getPublishes()) {
                if (isMessageRouterType(publishes.getType())) {
                    String topic = publishes.getConfig_key() + "_topic";
                    DmaapStreams mrStreams = new DmaapStreams();
                    retInputs = mrStreams
                        .createStreams(inps, componentSpec, topic, publishes.getType(), publishes.getConfig_key(),
                            publishes.getRoute(), 'p');
                    pubStreams.add(mrStreams);
                } else if (isDataRouterType(publishes.getType())) {
                    String feed = publishes.getConfig_key() + "_feed";
                    DmaapStreams drStreams = new DmaapStreams();
                    retInputs = drStreams
                        .createStreams(inps, componentSpec, feed, publishes.getType(), publishes.getConfig_key(),
                            publishes.getRoute(), 'p');
                    pubStreams.add(drStreams);
                }
            }
        }

        //set the stream subscribes
        ArrayList<DmaapStreams> subStreams = new ArrayList<>();
        if (componentSpec.getStreams().getSubscribes() != null) {
            for (Subscribes subscribes : componentSpec.getStreams().getSubscribes()) {
                if (isMessageRouterType(subscribes.getType())) {
                    String topic = subscribes.getConfig_key() + "_topic";
                    DmaapStreams mrStreams = new DmaapStreams();
                    retInputs = mrStreams
                        .createStreams(inps, componentSpec, topic, subscribes.getType(), subscribes.getConfig_key(),
                            subscribes.getRoute(), 's');
                    subStreams.add(mrStreams);
                } else if (isDataRouterType(subscribes.getType())) {
                    String feed = subscribes.getConfig_key() + "_feed";
                    DmaapStreams drStreams = new DmaapStreams();
                    retInputs = drStreams
                        .createStreams(inps, componentSpec, feed, subscribes.getType(), subscribes.getConfig_key(),
                            subscribes.getRoute(), 's');
                    subStreams.add(drStreams);
                }
            }
        }

        if (!pubStreams.isEmpty()) {
            this.setStreams_publishes(pubStreams);
        }
        if (!subStreams.isEmpty()) {
            this.setStreams_subscribes(subStreams);
        }

        //set the reource config
        ResourceConfig resource = new ResourceConfig();
        retInputs = resource.createResourceConfig(retInputs, componentSpec.getSelf().getName());
        this.setResource_config(resource);

        return retInputs;
    }

    private void addTlsInfo(ComponentSpec cs, TreeMap<String, LinkedHashMap<String, Object>> retInputs) {
        TlsInfo tlsInfo = new TlsInfo();
        tlsInfo.setCertDirectory((String) cs.getAuxilary().getTls_info().get("cert_directory"));
        GetInput useTLSFlag = new GetInput();
        useTLSFlag.setBpInputName("use_tls");
        tlsInfo.setUseTls(useTLSFlag);
        this.setTls_info(tlsInfo);
        LinkedHashMap<String, Object> useTlsFlagInput = createBooleanInput(
            "flag to indicate tls enable/disable",
            cs.getAuxilary().getTls_info().get("use_tls"));
        retInputs.put("use_tls", useTlsFlagInput);
    }

    private Map<String, LinkedHashMap<String, Object>> addExternalTlsInfo(ComponentSpec cs) {
        this.setExternal_cert(externalCertFactory.createFromComponentSpec(cs));
        return externalCertFactory.createInputListFromComponentSpec(cs);
    }

}