aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/webapp/app/vid/scripts/services/testEnvironmentsService.js
blob: 6ae675a01ef0f825d9d89c71741b0bd20eef2eda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(function () {
    'use strict';

    appDS2.service('TestEnvironmentsService', ['$q', '$http', '$log', 'COMPONENT', 'UtilityService', testEnvironmentsService]);

    function testEnvironmentsService($q, $http, $log, COMPONENT, UtilityService) {
        this.loadAAIestEnvironments = function(type) {
            var deferred = $q.defer();
            $http.get(COMPONENT.AAI_GET_TEST_ENVIRONMENTS + type)
                .success(function (response) {
                    if(response.httpCode == 200) {
                        deferred.resolve({operationalEnvironment: response.t.operationalEnvironment});
                    }
                    else {
                        deferred.reject({message: response.errorMessage, status: response.httpCode});
                    }
                })
                .error(function(data, status, headers, config) {
                    deferred.reject({message: data, status: status});
                });

            return deferred.promise;
        };

        this.createApplicationEnv = function(request) {
            var deferred = $q.defer();

            $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_CREATE, JSON.stringify(request.requestDetails))
                .success(function (response) {
                    deferred.resolve({data: response});
                }).error(function (data, status) {
                deferred.reject({message: data, status: status});
            });

            return deferred.promise;
        }

        this.deactivateApplicationEnv = function(request) {
            var deferred = $q.defer();

            $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_DEACTIVATE + request.envId, JSON.stringify({}))
                .success(function (response) {
                    deferred.resolve({data: response});
                }).error(function (data, status) {
                    deferred.reject({message: data, status: status});
            });

            return deferred.promise;
        };

        this.activateApplicationEnv = function(request) {
            var deferred = $q.defer();

            $http.post(COMPONENT.OPERATIONAL_ENVIRONMENT_ACTIVATE + request.envId, JSON.stringify({
                    "relatedInstanceId": request.relatedInstanceId
                    , "relatedInstanceName": request.relatedInstanceName
                    , "workloadContext": request.workloadContext
                    , "manifest": request.manifest
                }))
                .success(function (response) {
                    deferred.resolve({data: response});
                }).error(function (response, status) {
                    UtilityService.runHttpErrorHandler({data:response, status:status});
                });
            return deferred.promise;
        };

        this.getRequestStatus = function(requestId, successCallback) {
            $http.get(COMPONENT.OPERATIONAL_ENVIRONMENT_STATUS + requestId)
                .success(function(response) {
                    successCallback({data: response});
                } )
                .catch(UtilityService.runHttpErrorHandler);
        };
    }


})();