Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / scheduler / SchedulerServiceImpl.java
1 package org.onap.vid.scheduler;
2
3 import org.onap.vid.aai.ExceptionWithRequestInfo;
4 import org.onap.vid.model.probes.ErrorMetadata;
5 import org.onap.vid.model.probes.ExternalComponentStatus;
6 import org.onap.vid.model.probes.HttpRequestMetadata;
7 import org.onap.vid.mso.RestObjectWithRequestInfo;
8 import org.onap.vid.services.ChangeManagementService;
9 import org.onap.vid.utils.Logging;
10 import org.springframework.beans.factory.annotation.Autowired;
11
12 public class SchedulerServiceImpl implements SchedulerService{
13
14     private final ChangeManagementService changeManagementService;
15
16
17     @Autowired
18     public SchedulerServiceImpl(ChangeManagementService changeManagementService) {
19         this.changeManagementService = changeManagementService;
20     }
21
22     @Override
23     public ExternalComponentStatus probeGetSchedulerChangeManagements() {
24         long startTime = System.currentTimeMillis();
25         try {
26             RestObjectWithRequestInfo response = this.changeManagementService.getSchedulerChangeManagementsWithRequestInfo();
27             return new ExternalComponentStatus(
28                     ExternalComponentStatus.Component.SCHEDULER,
29                     true,
30                     new HttpRequestMetadata(response, "OK", startTime)
31             );
32         } catch (ExceptionWithRequestInfo e) {
33             long duration = System.currentTimeMillis() - startTime;
34             return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER,
35                     false,
36                     new HttpRequestMetadata(e, duration));
37         } catch (Exception e) {
38             long duration = System.currentTimeMillis() - startTime;
39             return new ExternalComponentStatus(ExternalComponentStatus.Component.SCHEDULER, false,
40                     new ErrorMetadata(Logging.exceptionToDescription(e), duration));
41         }
42     }
43 }