2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.clds.util;
26 import org.slf4j.Marker;
27 import org.slf4j.MarkerFactory;
30 * Constants for standard ONAP headers, MDCs, etc.
32 public final class OnapLogConstants {
34 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
38 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41 * Hide and forbid construction.
43 private OnapLogConstants() {
44 throw new UnsupportedOperationException();
47 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
51 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
56 public static final class Markers {
58 /** Marker reporting invocation. */
59 public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
61 /** Marker reporting invocation return. */
62 public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
64 /** Marker reporting synchronous invocation. */
65 public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
67 /** Marker reporting asynchronous invocation. */
68 public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
70 /** Marker reporting entry into a component. */
71 public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
73 /** Marker reporting exit from a component. */
74 public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
77 * Build nested, detached marker.
79 * @param m1 top token.
80 * @param m2 sub-token.
81 * @return detached Marker.
83 private static Marker build(final String m1, final String m2) {
84 final Marker marker = MarkerFactory.getDetachedMarker(m1);
85 marker.add(MarkerFactory.getDetachedMarker(m2));
90 * Hide and forbid construction.
93 throw new UnsupportedOperationException();
100 public static final class Mdcs {
102 // Tracing. ////////////////////////////////////////////////////////////
104 /** MDC correlating messages for an invocation. */
105 public static final String INVOCATION_ID = "InvocationID";
107 public static final String SERVER_INVOCATION_ID = "ServerInvocationId";
109 public static final String CLIENT_INVOCATION_ID = "ClientInvocationId";
111 /** MDC correlating messages for a logical transaction. */
112 public static final String REQUEST_ID = "RequestID";
114 /** MDC recording calling partner name. */
115 public static final String PARTNER_NAME = "PartnerName";
117 /** MDC recording current service. */
118 public static final String SERVICE_NAME = "ServiceName";
120 /** MDC recording target service. */
121 public static final String TARGET_SERVICE_NAME = "TargetServiceName";
123 /** MDC recording InvocationID Out. */
124 public static final String INVOCATIONID_OUT = "InvocationIDOut";
126 /** MDC recording target entity. */
127 public static final String TARGET_ENTITY = "TargetEntity";
129 /** MDC recording target element. */
130 public static final String TARGET_ELEMENT = "TargetElement";
132 /** MDC recording current service instance id. */
133 public static final String SERVICE_INSTANCE_ID = "ServiceInstanceID";
135 /** MDC recording current instance id. */
136 public static final String INSTANCE_UUID = "InstanceID";
138 // Network. ////////////////////////////////////////////////////////////
140 /** MDC recording caller address. */
141 public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
143 /** MDC recording server IP address. */
144 public static final String SERVER_IP_ADDRESS = "ServerIPAddress";
146 /** MDC recording server FQDN. */
147 public static final String SERVER_FQDN = "ServerFQDN";
149 /** MDC recording virtual server name. */
150 public static final String VIRTUAL_SERVER_NAME = "VirtualServerName";
152 /** MDC recording context name. */
153 public static final String CONTEXT_NAME = "ContextName";
156 * MDC recording timestamp at the start of the current request,
157 * with the same scope as {@link #REQUEST_ID}.
163 * Easily confused with {@link #INVOKE_TIMESTAMP}.
166 * No mechanism for propagation between components, e.g. via HTTP headers.
169 * Whatever mechanism we define, it's going to be costly.
174 public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
176 /** MDC recording timestamp at the start of the current invocation. */
177 public static final String INVOKE_TIMESTAMP = "InvokeTimestamp";
179 /** MDC recording elapsed time. */
180 public static final String ELAPSED_TIME = "ElapsedTime";
182 /** MDC recording log timestamp. */
183 public static final String LOG_TIMESTAMP = "LogTimestamp";
185 // Outcomes. ///////////////////////////////////////////////////////////
187 /** MDC reporting outcome code. */
188 public static final String RESPONSE_CODE = "ResponseCode";
190 /** MDC reporting outcome description. */
191 public static final String RESPONSE_DESCRIPTION = "ResponseDesc";
193 /** MDC reporting severity */
194 public static final String RESPONSE_SEVERITY = "Severity";
196 /** MDC reporting response status code */
197 public static final String RESPONSE_STATUS_CODE = "StatusCode";
199 /** MDC recording error code. */
200 public static final String ERROR_CODE = "ErrorCode";
202 /** MDC recording error description. */
203 public static final String ERROR_DESC = "ErrorDesc";
205 // Unsorted. ///////////////////////////////////////////////////////////
208 * Hide and forbid construction.
211 throw new UnsupportedOperationException();
216 * Header name constants.
218 public static final class Headers {
220 /** HTTP <tt>X-ONAP-RequestID</tt> header. */
221 public static final String REQUEST_ID = "X-ONAP-RequestID";
223 /** HTTP <tt>X-InvocationID</tt> header. */
224 public static final String INVOCATION_ID = "X-ONAP-InvocationID";
226 /** HTTP <tt>X-ONAP-PartnerName</tt> header. */
227 public static final String PARTNER_NAME = "X-ONAP-PartnerName";
230 * Hide and forbid construction.
233 throw new UnsupportedOperationException();
237 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
241 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
244 * Response success or not, for setting <tt>StatusCode</tt>.
246 public enum ResponseStatus {
259 * Synchronous or asynchronous execution, for setting invocation marker.
261 public enum InvocationMode {
263 /** Synchronous, blocking. */
264 SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
266 /** Asynchronous, non-blocking. */
267 ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
270 private String mString;
272 /** Corresponding marker. */
273 private Marker mMarker;
278 * @param s enum value.
279 * @param m corresponding Marker.
281 InvocationMode(final String s, final Marker m) {
287 * Get Marker for enum.
291 public Marker getMarker() {
299 public String toString() {