2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package com.onap.sdnc.vnfbackupservice.scheduler;
22 import java.util.List;
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;
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;
36 import java.time.LocalDateTime;
37 import java.time.format.DateTimeFormatter;
41 public class VnfConfigBackupScheduler {
44 VnfbackupService vnfConfigBackService;
47 VnfBackupServiceRepo vnfBackupServiceDao;
49 private static final Logger logger = Logger.getLogger(VnfbackupServiceImpl.class);
51 @Scheduled(cron = "0 0 * * * *")
52 public String initiateBackupService() {
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());
60 return lastupdatedtime;
63 public String invokeDetails(String vnfId) {
64 String formatDateTime = null;
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) {
72 vnfBackupServiceDao.insertSchedulerTime(id, formatDateTime);
74 vnfBackupServiceDao.updateSchedulerTime(formatDateTime);
75 } catch (Exception e) {
76 logger.error(":::::::::exception is at vackupVnfconfig():::: " + e);
78 vnfConfigBackService.backupVnfconfig(vnfId);
79 return formatDateTime;