2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.appc.flow.controller.node;
22 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VF_MODULE;
23 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VM;
24 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.fasterxml.jackson.core.type.TypeReference;
30 import com.fasterxml.jackson.databind.DeserializationFeature;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.List;
36 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
37 import org.onap.appc.flow.controller.interfaceData.Capabilities;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
41 public class CapabilitiesDataExtractor {
43 private static final EELFLogger log = EELFManager.getInstance().getLogger(CapabilitiesDataExtractor.class);
45 private final FlowControlDBService dbService;
46 private final ObjectMapper mapper;
48 public CapabilitiesDataExtractor() {
49 this(FlowControlDBService.initialise());
53 * Ctor for tests, prefer to use default one
55 public CapabilitiesDataExtractor(FlowControlDBService dbService) {
56 this.dbService = dbService;
58 mapper = new ObjectMapper();
59 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
60 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
63 Capabilities getCapabilitiesData(SvcLogicContext ctx) throws SvcLogicException, IOException {
65 String fn = "FlowExecutorNode.getCapabilitiesData";
66 String capabilitiesData = dbService.getCapabilitiesData(ctx);
67 log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
69 Capabilities capabilities = new Capabilities();
70 if (capabilitiesData == null) {
74 JsonNode capabilitiesNode = mapper.readTree(capabilitiesData);
75 log.info("capabilitiesNode:" + capabilitiesNode.toString());
77 capabilities.getVfModule().addAll(extractParameterList(capabilitiesNode, VF_MODULE));
78 capabilities.getVnfc().addAll(extractParameterList(capabilitiesNode, VNFC));
79 capabilities.getVnf().addAll(extractParameterList(capabilitiesNode, VNF));
80 capabilities.getVm().addAll(extractParameterList(capabilitiesNode, VM));
82 log.info("Capabilities Output:" + capabilities.toString());
87 private <T> List<T> extractParameterList(JsonNode root, String parameter) throws IOException {
88 JsonNode parameterNode = root.get(parameter);
89 if (parameterNode == null) {
90 return new ArrayList<>();
92 return mapper.readValue(parameterNode.toString(), new TypeReference<List<T>>() {});