Epic-231:versioning, and backup the configuration
[sdnc/oam.git] / configbackuprestore / vnfconfigbackupservice / src / main / webapp / js / sdnc-services / sdnc-compareConfig-service.js
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 myApp.service('deviceConfigService', ['$http','VNF_API_BASE', function($http, VNF_API_BASE) {
21
22    
23         this.getAllVNFFromRc = function() {
24         var rctestlist = {};
25         return $http.get('/getAllBackupVnfIds')
26             .then(function(response) {
27                    console.log("---validationTestService::getAllVNF From Restconf::TestResponse---" + JSON.stringify(response));
28                     vnflist = response.data;
29                     return vnflist;
30                 },
31                 function(response) {
32                    console.log("validationTestService::getAllVNF From Restconf::Status Code", response.status);
33                     return response;
34                 });
35
36     };
37     
38     
39         this.getAllVNF = function() {
40         var testlist = {};
41         return $http.get('/getAllBackupVnfIds')
42             .then(function(response) {
43                     console.log("---validationTestService::getAllVNF::TestResponse---" + JSON.stringify(response));
44                     vnflist = response.data;
45                     return vnflist;
46                 },
47                 function(response) {
48                     console.log("validationTestService::getAllVNF::Status Code", response.status);
49                     return response;
50                 });
51
52     };
53
54     this.getVersions = function(vnfId) {
55
56         var data = {};
57 //        data.selectedVnfName = vnfName;
58 //        data.selectedVnfType = vnfType;
59         data.vnfId = vnfId;
60         var config = {
61             params: data,
62             headers: {
63                 'Accept': 'application/json'
64             }
65         };
66
67         console.log("deviceConfigService::getVersions::config", JSON.stringify(config));
68
69         var baseUrl = VNF_API_BASE;
70         // var baseApi='runtest';
71         // var apiUrl= baseUrl + baseApi;
72
73         // Call the pre validation service
74         var request = {
75             method: 'GET',
76             url: '/configDetailsById/'+vnfId,
77             //url: 'sdnc-stubs/getAllConfigForVNF.json',
78             //data: data,
79             
80             headers: {
81                 'Content-Type': 'application/json',
82             }
83         };
84
85         return $http(request)
86             .then(function(response) {
87                     console.log("---deviceConfigService::getVersions::Response---" + JSON.stringify(response));
88                     return response;
89                 },
90                 function(response) {
91                     console.log("--deviceConfigService::getVersions::Status Code--", response.status);
92                     return response;
93                 });
94
95
96     }
97     
98     this.invokeBackup = function() {
99         var testlist = {};
100         return $http.get('/backup')
101             .then(function(response) {
102                     console.log("---validationTestService::getAllVNF::TestResponse---" + response);
103                     vnflist = response;
104                     return vnflist;
105                 },
106                 function(response) {
107                     console.log("validationTestService::getAllVNF::Status Code", response);
108                     return response;
109                 });
110
111     };
112     
113     this.getlastupdated = function() {
114         var testlist = {};
115         return $http.get('/backuptime')
116             .then(function(response) {
117                     console.log("---validationTestService::getBackuptime::---" + response);         
118                     return response;
119                 })          
120
121     };
122     
123     this.runApplyconfig = function(vnfid, newConfig) {
124
125  
126         
127         var url='/vnf-list/'+vnfid;
128         
129         
130         
131         var config = {
132                  headers : {
133                      'Content-Type': 'application/json'
134                  }
135              }
136
137          $http.put(url, newConfig, config)
138          .success(function(newConfig) {
139              console.log("---validationTestService::getAllVNF::TestResponse---" ,response);
140              
141              return  newConfig;
142          },
143          function(newConfig) {
144              console.log("validationTestService::getAllVNF::Status Code", response);
145              return newConfig;
146          });
147          /*.then(function (response) {
148                  if (response.data)
149                  { $scope.successMessage1 = "Put Data Method Executed Successfully!";
150                  return response;
151                  }
152                 var status=      response.status;
153                 if (status == 200){
154                  $window.alert("applyed successfully ");
155                  }
156                  var successMessage1 = "Put Data Method Executed Successfully!";
157          },
158          function (response) {
159                         var successMessage1 = "Service not Exists";
160          });
161         
162         */
163     };
164         
165
166 }]);