2 * ================================================================================
3 * Copyright (c) 2018 China Mobile. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
19 package org.onap.dcae.analytics.tca.core.util;
21 import java.util.Date;
23 import org.onap.dcae.analytics.model.TcaModelConstants;
24 import org.onap.dcae.analytics.model.ecomplogger.AnalyticsErrorType;
25 import org.onap.dcae.utils.eelf.logger.api.info.ErrorLogInfo;
26 import org.onap.dcae.utils.eelf.logger.api.info.ResponseLogInfo;
27 import org.onap.dcae.utils.eelf.logger.api.info.TargetServiceLogInfo;
28 import org.onap.dcae.utils.eelf.logger.api.spec.AuditLogSpec;
29 import org.onap.dcae.utils.eelf.logger.api.spec.DebugLogSpec;
30 import org.onap.dcae.utils.eelf.logger.api.spec.ErrorLogSpec;
31 import org.onap.dcae.utils.eelf.logger.model.info.ErrorLogInfoImpl;
32 import org.onap.dcae.utils.eelf.logger.model.info.RequestIdLogInfoImpl;
33 import org.onap.dcae.utils.eelf.logger.model.info.RequestTimingLogInfoImpl;
34 import org.onap.dcae.utils.eelf.logger.model.info.ResponseLogInfoImpl;
35 import org.onap.dcae.utils.eelf.logger.model.info.TargetServiceLogInfoImpl;
36 import org.onap.dcae.utils.eelf.logger.model.spec.AuditLogSpecImpl;
37 import org.onap.dcae.utils.eelf.logger.model.spec.DebugLogSpecImpl;
38 import org.onap.dcae.utils.eelf.logger.model.spec.ErrorLogSpecImpl;
43 public final class LogSpec {
46 // private constructor
52 * @param requestId requestId
54 * @return ErrorLogSpecImpl object
57 public static ErrorLogSpec createErrorLogSpec(final String requestId) {
58 final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId);
59 final TargetServiceLogInfo targetServiceLogInfo = new TargetServiceLogInfoImpl(
60 "DCAE-TCA", TcaModelConstants.TCA_SERVICE_NAME, "");
61 final ErrorLogInfo errorLogInfo =
62 new ErrorLogInfoImpl(AnalyticsErrorType.SCHEMA_ERROR.getErrorCode(),
63 AnalyticsErrorType.SCHEMA_ERROR.getErrorDescription());
64 return new ErrorLogSpecImpl(requestIdLogInfo,
65 TcaUtils.TCA_SERVICE_LOG_INFO, targetServiceLogInfo, errorLogInfo);
71 * @param requestId requestId
73 * @return DebugLogSpecImpl object
76 public static DebugLogSpec createDebugLogSpec(final String requestId) {
77 final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId);
78 return new DebugLogSpecImpl(requestIdLogInfo);
84 * @param requestId requestId
85 * @param requestBeginTimestamp requestBeginTimestamp
87 * @return AuditLogSpec object
90 public static AuditLogSpec createAuditLogSpec(final String requestId,
91 final Date requestBeginTimestamp) {
92 final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId);
93 final Date endTimestamp = new Date();
94 final RequestTimingLogInfoImpl requestTimingLogInfo = new RequestTimingLogInfoImpl(requestBeginTimestamp,
95 endTimestamp, endTimestamp.getTime() - requestBeginTimestamp.getTime());
96 final ResponseLogInfo responseLogInfo =
97 new ResponseLogInfoImpl(AnalyticsErrorType.SUCCESSFUL.getErrorCode(),
98 AnalyticsErrorType.SUCCESSFUL.getErrorDescription());
99 return new AuditLogSpecImpl(requestIdLogInfo, TcaUtils.TCA_SERVICE_LOG_INFO,
100 requestTimingLogInfo, responseLogInfo);