Add Enum
[logging-analytics.git] / reference / logging-slf4j / 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>See <tt>package-info.java</tt>.</p>
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 synchronous invocation. */
62         public static final Marker INVOKE_SYNCHRONOUS = build("INVOKE", "SYNCHRONOUS");
63
64         /** Marker reporting asynchronous invocation. */
65         public static final Marker INVOKE_ASYNCHRONOUS = build("INVOKE", "ASYNCHRONOUS");
66
67         /** Marker reporting entry into a component. */
68         public static final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
69
70         /** Marker reporting exit from a component. */
71         public static final Marker EXIT = MarkerFactory.getMarker("EXIT");
72
73         /**
74          * Build nested, detached marker.
75          * @param m1 top token.
76          * @param m2 sub-token.
77          * @return detached Marker.
78          */
79         private static Marker build(final String m1, final String m2) {
80             final Marker marker = MarkerFactory.getDetachedMarker(m1);
81             marker.add(MarkerFactory.getDetachedMarker(m2));
82             return marker;
83         }
84
85         /**
86          * Hide and forbid construction.
87          */
88         private Markers() {
89             throw new UnsupportedOperationException();
90         }
91     }
92
93     /**
94      * MDC name constants.
95      */
96     public static final class MDCs {
97
98         // Tracing. ////////////////////////////////////////////////////////////
99
100         /** MDC correlating messages for an invocation. */
101         public static final String INVOCATION_ID = "InvocationID";
102
103         /** MDC correlating messages for a logical transaction. */
104         public static final String REQUEST_ID = "RequestID";
105
106         /** MDC recording calling service. */
107         public static final String PARTNER_NAME = "PartnerName";
108
109         /** MDC recording current service. */
110         public static final String SERVICE_NAME = "ServiceName";
111
112         /** MDC recording target service. */
113         public static final String TARGET_SERVICE_NAME = "TargetServiceName";
114
115         /** MDC recording current service instance. */
116         public static final String INSTANCE_UUID = "InstanceUUID";
117
118         // Network. ////////////////////////////////////////////////////////////
119
120         /** MDC recording caller address. */
121         public static final String CLIENT_IP_ADDRESS = "ClientIPAddress";
122
123         /** MDC recording server address. */
124         public static final String SERVER_FQDN = "ServerFQDN";
125
126         /**
127          * MDC recording timestamp at the start of the current request,
128          * with the same scope as {@link #REQUEST_ID}.
129          *
130          * <p>Open issues:
131          * <ul>
132          *     <ul>Easily confused with {@link #INVOKE_TIMESTAMP}.</ul>
133          *     <ul>No mechanism for propagation between components, e.g. via HTTP headers.</ul>
134          *     <ul>Whatever mechanism we define, it's going to be costly.</ul>
135          * </ul>
136          * </p>
137          * */
138         public static final String ENTRY_TIMESTAMP = "EntryTimestamp";
139
140         /** MDC recording timestamp at the start of the current invocation. */
141         public static final String INVOKE_TIMESTAMP = "InvokeTimestamp";
142
143         // Outcomes. ///////////////////////////////////////////////////////////
144
145         /** MDC reporting outcome code. */
146         public static final String RESPONSE_CODE = "ResponseCode";
147
148         /** MDC reporting outcome description. */
149         public static final String RESPONSE_DESCRIPTION = "ResponseDescription";
150
151         /** MDC reporting outcome error level. */
152         public static final String RESPONSE_SEVERITY = "Severity";
153
154         /** MDC reporting outcome error level. */
155         public static final String RESPONSE_STATUS_CODE = "StatusCode";
156
157         // Unsorted. ///////////////////////////////////////////////////////////
158
159         /**
160          * Hide and forbid construction.
161          */
162         private MDCs() {
163             throw new UnsupportedOperationException();
164         }
165     }
166
167     /**
168      * Header name constants.
169      */
170     public static final class Headers {
171
172         /** HTTP <tt>X-ONAP-RequestID</tt> header. */
173         public static final String REQUEST_ID = "X-ONAP-RequestID";
174
175         /** HTTP <tt>X-ONAP-InvocationID</tt> header. */
176         public static final String INVOCATION_ID = "X-ONAP-InvocationID";
177
178         /** HTTP <tt>X-ONAP-PartnerName</tt> header. */
179         public static final String PARTNER_NAME = "X-ONAP-PartnerName";
180
181         /**
182          * Hide and forbid construction.
183          */
184         private Headers() {
185             throw new UnsupportedOperationException();
186         }
187     }
188
189     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
190     //
191     // Enums.
192     //
193     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
194
195     /**
196      * Response success or not, for setting <tt>StatusCode</tt>.
197      */
198     public enum ResponseStatus {
199
200         /** Success. */
201         COMPLETED,
202
203         /** Not. */
204         ERROR,
205         
206         /** In Progress. */
207         INPROGRESS
208     }
209
210     /**
211      * Synchronous or asynchronous execution, for setting invocation marker.
212      */
213     public enum InvocationMode {
214
215         /** Synchronous, blocking. */
216         SYNCHRONOUS("SYNCHRONOUS", Markers.INVOKE_SYNCHRONOUS),
217
218         /** Asynchronous, non-blocking. */
219         ASYNCHRONOUS("ASYNCHRONOUS", Markers.INVOKE_ASYNCHRONOUS);
220
221         /** Enum value. */
222         private String mString;
223
224         /** Corresponding marker. */
225         private Marker mMarker;
226
227         /**
228          * Construct enum.
229          *
230          * @param s enum value.
231          * @param m corresponding Marker.
232          */
233         InvocationMode(final String s, final Marker m) {
234             this.mString = s;
235             this.mMarker = m;
236         }
237
238         /**
239          * Get Marker for enum.
240          *
241          * @return Marker.
242          */
243         public Marker getMarker() {
244             return this.mMarker;
245         }
246
247         /**
248          * {@inheritDoc}
249          */
250         @Override
251         public String toString() {
252             return this.mString;
253         }
254     }
255
256 }