2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21 import java.io.IOException;
22 import java.util.Base64;
23 import java.util.HashMap;
25 import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPClient;
26 import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class FaultNotificationClient extends BaseHTTPClient {
32 private static final Logger LOG = LoggerFactory.getLogger(FaultNotificationClient.class);
33 private static final String FAULT_NOTIFICATION_URI = "restconf/operations/devicemanager:push-fault-notification";
34 private final Map<String, String> headerMap;
37 private static final String FAULT_PAYLOAD = "{\n"
38 + " \"devicemanager:input\": {\n"
39 + " \"devicemanager:node-id\": \"@node-id@\",\n"
40 + " \"devicemanager:counter\": \"@counter@\",\n"
41 + " \"devicemanager:timestamp\": \"@timestamp@\",\n"
42 + " \"devicemanager:object-id\": \"@object-id@\",\n"
43 + " \"devicemanager:problem\": \"@problem@\",\n"
44 + " \"devicemanager:severity\": \"@severity@\"\n"
50 public FaultNotificationClient(String baseUrl) {
53 this.headerMap = new HashMap<>();
54 this.headerMap.put("Content-Type", "application/json");
55 this.headerMap.put("Accept", "application/json");
58 public void setAuthorization(String username, String password) {
59 String credentials = username + ":" + password;
60 this.headerMap.put("Authorization", "Basic " + new String(Base64.getEncoder().encode(credentials.getBytes())));
64 public boolean sendFaultNotification(String faultNodeId, String faultCounter, String faultOccurrenceTime,
65 String faultObjectId, String faultReason, String faultSeverity) {
68 message = updateFaultPayload(faultNodeId, faultCounter, faultOccurrenceTime, faultObjectId, faultReason,
71 LOG.debug("Payload after updating values is: {}",message);
73 return sendFaultRequest("POST", message) == 200;
77 private static String updateFaultPayload(String faultNodeId, String faultCounter, String faultOccurrenceTime,
78 String faultObjectId, String faultReason, String faultSeverity) {
80 return FAULT_PAYLOAD.replace("@node-id@", faultNodeId)
81 .replace("@counter@", faultCounter)
82 .replace("@timestamp@", faultOccurrenceTime)
83 .replace("@object-id@", faultObjectId)
84 .replace("@problem@", faultReason)
85 .replace("@severity@", faultSeverity);
90 private int sendFaultRequest(String method, String message) {
91 LOG.debug("In sendFaultRequest - {}-{}",method,message);
92 BaseHTTPResponse response;
94 String uri = FAULT_NOTIFICATION_URI;
95 response = this.sendRequest(uri, method, message, headerMap);
96 LOG.debug("finished with responsecode {}", response.code);
98 } catch (IOException e) {
99 LOG.warn("problem sending fault message {}", e.getMessage());