2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Nokia Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
23 package org.onap.clamp.clds.sdc.controller.installer;
25 import java.util.LinkedList;
26 import java.util.List;
28 import java.util.stream.Collectors;
30 import org.springframework.stereotype.Component;
33 public class ChainGenerator {
38 public List<MicroService> getChainOfMicroServices(Set<MicroService> input) {
39 LinkedList<MicroService> returnList = new LinkedList<>();
40 if (preValidate(input)) {
41 LinkedList<MicroService> theList = new LinkedList<>();
42 for (MicroService ms : input) {
43 insertNodeTemplateIntoChain(ms, theList);
45 if (postValidate(theList)) {
52 private boolean preValidate(Set<MicroService> input) {
53 List<MicroService> noInputs = input.stream().filter(ms -> "".equals(ms.getInputFrom()))
54 .collect(Collectors.toList());
55 return noInputs.size() == 1;
58 private boolean postValidate(LinkedList<MicroService> microServices) {
59 for (int i = 1; i < microServices.size() - 1; i++) {
60 MicroService prev = microServices.get(i - 1);
61 MicroService current = microServices.get(i);
62 if (!current.getInputFrom().equals(prev.getName())) {
69 private void insertNodeTemplateIntoChain(MicroService microServicetoInsert,
70 LinkedList<MicroService> chainOfMicroServices) {
72 for (int i = 0; i < chainOfMicroServices.size(); i++) {
73 MicroService current = chainOfMicroServices.get(i);
74 if (microServicetoInsert.getName().equals(current.getInputFrom())) {
77 } else if (current.getName().equals(microServicetoInsert.getInputFrom())) {
82 chainOfMicroServices.add(insertIndex, microServicetoInsert);