VnfInPlaceFields and ScaleOut rendered dynamically
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / services / change-management.service.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
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
21 (function () {
22     'use strict';
23
24     appDS2.service('changeManagementService', ['$http', '$q', 'COMPONENT', 'VIDCONFIGURATION', changeManagementService]);
25
26     function changeManagementService($http, $q, COMPONENT, VIDCONFIGURATION) {
27         this.getWorkflows = function (vnfs) {
28             var requestVnfs = _.map(vnfs, function (vnf) {
29                 return {
30                     UUID: vnf["modelVersionId"],
31                     invariantUUID: vnf["invariant-id"]
32                 };
33             });
34             var requestDetails = {vnfsDetails: requestVnfs};
35             return $http.post(COMPONENT.GET_WORKFLOW, requestDetails)
36             .success(function (response) {
37                 return {data: response};
38             })
39                 .catch(function () {
40                     return {data: []};
41                 });
42         };
43
44         this.getSOWorkflows = function (vnfNames) {
45             return $http.get(COMPONENT.GET_SO_WORKFLOWS, {params: {vnfName: vnfNames}})
46             .success(function (response) {
47                 return {data: response};
48             }).catch(function () {
49                 return {data: []};
50             });
51         };
52
53         this.getSOWorkflowParameter = function (workflowID){
54           return $http.get(COMPONENT.GET_SO_WORKFLOW_PARAMETER.replace('@workflowID', workflowID))
55           .success(function (response) {
56             return {data: response.parameterDefinitions}
57           });
58         };
59
60       this.getLocalWorkflowParameter = function (workflowName){
61         return $http.get(COMPONENT.GET_LOCAL_WORKFLOW_PARAMETER.replace('@workflowName', encodeURIComponent(workflowName)))
62         .success(function (response) {
63           return {data: response.parameterDefinitions}
64         });
65       };
66
67         this.getMSOChangeManagements = function() {
68             var deferred = $q.defer();
69
70             $http.get(COMPONENT.GET_MSO_WORKFLOWS)
71             .success(function (response) {
72                 deferred.resolve({data: response});
73             })
74             .error(function(data, status, headers, config) {
75                 deferred.reject({message: data, status: status});
76             });
77
78             return deferred.promise;
79         };
80
81         this.getAllSDCServices = function () {
82             var deferred = $q.defer();
83
84             $http.get(COMPONENT.SERVICES_DIST_STATUS_PATH + VIDCONFIGURATION.ASDC_MODEL_STATUS)
85             .success(function (response) {
86                 deferred.resolve({data: response});
87             })
88             .error(function(data, status, headers, config) {
89                 deferred.reject({message: data, status: status});
90             });
91
92             return deferred.promise;
93         };
94
95         this.getSDCService = function(uuid) {
96             var deferred = $q.defer();
97
98             $http.get(COMPONENT.SERVICES_PATH + uuid)
99             .success(function (response) {
100                 deferred.resolve({data: response});
101             })
102             .error(function(data, status, headers, config) {
103                 deferred.reject({message: data, status: status});
104             });
105
106             return deferred.promise;
107         };
108
109         this.getSchedulerChangeManagements = function(){
110             var deferred = $q.defer();
111
112             $http.get(COMPONENT.GET_SCHEDULER_CHANGE_MANAGEMENTS)
113                 .success(function (response) {
114                     deferred.resolve({data: response});
115                 })
116                 .error(function(data, status, headers, config) {
117                     deferred.reject({message: data, status: status});
118                 });
119
120             return deferred.promise;
121         };
122                 
123                 this.postChangeManagementNow = function (requestData, vnfName) {
124                         var url = COMPONENT.CHANGE_MANAGEMENT_OPERATION_NO_SCHEDULER.replace('@vnfName', vnfName);
125             return $http.post(url, requestData)
126             .success(function (response) {
127                 return {data: response};
128             })
129                 .catch(function (err) {
130                     return {data: []};
131                 });
132         };
133
134         this.postChangeManagementScaleOutNow = function (requestData, serviceInstanceId, vnfId) {
135             var url = "mso/mso_create_vfmodule_instance/"+serviceInstanceId+"/vnfs/"+vnfId;
136             return $http.post(url, requestData)
137                 .success(function (response) {
138                     return {data: response};
139                 })
140                 .catch(function (err) {
141                     return {data: []};
142                 });
143         };
144     }
145 })();