2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.config.audit.node;
28 import java.util.HashMap;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
38 public class CompareNode implements SvcLogicJavaPlugin
41 private static final EELFLogger log = EELFManager.getInstance().getLogger(CompareNode.class);
43 public void compare( Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException
45 log.debug("Starting Compare Node Analysis");
47 HashMap<String, String> status = new HashMap<String, String>();
48 Parameters params = new Parameters(inParams);
51 if(params.getCompareDataType() != null)
53 if(params.getPayloadX() !=null && params.getPayloadY() !=null)
55 status = getCompareResults(params);
56 log.debug("Compare Result : " + status);
60 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
61 status.put(CompareConstants.ERROR_CODE, "200");
62 status.put(CompareConstants.ERROR_MESSAGE, "One of the Data Received by CompareNode is Empty");
67 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
68 status.put(CompareConstants.ERROR_CODE, "200");
69 status.put(CompareConstants.ERROR_MESSAGE, "Missing compareDataType value in input request: Expecting at least one of CLI/RESTCONF/XML");
75 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
76 status.put(CompareConstants.ERROR_CODE, "200");
77 status.put(CompareConstants.ERROR_MESSAGE, CompareConstants.ERROR_MESSAGE_DETAIL);
78 log.debug("Error in Comapre Node Execution " + e.getMessage());
82 createContextReposne(status, ctx, params.getRequestIdentifier());
85 private HashMap<String, String> getCompareResults(Parameters params) throws Exception
87 HashMap<String, String> resultMap = new HashMap<String, String>();
88 boolean cmpResult = false;
89 CompareDataInterface handler;
93 if(params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_JSON))
94 handler = new CompareJsonData(params.getPayloadX(), params.getPayloadY());
95 else if((params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_XML))
96 || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.NETCONF_XML))
97 || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.RESTCONF_XML)))
98 handler = new CompareXmlData(params.getPayloadX(), params.getPayloadY());
99 else if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_CLI))
100 handler = new CompareCliData(params.getPayloadX(), params.getPayloadY());
103 throw new Exception("Format " + params.getCompareDataType() + " not supported");
107 log.debug("Received Format to compare : " + params.getCompareDataType());
109 cmpResult = handler.compare();
112 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_SUCCESS);
117 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
118 resultMap.put(CompareConstants.ERROR_CODE, "500");
119 resultMap.put(CompareConstants.ERROR_MESSAGE, CompareConstants.NO_MATCH_MESSAGE);
130 private void createContextReposne(HashMap status, SvcLogicContext ctx, String requestIdentifier )
132 if(requestIdentifier == null)
133 requestIdentifier = "";
135 requestIdentifier = requestIdentifier + ".";
137 ctx.setAttribute(requestIdentifier.concat( CompareConstants.RESPONSE_STATUS), (String) status.get(CompareConstants.RESPONSE_STATUS));
138 ctx.setAttribute(requestIdentifier.concat(CompareConstants.ERROR_CODE), (String) status.get(CompareConstants.ERROR_CODE));
139 ctx.setAttribute(requestIdentifier.concat(CompareConstants.ERROR_MESSAGE), (String) status.get(CompareConstants.ERROR_MESSAGE));