2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 myApp.controller('TestController', ['$scope', '$http', 'growl', 'viewReportService', 'validationTestService','CERTIFICATION_API_BASE', function($scope, $http, growl, viewReportService, validationTestService,CERTIFICATION_API_BASE) {
24 $scope.showTestReport = false;
26 //Input data for validation test dropdown
27 var validationTestList = [{
29 "validationType": "Network Layer",
34 "validationType": "Protocol Layer",
39 $scope.validationTestList = validationTestList;
42 $scope.getselectval = function() {
43 $scope.selectedvalues = 'Name: ' + $scope.selitem.validationType + ' Id: ' + $scope.selitem.typeId;
46 $scope.showError = false;
47 $scope.errorMessage = "";
48 $scope.showSuccess = false;
49 $scope.successMessage = "";
50 $scope.showWarning = false;
51 $scope.warningMessage = "";
52 $scope.showInfo = false;
53 $scope.infoMessage = "";
54 $scope.ShowResult = false;
55 $scope.allowTestSelection = false;
56 $scope.hostNamePattern = /([a-z0-9](.[a-z0-9-]*[a-z0-9]))/;
58 //Called when user clicks on runtest button
59 $scope.runTest = function() {
61 $scope.showError = false;
62 $scope.vnfSelected = [];
63 $scope.testSelected = [];
66 for (var i = 0; i < $scope.validationTestList.length; i++) {
67 if ($scope.validationTestList[i].Selected) {
68 var typeId = $scope.validationTestList[i].typeId;
69 var validationType = $scope.validationTestList[i].validationType;
70 message += "typeId: " + typeId + " validationType: " + validationType + "\n";
71 console.log("--TestController::Runtest--", message);
73 testDetails.typeId = typeId;
74 testDetails.validationType = validationType;
75 $scope.testSelected.push(testDetails);
78 console.log("--TestController::Runtest--", JSON.stringify($scope.testSelected));
81 if ($scope.IPAddress != null && $scope.HostName != null && $scope.testSelected.length >= 1) {
82 vnfDetails.IpAddress = $scope.IPAddress;
83 vnfDetails.HostName = $scope.HostName;
84 $scope.vnfSelected.push(vnfDetails);
85 console.log("--TestController::Runtest--", JSON.stringify($scope.vnfSelected));
87 //Call the validation test service with vnfselected and testType as the parameter
89 validationTestService.runPretest($scope.vnfSelected, $scope.testSelected).then(function(response) {
90 console.log("--TestController::runTest--", JSON.stringify(response));
92 //in case of success, build the model object to store the service output here
93 if (response.status === 200) {
94 if (response.preTestResponse != null && response.preTestResponse.length >= 1) {
95 $scope.ShowResult = true;
96 $scope.createTestModel(response.preTestResponse);
97 $scope.showMessage(response.preTestResponse);
100 console.log(response);
101 $scope.showError = true;
102 $scope.errorMessage = "Something went wrong!!!";
103 growl.error($scope.errorMessage, {
105 globalDisableCloseButton:false
109 console.log(response);
110 $scope.showError = true;
111 $scope.errorMessage = "Something went wrong!!! Please try again later";
112 growl.error($scope.errorMessage, {
114 globalDisableCloseButton:false
119 console.log("--TestController--", response);
122 $scope.showError = true;
123 $scope.errorMessage = "Please provide the inputs for VNF and test to be performed!!";
124 growl.error($scope.errorMessage, {
126 globalDisableCloseButton:false
132 $scope.showMessage=function(data){
135 if(angular.isDefined(data) && data.length>=1){
138 angular.forEach(data, function(value, key){
141 if(value.status == "unreachable"){
142 console.log("--TestController::showMessage--",value.status);
143 $scope.showError = true;
144 $scope.errorMessage = "PreTest validation Failed, Please check logs for further details!!!";
145 growl.error($scope.errorMessage, {
147 globalDisableCloseButton:false
154 $scope.showSuccess = true;
155 $scope.successMessage = "Pre test validation completed!!";
156 growl.success($scope.successMessage, {
158 globalDisableCloseButton:false
167 //Function to build the UI model to be shown
168 $scope.createTestModel = function(result) {
170 $scope.showError = false;
171 $scope.showWarning = false;
172 $scope.objPreTestModel = result;
173 $scope.objPreTest = [];
176 if ($scope.objPreTestModel.length >= 1) {
177 for (var i = 0; i < $scope.objPreTestModel.length; i++) {
178 var objTestReport = {};
179 objTestReport.ipaddress = $scope.objPreTestModel[i].ipaddress;
180 objTestReport.status = $scope.objPreTestModel[i].status;
181 objTestReport.testtype = $scope.objPreTestModel[i].testtype;
182 objTestReport.statistics = $scope.objPreTestModel[i].statistics;
183 objTestReport.avgTime = $scope.objPreTestModel[i].avgTime;
186 if ($scope.objPreTestModel[i].testtype === "Network Layer") {
187 if (objTestReport.statistics != null) {
188 //fetching the statistics to show in progress bar
190 var statistics = objTestReport.statistics;
191 statistics = statistics.split("%");
192 objTestReport.statistics = statistics[0];
193 if (objTestReport.statistics == 0) {
194 objTestReport.statisticPer = parseInt(objTestReport.statistics) + 50;
196 objTestReport.statisticPer = objTestReport.statistics;
199 //fetching the avg time to show in progress bar
201 if (objTestReport.avgTime != null) {
202 var avgTime = objTestReport.avgTime;
203 avgTime = avgTime.split("=");
204 var Testtime = avgTime[1];
205 objTestReport.avgTime = Testtime.slice(0, -2).trim();
206 console.log("--TestController::createTestModel--", objTestReport.avgTime);
207 if (objTestReport.avgTime < 50) {
208 objTestReport.avgTimePer = parseInt(objTestReport.avgTime) + 10;
210 objTestReport.avgTimePer = objTestReport.avgTime;
214 $scope.objPreTest.push(objTestReport);
215 console.log("--TestController::createTestModel--", JSON.stringify($scope.objPreTest));
218 console.log("--TestController::createTestModel::final PreTestModel--" + JSON.stringify($scope.objPreTest));