org.onap migration
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / services / testEnvironmentsService.js
1 (function () {
2     'use strict';
3
4     appDS2.service('TestEnvironmentsService', ['$q', '$http', '$log', 'COMPONENT', 'UtilityService', testEnvironmentsService]);
5
6     function testEnvironmentsService($q, $http, $log, COMPONENT, UtilityService) {
7         this.loadAAIestEnvironments = function(type) {
8             var deferred = $q.defer();
9             $http.get(COMPONENT.AAI_GET_TEST_ENVIRONMENTS + type)
10                 .success(function (response) {
11                     if(response.httpCode == 200) {
12                         deferred.resolve({operationalEnvironment: response.t.operationalEnvironment});
13                     }
14                     else {
15                         deferred.reject({message: response.errorMessage, status: response.httpCode});
16                     }
17                 })
18                 .error(function(data, status, headers, config) {
19                     deferred.reject({message: data, status: status});
20                 });
21
22             return deferred.promise;
23         };
24
25         this.createApplicationEnv = function(request) {
26             var deferred = $q.defer();
27
28             $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_CREATE, JSON.stringify(request.requestDetails))
29                 .success(function (response) {
30                     deferred.resolve({data: response});
31                 }).error(function (data, status) {
32                 deferred.reject({message: data, status: status});
33             });
34
35             return deferred.promise;
36         }
37
38         this.deactivateApplicationEnv = function(request) {
39             var deferred = $q.defer();
40
41             $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_DEACTIVATE + request.envId, JSON.stringify({}))
42                 .success(function (response) {
43                     deferred.resolve({data: response});
44                 }).error(function (data, status) {
45                     deferred.reject({message: data, status: status});
46             });
47
48             return deferred.promise;
49         };
50
51         this.activateApplicationEnv = function(request) {
52             var deferred = $q.defer();
53
54             $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_ACTIVATE + request.envId, JSON.stringify({
55                     "relatedInstanceId": request.relatedInstanceId
56                     , "relatedInstanceName": request.relatedInstanceName
57                     , "workloadContext": request.workloadContext
58                     , "manifest": request.manifest
59                 }))
60                 .success(function (response) {
61                     deferred.resolve({data: response});
62                 }).error(function (response, status) {
63                     UtilityService.runHttpErrorHandler({data:response, status:status});
64                 });
65             return deferred.promise;
66         };
67
68         this.getRequestStatus = function(requestId, successCallback) {
69             $http.get(COMPONENT.OPERATIONAL_ENVIRONMENT_STATUS + requestId)
70                 .success(function(response) {
71                     successCallback({data: response});
72                 } )
73                 .catch(UtilityService.runHttpErrorHandler);
74         };
75     }
76
77
78 })();
79