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 requestInfo.requestId = _this.requestId;
\r
78 requestInfo.serviceUuid = $scope.service.model.service.uuid;
\r
80 const modalWindow = $uibModal.open({
\r
81 templateUrl: 'app/vid/scripts/modals/report-modal/report-modal.html',
\r
82 controller: 'reportModalInstanceController',
\r
85 errorMsg: function () {
\r
88 requestInfo: function () {
\r
94 $scope.isViewVisible = false;
\r
95 $scope.popup.isVisible = false;
\r
98 $scope.$on("createInstance", function(event, request) {
\r
99 init(request, COMPONENT.MSO_CREATE_REQ, getOrchestrationRequestStatus );
\r
100 MsoService.createInstance(request, handleInitialResponse);
\r
103 $scope.$on("deleteInstance", function(event, request) {
\r
104 init(request, COMPONENT.MSO_DELETE_REQ, getOrchestrationRequestStatus);
\r
105 MsoService.deleteInstance(request, handleInitialResponse);
\r
108 $scope.$on(COMPONENT.MSO_CREATE_ENVIRONMENT, function(event, request) {
\r
109 init(request, COMPONENT.MSO_CREATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
110 TestEnvironmentsService.createApplicationEnv(request).then(handleInitialResponse);
\r
113 $scope.$on(COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, function(event, request) {
\r
114 init(request, COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
115 TestEnvironmentsService.deactivateApplicationEnv(request).then(handleInitialResponse)
\r
118 $scope.$on(COMPONENT.MSO_ACTIVATE_ENVIRONMENT, function(event, request) {
\r
119 init(request, COMPONENT.MSO_ACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
120 TestEnvironmentsService.activateApplicationEnv(request).then(handleInitialResponse)
\r
124 var init = function(request, msoRequestType, getStatusRequest ) {
\r
125 getRequestStatusFunc = getStatusRequest;
\r
126 $scope.status = FIELD.STATUS.SUBMITTING_REQUEST;
\r
127 $scope.isSpinnerVisible = true;
\r
128 $scope.isProgressVisible = true;
\r
131 $scope.isCloseEnabled = false;
\r
132 $scope.isViewVisible = true;
\r
133 $scope.popup.isVisible = true;
\r
135 _this.pollAttempts = 0;
\r
136 _this.callbackFunction = request.callbackFunction;
\r
137 _this.componentId = request.componentId;
\r
138 _this.msoRequestType = msoRequestType;
\r
139 _this.isMsoError = false;
\r
141 if (angular.isFunction($scope.progressBarControl.reset)) {
\r
142 $scope.progressBarControl.reset();
\r
144 $scope.percentProgress = 2; // Show "a little" progress
\r
146 UtilityService.setHttpErrorHandler(function(response) {
\r
147 $scope.isCloseEnabled = true;
\r
148 _this.isMsoError = true;
\r
149 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
\r
150 .getHttpErrorMessage(response));
\r
154 var handleInitialResponse = function(response) {
\r
156 updateViewAfterInitialResponse(response);
\r
158 _this.timer = $timeout(getRequestStatusFunc, PropertyService
\r
159 .getMsoMaxPollingIntervalMsec());
\r
161 $scope.instanceId = response.data.entity.instanceId;
\r
162 if ($scope.instanceId == null) {
\r
163 $scope.instanceId = response.data.entity.requestReferences.instanceId;
\r
166 if ( response.data != null && response.data.status != null ) {
\r
167 if (response.data.status > 299 || response.data.status < 200 ) {
\r
168 // MSO returned an error
\r
169 _this.isMsoError = true;
\r
172 MsoService.showResponseContentError(error, showError);
\r
176 function getOrchestrationRequestStatus() {
\r
177 MsoService.getOrchestrationRequest(_this.requestId, handleGetStatusResponse);
\r
180 function getCloudResourcesRequestStatus() {
\r
181 TestEnvironmentsService.getRequestStatus(_this.requestId, handleGetStatusResponse);
\r
185 var handleGetStatusResponse = function(response) {
\r
187 if (isUpdateViewAfterGetResponseComplete(response)) {
\r
190 //console.log ( "msoCommitController _this.pollAttempts=" + _this.pollAttempts + " max polls=" + PropertyService.getMsoMaxPolls());
\r
191 if (++_this.pollAttempts > PropertyService.getMsoMaxPolls()) {
\r
192 _this.isMsoError = true;
\r
193 showError(FIELD.ERROR.MAX_POLLS_EXCEEDED);
\r
195 _this.timer = $timeout(getRequestStatusFunc, PropertyService
\r
196 .getMsoMaxPollingIntervalMsec());
\r
199 _this.isMsoError = true;
\r
200 MsoService.showResponseContentError(error, showError);
\r
204 var updateViewAfterInitialResponse = function(response) {
\r
205 $scope.isCloseEnabled = true;
\r
207 updateLog(response);
\r
209 _this.requestId = UtilityService.checkUndefined(FIELD.ID.REQUEST_ID,
\r
210 UtilityService.checkUndefined(FIELD.ID.REQUEST_REFERENCES,
\r
211 response.data.entity.requestReferences).requestId);
\r
213 $scope.percentProgress = 4; // Show "a little more" progress
\r
214 $scope.status = FIELD.STATUS.IN_PROGRESS;
\r
218 * Updates the view and returns "true" if the MSO operation has returned a
\r
219 * "Complete" status.
\r
221 var isUpdateViewAfterGetResponseComplete = function(response) {
\r
222 //console.log("msoCommitController isUpdateViewAfterGetResponseComplete");
\r
223 updateLogFinalResponse(response);
\r
225 var requestStatus = UtilityService.checkUndefined(FIELD.ID.REQUEST_STATUS,
\r
226 UtilityService.checkUndefined(FIELD.ID.REQUEST,
\r
227 response.data.entity.request).requestStatus);
\r
229 var requestState = requestStatus.requestState;
\r
230 console.log("msoCommitController requestState=" + requestState);
\r
231 // look for "progress" or "pending"
\r
232 var patt1 = /progress/i;
\r
233 var patt2 = /pending/i;
\r
234 var result1 = patt1.test(requestState);
\r
235 var result2 = patt2.test(requestState)
\r
236 if (result1 || result2) {
\r
237 requestState = FIELD.STATUS.IN_PROGRESS;
\r
239 var statusMessage = requestStatus.statusMessage;
\r
240 console.log("msoCommitController statusMessage=" + statusMessage);
\r
241 if (UtilityService.hasContents(statusMessage)) {
\r
242 $scope.status = requestState + " - " + statusMessage;
\r
244 $scope.status = requestState;
\r
246 if (UtilityService.hasContents(requestStatus.percentProgress)) {
\r
247 $scope.percentProgress = requestStatus.percentProgress;
\r
250 if ( (requestState.toLowerCase() === FIELD.STATUS.FAILED.toLowerCase()) || (requestState.toLowerCase() === FIELD.STATUS.UNLOCKED.toLowerCase())) {
\r
252 type : FIELD.STATUS.MSO_FAILURE
\r
256 if (requestState.toLowerCase() === FIELD.STATUS.COMPLETE.toLowerCase()) {
\r
257 $scope.isSpinnerVisible = false;
\r
264 var updateLog = function(response) {
\r
265 $scope.log = MsoService.getFormattedCommonResponse(response)
\r
267 UtilityService.checkUndefined("entity", response.data.entity);
\r
268 UtilityService.checkUndefined("status", response.data.status);
\r
269 MsoService.checkValidStatus(response);
\r
271 var updateLogFinalResponse = function(response) {
\r
272 $scope.log = MsoService.getFormattedSingleGetOrchestrationRequestResponse(response)
\r
274 UtilityService.checkUndefined("entity", response.data.entity);
\r
275 UtilityService.checkUndefined("status", response.data.status);
\r
276 MsoService.checkValidStatus(response);
\r
278 $scope.close = function() {
\r
279 if (_this.timer !== undefined) {
\r
280 $timeout.cancel(_this.timer);
\r
282 $scope.isViewVisible = false;
\r
283 if (angular.isFunction(_this.callbackFunction)) {
\r
284 if ($scope.error === "") {
\r
285 _this.callbackFunction({
\r
286 isSuccessful : true,
\r
287 instanceId : $scope.instanceId
\r
290 _this.callbackFunction({
\r
291 isSuccessful : false
\r
293 findNextPage(_this.componentId, _this.msoRequestType, _this.isMsoError);
\r
296 $scope.popup.isVisible = false;
\r
300 var showError = function(summary, details) {
\r
301 var message = summary;
\r
302 if (UtilityService.hasContents(details)) {
\r
303 message += " (" + details + ")";
\r
305 $scope.isSpinnerVisible = false;
\r
306 $scope.isProgressVisible = false;
\r
307 $scope.error = message;
\r
308 $scope.status = FIELD.STATUS.ERROR;
\r
311 var findNextPage = function ( cid, msoRequestType, isMsoError ) {
\r
312 //console.log ("window.location.href" + window.location.href);
\r
313 //console.log ("component id " + cid);
\r
314 var originalUrl = window.location.href;
\r
315 if ( (cid === COMPONENT.SERVICE) && (msoRequestType === COMPONENT.MSO_CREATE_REQ) ) {
\r
316 var url = originalUrl;
\r
320 for ( x = 0; x < url.length; x++) {
\r
321 if ( url.charAt(x) == '/' ) {
\r
323 if ( count == 4 ) {
\r
324 firstStr = url.substring (0,x);
\r
329 // By default show the search existing service instances screen
\r
330 //var newUrl = firstStr + COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
331 var newUrl = COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
333 if ( isMsoError ) {
\r
334 //Show the Browse SDC models screen
\r
335 //newUrl = firstStr + COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
336 newUrl = COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
338 window.location.href = newUrl;
\r
343 appDS2.controller("msoCommitController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",
\r
344 "$window", "$log", "$uibModal", "MsoService", "PropertyService", "UtilityService", "TestEnvironmentsService", "DataService",
\r
345 msoCommitController ]);
\r