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=========================================================
21 myApp.controller('TestController', ['$scope', '$http', 'growl', 'viewReportService', 'validationTestService', function($scope, $http, growl, viewReportService, validationTestService) {
23 $scope.showTestReport = false;
25 //Input data for validation test dropdown
26 var validationTestList = [{
28 "validationType": "Network Layer",
34 $scope.validationTestList = validationTestList;
37 $scope.getselectval = function() {
38 $scope.selectedvalues = 'Name: ' + $scope.selitem.validationType + ' Id: ' + $scope.selitem.typeId;
41 $scope.showError = false;
42 $scope.errorMessage = "";
43 $scope.showSuccess = false;
44 $scope.successMessage = "";
45 $scope.showWarning = false;
46 $scope.warningMessage = "";
47 $scope.showInfo = false;
48 $scope.infoMessage = "";
49 $scope.ShowResult = false;
50 $scope.allowTestSelection = false;
51 $scope.hostNamePattern = /([a-z0-9](.[a-z0-9-]*[a-z0-9]))/;
53 //Called when user clicks on runtest button
54 $scope.runTest = function() {
56 $scope.showError = false;
57 $scope.vnfSelected = [];
58 $scope.testSelected = [];
61 for (var i = 0; i < $scope.validationTestList.length; i++) {
62 if ($scope.validationTestList[i].Selected) {
63 var typeId = $scope.validationTestList[i].typeId;
64 var validationType = $scope.validationTestList[i].validationType;
65 message += "typeId: " + typeId + " validationType: " + validationType + "\n";
66 console.log("--TestController::Runtest--", message);
68 testDetails.typeId = typeId;
69 testDetails.validationType = validationType;
70 $scope.testSelected.push(testDetails);
73 console.log("--TestController::Runtest--", JSON.stringify($scope.testSelected));
76 if ($scope.IPAddress != null && $scope.HostName != null && $scope.testSelected.length >= 1) {
77 vnfDetails.ipAddress = $scope.IPAddress;
78 vnfDetails.hostName = $scope.HostName;
79 $scope.vnfSelected.push(vnfDetails);
80 console.log("--TestController::Runtest--", JSON.stringify($scope.vnfSelected));
82 //Call the validation test service with vnfselected and testType as the parameter
84 validationTestService.runPretest($scope.vnfSelected, $scope.testSelected).then(function(response) {
85 console.log("--TestController::runTest--", JSON.stringify(response));
86 var status = response.status;
87 var response = response.data;
88 //in case of success, build the model object to store the service output here
90 if (response.preTestResponse != null && response.preTestResponse.length >= 1) {
91 $scope.ShowResult = true;
92 $scope.createTestModel(response.preTestResponse);
93 $scope.showMessage(response.preTestResponse);
96 console.log(response);
97 $scope.showError = true;
98 $scope.errorMessage = "Something went wrong!!!";
99 growl.error($scope.errorMessage, {
104 console.log(response);
105 $scope.showError = true;
106 $scope.errorMessage = "Pre test validation failed!!! Check the report for more details";
107 growl.error($scope.errorMessage, {
113 console.log("--TestController--", response);
116 $scope.showError = true;
117 $scope.errorMessage = "Please provide the inputs for VNF and test to be performed!!";
118 growl.error($scope.errorMessage, {
125 $scope.showMessage=function(data){
127 if(angular.isDefined(data) && data.length>=1){
129 angular.forEach(data, function(value, key){
130 if(value.status == "unreachable"){
131 console.log("--TestController::showMessage--",value.status);
132 $scope.showError = true;
133 $scope.errorMessage = "PreTest validation Failed, Please check logs for further details!!!";
134 growl.error($scope.errorMessage, {
140 $scope.showSuccess = true;
141 $scope.successMessage = "Pre test validation completed!!";
142 growl.success($scope.successMessage, {
152 //Function to build the UI model to be shown
153 $scope.createTestModel = function(result) {
155 $scope.showError = false;
156 $scope.showWarning = false;
157 $scope.objPreTestModel = result;
158 $scope.objPreTest = [];
161 if ($scope.objPreTestModel.length >= 1) {
162 for (var i = 0; i < $scope.objPreTestModel.length; i++) {
163 var objTestReport = {};
164 objTestReport.ipaddress = $scope.objPreTestModel[i].ipaddress;
165 objTestReport.status = $scope.objPreTestModel[i].status;
166 objTestReport.testtype = $scope.objPreTestModel[i].testtype;
167 objTestReport.statistics = $scope.objPreTestModel[i].statistics;
168 objTestReport.avgTime = $scope.objPreTestModel[i].avgTime;
171 if ($scope.objPreTestModel[i].testtype === "Network Layer") {
172 if (objTestReport.statistics != null) {
173 //fetching the statistics to show in progress bar
175 var statistics = objTestReport.statistics;
176 statistics = statistics.split("%");
177 objTestReport.statistics = statistics[0];
178 if (objTestReport.statistics == 0) {
179 objTestReport.statisticPer = parseInt(objTestReport.statistics) + 50;
181 objTestReport.statisticPer = objTestReport.statistics;
184 //fetching the avg time to show in progress bar
186 if (objTestReport.avgTime != null) {
187 var avgTime = objTestReport.avgTime;
188 avgTime = avgTime.split("=");
189 var Testtime = avgTime[1];
190 objTestReport.avgTime = Testtime.slice(0, -2).trim();
191 console.log("--TestController::createTestModel--", objTestReport.avgTime);
192 if (objTestReport.avgTime < 50) {
193 objTestReport.avgTimePer = parseInt(objTestReport.avgTime) + 10;
195 objTestReport.avgTimePer = objTestReport.avgTime;
199 $scope.objPreTest.push(objTestReport);
200 console.log("--TestController::createTestModel--", JSON.stringify($scope.objPreTest));
203 console.log("--TestController::createTestModel::final PreTestModel--" + JSON.stringify($scope.objPreTest));