Don't fetch scheduled tasks when there's no scheduler
[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', 'featureFlags', changeManagementService]);
25
26     function changeManagementService($http, $q, COMPONENT, VIDCONFIGURATION, featureFlags) {
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 (vnfIDs) {
45             return $http.get(COMPONENT.GET_SO_WORKFLOWS, {params: {vnfModelId: vnfIDs}})
46             .success(function (response) {
47                 return {data: response};
48             }).catch(function (ex) {
49                 console.error("Problem when getting workflows from SO API occurred.", ex.stack);
50                 return {data: []};
51             });
52         };
53
54         this.getSOWorkflowParameter = function (workflowID){
55           return $http.get(COMPONENT.GET_SO_WORKFLOW_PARAMETER.replace('@workflowID', workflowID))
56           .success(function (response) {
57             return {data: response.parameterDefinitions}
58           });
59         };
60
61       this.getLocalWorkflowParameter = function (workflowName){
62         return $http.get(COMPONENT.GET_LOCAL_WORKFLOW_PARAMETER.replace('@workflowName', encodeURIComponent(workflowName)))
63         .success(function (response) {
64           return {data: response.parameterDefinitions}
65         });
66       };
67
68         this.getMSOChangeManagements = function() {
69             var deferred = $q.defer();
70
71             if(featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_GUILIN_CHANGEMG_SUBMIT_TO_SO)) {
72                 deferred.resolve({data: []}); // no scheduler
73             } else {
74                 $http.get(COMPONENT.GET_MSO_WORKFLOWS)
75                 .success(function (response) {
76                     deferred.resolve({data: response});
77                 })
78                 .error(function (data, status, headers, config) {
79                     deferred.reject({message: data, status: status});
80                 });
81             }
82
83             return deferred.promise;
84         };
85
86         this.getAllSDCServices = function () {
87             var deferred = $q.defer();
88
89             $http.get(COMPONENT.SERVICES_DIST_STATUS_PATH + VIDCONFIGURATION.ASDC_MODEL_STATUS)
90             .success(function (response) {
91                 deferred.resolve({data: response});
92             })
93             .error(function(data, status, headers, config) {
94                 deferred.reject({message: data, status: status});
95             });
96
97             return deferred.promise;
98         };
99
100         this.getSDCService = function(uuid) {
101             var deferred = $q.defer();
102
103             $http.get(COMPONENT.SERVICES_PATH + uuid)
104             .success(function (response) {
105                 deferred.resolve({data: response});
106             })
107             .error(function(data, status, headers, config) {
108                 deferred.reject({message: data, status: status});
109             });
110
111             return deferred.promise;
112         };
113
114         this.getSchedulerChangeManagements = function(){
115             var deferred = $q.defer();
116
117             $http.get(COMPONENT.GET_SCHEDULER_CHANGE_MANAGEMENTS)
118                 .success(function (response) {
119                     deferred.resolve({data: response});
120                 })
121                 .error(function(data, status, headers, config) {
122                     deferred.reject({message: data, status: status});
123                 });
124
125             return deferred.promise;
126         };              
127                 this.postChangeManagementNow = function (requestData, vnfName) {
128                         var url = COMPONENT.CHANGE_MANAGEMENT_OPERATION_NO_SCHEDULER.replace('@vnfName', vnfName);
129             return $http.post(url, requestData)
130             .success(function (response) {
131                 return {data: response};
132             })
133                 .catch(function (err) {
134                     return {data: []};
135                 });
136         };
137
138         this.postChangeManagementScaleOutNow = function (requestData, serviceInstanceId, vnfId) {
139             var url = "mso/mso_create_vfmodule_instance/"+serviceInstanceId+"/vnfs/"+vnfId;
140             return $http.post(url, requestData)
141                 .success(function (response) {
142                     return {data: response};
143                 })
144                 .catch(function (err) {
145                     return {data: []};
146                 });
147         };
148
149         this.postWorkflowsParametersNow = function (serviceInstanceId,vnfInstanceId,workflow_UUID,requestData) {
150             let baseUrl = "workflows-management/{serviceInstanceId}/{vnfInstanceId}/{workflow_UUID}";
151             let url = baseUrl.
152                 replace("{serviceInstanceId}",serviceInstanceId).
153                 replace("{vnfInstanceId}",vnfInstanceId).
154                 replace("{workflow_UUID}",workflow_UUID);
155
156             return $http.post(url, requestData)
157                 .success(function (response) {
158                     return {data: response};
159                 })
160                 .catch(function (err) {
161                     return {data: []};
162                 });
163         };
164
165     }
166 })();