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