diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java')
2 files changed, 198 insertions, 19 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java index 7292762474..fdef45a57f 100644 --- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/AuditData.java @@ -17,34 +17,186 @@ package org.openecomp.sdc.logging.api; /** - * @author KATYR + * Builder to populate audit data for logging according to + * <a href="https://wiki.onap.org/download/attachments/1015849/ONAP%20application%20logging%20guidelines.pdf?api=v2> + * ONAP application logging guidelines</a>. This includes only data known to an application, and not otherwise available + * to the logging framework. + * + * @author KATYR, evitaliy * @since February 15, 2018 - * This interface defines part of the Audit log application is responsible to provide. - * Fields list is according to ONAP application logging guidelines - * (https://wiki.onap.org/download/attachments/1015849/ONAP%20application%20logging%20guidelines.pdf?api=v2) - * StartTime -> BeginTimestamp (Date-time that processing for the activities begins) - * EndTime-> EndTimestamp (Date-time that processing for the activities being logged ends) - * StatusCode -> StatusCode (indicate high level success or failure of the operation activities that is invoked) - * ResponseCode -> ResponseCode(application-specific response code returned by the operation activities) - * ResponseDescription - > ResponseDescription (human readable description of the response code) - * ClientIpAddress -> ClientIpAddress (Requesting remote client application’s IP address) */ +public class AuditData { + + // A concrete implementation interface was chosen over an interface to enable to gracefully + // add new fields without affecting client code + + private final long startTime; + private final long endTime; + private final StatusCode statusCode; + private final String responseCode; + private final String responseDescription; + private final String clientIpAddress; -public interface AuditData { + AuditData(final AuditDataBuilder builder) { + this.startTime = builder.startTime; + this.endTime = builder.endTime; + this.statusCode = builder.statusCode; + this.responseCode = builder.responseCode; + this.responseDescription = builder.responseDescription; + this.clientIpAddress = builder.clientIpAddress; + } + + /** + * Begin timestamp of an API invocation + * + * @return timestamp + */ + public long getStartTime() { + return startTime; + } - enum StatusCode { - COMPLETE, ERROR + /** + * End timestamp of an API invocation + * + * @return timestamp + */ + public long getEndTime() { + return endTime; } - long getStartTime(); + /** + * Result status of an API invocation + * + * @return protocol and application agnostic status code + */ + public StatusCode getStatusCode() { + return statusCode; + } - long getEndTime(); + /** + * Application/protocol specific response status of an API invocation + * + * @return response code + */ + public String getResponseCode() { + return responseCode; + } - StatusCode getStatusCode(); + /** + * Application/protocol specific response in a human-friendly way + * + * @return human-friendly response description + */ + public String getResponseDescription() { + return responseDescription; + } - String getResponseCode(); + /** + * IP address of the invoking client when available + * + * @return IP address + */ + public String getClientIpAddress() { + return clientIpAddress; + } - String getResponseDescription(); + @Override + public String toString() { + return "AuditData{startTime=" + startTime + ", endTime=" + endTime + ", statusCode=" + statusCode + + ", responseCode='" + responseCode + ", responseDescription=" + responseDescription + ", clientIpAddress=" + + clientIpAddress + '}'; + } - String getClientIpAddress(); + public static AuditDataBuilder builder() { + return new AuditDataBuilder(); + } + + public static class AuditDataBuilder { + + private long startTime; + private long endTime; + private StatusCode statusCode; + private String responseCode; + private String responseDescription; + private String clientIpAddress; + + AuditDataBuilder() { /* package-private default constructor to hide the public one */ } + + /** + * Begin timestamp of an activity being audited + * + * @param startTime local timestamp, usually received from {@link System#currentTimeMillis()} + * @return this builder for fluent API + */ + public AuditDataBuilder startTime(final long startTime) { + this.startTime = startTime; + return this; + } + + /** + * End timestamp of an activity being audited + * + * @param endTime local timestamp, usually received from {@link System#currentTimeMillis()} + * @return this builder for fluent API + */ + public AuditDataBuilder endTime(final long endTime) { + this.endTime = endTime; + return this; + } + + /** + * Indicate whether an invocation was successful. It is up the the application to decide if a particular result + * must be treated as a success or a failure. + * + * @param statusCode invocation status success/failure + * @return this builder for fluent API + */ + public AuditDataBuilder statusCode(final StatusCode statusCode) { + this.statusCode = statusCode; + return this; + } + + /** + * Application/protocol specific response code. For a Web API, it is likely a standard HTTP response code. + * + * @param responseCode response code that depends on application and invocation protocol + * @return this builder for fluent API + */ + public AuditDataBuilder responseCode(final String responseCode) { + this.responseCode = responseCode; + return this; + } + + /** + * Response description that explains {@link #responseCode(String)} in a human-friendly way. For a Web API, it + * is likely to be a standard HTTP response phrase. + * + * @param responseDescription human-friendly response description + * @return this builder for fluent API + */ + public AuditDataBuilder responseDescription(final String responseDescription) { + this.responseDescription = responseDescription; + return this; + } + + /** + * IP address of an invoking client. + * + * @param clientIpAddress IP address + * @return this builder for fluent API + */ + public AuditDataBuilder clientIpAddress(final String clientIpAddress) { + this.clientIpAddress = clientIpAddress; + return this; + } + + /** + * Create an instance of {@link AuditData} + * + * @return a populated instance of audit data + */ + public AuditData build() { + return new AuditData(this); + } + } } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/StatusCode.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/StatusCode.java new file mode 100644 index 0000000000..dd8bd57dcc --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/StatusCode.java @@ -0,0 +1,27 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openecomp.sdc.logging.api; + +/** + * Protocol-agnostic status codes to indicate the result status (success, failure) of an API invocation. + * + * @author EVITALIY + * @since 04 Mar 18 + */ +public enum StatusCode { + COMPLETE, ERROR +} |