f26a30de8a137707387b7d202d1e764d912b741d
[ccsdk/features.git] /
1 /*******************************************************************************
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
19
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22 import javax.annotation.Nonnull;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Fault;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
26
27 public class FaultEntityManager {
28
29     private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]");
30
31     /**
32      * The leading indication for notification or events that are not in the
33      * currentProblem data of the ONF Coremodel
34      */
35     private static final String NOCURRENTPROBLEMINDICATION = "#";
36
37     /**
38      * Specific problems are not moving into current problem list
39      * @param problemName to be verified
40      * @return true if problem is current
41      */
42     public static boolean isManagedAsCurrentProblem(String problemName) {
43         return ! problemName.startsWith(NOCURRENTPROBLEMINDICATION);
44     }
45
46     public static boolean isManagedAsCurrentProblem(Fault problem) {
47         return isManagedAsCurrentProblem(problem.getProblem());
48     }
49
50     /**
51      * Specific problems are not moving into current problem list
52      * @param fault to be verified
53      * @return true if cleared indication
54      */
55     public static boolean isNoAlarmIndication(@Nonnull Fault fault) {
56         return SeverityType.NonAlarmed.equals(fault.getSeverity());
57     }
58
59     /**
60      * Create a specific ES id for the current log.
61      * @return a string with the generated ES Id
62      */
63      public static String genSpecificEsId(String nodeName, String objectId, String problemName) {
64
65         String uuId;
66
67         Matcher matcher = pattern.matcher(objectId);
68         if (matcher.matches() && matcher.groupCount() == 1) {
69             uuId = matcher.group(1);
70         } else {
71             uuId = objectId;
72         }
73
74         StringBuffer strBuf = new StringBuffer();
75         strBuf.append(nodeName);
76         strBuf.append("/");
77         strBuf.append(uuId);
78         strBuf.append("/");
79         strBuf.append(problemName);
80         return strBuf.toString();
81     }
82
83     /**
84      * Create Es id
85      * @param fault used to create uuid for faultcurrent
86      * @return String with Id
87      */
88     public static String genSpecificEsId(FaultcurrentEntity fault) {
89         return genSpecificEsId(fault.getNodeId(), fault.getObjectId(), fault.getProblem());
90     }
91 }