2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
24 * "msoCommitController.js" provides controller code to commit MSO requests.
\r
28 * Parent HTML/JSP code is expected to include "msoCommit.htm" (via
\r
29 * "ng-include") and this file (via "<script>"). "msoCommit.jsp" (displayed
\r
30 * when the parent code includes "msoCommit.htm") renders a popup window, but
\r
31 * initially hides the display.
\r
33 * The parent controller code is expected to broadcast either the
\r
34 * "createInstance" or "deleteInstance" events when it is ready to commit the
\r
37 * This controller receives these events (via "$scope.on" declarations), calls
\r
38 * "$scope.init()" to "unhide" and initialize the popup display and then makes a
\r
39 * REST request to the appropriate server Java controller.
\r
41 * The initial REST response is handled by "handleInitialResponse". This method
\r
42 * then polls the server (via "getRequestStatus") if the request is successful.
\r
44 * The subsequent "getRequestStatus" responses are handled by
\r
45 * "handleGetResponse".
\r
47 * "handleInitialResponse" and "handleGetResponse" primarily filter response
\r
48 * data, manipulate the display and provide error handling.
\r
50 * The mechanism has these dependencies (in addition to "msoCommit.htm"):
\r
52 * 1) Three services: MsoService, PropertyService and UtilityService
\r
54 * 2) The popup window directive found in "popupWindow.htm" and
\r
55 * "popupWindowDirective.js"
\r
57 * 2) Display styling defined in "dialogs.css"
\r
61 * The parent HTML is assumed to be the "popup-window" directive and the
\r
62 * corresponding parent controller is assumed to define the object
\r
66 var msoCommitController = function(COMPONENT, FIELD, $scope, $http, $timeout, $window, $log, $uibModal,
\r
67 MsoService, PropertyService, UtilityService, TestEnvironmentsService, DataService) {
\r
69 $scope.isViewVisible = false;
\r
70 $scope.progressBarControl = {};
\r
71 $scope.popupWindowControl = {};
\r
72 var getRequestStatusFunc = getOrchestrationRequestStatus; //default
\r
75 $scope.showReportWindow = function() {
\r
76 let requestInfo = {};
\r
77 if(_this.requestId !== undefined) {
\r
78 requestInfo.requestId = _this.requestId;
\r
80 requestInfo.requestId = null;
\r
82 if($scope.service !== undefined) {
\r
83 requestInfo.serviceUuid = $scope.service.model.service.uuid;
\r
85 requestInfo.serviceUuid = null;
\r
88 const modalWindow = $uibModal.open({
\r
89 templateUrl: 'app/vid/scripts/modals/report-modal/report-modal.html',
\r
90 controller: 'reportModalInstanceController',
\r
93 errorMsg: function () {
\r
96 requestInfo: function () {
\r
102 $scope.isViewVisible = false;
\r
103 $scope.popup.isVisible = false;
\r
106 $scope.$on("createInstance", function(event, request) {
\r
107 init(request, COMPONENT.MSO_CREATE_REQ, getOrchestrationRequestStatus );
\r
108 MsoService.createInstance(request, handleInitialResponse);
\r
111 $scope.$on("deleteInstance", function(event, request) {
\r
112 init(request, COMPONENT.MSO_DELETE_REQ, getOrchestrationRequestStatus);
\r
113 MsoService.deleteInstance(request, handleInitialResponse);
\r
116 $scope.$on(COMPONENT.MSO_CREATE_ENVIRONMENT, function(event, request) {
\r
117 init(request, COMPONENT.MSO_CREATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
118 TestEnvironmentsService.createApplicationEnv(request).then(handleInitialResponse);
\r
121 $scope.$on(COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, function(event, request) {
\r
122 init(request, COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
123 TestEnvironmentsService.deactivateApplicationEnv(request).then(handleInitialResponse)
\r
126 $scope.$on(COMPONENT.MSO_ACTIVATE_ENVIRONMENT, function(event, request) {
\r
127 init(request, COMPONENT.MSO_ACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
128 TestEnvironmentsService.activateApplicationEnv(request).then(handleInitialResponse)
\r
132 var init = function(request, msoRequestType, getStatusRequest ) {
\r
133 getRequestStatusFunc = getStatusRequest;
\r
134 $scope.status = FIELD.STATUS.SUBMITTING_REQUEST;
\r
135 $scope.isSpinnerVisible = true;
\r
136 $scope.isProgressVisible = true;
\r
139 $scope.isCloseEnabled = false;
\r
140 $scope.isViewVisible = true;
\r
141 $scope.popup.isVisible = true;
\r
143 _this.pollAttempts = 0;
\r
144 _this.callbackFunction = request.callbackFunction;
\r
145 _this.componentId = request.componentId;
\r
146 _this.msoRequestType = msoRequestType;
\r
147 _this.isMsoError = false;
\r
149 if (angular.isFunction($scope.progressBarControl.reset)) {
\r
150 $scope.progressBarControl.reset();
\r
152 $scope.percentProgress = 2; // Show "a little" progress
\r
154 UtilityService.setHttpErrorHandler(function(response) {
\r
155 $scope.isCloseEnabled = true;
\r
156 _this.isMsoError = true;
\r
157 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
\r
158 .getHttpErrorMessage(response));
\r
162 var handleInitialResponse = function(response) {
\r
164 updateViewAfterInitialResponse(response);
\r
166 _this.timer = $timeout(getRequestStatusFunc, PropertyService
\r
167 .getMsoMaxPollingIntervalMsec());
\r
169 $scope.instanceId = response.data.entity.instanceId;
\r
170 if ($scope.instanceId == null) {
\r
171 $scope.instanceId = response.data.entity.requestReferences.instanceId;
\r
174 if ( response.data != null && response.data.status != null ) {
\r
175 if (response.data.status > 299 || response.data.status < 200 ) {
\r
176 // MSO returned an error
\r
177 _this.isMsoError = true;
\r
180 MsoService.showResponseContentError(error, showError);
\r
184 function getOrchestrationRequestStatus() {
\r
185 MsoService.getOrchestrationRequest(_this.requestId, handleGetStatusResponse);
\r
188 function getCloudResourcesRequestStatus() {
\r
189 TestEnvironmentsService.getRequestStatus(_this.requestId, handleGetStatusResponse);
\r
193 var handleGetStatusResponse = function(response) {
\r
195 if (isUpdateViewAfterGetResponseComplete(response)) {
\r
198 //console.log ( "msoCommitController _this.pollAttempts=" + _this.pollAttempts + " max polls=" + PropertyService.getMsoMaxPolls());
\r
199 if (++_this.pollAttempts > PropertyService.getMsoMaxPolls()) {
\r
200 _this.isMsoError = true;
\r
201 showError(FIELD.ERROR.MAX_POLLS_EXCEEDED);
\r
203 _this.timer = $timeout(getRequestStatusFunc, PropertyService
\r
204 .getMsoMaxPollingIntervalMsec());
\r
207 _this.isMsoError = true;
\r
208 MsoService.showResponseContentError(error, showError);
\r
212 var updateViewAfterInitialResponse = function(response) {
\r
213 $scope.isCloseEnabled = true;
\r
215 updateLog(response);
\r
217 _this.requestId = UtilityService.checkUndefined(FIELD.ID.REQUEST_ID,
\r
218 UtilityService.checkUndefined(FIELD.ID.REQUEST_REFERENCES,
\r
219 response.data.entity.requestReferences).requestId);
\r
221 $scope.percentProgress = 4; // Show "a little more" progress
\r
222 $scope.status = FIELD.STATUS.IN_PROGRESS;
\r
226 * Updates the view and returns "true" if the MSO operation has returned a
\r
227 * "Complete" status.
\r
229 var isUpdateViewAfterGetResponseComplete = function(response) {
\r
230 //console.log("msoCommitController isUpdateViewAfterGetResponseComplete");
\r
231 updateLogFinalResponse(response);
\r
233 var requestStatus = UtilityService.checkUndefined(FIELD.ID.REQUEST_STATUS,
\r
234 UtilityService.checkUndefined(FIELD.ID.REQUEST,
\r
235 response.data.entity.request).requestStatus);
\r
237 var requestState = requestStatus.requestState;
\r
238 console.log("msoCommitController requestState=" + requestState);
\r
239 // look for "progress" or "pending"
\r
240 var patt1 = /progress/i;
\r
241 var patt2 = /pending/i;
\r
242 var result1 = patt1.test(requestState);
\r
243 var result2 = patt2.test(requestState)
\r
244 if (result1 || result2) {
\r
245 requestState = FIELD.STATUS.IN_PROGRESS;
\r
247 var statusMessage = requestStatus.statusMessage;
\r
248 console.log("msoCommitController statusMessage=" + statusMessage);
\r
249 if (UtilityService.hasContents(statusMessage)) {
\r
250 $scope.status = requestState + " - " + statusMessage;
\r
252 $scope.status = requestState;
\r
254 if (UtilityService.hasContents(requestStatus.percentProgress)) {
\r
255 $scope.percentProgress = requestStatus.percentProgress;
\r
258 if ( (requestState.toLowerCase() === FIELD.STATUS.FAILED.toLowerCase()) || (requestState.toLowerCase() === FIELD.STATUS.UNLOCKED.toLowerCase())) {
\r
260 type : FIELD.STATUS.MSO_FAILURE
\r
264 if (requestState.toLowerCase() === FIELD.STATUS.COMPLETE.toLowerCase()) {
\r
265 $scope.isSpinnerVisible = false;
\r
272 var updateLog = function(response) {
\r
273 $scope.log = MsoService.getFormattedCommonResponse(response)
\r
275 UtilityService.checkUndefined("entity", response.data.entity);
\r
276 UtilityService.checkUndefined("status", response.data.status);
\r
277 MsoService.checkValidStatus(response);
\r
279 var updateLogFinalResponse = function(response) {
\r
280 $scope.log = MsoService.getFormattedSingleGetOrchestrationRequestResponse(response)
\r
282 UtilityService.checkUndefined("entity", response.data.entity);
\r
283 UtilityService.checkUndefined("status", response.data.status);
\r
284 MsoService.checkValidStatus(response);
\r
286 $scope.close = function() {
\r
287 if (_this.timer !== undefined) {
\r
288 $timeout.cancel(_this.timer);
\r
290 $scope.isViewVisible = false;
\r
291 if (angular.isFunction(_this.callbackFunction)) {
\r
292 if ($scope.error === "") {
\r
293 _this.callbackFunction({
\r
294 isSuccessful : true,
\r
295 instanceId : $scope.instanceId
\r
298 _this.callbackFunction({
\r
299 isSuccessful : false
\r
301 findNextPage(_this.componentId, _this.msoRequestType, _this.isMsoError);
\r
304 $scope.popup.isVisible = false;
\r
308 var showError = function(summary, details) {
\r
309 var message = summary;
\r
310 if (UtilityService.hasContents(details)) {
\r
311 message += " (" + details + ")";
\r
313 $scope.isSpinnerVisible = false;
\r
314 $scope.isProgressVisible = false;
\r
315 $scope.error = message;
\r
316 $scope.status = FIELD.STATUS.ERROR;
\r
319 var findNextPage = function ( cid, msoRequestType, isMsoError ) {
\r
320 //console.log ("window.location.href" + window.location.href);
\r
321 //console.log ("component id " + cid);
\r
322 var originalUrl = window.location.href;
\r
323 if ( (cid === COMPONENT.SERVICE) && (msoRequestType === COMPONENT.MSO_CREATE_REQ) ) {
\r
324 var url = originalUrl;
\r
328 for ( x = 0; x < url.length; x++) {
\r
329 if ( url.charAt(x) == '/' ) {
\r
331 if ( count == 4 ) {
\r
332 firstStr = url.substring (0,x);
\r
337 // By default show the search existing service instances screen
\r
338 //var newUrl = firstStr + COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
339 var newUrl = COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
341 if ( isMsoError ) {
\r
342 //Show the Browse SDC models screen
\r
343 //newUrl = firstStr + COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
344 newUrl = COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
346 window.location.href = newUrl;
\r
351 appDS2.controller("msoCommitController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",
\r
352 "$window", "$log", "$uibModal", "MsoService", "PropertyService", "UtilityService", "TestEnvironmentsService", "DataService",
\r
353 msoCommitController ]);
\r