summaryrefslogtreecommitdiffstats
path: root/cmso-ticketmgt/src/main/java/org/onap/observations
diff options
context:
space:
mode:
Diffstat (limited to 'cmso-ticketmgt/src/main/java/org/onap/observations')
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java103
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java62
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java96
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java15
-rw-r--r--cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java48
5 files changed, 238 insertions, 86 deletions
diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java b/cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java
index 32aa60c..41fd3df 100644
--- a/cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java
+++ b/cmso-ticketmgt/src/main/java/org/onap/observations/Mdc.java
@@ -1,32 +1,33 @@
/*
* Copyright © 2019 AT&T Intellectual Property.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- *
+ *
+ *
* Unless otherwise specified, all documentation contained herein is licensed
* under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* https://creativecommons.org/licenses/by/4.0/
- *
+ *
* Unless required by applicable law or agreed to in writing, documentation
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.observations;
import static com.att.eelf.configuration.Configuration.MDC_BEGIN_TIMESTAMP;
@@ -39,6 +40,7 @@ import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_DESC;
import static com.att.eelf.configuration.Configuration.MDC_STATUS_CODE;
import static com.att.eelf.configuration.Configuration.MDC_TARGET_ENTITY;
import static com.att.eelf.configuration.Configuration.MDC_TARGET_SERVICE_NAME;
+
import com.att.eelf.utils.Stopwatch;
import java.net.URI;
import java.util.Date;
@@ -58,8 +60,13 @@ import org.slf4j.MDC;
* EELF logging MDC fields not defined in the MDC Configuration (i.e. MDC_ALERT_SEVERITY)
**/
public class Mdc {
+
+ /** The Constant SERVICE_NAME. */
public static final String SERVICE_NAME = "CSS-Scheduler";
+ /**
+ * The Enum Enum.
+ */
public enum Enum {
// BeginTimestamp,
// EndTimeStamp,
@@ -92,54 +99,105 @@ public class Mdc {
Timer,
}
+ /**
+ * Gets the caller.
+ *
+ * @param back the back
+ * @return the caller
+ */
public static String getCaller(int back) {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
return stackTraceElements[back].getClassName() + "." + stackTraceElements[back].getMethodName();
}
+ /**
+ * Sets the caller.
+ *
+ * @param back the new caller
+ */
public static void setCaller(int back) {
String caller = MDC.get(Enum.ClassName.name());
- if (caller == null)
+ if (caller == null) {
MDC.put(Enum.ClassName.name(), getCaller(back));
+ }
}
- public static void setObservation(ObservationInterface o) {
- MDC.put(Enum.CustomField4.name(), o.name());
+ /**
+ * Sets the observation.
+ *
+ * @param obs the new observation
+ */
+ public static void setObservation(ObservationInterface obs) {
+ MDC.put(Enum.CustomField4.name(), obs.name());
}
+ /**
+ * Clear caller.
+ */
public static void clearCaller() {
MDC.remove(Enum.ClassName.name());
}
+ /**
+ * Save.
+ *
+ * @return the map
+ */
public static Map<String, String> save() {
Map<String, String> save = MDC.getCopyOfContextMap();
return save;
}
+ /**
+ * Restore.
+ *
+ * @param mdcSave the mdc save
+ */
public static void restore(Map<String, String> mdcSave) {
MDC.clear();
- for (String name : mdcSave.keySet())
+ for (String name : mdcSave.keySet()) {
MDC.put(name, mdcSave.get(name));
+ }
}
+ /**
+ * Sets the request id if not set.
+ *
+ * @param requestId the new request id if not set
+ */
public static void setRequestIdIfNotSet(String requestId) {
if (MDC.get(MDC_KEY_REQUEST_ID) == null || MDC.get(MDC_KEY_REQUEST_ID).equals("")) {
setRequestId(requestId);
}
}
+ /**
+ * Sets the request id.
+ *
+ * @param requestId the new request id
+ */
public static void setRequestId(String requestId) {
MDC.put(MDC_KEY_REQUEST_ID, requestId);
}
+ /**
+ * Metric start.
+ *
+ * @param requestContext the request context
+ */
public static void metricStart(ClientRequestContext requestContext) {
MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP));
setPartnerTargetFromUri(requestContext.getUri());
}
+ /**
+ * Metric end.
+ *
+ * @param response the response
+ */
public static void metricEnd(ClientResponseContext response) {
Date now = new Date();
@@ -149,13 +207,19 @@ public class Mdc {
}
+ /**
+ * Audit start.
+ *
+ * @param requestContext the request context
+ * @param servletRequest the servlet request
+ */
public static void auditStart(ContainerRequestContext requestContext, HttpServletRequest servletRequest) {
MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP));
MDC.put(MDC_REMOTE_HOST, servletRequest.getRemoteHost());
MDC.put(Enum.ClassName.name(), getCaller(4));
MultivaluedMap<String, String> headers = requestContext.getHeaders();
- String transactionId = (String) headers.getFirst(HeadersEnum.TransactionID.toString());
+ String transactionId = headers.getFirst(HeadersEnum.TransactionID.toString());
if (transactionId != null) {
setRequestId(transactionId);
} else {
@@ -164,6 +228,12 @@ public class Mdc {
}
+ /**
+ * Audit end.
+ *
+ * @param requestContext the request context
+ * @param response the response
+ */
public static void auditEnd(ContainerRequestContext requestContext, ContainerResponseContext response) {
Date now = new Date();
// MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(now));
@@ -185,10 +255,15 @@ public class Mdc {
MDC.put(MDC_STATUS_CODE, completed);
}
- public static void setEvent(String requestID) {
+ /**
+ * Sets the event.
+ *
+ * @param requestId the new event
+ */
+ public static void setEvent(String requestId) {
MDC.put(MDC_BEGIN_TIMESTAMP, Stopwatch.isoFormatter.format(new Date()));
MDC.put(MDC_END_TIMESTAMP, MDC.get(MDC_BEGIN_TIMESTAMP));
- setRequestId(requestID);
+ setRequestId(requestId);
}
private static void setPartnerTargetFromUri(URI uri) {
diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java b/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java
index c936444..f140aec 100644
--- a/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java
+++ b/cmso-ticketmgt/src/main/java/org/onap/observations/MessageHeaders.java
@@ -35,7 +35,14 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+/**
+ * The Class MessageHeaders.
+ */
public class MessageHeaders {
+
+ /**
+ * The Enum HeadersEnum.
+ */
public enum HeadersEnum {
UNDEFINED("UNDEFINED"),
TransactionID("X-TransactionId"),
@@ -50,51 +57,98 @@ public class MessageHeaders {
this.text = text;
}
+ /**
+ * To string.
+ *
+ * @return the string
+ */
@Override
public String toString() {
return text;
}
}
+ /** The Constant supportedMajorVersions. */
public static final Map<String, String> supportedMajorVersions = new HashMap<String, String>();
+
static {
supportedMajorVersions.put("v1", "0");
supportedMajorVersions.put("v2", "0");
}
+
+ /** The Constant supportedMajorMinorVersions. */
public static final Set<String> supportedMajorMinorVersions = new HashSet<String>();
+
static {
supportedMajorMinorVersions.add("v1.0");
supportedMajorMinorVersions.add("v2.0");
}
+
+ /** The Constant latestVersion. */
public static final String latestVersion = "2.0.0";
+
+ /** The Constant patchVersion. */
public static final String patchVersion = "0";
+ /**
+ * From string.
+ *
+ * @param text the text
+ * @return the headers enum
+ */
public static HeadersEnum fromString(String text) {
- for (HeadersEnum e : HeadersEnum.values())
- if (e.text.equals(text))
+ for (HeadersEnum e : HeadersEnum.values()) {
+ if (e.text.equals(text)) {
return e;
+ }
+ }
return HeadersEnum.UNDEFINED;
}
+ /**
+ * Gets the patch version.
+ *
+ * @return the patch version
+ */
public static String getPatchVersion() {
return patchVersion;
}
+ /**
+ * Gets the latest version.
+ *
+ * @return the latest version
+ */
public static String getLatestVersion() {
return latestVersion;
}
+ /**
+ * Validate major version.
+ *
+ * @param major the major
+ * @return true, if successful
+ */
public static boolean validateMajorVersion(String major) {
String majorKey = major.toLowerCase();
- if (!supportedMajorVersions.containsKey(majorKey))
+ if (!supportedMajorVersions.containsKey(majorKey)) {
return false;
+ }
return true;
}
+ /**
+ * Validate major minor version.
+ *
+ * @param major the major
+ * @param minor the minor
+ * @return true, if successful
+ */
public static boolean validateMajorMinorVersion(String major, String minor) {
String majorKey = major.toLowerCase();
- if (!supportedMajorVersions.containsKey(majorKey))
+ if (!supportedMajorVersions.containsKey(majorKey)) {
return false;
+ }
if (minor != null) {
String majorMinorKey = majorKey + "." + minor;
diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java b/cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java
index 83b8f8d..8d053bf 100644
--- a/cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java
+++ b/cmso-ticketmgt/src/main/java/org/onap/observations/Observation.java
@@ -1,32 +1,33 @@
/*
* Copyright © 2019 AT&T Intellectual Property.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- *
+ *
+ *
* Unless otherwise specified, all documentation contained herein is licensed
* under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* https://creativecommons.org/licenses/by/4.0/
- *
+ *
* Unless required by applicable law or agreed to in writing, documentation
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.observations;
import com.att.eelf.configuration.EELFLogger;
@@ -41,73 +42,86 @@ public class Observation {
private static EELFLogger errors = EELFManager.getInstance().getErrorLogger();
private static EELFLogger debug = EELFManager.getInstance().getDebugLogger();
+ /**
+ * Report.
+ *
+ * @param obs the obs
+ * @param exc the exc
+ * @param arguments the arguments
+ */
// *************************************************************************************************
- public static void report(ObservationInterface o, Exception e, String... arguments) {
+ public static void report(ObservationInterface obs, Exception exc, String... arguments) {
Mdc.setCaller(4);
- Mdc.setObservation(o);
- if (o.getAudit()) {
- audit.info(o, e, arguments);
+ Mdc.setObservation(obs);
+ if (obs.getAudit()) {
+ audit.info(obs, exc, arguments);
}
- if (o.getMetric()) {
- metrics.info(o, e, arguments);
+ if (obs.getMetric()) {
+ metrics.info(obs, exc, arguments);
}
- Level l = o.getLevel();
- switch (l.toInt()) {
+ Level lev = obs.getLevel();
+ switch (lev.toInt()) {
case Level.WARN_INT:
- errors.warn(o, arguments);
- debug.debug(o, e, arguments);
+ errors.warn(obs, arguments);
+ debug.debug(obs, exc, arguments);
break;
case Level.INFO_INT:
- log.info(o, e, arguments);
- debug.debug(o, e, arguments);
+ log.info(obs, exc, arguments);
+ debug.debug(obs, exc, arguments);
break;
case Level.ERROR_INT:
- errors.error(o, arguments);
- debug.debug(o, e, arguments);
+ errors.error(obs, arguments);
+ debug.debug(obs, exc, arguments);
break;
case Level.TRACE_INT:
- debug.trace(o, e, arguments);
+ debug.trace(obs, exc, arguments);
break;
case Level.DEBUG_INT:
- debug.debug(o, e, arguments);
+ debug.debug(obs, exc, arguments);
break;
default:
- log.info(o, e, arguments);
+ log.info(obs, exc, arguments);
}
Mdc.clearCaller();
}
- public static void report(ObservationInterface o, String... arguments) {
+ /**
+ * Report.
+ *
+ * @param obs the obs
+ * @param arguments the arguments
+ */
+ public static void report(ObservationInterface obs, String... arguments) {
Mdc.setCaller(4);
- Mdc.setObservation(o);
- if (o.getAudit()) {
- audit.info(o, arguments);
+ Mdc.setObservation(obs);
+ if (obs.getAudit()) {
+ audit.info(obs, arguments);
}
- if (o.getMetric()) {
- metrics.info(o, arguments);
+ if (obs.getMetric()) {
+ metrics.info(obs, arguments);
}
- Level l = o.getLevel();
- switch (l.toInt()) {
+ Level lev = obs.getLevel();
+ switch (lev.toInt()) {
case Level.WARN_INT:
- errors.warn(o, arguments);
- debug.debug(o, arguments);
+ errors.warn(obs, arguments);
+ debug.debug(obs, arguments);
break;
case Level.INFO_INT:
- log.info(o, arguments);
- debug.debug(o, arguments);
+ log.info(obs, arguments);
+ debug.debug(obs, arguments);
break;
case Level.ERROR_INT:
- errors.error(o, arguments);
- debug.debug(o, arguments);
+ errors.error(obs, arguments);
+ debug.debug(obs, arguments);
break;
case Level.TRACE_INT:
- debug.debug(o, arguments);
+ debug.debug(obs, arguments);
break;
case Level.DEBUG_INT:
- debug.debug(o, arguments);
+ debug.debug(obs, arguments);
break;
default:
- log.info(o, arguments);
+ log.info(obs, arguments);
}
Mdc.clearCaller();
}
diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java
index 7a16a3f..ebe657a 100644
--- a/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java
+++ b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationInterface.java
@@ -1,32 +1,33 @@
/*
* Copyright © 2019 AT&T Intellectual Property.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- *
+ *
+ *
* Unless otherwise specified, all documentation contained herein is licensed
* under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* https://creativecommons.org/licenses/by/4.0/
- *
+ *
* Unless required by applicable law or agreed to in writing, documentation
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.observations;
import com.att.eelf.i18n.EELFResolvableErrorEnum;
diff --git a/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java
index f41c134..8544047 100644
--- a/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java
+++ b/cmso-ticketmgt/src/main/java/org/onap/observations/ObservationObject.java
@@ -1,32 +1,33 @@
/*
* Copyright © 2019 AT&T Intellectual Property.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- *
+ *
+ *
* Unless otherwise specified, all documentation contained herein is licensed
* under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* https://creativecommons.org/licenses/by/4.0/
- *
+ *
* Unless required by applicable law or agreed to in writing, documentation
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.observations;
import com.att.eelf.i18n.EELFResolvableErrorEnum;
@@ -44,24 +45,30 @@ public class ObservationObject implements ObservationInterface {
//
//
private Enum<?> value = null;
- private Level level = null;;
+ private Level level = null;
private String message = null;
private Status status = null;
private String domain = null;
private Boolean metric = false;
private Boolean audit = false;
- public ObservationObject(ObservationInterface o) {
- this.value = o.getValue();
- this.level = o.getLevel();
- this.message = o.getMessage();
- this.status = o.getStatus();
- this.domain = o.getDomain();
- this.metric = o.getMetric();
- this.audit = o.getAudit();
+ /**
+ * Instantiates a new observation object.
+ *
+ * @param obs the o
+ */
+ public ObservationObject(ObservationInterface obs) {
+ this.value = obs.getValue();
+ this.level = obs.getLevel();
+ this.message = obs.getMessage();
+ this.status = obs.getStatus();
+ this.domain = obs.getDomain();
+ this.metric = obs.getMetric();
+ this.audit = obs.getAudit();
}
+ @Override
public Enum<?> getValue() {
return value;
}
@@ -71,6 +78,11 @@ public class ObservationObject implements ObservationInterface {
return message;
}
+ public String getMessage(String... arguments) {
+ return EELFResourceManager.format((EELFResolvableErrorEnum) value, arguments);
+ }
+
+
@Override
public Status getStatus() {
return status;
@@ -101,10 +113,6 @@ public class ObservationObject implements ObservationInterface {
return metric;
}
- public String getMessage(String... arguments) {
- return EELFResourceManager.format((EELFResolvableErrorEnum) value, arguments);
- }
-
public void setValue(Enum<?> value) {
this.value = value;
}