fix debug log
[dcaegen2/analytics/tca-gen2.git] / dcae-analytics / dcae-analytics-tca-core / src / main / java / org / onap / dcae / analytics / tca / core / util / LogSpec.java
1 /*
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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=========================================================
17  *
18  */
19 package org.onap.dcae.analytics.tca.core.util;
20
21 import java.util.Date;
22
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;
39
40 /**
41  * @author Kai Lu
42  */
43 public final class LogSpec {
44
45     private LogSpec( ) {
46         // private constructor
47     }
48
49     /**
50      * create ErrorLogSpec
51      *
52      * @param requestId requestId
53      *
54      * @return ErrorLogSpecImpl object
55      *
56      */
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);
66     }
67
68     /**
69      * create DebugLogSpec
70      *
71      * @param requestId requestId
72      *
73      * @return DebugLogSpecImpl object
74      *
75      */
76     public static DebugLogSpec createDebugLogSpec(final String requestId) {
77         final RequestIdLogInfoImpl requestIdLogInfo = new RequestIdLogInfoImpl(requestId);
78         return new DebugLogSpecImpl(requestIdLogInfo);
79     }
80
81     /**
82      * create AuditLogSpec
83      *
84      * @param requestId requestId
85      * @param requestBeginTimestamp requestBeginTimestamp
86      *
87      * @return AuditLogSpec object
88      *
89      */
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);
101     }
102
103 }