2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T 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 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.client.req;
26 import java.io.IOException;
27 import java.util.List;
29 import org.onap.clamp.clds.model.prop.Global;
30 import org.onap.clamp.clds.model.prop.ModelProperties;
31 import org.onap.clamp.clds.model.prop.StringMatch;
32 import org.onap.clamp.clds.model.refprop.RefProp;
34 import com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
36 import com.fasterxml.jackson.core.JsonParseException;
37 import com.fasterxml.jackson.databind.JsonMappingException;
38 import com.fasterxml.jackson.databind.node.ObjectNode;
41 * Construct a DCAE request given CLDS objects.
43 public class DcaeReq {
44 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeReq.class);
45 protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
48 * Format DCAE request.
54 * @throws JsonMappingException
55 * @throws JsonParseException
57 public static String format(RefProp refProp, ModelProperties prop) throws IOException {
58 Global globalProp = prop.getGlobal();
60 StringMatch smProp = prop.getType(StringMatch.class);
61 prop.setCurrentModelElementId(smProp.getId());
63 ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("dcae.template");
66 ObjectNode properties = rootNode.with("properties");
68 properties.put("service_name", globalProp.getService());
70 List<String> serviceIds = refProp.decodeToList("dcae.decode.service_ids", globalProp.getService());
71 JsonUtil.addArrayField(properties, "service_ids", serviceIds);
73 JsonUtil.addArrayField(properties, "vnf_ids", globalProp.getResourceVf());
75 JsonUtil.addArrayField(properties, "location_ids", globalProp.getLocation());
78 ObjectNode template = rootNode.with("template");
79 // "string_matching":{
80 ObjectNode stringMatching = template.with("string_matching");
82 ObjectNode dcae = stringMatching.with("dcae");
84 dcae.put("inputTopic", smProp.getTopicSubscribes());
85 dcae.put("outputTopic", smProp.getTopicPublishes());
86 dcae.put("closedLoopControlName", prop.getControlName());
87 dcae.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
89 // "serviceConfigurations":[
90 StringMatchPolicyReq.appendServiceConfigurations(refProp, globalProp.getService(), dcae, smProp, prop);
92 String dcaeReq = rootNode.toString();
93 logger.info("dcaeReq=" + dcaeReq);