3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Modifications Copyright (c) 2021 Nokia
9 * * ================================================================================
10 * * Licensed under the Apache License, Version 2.0 (the "License");
11 * * you may not use this file except in compliance with the License.
12 * * You may obtain a copy of the License at
14 * * http://www.apache.org/licenses/LICENSE-2.0
16 * * Unless required by applicable law or agreed to in writing, software
17 * * distributed under the License is distributed on an "AS IS" BASIS,
18 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * * See the License for the specific language governing permissions and
20 * * limitations under the License.
21 * * ============LICENSE_END=========================================================
26 package org.onap.blueprintgenerator.service.common;
28 import java.util.LinkedHashMap;
30 import java.util.TreeMap;
31 import org.onap.blueprintgenerator.constants.Constants;
32 import org.onap.blueprintgenerator.model.common.Dmaap;
33 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
34 import org.onap.blueprintgenerator.model.componentspec.common.Publishes;
35 import org.onap.blueprintgenerator.model.componentspec.common.Subscribes;
36 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
37 import org.springframework.stereotype.Service;
40 * @author : Joanna Jeremicz
41 * @date 01/15/2021 Application: ONAP - Blueprint Generator Common ONAP Service
42 * to create publishes and subscribes streams
44 @Service("streamService")
45 public class StreamService {
48 * Creates publishes stream for given Inputs and ComponentSpec
50 * @param onapComponentSpec Onap Component Specification
51 * @param blueprintHelperService Blueprint Helper Service
52 * @param dmaapService Dmaap Service
53 * @param inputs Inputs
54 * @param isDmaap Dmaap Argument
57 public Map<String, Dmaap> createStreamPublishes(
58 OnapComponentSpec onapComponentSpec,
59 BlueprintHelperService blueprintHelperService,
60 DmaapService dmaapService,
61 Map<String, LinkedHashMap<String, Object>> inputs,
64 Map<String, Dmaap> streamPublishes = new TreeMap<>();
65 if (onapComponentSpec.getStreams() == null || onapComponentSpec.getStreams().getPublishes() == null) {
66 return streamPublishes;
69 for (Publishes publishes : onapComponentSpec.getStreams().getPublishes()) {
70 if (blueprintHelperService.isDataRouterType(publishes.getType())) {
71 String config = publishes.getConfig_key();
72 String name = config + Constants._FEED;
73 Map<String, Object> dmaapDataRouterResponse =
74 dmaapService.createDmaapDataRouter(inputs, config, name, isDmaap);
76 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
78 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
79 dmaap.setType(publishes.getType());
80 streamPublishes.put(config, dmaap);
81 } else if (blueprintHelperService.isMessageRouterType(publishes.getType())) {
82 String config = publishes.getConfig_key();
83 String name = config + Constants._TOPIC;
84 Map<String, Object> dmaapDataRouterResponse =
86 .createDmaapMessageRouter(inputs, config, 'p', name, name, isDmaap);
88 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
90 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
91 dmaap.setType(publishes.getType());
92 streamPublishes.put(config, dmaap);
95 return streamPublishes;
99 * Creates subscribes stream for given Inputs and ComponentSpec
101 * @param onapComponentSpec Onap Component Specification
102 * @param blueprintHelperService Blueprint Helper Service
103 * @param dmaapService Dmaap Service
104 * @param inputs Inputs
105 * @param isDmaap Dmaap Argument
108 public Map<String, Dmaap> createStreamSubscribes(
109 OnapComponentSpec onapComponentSpec,
110 BlueprintHelperService blueprintHelperService,
111 DmaapService dmaapService,
112 Map<String, LinkedHashMap<String, Object>> inputs,
115 Map<String, Dmaap> streamSubscribes = new TreeMap<>();
116 if (onapComponentSpec.getStreams() == null || onapComponentSpec.getStreams().getSubscribes() == null) {
117 return streamSubscribes;
120 for (Subscribes subscribes : onapComponentSpec.getStreams().getSubscribes()) {
121 if (blueprintHelperService.isDataRouterType(subscribes.getType())) {
122 String config = subscribes.getConfig_key();
123 String name = config + Constants._FEED;
124 Map<String, Object> dmaapDataRouterResponse =
125 dmaapService.createDmaapDataRouter(inputs, config, name, isDmaap);
127 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
129 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
130 dmaap.setType(subscribes.getType());
131 streamSubscribes.put(config, dmaap);
132 } else if (blueprintHelperService.isMessageRouterType(subscribes.getType())) {
133 String config = subscribes.getConfig_key();
134 String name = config + Constants._TOPIC;
135 Map<String, Object> dmaapDataRouterResponse =
137 .createDmaapMessageRouter(inputs, config, 's', name, name, isDmaap);
139 (Map<String, LinkedHashMap<String, Object>>) dmaapDataRouterResponse
141 Dmaap dmaap = (Dmaap) dmaapDataRouterResponse.get("dmaap");
142 dmaap.setType(subscribes.getType());
143 streamSubscribes.put(config, dmaap);
146 return streamSubscribes;