2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.logging.api;
20 * Builder to populate logging context data. This includes only data known to an application, and not otherwise
21 * available to the logging framework.
26 public class ContextData {
28 private final String requestId;
29 private final String serviceName;
30 private final String partnerName;
32 private ContextData(final ContextDataBuilder builder) {
33 this.requestId = builder.requestId;
34 this.serviceName = builder.serviceName;
35 this.partnerName = builder.partnerName;
39 * Uniques request ID received from a calling peer, or created.
41 * @return unique identifier of a request
43 public String getRequestId() {
48 * Service, in the context of which logs will be written.
50 * @return a string that identifies an exposed service
52 public String getServiceName() {
57 * Identifies a peer (if any).
59 * @return identification of a calling partner
61 public String getPartnerName() {
66 public String toString() {
67 return "ContextData{responseCode=" + requestId + ", responseDescription=" + serviceName
68 + ", clientIpAddress=" + partnerName + '}';
71 public static ContextDataBuilder builder() {
72 return new ContextDataBuilder();
76 * Fluent API for building context data.
78 public static class ContextDataBuilder {
80 private String requestId;
81 private String serviceName;
82 private String partnerName;
84 ContextDataBuilder() { /* package-private default constructor to hide the public one */ }
87 * Unique request ID, most likely propagated via an HTTP header.
89 * @param requestId generated or propagated request ID.
90 * @return this builder for fluent API
92 public ContextDataBuilder requestId(final String requestId) {
93 this.requestId = requestId;
98 * Name of a invoked API, by which it can be identified in the application.
100 * @param serviceName human-friendly service identifier
101 * @return this builder for fluent API
103 public ContextDataBuilder serviceName(final String serviceName) {
104 this.serviceName = serviceName;
109 * Identifier of a peer calling a service {@link #serviceName(String)}).
111 * @param partnerName an string that is received from a calling peer and can identify it
112 * @return this builder for fluent API
114 public ContextDataBuilder partnerName(final String partnerName) {
115 this.partnerName = partnerName;
120 * Create an instance of {@link ContextData}.
122 * @return a populated instance of audit data
124 public ContextData build() {
125 return new ContextData(this);