summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/dmaapbp/DmaapBlueprint.java
blob: 0c8f8a9cd17247a418e4bb018414a7b2ae039994 (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
/*============LICENSE_START=======================================================
 org.onap.dcae
 ================================================================================
 Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
 ================================================================================
 Modifications 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.dmaapbp;

import java.util.LinkedHashMap;
import java.util.TreeMap;

import org.onap.blueprintgenerator.core.PgaasNodeBuilder;
import org.onap.blueprintgenerator.core.PolicyNodeBuilder;
import org.onap.blueprintgenerator.models.blueprint.Blueprint;
import org.onap.blueprintgenerator.models.blueprint.Node;
import org.onap.blueprintgenerator.models.componentspec.ComponentSpec;
import org.onap.blueprintgenerator.models.componentspec.Publishes;
import org.onap.blueprintgenerator.models.componentspec.Subscribes;

import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isDataRouterType;
import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.isMessageRouterType;
import static org.onap.blueprintgenerator.common.blueprint.BlueprintHelper.joinUnderscore;
import static org.onap.blueprintgenerator.models.blueprint.Imports.createDmaapImports;
import static org.onap.blueprintgenerator.models.blueprint.Imports.createImportsFromFile;
import static org.onap.blueprintgenerator.models.blueprint.BpConstants.CLOUDIFY_DSL_1_3;

public class DmaapBlueprint extends Blueprint {

    private static final String TOPIC = "topic";
    private static final String FEED = "feed";

    public Blueprint createDmaapBlueprint(ComponentSpec componentSpec, String importPath, String override) {
        Blueprint blueprint = new Blueprint();

        //set tosca definition
        blueprint.setTosca_definitions_version(CLOUDIFY_DSL_1_3);

        //set the description
        blueprint.setDescription(componentSpec.getSelf().getDescription());

        //create the inpus object that will be added to over the creation of the blueprint
        TreeMap<String, LinkedHashMap<String, Object>> inps = new TreeMap<>();

        //set the imports
        if (importPath.equals("")) {
            blueprint.setImports(createDmaapImports());
        } else {
            blueprint.setImports(createImportsFromFile(importPath));
        }

        //set and create the node templates
        TreeMap<String, Node> nodeTemplate = new TreeMap();

        //create and add the main dmaap node
        DmaapNode dmaap = new DmaapNode();
        inps = dmaap.createDmaapNode(componentSpec, inps, override);
        nodeTemplate.put(componentSpec.getSelf().getName(), dmaap);

        //create and add the topic/feed nodes

        //go through the streams publishes
        if (componentSpec.getStreams().getPublishes() != null) {
            for (Publishes publisher : componentSpec.getStreams().getPublishes()) {
                if (isMessageRouterType(publisher.getType())) {
                    String topic = joinUnderscore(publisher.getConfig_key(), TOPIC);
                    DmaapNode topicNode = new DmaapNode();
                    inps = topicNode.createTopicNode(componentSpec, inps, topic);
                    nodeTemplate.put(topic, topicNode);
                } else if (isDataRouterType(publisher.getType())) {
                    String feed = joinUnderscore(publisher.getConfig_key(), FEED);
                    DmaapNode feedNode = new DmaapNode();
                    inps = feedNode.createFeedNode(componentSpec, inps, feed);
                    nodeTemplate.put(feed, feedNode);
                }
            }
        }
        //go through the stream subscribes
        if (componentSpec.getStreams().getSubscribes() != null) {
            for (Subscribes subscriber : componentSpec.getStreams().getSubscribes()) {
                if (isMessageRouterType(subscriber.getType())) {
                    String topic = joinUnderscore(subscriber.getConfig_key(), TOPIC);
                    DmaapNode topicNode = new DmaapNode();
                    inps = topicNode.createTopicNode(componentSpec, inps, topic);
                    nodeTemplate.put(topic, topicNode);
                } else if (isDataRouterType(subscriber.getType())) {
                    String feed = joinUnderscore(subscriber.getConfig_key(), FEED);
                    DmaapNode feedNode = new DmaapNode();
                    inps = feedNode.createFeedNode(componentSpec, inps, feed);
                    nodeTemplate.put(feed, feedNode);
                }
            }
        }

        //if present in component spec, populate policyNodes information in the blueprint
        if (componentSpec.getPolicyInfo() != null) {
            PolicyNodeBuilder.addPolicyNodesAndInputs(componentSpec, nodeTemplate, inps);
        }

        //if present in component spec, populate pgaasNodes information in the blueprint
        if (componentSpec.getAuxilary().getDatabases() != null) {
            PgaasNodeBuilder.addPgaasNodesAndInputs(componentSpec, nodeTemplate, inps);
        }

        blueprint.setNode_templates(nodeTemplate);

        blueprint.setInputs(inps);
        return blueprint;
    }

}