aboutsummaryrefslogtreecommitdiffstats
path: root/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-validationTest-controller.js
blob: 0e80836f2f946d66393c2e0bd7888f8dacad6914 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* ============LICENSE_START=======================================================
* ONAP : SDNC-FEATURES
* ================================================================================
* Copyright 2018 TechMahindra
*=================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/


myApp.controller('TestController', ['$scope', '$http', 'growl', 'viewReportService', 'validationTestService','CERTIFICATION_API_BASE', function($scope, $http, growl, viewReportService, validationTestService,CERTIFICATION_API_BASE) {

    $scope.showTestReport = false;

    //Input data for validation test dropdown
    var validationTestList = [{
            "typeId": 1,
            "validationType": "Network Layer",
            "Selected": false
        },
        {
            "typeId": 2,
            "validationType": "Protocol Layer",
            "Selected": false
        }
    ];

    $scope.validationTestList = validationTestList;


    $scope.getselectval = function() {
        $scope.selectedvalues = 'Name: ' + $scope.selitem.validationType + ' Id: ' + $scope.selitem.typeId;
    }

    $scope.showError = false;
    $scope.errorMessage = "";
    $scope.showSuccess = false;
    $scope.successMessage = "";
    $scope.showWarning = false;
    $scope.warningMessage = "";
    $scope.showInfo = false;
    $scope.infoMessage = "";
    $scope.ShowResult = false;
    $scope.allowTestSelection = false;
    $scope.hostNamePattern = /([a-z0-9](.[a-z0-9-]*[a-z0-9]))/;

    //Called when user clicks on runtest button
    $scope.runTest = function() {

        $scope.showError = false;
        $scope.vnfSelected = [];
        $scope.testSelected = [];

        var message = "";
        for (var i = 0; i < $scope.validationTestList.length; i++) {
            if ($scope.validationTestList[i].Selected) {
                var typeId = $scope.validationTestList[i].typeId;
                var validationType = $scope.validationTestList[i].validationType;
                message += "typeId: " + typeId + " validationType: " + validationType + "\n";
                console.log("--TestController::Runtest--", message);
                var testDetails = {};
                testDetails.typeId = typeId;
                testDetails.validationType = validationType;
                $scope.testSelected.push(testDetails);
            }
        }
        console.log("--TestController::Runtest--", JSON.stringify($scope.testSelected));

        var vnfDetails = {};
        if ($scope.IPAddress != null && $scope.HostName != null && $scope.testSelected.length >= 1) {
            vnfDetails.IpAddress = $scope.IPAddress;
            vnfDetails.HostName = $scope.HostName;
            $scope.vnfSelected.push(vnfDetails);
            console.log("--TestController::Runtest--", JSON.stringify($scope.vnfSelected));

            //Call the validation test service with vnfselected and testType as the parameter

            validationTestService.runPretest($scope.vnfSelected, $scope.testSelected).then(function(response) {
                    console.log("--TestController::runTest--", JSON.stringify(response));
                    
                    //in case of success, build the model object to store the service output here
                    if (response.status === 200) {
                        if (response.preTestResponse != null && response.preTestResponse.length >= 1) {
                            $scope.ShowResult = true;
                            $scope.createTestModel(response.preTestResponse);
                            $scope.showMessage(response.preTestResponse);
                         
                        } else {
                            console.log(response);
                            $scope.showError = true;
                            $scope.errorMessage = "Something went wrong!!!";
                            growl.error($scope.errorMessage, {
                                title: 'Error!',
                                globalDisableCloseButton:false
                            });
                        }
                    } else {
                        console.log(response);
                        $scope.showError = true;
                        $scope.errorMessage = "Something went wrong!!! Please try again later";
                        growl.error($scope.errorMessage, {
                            title: 'Error!',
                            globalDisableCloseButton:false
                        });
                    }
                },
                function(response) {
                    console.log("--TestController--", response);
                });
        } else {
            $scope.showError = true;
            $scope.errorMessage = "Please provide the inputs for VNF and test to be performed!!";
            growl.error($scope.errorMessage, {
                title: 'Error!',
                globalDisableCloseButton:false
            });
        }

    };
    
$scope.showMessage=function(data){
    	
        var iterate = true;
    	if(angular.isDefined(data) && data.length>=1){
    		
             iterate=true;
    		 angular.forEach(data, function(value, key){

                if(iterate=true){
    	         if(value.status == "unreachable"){
    	           console.log("--TestController::showMessage--",value.status);
    	           $scope.showError = true;
                   $scope.errorMessage = "PreTest validation Failed, Please check logs for further details!!!";
                   growl.error($scope.errorMessage, {
                     title: 'Error!',
                     globalDisableCloseButton:false
                   });
                   iterate=false;
                 }
             }
    	         else
    	        	 {
    	        	  $scope.showSuccess = true;
                      $scope.successMessage = "Pre test validation completed!!";
                      growl.success($scope.successMessage, {
                          title: 'Success!',
                          globalDisableCloseButton:false
                      });
    	        	 }
    	         
    		 });
    		
    	}   	
    }

    //Function to build the UI model to be shown
    $scope.createTestModel = function(result) {

        $scope.showError = false;
        $scope.showWarning = false;
        $scope.objPreTestModel = result;
        $scope.objPreTest = [];


        if ($scope.objPreTestModel.length >= 1) {
            for (var i = 0; i < $scope.objPreTestModel.length; i++) {
                var objTestReport = {};
                objTestReport.ipaddress = $scope.objPreTestModel[i].ipaddress;
                objTestReport.status = $scope.objPreTestModel[i].status;
                objTestReport.testtype = $scope.objPreTestModel[i].testtype;
                objTestReport.statistics = $scope.objPreTestModel[i].statistics;
                objTestReport.avgTime = $scope.objPreTestModel[i].avgTime;


                if ($scope.objPreTestModel[i].testtype === "Network Layer") {
                    if (objTestReport.statistics != null) {
                        //fetching the statistics to show in progress bar
                    	
                        var statistics = objTestReport.statistics;
                        statistics = statistics.split("%");
                        objTestReport.statistics = statistics[0];
                        if (objTestReport.statistics == 0) {
                            objTestReport.statisticPer = parseInt(objTestReport.statistics) + 50;
                        } else
                            objTestReport.statisticPer = objTestReport.statistics;
                    }

                    //fetching the avg time to show in progress bar
                    
                    if (objTestReport.avgTime != null) {
                        var avgTime = objTestReport.avgTime;
                        avgTime = avgTime.split("=");
                        var Testtime = avgTime[1];
                        objTestReport.avgTime = Testtime.slice(0, -2).trim();
                        console.log("--TestController::createTestModel--", objTestReport.avgTime);
                        if (objTestReport.avgTime < 50) {
                            objTestReport.avgTimePer = parseInt(objTestReport.avgTime) + 10;
                        } else
                            objTestReport.avgTimePer = objTestReport.avgTime;

                    }
                }
                $scope.objPreTest.push(objTestReport);
                console.log("--TestController::createTestModel--", JSON.stringify($scope.objPreTest));
            }
        }
       console.log("--TestController::createTestModel::final PreTestModel--" + JSON.stringify($scope.objPreTest));

    }

}]);