Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 AT&T
|
| 6 | * ================================================================================
|
| 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 | * you may not use this file except in compliance with the License.
|
| 9 | * You may obtain a copy of the License at
|
| 10 | *
|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 12 | *
|
| 13 | * Unless required by applicable law or agreed to in writing, software
|
| 14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 | * See the License for the specific language governing permissions and
|
| 17 | * limitations under the License.
|
| 18 | * ============LICENSE_END=========================================================
|
| 19 | */
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 | package org.onap.osam.services;
|
| 24 |
|
| 25 | import org.onap.osam.model.Workflow;
|
| 26 | import org.springframework.stereotype.Service;
|
| 27 |
|
| 28 | import java.util.ArrayList;
|
| 29 | import java.util.Arrays;
|
| 30 | import java.util.Collection;
|
| 31 | import java.util.stream.Collectors;
|
| 32 |
|
| 33 | @Service
|
| 34 | public class WorkflowServiceImpl implements IWorkflowService {
|
| 35 | //TODO: Add the list of workflows hard coded or from DB.
|
| 36 | private ArrayList<Workflow> workflows = new ArrayList<>(Arrays.asList(
|
| 37 | new Workflow(0, "Upgrade", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF3", "VNF4"))),
|
| 38 | new Workflow(1, "Clean", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF3"))),
|
| 39 | new Workflow(2, "Reinstall", new ArrayList<>(Arrays.asList("VNF1", "VNF2", "VNF4"))),
|
| 40 | new Workflow(3, "Dump", new ArrayList<>(Arrays.asList("VNF1", "VNF3", "VNF4"))),
|
| 41 | new Workflow(4, "Flush", new ArrayList<>(Arrays.asList("VNF2", "VNF3", "VNF4")))
|
| 42 | ));
|
| 43 |
|
| 44 | @Override
|
| 45 | public Collection<String> getWorkflowsForVNFs(Collection<String> vnfNames) {
|
| 46 | Collection<String> result = workflows.stream()
|
| 47 | .filter(workflow -> workflow.getVnfNames().containsAll(vnfNames))
|
| 48 | .map(workflow -> workflow.getWorkflowName())
|
| 49 | .distinct()
|
| 50 | .collect(Collectors.toList());
|
| 51 |
|
| 52 | return result;
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | public Collection<String> getAllWorkflows() {
|
| 57 | return workflows.stream()
|
| 58 | .map(workflow -> workflow.getWorkflowName())
|
| 59 | .distinct()
|
| 60 | .collect(Collectors.toList());
|
| 61 | }
|
| 62 | }
|