aboutsummaryrefslogtreecommitdiffstats
path: root/configbackuprestore/vnfconfigbackupservice/src/main/java
diff options
context:
space:
mode:
authorDushyantSinghThakur <dt00503496@techmahindra.com>2018-09-06 12:46:04 +0530
committerDan Timoney <dt5972@att.com>2018-09-12 13:10:46 +0000
commit43d4b00848ebd0567b020fe219f07d4f7049ff0b (patch)
treef5c09d0006348c82a94693605349e79db4889b71 /configbackuprestore/vnfconfigbackupservice/src/main/java
parent4e2db0d6e56bc19425e6afa3efc7011820942e9e (diff)
Epic-231:versioning, and backup the configuration
Merging the sdnc jira stories- 255,256 Change-Id: Iacb9274dae93f534f1331c4eb7d0669896d379d4 Issue-ID: SDNC-256 Signed-off-by: DushyantSinghThakur <dt00503496@techmahindra.com> Former-commit-id: 94d8b3d82b82dedfd5949da2e5d1ed348ab066e2
Diffstat (limited to 'configbackuprestore/vnfconfigbackupservice/src/main/java')
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ApplicationConfiguration.java49
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ServletInitializer.java32
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/controller/VnfBackupServiceController.java74
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/dao/VnfBackupServiceRepo.java68
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigDetailsDB.java137
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigSchedulerTimeStamp.java55
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfDisplayParams.java39
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfServiceResponse.java36
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfConfigBackupScheduler.java82
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClient.java58
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupService.java31
-rw-r--r--configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupServiceImpl.java234
12 files changed, 895 insertions, 0 deletions
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ApplicationConfiguration.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ApplicationConfiguration.java
new file mode 100644
index 00000000..03d65a68
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ApplicationConfiguration.java
@@ -0,0 +1,49 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.config;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.web.client.RestTemplate;
+
+@SpringBootApplication
+@EnableJpaRepositories("com.onap.sdnc.*")
+@EntityScan("com.onap.sdnc.*")
+@ComponentScan({"com.onap.sdnc.*"})
+@EnableAutoConfiguration
+public class ApplicationConfiguration {
+ private static final Logger logger = LogManager.getLogger(ApplicationConfiguration.class);
+ public static void main(String[] args) {
+
+ SpringApplication.run(ApplicationConfiguration.class, args);
+ logger.info("SDNC REPORTS API Has Started..");
+ }
+ @Bean
+ public RestTemplate template() {
+ return new RestTemplate();
+ }
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ServletInitializer.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ServletInitializer.java
new file mode 100644
index 00000000..5267262f
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/config/ServletInitializer.java
@@ -0,0 +1,32 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.config;
+
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.support.SpringBootServletInitializer;
+
+public class ServletInitializer extends SpringBootServletInitializer {
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(ApplicationConfiguration.class);
+ }
+
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/controller/VnfBackupServiceController.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/controller/VnfBackupServiceController.java
new file mode 100644
index 00000000..a04aac7f
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/controller/VnfBackupServiceController.java
@@ -0,0 +1,74 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.controller;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.onap.sdnc.vnfbackupservice.model.VnfServiceResponse;
+import com.onap.sdnc.vnfbackupservice.scheduler.VnfConfigBackupScheduler;
+import com.onap.sdnc.vnfbackupservice.service.VnfbackupService;
+
+@RestController
+public class VnfBackupServiceController {
+
+ @Autowired
+ VnfbackupService vnfbackupService;
+
+ @Autowired
+ VnfConfigBackupScheduler vnfConfigBackupScheduler;
+
+ @RequestMapping("/")
+ ModelAndView home(ModelAndView modelAndView) {
+ modelAndView.setViewName("index");
+ return modelAndView;
+ }
+
+ @RequestMapping(value="/getAllVnfIds", method=RequestMethod.GET,produces="application/json")
+ public VnfServiceResponse getAllVnfIds() {
+ return vnfbackupService.getAllVnfDetails();
+ }
+
+ @RequestMapping(value="/backupVnfconfigById/{vnfId}", method=RequestMethod.GET)
+ public String getAllVnfIds(@PathVariable("vnfId") String vnfId) {
+ return vnfbackupService.backupVnfconfig(vnfId);
+ }
+
+ @RequestMapping(value="/vnf-list/{vnf-Id}", method=RequestMethod.PUT)
+ public String putOneVnfconfig(@RequestBody String configfile, @PathVariable("vnf-Id") String vnfId) {
+ String vnfconfigupdated = vnfbackupService.putVnfconfig(configfile,vnfId);
+ return vnfconfigupdated;
+ }
+
+ @RequestMapping(value="/backup", method=RequestMethod.GET, produces="application/text")
+ public String backupVnfConfigs() {
+ return "current time: " + vnfConfigBackupScheduler.initiateBackupService() ;
+ }
+
+ @RequestMapping(value="/backuptime", method=RequestMethod.GET, produces="application/text")
+ public String lastUpdatedBackuptime() {
+ return vnfbackupService.updatedBackuptime();
+ }
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/dao/VnfBackupServiceRepo.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/dao/VnfBackupServiceRepo.java
new file mode 100644
index 00000000..7a132338
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/dao/VnfBackupServiceRepo.java
@@ -0,0 +1,68 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.dao;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+import javax.transaction.Transactional;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+
+import com.onap.sdnc.vnfbackupservice.model.VnfConfigDetailsDB;
+
+@Repository
+public interface VnfBackupServiceRepo extends JpaRepository<VnfConfigDetailsDB, Long> {
+
+ @Query(value = "Select * from vnfconfigdetails where vnfid = :vnfid", nativeQuery = true)
+ List<VnfConfigDetailsDB> getVnfDetails(@Param("vnfid") String vnfid);
+
+ @Query(value = "Select * from vnfconfigdetails where vnfid = :vnfid ORDER BY vnfversion DESC LIMIT 1", nativeQuery = true)
+ VnfConfigDetailsDB getVnfDetail(@Param("vnfid") String vnfid);
+
+ @Modifying
+ @Query(value = "insert into vnfconfigdetails (configinfo,creationdate,lastupdated,status,vnfid,vnfname,vnfversion) VALUES (:configinfo,:creationdate,:lastupdated,:status,:vnfid,:vnfname,:vnfversion)", nativeQuery = true)
+ @Transactional
+ void saveVnfDetails(@Param("configinfo") String configinfo, @Param("creationdate") Timestamp creationDate,
+ @Param("lastupdated") Timestamp lastupdated, @Param("status") int status, @Param("vnfid") String vnfid,
+ @Param("vnfname") String vnfname,@Param("vnfversion") String vnfversion);
+
+ @Query(value = "Select configinfo && vnfversion from vnfconfigdetails where vnfid = :vnfid", nativeQuery = true)
+ List<VnfConfigDetailsDB> getVnfDetailhavingAllVersion(@Param("vnfid") String vnfid);
+
+ @Query(value = "Select backuptime from vnfschedulertime where id=1", nativeQuery = true)
+ String getvnfschedulertime();
+
+ @Modifying
+ @Query(value = "insert into vnfschedulertime(id, backuptime) VALUES (:id, :backuptime)", nativeQuery = true)
+ @Transactional
+ void insertSchedulerTime(@Param("id") int id, @Param("backuptime") String backuptime);
+
+ @Modifying
+ @Query(value = "UPDATE vnfschedulertime SET backuptime =:formatDateTime WHERE id = 1", nativeQuery = true)
+ @Transactional
+ void updateSchedulerTime(@Param("formatDateTime") String formatDateTime);
+
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigDetailsDB.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigDetailsDB.java
new file mode 100644
index 00000000..5ac86b3d
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigDetailsDB.java
@@ -0,0 +1,137 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.model;
+
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Table;
+import org.springframework.data.annotation.CreatedDate;
+import org.springframework.data.annotation.LastModifiedDate;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
+@Entity
+@Table(name = "vnfconfigdetails", schema = "testreports")
+@JsonIgnoreProperties(value = {"createdAt", "updatedAt"},
+ allowGetters = true)
+public class VnfConfigDetailsDB implements Serializable{
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private int id;
+
+ @Column(name = "vnfid")
+ private String vnfid;
+
+ @Column(name = "vnfversion")
+ private String vnfversion;
+
+ @Column(name = "vnfname")
+ private String vnfname;
+
+ @Column(name = "configinfo")
+ @Lob
+ private String configinfo;
+
+ @Column(nullable = false, updatable = false,columnDefinition="DATETIME")
+ @CreatedDate
+ private Timestamp creationdate;
+
+ @Column(nullable = false,columnDefinition="DATETIME")
+ @LastModifiedDate
+ private Timestamp lastupdated;
+
+ @Column(name = "status")
+ private int status;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getVnfid() {
+ return vnfid;
+ }
+
+ public void setVnfid(String vnfid) {
+ this.vnfid = vnfid;
+ }
+
+ public String getVnfversion() {
+ return vnfversion;
+ }
+
+ public void setVnfversion(String vnfversion) {
+ this.vnfversion = vnfversion;
+ }
+
+ public String getVnfname() {
+ return vnfname;
+ }
+
+ public void setVnfname(String vnfname) {
+ this.vnfname = vnfname;
+ }
+
+ public String getConfiginfo() {
+ return configinfo;
+ }
+
+ public void setConfiginfo(String configinfo) {
+ this.configinfo = configinfo;
+ }
+
+ public Timestamp getCreationdate() {
+ return creationdate;
+ }
+
+ public void setCreationdate(Timestamp creationdate) {
+ this.creationdate = creationdate;
+ }
+
+ public int getStatus() {
+ return status;
+ }
+
+ public void setStatus(int status) {
+ this.status = status;
+ }
+
+ public Timestamp getLastupdated() {
+ return lastupdated;
+ }
+
+ public void setLastupdated(Timestamp lastupdated) {
+ this.lastupdated = lastupdated;
+ }
+
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigSchedulerTimeStamp.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigSchedulerTimeStamp.java
new file mode 100644
index 00000000..a5293265
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfConfigSchedulerTimeStamp.java
@@ -0,0 +1,55 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.model;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "vnfschedulertime", schema = "testreports")
+public class VnfConfigSchedulerTimeStamp {
+
+ @Id
+ @GeneratedValue
+ private int id;
+
+ @Column(name = "backuptime")
+ private String backuptime;
+
+ public String getBackuptime() {
+ return backuptime;
+ }
+
+ public void setBackuptime(String backuptime) {
+ this.backuptime = backuptime;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfDisplayParams.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfDisplayParams.java
new file mode 100644
index 00000000..9f0753bf
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfDisplayParams.java
@@ -0,0 +1,39 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.model;
+
+public class VnfDisplayParams {
+
+ private String vnfName;
+ private String vnfId;
+
+ public String getVnfName() {
+ return vnfName;
+ }
+ public void setVnfName(String vnfName) {
+ this.vnfName = vnfName;
+ }
+ public String getVnfId() {
+ return vnfId;
+ }
+ public void setVnfId(String vnfId) {
+ this.vnfId = vnfId;
+ }
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfServiceResponse.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfServiceResponse.java
new file mode 100644
index 00000000..e9c311fb
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/model/VnfServiceResponse.java
@@ -0,0 +1,36 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class VnfServiceResponse {
+
+ private List<VnfDisplayParams> vnfDisplayList = new ArrayList<VnfDisplayParams>();
+
+ public List<VnfDisplayParams> getVnfDisplayList() {
+ return vnfDisplayList;
+ }
+
+ public void setVnfDisplayList(List<VnfDisplayParams> vnfDisplayList) {
+ this.vnfDisplayList = vnfDisplayList;
+ }
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfConfigBackupScheduler.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfConfigBackupScheduler.java
new file mode 100644
index 00000000..13363300
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfConfigBackupScheduler.java
@@ -0,0 +1,82 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.scheduler;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import com.onap.sdnc.vnfbackupservice.dao.VnfBackupServiceRepo;
+import com.onap.sdnc.vnfbackupservice.model.VnfDisplayParams;
+import com.onap.sdnc.vnfbackupservice.model.VnfServiceResponse;
+import com.onap.sdnc.vnfbackupservice.service.VnfbackupService;
+import com.onap.sdnc.vnfbackupservice.service.VnfbackupServiceImpl;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+@Component
+@EnableScheduling
+public class VnfConfigBackupScheduler {
+
+ @Autowired
+ VnfbackupService vnfConfigBackService;
+
+ @Autowired
+ VnfBackupServiceRepo vnfBackupServiceDao;
+
+ private static final Logger logger = Logger.getLogger(VnfbackupServiceImpl.class);
+
+ @Scheduled(cron = "0 0 * * * *")
+ public String initiateBackupService() {
+
+ String lastupdatedtime = null;
+ VnfServiceResponse s = vnfConfigBackService.getAllVnfDetails();
+ List<VnfDisplayParams> displayParams = s.getVnfDisplayList();
+ for (VnfDisplayParams params : displayParams) {
+ lastupdatedtime = invokeDetails(params.getVnfId());
+ }
+ return lastupdatedtime;
+ }
+
+ public String invokeDetails(String vnfId) {
+ String formatDateTime = null;
+ try {
+ LocalDateTime now = LocalDateTime.now();
+ DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss");
+ formatDateTime = now.format(format);
+ String dbschedulertime = vnfBackupServiceDao.getvnfschedulertime();
+ if (dbschedulertime == null) {
+ int id = 1;
+ vnfBackupServiceDao.insertSchedulerTime(id, formatDateTime);
+ }
+ vnfBackupServiceDao.updateSchedulerTime(formatDateTime);
+ } catch (Exception e) {
+ logger.error(":::::::::exception is at vackupVnfconfig():::: " + e);
+ }
+ vnfConfigBackService.backupVnfconfig(vnfId);
+ return formatDateTime;
+ }
+
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClient.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClient.java
new file mode 100644
index 00000000..2af4e084
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClient.java
@@ -0,0 +1,58 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.scheduler;
+
+
+import java.util.Arrays;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+
+@Service
+public class VnfRestClient {
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ public String vnfRestClient(String url, String userName, String password) {
+ restTemplate = new RestTemplate();
+ HttpHeaders headers = new HttpHeaders();
+ HttpEntity<String> entity = new HttpEntity<String>(generateHeaders(headers, userName, password));
+ ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
+ String result = response.getBody();
+ return result;
+ }
+
+ public HttpHeaders generateHeaders(HttpHeaders headers, String userName, String password) {
+ headers.setAccept(Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON }));
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ String base64Username = userName + ":" + password;
+ byte[] message = base64Username.getBytes();
+ headers.set("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString(message));
+ return headers;
+ }
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupService.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupService.java
new file mode 100644
index 00000000..d7cb1f51
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupService.java
@@ -0,0 +1,31 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.service;
+
+import com.onap.sdnc.vnfbackupservice.model.VnfServiceResponse;
+
+public interface VnfbackupService {
+
+ public VnfServiceResponse getAllVnfDetails();
+ public String backupVnfconfig(String vnfId);
+ public String putVnfconfig(String configfile, String vnfId);
+ public String updatedBackuptime();
+
+}
diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupServiceImpl.java b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupServiceImpl.java
new file mode 100644
index 00000000..c3c86df7
--- /dev/null
+++ b/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/service/VnfbackupServiceImpl.java
@@ -0,0 +1,234 @@
+/*
+* ============LICENSE_START=======================================================
+* ONAP : SDNC-FEATURES
+* ================================================================================
+* Copyright 2018 TechMahindra
+*=================================================================================
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+* ============LICENSE_END=========================================================
+*/
+package com.onap.sdnc.vnfbackupservice.service;
+
+import java.io.IOException;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.onap.sdnc.vnfbackupservice.dao.VnfBackupServiceRepo;
+import com.onap.sdnc.vnfbackupservice.model.VnfConfigDetailsDB;
+import com.onap.sdnc.vnfbackupservice.model.VnfDisplayParams;
+import com.onap.sdnc.vnfbackupservice.model.VnfServiceResponse;
+
+import com.onap.sdnc.vnfbackupservice.scheduler.VnfConfigBackupScheduler;
+import com.onap.sdnc.vnfbackupservice.scheduler.VnfRestClient;
+
+@Service
+public class VnfbackupServiceImpl implements VnfbackupService {
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ VnfBackupServiceRepo vnfBackupServiceDao;
+
+ @Autowired
+ VnfConfigBackupScheduler vnfConfigBackupScheduler;
+
+ @Value("${sdnc.rest.vnf.api.host}")
+ private String host;
+
+ @Value("${sdnc.rest.vnf.api.port}")
+ private String port;
+
+ @Value("${sdnc.rest.vnf.api.basepath}")
+ private String basePath;
+
+ @Value("${sdnc.rest.vnf.api.username}")
+ private String username;
+
+ @Value("${sdnc.rest.vnf.api.password}")
+ private String password;
+
+ @Autowired
+ VnfRestClient vnfRestClientlocal;
+
+ private static final Logger logger = Logger.getLogger(VnfbackupServiceImpl.class);
+
+ @Override
+ public VnfServiceResponse getAllVnfDetails() {
+ VnfServiceResponse vnfServiceResponse = new VnfServiceResponse();
+ String finalURL = "http://" + host + ":" + port + basePath + "/config/VNF-API:vnfs";
+ String response = vnfRestClientlocal.vnfRestClient(finalURL, username, password);
+ List<VnfDisplayParams> displayParams = parseVnfConfigDetails(response);
+ vnfServiceResponse.setVnfDisplayList(displayParams);
+ return vnfServiceResponse;
+ }
+
+ public List<VnfDisplayParams> parseVnfConfigDetails(String jsonInput) {
+ List<VnfDisplayParams> displayParams = new ArrayList<VnfDisplayParams>();
+
+ try {
+ JSONObject vnf = new JSONObject(jsonInput);
+ JSONArray vnfList = vnf.getJSONObject("vnfs").getJSONArray("vnf-list");
+
+ for (int i = 0; i < vnfList.length(); i++) {
+ VnfDisplayParams vnfDisplayParams = new VnfDisplayParams();
+ String responseStatus = vnfList.getJSONObject(i).getJSONObject("service-status").get("response-code")
+ .toString();
+ if ("200".equalsIgnoreCase(responseStatus)) {
+ String vnfId = vnfList.getJSONObject(i).get("vnf-id").toString();
+ String vnfName = vnfList.getJSONObject(i).getJSONObject("service-data")
+ .getJSONObject("vnf-request-information").get("vnf-name").toString();
+ vnfDisplayParams.setVnfId(vnfId);
+ vnfDisplayParams.setVnfName(vnfName);
+ displayParams.add(vnfDisplayParams);
+ }
+ }
+ } catch (JSONException e) {
+ logger.error("Exception is at parseVnfConfigDetails() : " + e);
+ }
+ return displayParams;
+ }
+
+ @Override
+ public String backupVnfconfig(String vnfId) {
+ long millis = System.currentTimeMillis();
+ Timestamp date = new java.sql.Timestamp(millis);
+ String finalURL = "http://" + host + ":" + port + basePath + "/config/VNF-API:vnfs/vnf-list/" + vnfId;
+ logger.debug("connecting to restconf device:::" + finalURL);
+ String response = vnfRestClientlocal.vnfRestClient(finalURL, username, password);
+ String configInfo = response;
+ Timestamp creationDate = date;
+ Timestamp lastupdated = date;
+ int status = 1;
+ String vnfid = vnfId;
+ String vnfname = "";
+ VnfConfigDetailsDB getVnfDetails = null;
+ String vnfversion = "Version-1";
+ try {
+ getVnfDetails = vnfBackupServiceDao.getVnfDetail(vnfId);
+ } catch (Exception e) {
+ logger.error("exception is at getVnfdetails() : " + e);
+ }
+ if (getVnfDetails == null) {
+ JSONObject vnf;
+ try {
+ vnf = new JSONObject(response);
+ vnfname = vnf.getJSONArray("vnf-list").getJSONObject(0).getJSONObject("service-data")
+ .getJSONObject("vnf-request-information").get("vnf-name").toString();
+
+ } catch (JSONException e) {
+ logger.error("exception is at getVnfdetails() : " + e);
+ }
+ vnfBackupServiceDao.saveVnfDetails(configInfo, creationDate, lastupdated, status, vnfid, vnfname,
+ vnfversion);
+ } else {
+ try {
+ String[] vnfvesionsplit = getVnfDetails.getVnfversion().split("-");
+ int tmpVnfversion = Integer.parseInt(vnfvesionsplit[1]) + 1;
+ vnfversion = vnfvesionsplit[0] + "-" + String.valueOf(tmpVnfversion);
+
+ ObjectMapper om = new ObjectMapper();
+ try {
+ Map<String, Object> m1 = (Map<String, Object>) (om.readValue(getVnfDetails.getConfiginfo(),
+ Map.class));
+ Map<String, Object> m2 = (Map<String, Object>) (om.readValue(response, Map.class));
+
+ JSONObject vnf;
+ vnf = new JSONObject(response);
+ vnfname = vnf.getJSONArray("vnf-list").getJSONObject(0).getJSONObject("service-data")
+ .getJSONObject("vnf-request-information").get("vnf-name").toString();
+
+ if (!m1.equals(m2)) {
+ vnfBackupServiceDao.saveVnfDetails(configInfo, creationDate, lastupdated, status, vnfid,
+ vnfname, vnfversion);
+ }
+ } catch (Exception e) {
+ logger.error("exception is at getVnfdetails() : " + e);
+ }
+ } catch (Exception e) {
+ logger.error("exception is at getVnfdetails() : " + e);
+ }
+ }
+ return "success";
+ }
+
+ @Override
+ public String putVnfconfig(String configfile, String vnfId) {
+
+ String indented = null;
+
+ if (configfile != null) {
+ restTemplate = new RestTemplate();
+ String finalURL = "http://" + host + ":" + port + basePath + "/config/VNF-API:vnfs/vnf-list/" + vnfId;
+
+ HttpHeaders headers = new HttpHeaders();
+
+ logger.info("connecting to restconf device:::" + finalURL);
+ String response = vnfRestClientlocal.vnfRestClient(finalURL, username, password);
+ logger.info(response);
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ Object json = mapper.readValue(response, Object.class);
+ indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json);
+ logger.info(indented);
+ } catch (JsonParseException e) {
+ logger.error("exception occer" + e);
+ } catch (JsonMappingException e) {
+ logger.error("exception occer" + e);
+ } catch (IOException e) {
+ logger.error("exception occer" + e);
+ }
+
+ if (!(configfile.equals(indented))) {
+ HttpEntity<String> requestEntity = new HttpEntity<String>(configfile,
+ vnfRestClientlocal.generateHeaders(headers, username, password));
+
+ ResponseEntity<String> uri = restTemplate.exchange(finalURL, HttpMethod.PUT, requestEntity,
+ String.class);
+ logger.info(uri.getStatusCode());
+ if (uri.getStatusCodeValue() == 200) {
+ vnfConfigBackupScheduler.initiateBackupService();
+ }
+ return "ok";
+ } else {
+ throw new RuntimeException("Both configurations are same");
+ }
+ }
+ return "ok";
+ }
+
+ @Override
+ public String updatedBackuptime() {
+ String sdtime = vnfBackupServiceDao.getvnfschedulertime();
+ return sdtime;
+ }
+
+}