868e424e84d4be50f20843b59b8385a4874bfc2d
[clamp.git] / src / main / java / org / onap / clamp / flow / log / FlowLogOperation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights
6  *                             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  */
23
24 package org.onap.clamp.flow.log;
25
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28
29 import javax.servlet.http.HttpServletRequest;
30
31 import org.apache.camel.Exchange;
32 import org.onap.clamp.clds.util.LoggingUtils;
33 import org.onap.clamp.clds.util.OnapLogConstants;
34 import org.slf4j.event.Level;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.http.HttpStatus;
37 import org.springframework.stereotype.Component;
38
39 /**
40  * The Flow log operations.
41  */
42 @Component
43 public class FlowLogOperation {
44
45     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(FlowLogOperation.class);
46     protected static final EELFLogger auditLogger = EELFManager.getInstance().getMetricsLogger();
47     private LoggingUtils util = new LoggingUtils(logger);
48
49     @Autowired
50     private HttpServletRequest request;
51
52     /**
53      * Generate the entry log.
54      *
55      * @param serviceDesc
56      *        The service description the loop name
57      */
58     public void startLog(Exchange exchange, String serviceDesc) {
59         util.entering(request, serviceDesc);
60         exchange.setProperty(OnapLogConstants.Headers.REQUEST_ID, util.getProperties(OnapLogConstants.Mdcs.REQUEST_ID));
61         exchange.setProperty(OnapLogConstants.Headers.INVOCATION_ID,
62             util.getProperties(OnapLogConstants.Mdcs.INVOCATION_ID));
63         exchange.setProperty(OnapLogConstants.Headers.PARTNER_NAME,
64             util.getProperties(OnapLogConstants.Mdcs.PARTNER_NAME));
65     }
66
67     /**
68      * Generate the exiting log.
69      */
70     public void endLog() {
71         util.exiting(HttpStatus.OK.toString(), "Successful", Level.INFO, OnapLogConstants.ResponseStatus.COMPLETED);
72     }
73
74     /**
75      * Generate the error exiting log.
76      */
77     public void errorLog() {
78         util.exiting(HttpStatus.INTERNAL_SERVER_ERROR.toString(), "Failed", Level.INFO,
79             OnapLogConstants.ResponseStatus.ERROR);
80     }
81
82     /**
83      * Generate the error exiting log.
84      */
85     public void httpErrorLog() {
86
87     }
88
89     /**
90      * Generate the invoke log.
91      */
92     public void invokeLog(String targetEntity, String targetServiceName) {
93         util.invoke(targetEntity, targetServiceName);
94     }
95
96     /**
97      * Generate the invoke return marker.
98      */
99     public void invokeReturnLog() {
100         util.invokeReturn();
101     }
102 }