2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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=========================================================
21 package org.openecomp.sdnc.config.audit.node;
24 import java.util.HashMap;
28 import com.att.eelf.configuration.EELFLogger;
29 import com.att.eelf.configuration.EELFManager;
30 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
34 public class CompareNode implements SvcLogicJavaPlugin
37 private static final EELFLogger log = EELFManager.getInstance().getLogger(CompareNode.class);
39 public void compare( Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException
41 log.debug("Starting Compare Node Analysis");
43 HashMap<String, String> status = new HashMap<String, String>();
44 Parameters params = new Parameters(inParams);
47 if(params.getCompareDataType() != null)
49 if(params.getPayloadX() !=null && params.getPayloadY() !=null)
51 status = getCompareResults(params);
52 log.debug("Compare Result : " + status);
56 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
57 status.put(CompareConstants.ERROR_CODE, "200");
58 status.put(CompareConstants.ERROR_MESSAGE, "One of the Data Received by CompareNode is Empty");
63 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
64 status.put(CompareConstants.ERROR_CODE, "200");
65 status.put(CompareConstants.ERROR_MESSAGE, "Missing compareDataType value in input request: Expecting at least one of CLI/RESTCONF/XML");
71 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
72 status.put(CompareConstants.ERROR_CODE, "200");
73 status.put(CompareConstants.ERROR_MESSAGE, CompareConstants.ERROR_MESSAGE_DEATIL);
74 log.debug("Error in Comapre Node Execution " + e.getMessage());
78 createContextReposne(status, ctx, params.getRequestIdentifier());
81 private HashMap<String, String> getCompareResults(Parameters params) throws Exception
83 HashMap<String, String> resultMap = new HashMap<String, String>();
84 boolean cmpResult = false;
85 CompareDataInterface handler;
89 if(params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_JSON))
90 handler = new CompareJsonData(params.getPayloadX(), params.getPayloadY());
91 else if((params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_XML))
92 || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.NETCONF_XML))
93 || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.RESTCONF_XML)))
94 handler = new CompareXmlData(params.getPayloadX(), params.getPayloadY());
95 else if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_CLI))
96 handler = new CompareCliData(params.getPayloadX(), params.getPayloadY());
99 throw new Exception("Format " + params.getCompareDataType() + " not supported");
103 log.debug("Received Format to compare : " + params.getCompareDataType());
105 cmpResult = handler.compare();
108 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_SUCCESS);
113 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
114 resultMap.put(CompareConstants.ERROR_CODE, "500");
115 resultMap.put(CompareConstants.ERROR_MESSAGE, CompareConstants.NO_MATCH_MESSAGE);
126 private void createContextReposne(HashMap status, SvcLogicContext ctx, String requestIdentifier )
128 if(requestIdentifier == null)
129 requestIdentifier = "";
131 requestIdentifier = requestIdentifier + ".";
133 ctx.setAttribute(requestIdentifier.concat( CompareConstants.RESPONSE_STATUS), (String) status.get(CompareConstants.RESPONSE_STATUS));
134 ctx.setAttribute(requestIdentifier.concat(CompareConstants.ERROR_CODE), (String) status.get(CompareConstants.ERROR_CODE));
135 ctx.setAttribute(requestIdentifier.concat(CompareConstants.ERROR_MESSAGE), (String) status.get(CompareConstants.ERROR_MESSAGE));