2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.config.audit.node;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import java.util.HashMap;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
35 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 {
40 log.debug("Starting Compare Node Analysis");
42 Map<String, String> status = new HashMap<>();
43 Parameters params = new Parameters(inParams);
45 if (params.getCompareDataType() != null) {
46 if (params.getPayloadX() != null && params.getPayloadY() != null) {
47 status = getCompareResults(params);
48 log.debug("Compare Result : " + status);
50 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
51 status.put(CompareConstants.ERROR_CODE, "200");
52 status.put(CompareConstants.ERROR_MESSAGE, "One of the Data Received by CompareNode is Empty");
55 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
56 status.put(CompareConstants.ERROR_CODE, "200");
57 status.put(CompareConstants.ERROR_MESSAGE,
58 "Missing compareDataType value in input request: Expecting at least one of CLI/RESTCONF/XML");
61 } catch (Exception e) {
62 status.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
63 status.put(CompareConstants.ERROR_CODE, "200");
64 status.put(CompareConstants.ERROR_MESSAGE, CompareConstants.ERROR_MESSAGE_DETAIL);
65 log.debug("Error in Comapre Node Execution", e);
67 createContextResponse(status, ctx, params.getRequestIdentifier());
70 private HashMap<String, String> getCompareResults(Parameters params) throws Exception {
71 HashMap<String, String> resultMap = new HashMap<>();
73 CompareDataInterface handler;
75 if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_JSON)) {
76 handler = new CompareJsonData(params.getPayloadX(), params.getPayloadY());
77 } else if ((params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_XML))
78 || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.NETCONF_XML))
79 || (params.getCompareDataType().equalsIgnoreCase(CompareConstants.RESTCONF_XML))) {
80 handler = new CompareXmlData(params.getPayloadX(), params.getPayloadY());
81 } else if (params.getCompareDataType().equalsIgnoreCase(CompareConstants.FORMAT_CLI)) {
82 handler = new CompareCliData(params.getPayloadX(), params.getPayloadY());
84 throw new SvcLogicException("Format " + params.getCompareDataType() + " not supported");
87 log.debug("Received Format to compare : " + params.getCompareDataType());
89 cmpResult = handler.compare();
91 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_SUCCESS);
94 resultMap.put(CompareConstants.RESPONSE_STATUS, CompareConstants.STATUS_FAILURE);
95 resultMap.put(CompareConstants.ERROR_CODE, "500");
96 resultMap.put(CompareConstants.ERROR_MESSAGE, CompareConstants.NO_MATCH_MESSAGE);
98 } catch (Exception e) {
104 private void createContextResponse(Map<String, String> status, SvcLogicContext ctx, String requestIdentifier) {
105 String requestId = requestIdentifier == null ? "" : requestIdentifier + ".";
107 ctx.setAttribute(requestId.concat(CompareConstants.RESPONSE_STATUS),
108 status.get(CompareConstants.RESPONSE_STATUS));
109 ctx.setAttribute(requestId.concat(CompareConstants.ERROR_CODE),
110 status.get(CompareConstants.ERROR_CODE));
111 ctx.setAttribute(requestId.concat(CompareConstants.ERROR_MESSAGE),
112 status.get(CompareConstants.ERROR_MESSAGE));