2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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=========================================================
23 var msoCommitModalController = function(COMPONENT, FIELD, $scope, $http, $timeout, $window, $log,
24 MsoService, PropertyService, UtilityService, DataService, $uibModalInstance, msoType, requestParams, vidService) {
26 $scope.isSpinnerVisible = true;
27 $scope.isProgressVisible = true;
28 $scope.status = FIELD.STATUS.SUBMITTING_REQUEST;
31 $scope.progressBarControl = {};
32 $scope.isCloseEnabled = false;
35 _this.pollAttempts = 0;
36 _this.callbackFunction = requestParams.callbackFunction;
37 _this.isMsoError = false;
40 if (angular.isFunction($scope.progressBarControl.reset)) {
41 $scope.progressBarControl.reset();
43 $scope.percentProgress = 2; // Show "a little" progress
47 * Updates the view and returns "true" if the MSO operation has returned a
50 var isUpdateViewAfterGetResponseComplete = function(response) {
51 //console.log("msoCommitController isUpdateViewAfterGetResponseComplete");
52 updateLogFinalResponse(response);
54 var requestStatus = UtilityService.checkUndefined(FIELD.ID.REQUEST_STATUS,
55 UtilityService.checkUndefined(FIELD.ID.REQUEST,
56 response.data.entity.request).requestStatus);
58 var requestState = requestStatus.requestState;
59 console.log("msoCommitController requestState=" + requestState);
60 // look for "progress" or "pending"
61 var patt1 = /progress/i;
62 var patt2 = /pending/i;
63 var result1 = patt1.test(requestState);
64 var result2 = patt2.test(requestState);
65 if (result1 || result2) {
66 requestState = FIELD.STATUS.IN_PROGRESS;
68 var statusMessage = requestStatus.statusMessage;
69 console.log("msoCommitController statusMessage=" + statusMessage);
70 if (UtilityService.hasContents(statusMessage)) {
71 $scope.status = requestState + " - " + statusMessage;
73 $scope.status = requestState;
75 if (UtilityService.hasContents(requestStatus.percentProgress)) {
76 $scope.percentProgress = requestStatus.percentProgress;
79 if ( (requestState.toLowerCase() === FIELD.STATUS.FAILED.toLowerCase()) || (requestState.toLowerCase() === FIELD.STATUS.UNLOCKED.toLowerCase())) {
81 type : FIELD.STATUS.MSO_FAILURE
85 if (requestState.toLowerCase() === FIELD.STATUS.COMPLETE.toLowerCase()) {
86 $scope.isSpinnerVisible = false;
93 var handleGetResponse = function(response) {
95 if (isUpdateViewAfterGetResponseComplete(response)) {
98 if (++_this.pollAttempts > PropertyService.getMsoMaxPolls()) {
99 _this.isMsoError = true;
100 showError(FIELD.ERROR.MAX_POLLS_EXCEEDED);
102 _this.timer = $timeout(getRequestStatus, PropertyService
103 .getMsoMaxPollingIntervalMsec());
106 _this.isMsoError = true;
107 MsoService.showResponseContentError(error, showError);
111 var showError = function(summary, details) {
112 var message = summary;
113 if (UtilityService.hasContents(details)) {
114 message += " (" + details + ")";
116 $scope.isSpinnerVisible = false;
117 $scope.isProgressVisible = false;
118 $scope.error = message;
119 $scope.status = FIELD.STATUS.ERROR;
122 var getRequestStatus = function() {
123 MsoService.getOrchestrationRequest(_this.requestId, handleGetResponse);
126 var updateLog = function(response) {
127 $scope.log = MsoService.getFormattedCommonResponse(response)
129 UtilityService.checkUndefined("entity", response.data.entity);
130 UtilityService.checkUndefined("status", response.data.status);
131 MsoService.checkValidStatus(response);
134 var updateLogFinalResponse = function(response) {
135 $scope.log = MsoService.getFormattedSingleGetOrchestrationRequestResponse(response)
137 UtilityService.checkUndefined("entity", response.data.entity);
138 UtilityService.checkUndefined("status", response.data.status);
139 MsoService.checkValidStatus(response);
142 var updateViewAfterInitialResponse = function(response) {
143 $scope.isCloseEnabled = true;
146 _this.requestId = UtilityService.checkUndefined(FIELD.ID.REQUEST_ID,
147 UtilityService.checkUndefined(FIELD.ID.REQUEST_REFERENCES,
148 response.data.entity.requestReferences).requestId);
150 $scope.percentProgress = 4; // Show "a little more" progress
151 $scope.status = FIELD.STATUS.IN_PROGRESS;
154 var init = function(msoType) {
156 case COMPONENT.MSO_CREATE_REQ:
157 return MsoService.createConfigurationInstance(requestParams);
158 case COMPONENT.MSO_CHANGE_CONFIG_STATUS_REQ:
159 return MsoService.toggleConfigurationStatus(requestParams);
160 case COMPONENT.MSO_CHANGE_PORT_STATUS_REQ:
161 return MsoService.togglePortStatus(requestParams);
162 case COMPONENT.MSO_CREATE_REALATIONSHIP:
163 return MsoService.associatePnf(requestParams);
164 case COMPONENT.MSO_REMOVE_RELATIONSHIP:
165 return MsoService.dissociatePnf(requestParams);
166 case COMPONENT.MSO_ACTIVATE_SERVICE_REQ:
167 return MsoService.activateInstance(requestParams);
168 case COMPONENT.MSO_DEACTIVATE_SERVICE_REQ:
169 return MsoService.deactivateInstance(requestParams);
173 var successCallbackFunction = function(response) {
175 updateViewAfterInitialResponse(response);
176 _this.timer = $timeout(getRequestStatus, PropertyService
177 .getMsoMaxPollingIntervalMsec());
179 $scope.instanceId = response.data.entity.instanceId;
180 if ($scope.instanceId == null) {
181 $scope.instanceId = response.data.entity.requestReferences.instanceId;
184 if ( response.data != null && response.data.status != null ) {
185 if (response.data.status > 299 || response.data.status < 200 ) {
186 // MSO returned an error
187 _this.isMsoError = true;
190 MsoService.showResponseContentError(error, showError);
194 var errorCallbackFunction = function (error) {
195 UtilityService.setHttpErrorHandler(function(error) {
196 $scope.isCloseEnabled = true;
197 _this.isMsoError = true;
198 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
199 .getHttpErrorMessage(error));
203 $scope.close = function() {
204 $uibModalInstance.dismiss('cancel');
206 if (_this.timer !== undefined) {
207 $timeout.cancel(_this.timer);
210 if (angular.isFunction(_this.callbackFunction)) {
211 if ($scope.error === "") {
212 _this.callbackFunction({
214 instanceId : $scope.instanceId
217 _this.callbackFunction({
224 _this.msoRequestType = msoType;
226 init(_this.msoRequestType)
227 .then(function (response) {
228 successCallbackFunction(response);
230 .catch(function (error) {
231 errorCallbackFunction(error);
235 appDS2.controller("msoCommitModalController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",
236 "$window", "$log", "MsoService", "PropertyService", "UtilityService", "DataService", "$uibModalInstance", "msoType", "requestParams", "vidService",
237 msoCommitModalController ]);