NonRT-RIC A1 Northbound API
[nonrtric.git] / sdnc-a1-controller / oam / configbackuprestore / vnfconfigbackupservice / src / main / java / com / onap / sdnc / vnfbackupservice / scheduler / VnfConfigBackupScheduler.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : SDNC-FEATURES
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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 package com.onap.sdnc.vnfbackupservice.scheduler;
21
22 import java.util.List;
23
24 import org.apache.log4j.Logger;
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.scheduling.annotation.EnableScheduling;
27 import org.springframework.scheduling.annotation.Scheduled;
28 import org.springframework.stereotype.Component;
29
30 import com.onap.sdnc.vnfbackupservice.dao.VnfBackupServiceRepo;
31 import com.onap.sdnc.vnfbackupservice.model.VnfDisplayParams;
32 import com.onap.sdnc.vnfbackupservice.model.VnfServiceResponse;
33 import com.onap.sdnc.vnfbackupservice.service.VnfbackupService;
34 import com.onap.sdnc.vnfbackupservice.service.VnfbackupServiceImpl;
35
36 import java.time.LocalDateTime;
37 import java.time.format.DateTimeFormatter;
38
39 @Component
40 @EnableScheduling
41 public class VnfConfigBackupScheduler {
42         
43         @Autowired
44         VnfbackupService vnfConfigBackService;
45
46         @Autowired
47         VnfBackupServiceRepo vnfBackupServiceDao;
48         
49         private static final Logger logger = Logger.getLogger(VnfbackupServiceImpl.class);
50         
51         @Scheduled(cron = "0 0 * * * *")
52         public String initiateBackupService() {
53                 
54                 String lastupdatedtime = null;
55                 VnfServiceResponse s = vnfConfigBackService.getAllVnfDetails();
56                 List<VnfDisplayParams> displayParams = s.getVnfDisplayList();
57                 for (VnfDisplayParams params : displayParams) {
58                         lastupdatedtime = invokeDetails(params.getVnfId());
59                 }
60                 return lastupdatedtime;
61         }
62
63         public String invokeDetails(String vnfId) {
64                 String formatDateTime = null;
65                 try {
66                         LocalDateTime now = LocalDateTime.now();
67                         DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
68                         formatDateTime = now.format(format);
69                         String dbschedulertime = vnfBackupServiceDao.getvnfschedulertime();
70                         if (dbschedulertime == null) {
71                                 int id = 1;
72                                 vnfBackupServiceDao.insertSchedulerTime(id, formatDateTime);
73                         }
74                         vnfBackupServiceDao.updateSchedulerTime(formatDateTime);
75                 } catch (Exception e) {
76                         logger.error(":::::::::exception is at vackupVnfconfig()::::   " + e);
77                 }
78                 vnfConfigBackService.backupVnfconfig(vnfId);
79                 return formatDateTime;
80         }
81
82 }