Merge "Templates: show correct values of sdnc-preload, volume-group name"
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / services / testEnvironmentsService.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('TestEnvironmentsService', ['$q', '$http', '$log', 'COMPONENT', 'UtilityService', testEnvironmentsService]);
25
26     function testEnvironmentsService($q, $http, $log, COMPONENT, UtilityService) {
27         this.loadAAIestEnvironments = function(type) {
28             var deferred = $q.defer();
29             $http.get(COMPONENT.AAI_GET_TEST_ENVIRONMENTS + type)
30                 .success(function (response) {
31                     if(response.httpCode == 200) {
32                         deferred.resolve({operationalEnvironment: response.t.operationalEnvironment});
33                     }
34                     else {
35                         deferred.reject({message: response.errorMessage, status: response.httpCode});
36                     }
37                 })
38                 .error(function(data, status, headers, config) {
39                     deferred.reject({message: data, status: status});
40                 });
41
42             return deferred.promise;
43         };
44
45         this.createApplicationEnv = function(request) {
46             var deferred = $q.defer();
47
48             $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_CREATE, JSON.stringify(request.requestDetails))
49                 .success(function (response) {
50                     deferred.resolve({data: response});
51                 }).error(function (data, status) {
52                 deferred.reject({message: data, status: status});
53             });
54
55             return deferred.promise;
56         }
57
58         this.deactivateApplicationEnv = function(request) {
59             var deferred = $q.defer();
60
61             $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_DEACTIVATE + request.envId, JSON.stringify({}))
62                 .success(function (response) {
63                     deferred.resolve({data: response});
64                 }).error(function (data, status) {
65                     deferred.reject({message: data, status: status});
66             });
67
68             return deferred.promise;
69         };
70
71         this.activateApplicationEnv = function(request) {
72             var deferred = $q.defer();
73
74             $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_ACTIVATE + request.envId, JSON.stringify({
75                     "relatedInstanceId": request.relatedInstanceId
76                     , "relatedInstanceName": request.relatedInstanceName
77                     , "workloadContext": request.workloadContext
78                     , "manifest": request.manifest
79                 }))
80                 .success(function (response) {
81                     deferred.resolve({data: response});
82                 }).error(function (response, status) {
83                     UtilityService.runHttpErrorHandler({data:response, status:status});
84                 });
85             return deferred.promise;
86         };
87
88         this.getRequestStatus = function(requestId, successCallback) {
89             $http.get(COMPONENT.OPERATIONAL_ENVIRONMENT_STATUS + requestId)
90                 .success(function(response) {
91                     successCallback({data: response});
92                 } )
93                 .catch(UtilityService.runHttpErrorHandler);
94         };
95     }
96
97
98 })();
99