Reduce the number of problems in aai-common by removing unused imports
[aai/aai-common.git] / aai-els-onap-logging / src / main / java / org / onap / logging / ref / slf4j / ONAPLogConstants.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.logging
4  * ================================================================================
5  * Copyright © 2018 Amdocs
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.logging.ref.slf4j;
23
24 import org.slf4j.Marker;
25 import org.slf4j.MarkerFactory;
26
27 /**
28  * Constants for standard ONAP headers, MDCs, etc.
29  *
30  * <p>
31  * See <tt>package-info.java</tt>.
32  * </p>
33  */
34 public final class ONAPLogConstants {
35
36     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37     //
38     // Constructors.
39     //
40     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
41
42     /**
43      * Hide and forbid construction.
44      */
45     private ONAPLogConstants() {
46         throw new UnsupportedOperationException();
47     }
48
49     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50     //
51     // Inner classes.
52     //
53     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54
55     /**
56      * Marker constants.
57      */
58     public static final class Markers {
59
60         /** Marker reporting invocation. */
61         public static final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
62
63         /** Marker reporting invocation return. */
64         public static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE_RETURN");
65
66         /** Marker reporting synchronous invocation. */
67         public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
68
69         /** Marker reporting asynchronous invocation. */
70         public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
71
72         /** Marker reporting entry into a component. */
73         public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
74
75         /** Marker reporting exit from a component. */
76         public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
77
78         /**
79          * Build nested, detached marker.
80          * 
81          * @param m1 top token.
82          * @param m2 sub-token.
83          * @return detached Marker.
84          */
85         private static Marker build(final String m1, final String m2) {
86             final Marker marker = MarkerFactory.getDetachedMarker(m1);
87             marker.add(MarkerFactory.getDetachedMarker(m2));
88             return marker;
89         }
90
91         /**
92          * Hide and forbid construction.
93          */
94         private Markers() {
95             throw new UnsupportedOperationException();
96         }
97     }
98
99     /**
100      * MDC name constants.
101      */
102     public static final class MDCs {
103
104         // Tracing. ////////////////////////////////////////////////////////////
105
106         /** MDC correlating messages for an invocation. */
107         public static final String INVOCATION_ID = "InvocationID";
108
109         /** MDC correlating messages for a logical transaction. */
110         public static final String REQUEST_ID = "RequestID";
111
112         /** MDC recording calling partner name. */
113         public static final String PARTNER_NAME = "PartnerName";
114
115         /** MDC recording current service. */
116         public static final String SERVICE_NAME = "ServiceName";
117
118         /** MDC recording target service. */
119         public static final String TARGET_SERVICE_NAME = "TargetServiceName";
120
121         /** MDC recording target entity. */
122         public static final String TARGET_ENTITY = "TargetEntity";
123
124         /** MDC recording target element. */
125         public static final String TARGET_ELEMENT = "TargetElement";
126
127         /** MDC recording current service instance id. */
128         public static final String SERVICE_INSTANCE_ID = "ServiceInstanceID";
129
130         /** MDC recording current instance id. */
131         public static final String INSTANCE_UUID = "InstanceID";
132
133         // Network. ////////////////////////////////////////////////////////////
134
135         /** MDC recording caller address. */
136         public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
137
138         /** MDC recording server IP address. */
139         public static final String SERVER_IP_ADDRESS = "ServerIPAddress";
140
141         /** MDC recording server FQDN. */
142         public static final String SERVER_FQDN = "ServerFQDN";
143
144         /** MDC recording virtual server name. */
145         public static final String VIRTUAL_SERVER_NAME = "VirtualServerName";
146
147         /** MDC recording context name. */
148         public static final String CONTEXT_NAME = "ContextName";
149
150         /**
151          * MDC recording timestamp at the start of the current request,
152          * with the same scope as {@link #REQUEST_ID}.
153          *
154          * <p>
155          * Open issues:
156          * <ul>
157          * <ul>
158          * Easily confused with {@link #INVOKE_TIMESTAMP}.
159          * </ul>
160          * <ul>
161          * No mechanism for propagation between components, e.g. via HTTP headers.
162          * </ul>
163          * <ul>
164          * Whatever mechanism we define, it's going to be costly.
165          * </ul>
166          * </ul>
167          * </p>
168          */
169         public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
170
171         /** MDC recording timestamp at the start of the current invocation. */
172         public static final String INVOKE_TIMESTAMP = "InvokeTimestamp";
173
174         /** MDC recording elapsed time. */
175         public static final String ELAPSED_TIME = "ElapsedTime";
176
177         /** MDC recording log timestamp. */
178         public static final String LOG_TIMESTAMP = "LogTimestamp";
179
180         // Outcomes. ///////////////////////////////////////////////////////////
181
182         /** MDC reporting outcome code. */
183         public static final String RESPONSE_CODE = "ResponseCode";
184
185         /** MDC reporting outcome description. */
186         public static final String RESPONSE_DESCRIPTION = "ResponseDesc";
187
188         /** MDC reporting severity */
189         public static final String RESPONSE_SEVERITY = "Severity";
190
191         /** MDC reporting response status code */
192         public static final String RESPONSE_STATUS_CODE = "StatusCode";
193
194         /** MDC recording error code. */
195         public static final String ERROR_CODE = "ErrorCode";
196
197         /** MDC recording error description. */
198         public static final String ERROR_DESC = "ErrorDesc";
199
200         // Unsorted. ///////////////////////////////////////////////////////////
201
202         /**
203          * Hide and forbid construction.
204          */
205         private MDCs() {
206             throw new UnsupportedOperationException();
207         }
208     }
209
210     /**
211      * Header name constants.
212      */
213     public static final class Headers {
214
215         /** HTTP <tt>X-ONAP-RequestID</tt> header. */
216         public static final String REQUEST_ID = "X-ONAP-RequestID";
217
218         /** HTTP <tt>X-ONAP-InvocationID</tt> header. */
219         public static final String INVOCATION_ID = "X-ONAP-InvocationID";
220
221         /** HTTP <tt>X-ONAP-PartnerName</tt> header. */
222         public static final String PARTNER_NAME = "X-ONAP-PartnerName";
223
224         /**
225          * Hide and forbid construction.
226          */
227         private Headers() {
228             throw new UnsupportedOperationException();
229         }
230     }
231
232     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233     //
234     // Enums.
235     //
236     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
237
238     /**
239      * Response success or not, for setting <tt>StatusCode</tt>.
240      */
241     public enum ResponseStatus {
242
243         /** Success. */
244         COMPLETE,
245
246         /** Not. */
247         ERROR,
248
249         /** In Progress. */
250         INPROGRESS
251     }
252
253     /**
254      * Synchronous or asynchronous execution, for setting invocation marker.
255      */
256     public enum InvocationMode {
257
258         /** Synchronous, blocking. */
259         SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
260
261         /** Asynchronous, non-blocking. */
262         ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
263
264         /** Enum value. */
265         private String mString;
266
267         /** Corresponding marker. */
268         private Marker mMarker;
269
270         /**
271          * Construct enum.
272          *
273          * @param s enum value.
274          * @param m corresponding Marker.
275          */
276         InvocationMode(final String s, final Marker m) {
277             this.mString = s;
278             this.mMarker = m;
279         }
280
281         /**
282          * Get Marker for enum.
283          *
284          * @return Marker.
285          */
286         public Marker getMarker() {
287             return this.mMarker;
288         }
289
290         /**
291          * {@inheritDoc}
292          */
293         @Override
294         public String toString() {
295             return this.mString;
296         }
297     }
298
299 }