16b13ba9626458dc4b3b7c76f3737660c5f346a8
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.data;
23
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
26 import javax.annotation.Nonnull;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Fault;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.FaultcurrentEntity;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SeverityType;
30
31 public class FaultEntityManager {
32
33     private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]");
34
35     /**
36      * The leading indication for notification or events that are not in the
37      * currentProblem data of the ONF Coremodel
38      */
39     private static final String NOCURRENTPROBLEMINDICATION = "#";
40
41     /**
42      * Specific problems are not moving into current problem list
43      * @param problemName to be verified
44      * @return true if problem is current
45      */
46     public static boolean isManagedAsCurrentProblem(String problemName) {
47         return ! problemName.startsWith(NOCURRENTPROBLEMINDICATION);
48     }
49
50     public static boolean isManagedAsCurrentProblem(Fault problem) {
51         return isManagedAsCurrentProblem(problem.getProblem());
52     }
53
54     /**
55      * Specific problems are not moving into current problem list
56      * @param fault to be verified
57      * @return true if cleared indication
58      */
59     public static boolean isNoAlarmIndication(@Nonnull Fault fault) {
60         return SeverityType.NonAlarmed.equals(fault.getSeverity());
61     }
62
63     /**
64      * Create a specific ES id for the current log.
65      * @return a string with the generated ES Id
66      */
67      public static String genSpecificEsId(String nodeName, String objectId, String problemName) {
68
69         String uuId;
70
71         Matcher matcher = pattern.matcher(objectId);
72         if (matcher.matches() && matcher.groupCount() == 1) {
73             uuId = matcher.group(1);
74         } else {
75             uuId = objectId;
76         }
77
78         StringBuffer strBuf = new StringBuffer();
79         strBuf.append(nodeName);
80         strBuf.append("/");
81         strBuf.append(uuId);
82         strBuf.append("/");
83         strBuf.append(problemName);
84         return strBuf.toString();
85     }
86
87     /**
88      * Create Es id
89      * @param fault used to create uuid for faultcurrent
90      * @return String with Id
91      */
92     public static String genSpecificEsId(FaultcurrentEntity fault) {
93         return genSpecificEsId(fault.getNodeId(), fault.getObjectId(), fault.getProblem());
94     }
95 }