make Logging a service and inject it to SyncRestClient
[vid.git] / vid-app-common / src / main / java / org / onap / vid / scheduler / SchedulerServiceImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.scheduler;
22
23 import org.onap.vid.aai.ExceptionWithRequestInfo;
24 import org.onap.vid.model.probes.ErrorMetadata;
25 import org.onap.vid.model.probes.ExternalComponentStatus;
26 import org.onap.vid.model.probes.HttpRequestMetadata;
27 import org.onap.vid.mso.RestObjectWithRequestInfo;
28 import org.onap.vid.services.ChangeManagementService;
29 import org.onap.vid.utils.Logging;
30 import org.springframework.beans.factory.annotation.Autowired;
31
32 public class SchedulerServiceImpl implements SchedulerService{
33
34     private final ChangeManagementService changeManagementService;
35
36
37     @Autowired
38     public SchedulerServiceImpl(ChangeManagementService changeManagementService) {
39         this.changeManagementService = changeManagementService;
40     }
41
42     @Override
43     public ExternalComponentStatus probeComponent() {
44         long startTime = System.currentTimeMillis();
45         try {
46             RestObjectWithRequestInfo response = this.changeManagementService.getSchedulerChangeManagementsWithRequestInfo();
47             return new ExternalComponentStatus(
48                     ExternalComponentStatus.Component.SCHEDULER,
49                     true,
50                     new HttpRequestMetadata(response, "OK", startTime)
51             );
52         } catch (ExceptionWithRequestInfo e) {
53             long duration = System.currentTimeMillis() - startTime;
54             return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
55                     false,
56                     new HttpRequestMetadata(e, duration));
57         } catch (Exception e) {
58             long duration = System.currentTimeMillis() - startTime;
59             return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER, false,
60                     new ErrorMetadata(Logging.exceptionToDescription(e), duration));
61         }
62     }
63 }