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,
\r
67 MsoService, PropertyService, UtilityService, TestEnvironmentsService) {
\r
69 $scope.isViewVisible = false;
\r
70 $scope.progressBarControl = {};
\r
71 $scope.popupWindowControl = {};
\r
72 var getRequestStatusFunc = getOrchestrationRequestStatus; //default
\r
75 $scope.$on("createInstance", function(event, request) {
\r
76 init(request, COMPONENT.MSO_CREATE_REQ, getOrchestrationRequestStatus );
\r
77 MsoService.createInstance(request, handleInitialResponse);
\r
80 $scope.$on("deleteInstance", function(event, request) {
\r
81 init(request, COMPONENT.MSO_DELETE_REQ, getOrchestrationRequestStatus);
\r
82 MsoService.deleteInstance(request, handleInitialResponse);
\r
85 $scope.$on(COMPONENT.MSO_CREATE_ENVIRONMENT, function(event, request) {
\r
86 init(request, COMPONENT.MSO_CREATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
87 TestEnvironmentsService.createApplicationEnv(request).then(handleInitialResponse);
\r
90 $scope.$on(COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, function(event, request) {
\r
91 init(request, COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
92 TestEnvironmentsService.deactivateApplicationEnv(request).then(handleInitialResponse)
\r
95 $scope.$on(COMPONENT.MSO_ACTIVATE_ENVIRONMENT, function(event, request) {
\r
96 init(request, COMPONENT.MSO_ACTIVATE_ENVIRONMENT, getCloudResourcesRequestStatus);
\r
97 TestEnvironmentsService.activateApplicationEnv(request).then(handleInitialResponse)
\r
101 var init = function(request, msoRequestType, getStatusRequest ) {
\r
102 getRequestStatusFunc = getStatusRequest;
\r
103 $scope.status = FIELD.STATUS.SUBMITTING_REQUEST;
\r
104 $scope.isSpinnerVisible = true;
\r
105 $scope.isProgressVisible = true;
\r
108 $scope.isCloseEnabled = false;
\r
109 $scope.isViewVisible = true;
\r
110 $scope.popup.isVisible = true;
\r
112 _this.pollAttempts = 0;
\r
113 _this.callbackFunction = request.callbackFunction;
\r
114 _this.componentId = request.componentId;
\r
115 _this.msoRequestType = msoRequestType;
\r
116 _this.isMsoError = false;
\r
118 if (angular.isFunction($scope.progressBarControl.reset)) {
\r
119 $scope.progressBarControl.reset();
\r
121 $scope.percentProgress = 2; // Show "a little" progress
\r
123 UtilityService.setHttpErrorHandler(function(response) {
\r
124 $scope.isCloseEnabled = true;
\r
125 _this.isMsoError = true;
\r
126 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
\r
127 .getHttpErrorMessage(response));
\r
131 var handleInitialResponse = function(response) {
\r
133 updateViewAfterInitialResponse(response);
\r
135 _this.timer = $timeout(getRequestStatusFunc, PropertyService
\r
136 .getMsoMaxPollingIntervalMsec());
\r
138 $scope.instanceId = response.data.entity.instanceId;
\r
139 if ($scope.instanceId == null) {
\r
140 $scope.instanceId = response.data.entity.requestReferences.instanceId;
\r
143 if ( response.data != null && response.data.status != null ) {
\r
144 if (response.data.status > 299 || response.data.status < 200 ) {
\r
145 // MSO returned an error
\r
146 _this.isMsoError = true;
\r
149 MsoService.showResponseContentError(error, showError);
\r
153 function getOrchestrationRequestStatus() {
\r
154 MsoService.getOrchestrationRequest(_this.requestId, handleGetStatusResponse);
\r
157 function getCloudResourcesRequestStatus() {
\r
158 TestEnvironmentsService.getRequestStatus(_this.requestId, handleGetStatusResponse);
\r
162 var handleGetStatusResponse = function(response) {
\r
164 if (isUpdateViewAfterGetResponseComplete(response)) {
\r
167 //console.log ( "msoCommitController _this.pollAttempts=" + _this.pollAttempts + " max polls=" + PropertyService.getMsoMaxPolls());
\r
168 if (++_this.pollAttempts > PropertyService.getMsoMaxPolls()) {
\r
169 _this.isMsoError = true;
\r
170 showError(FIELD.ERROR.MAX_POLLS_EXCEEDED);
\r
172 _this.timer = $timeout(getRequestStatusFunc, PropertyService
\r
173 .getMsoMaxPollingIntervalMsec());
\r
176 _this.isMsoError = true;
\r
177 MsoService.showResponseContentError(error, showError);
\r
181 var updateViewAfterInitialResponse = function(response) {
\r
182 $scope.isCloseEnabled = true;
\r
184 updateLog(response);
\r
186 _this.requestId = UtilityService.checkUndefined(FIELD.ID.REQUEST_ID,
\r
187 UtilityService.checkUndefined(FIELD.ID.REQUEST_REFERENCES,
\r
188 response.data.entity.requestReferences).requestId);
\r
190 $scope.percentProgress = 4; // Show "a little more" progress
\r
191 $scope.status = FIELD.STATUS.IN_PROGRESS;
\r
195 * Updates the view and returns "true" if the MSO operation has returned a
\r
196 * "Complete" status.
\r
198 var isUpdateViewAfterGetResponseComplete = function(response) {
\r
199 //console.log("msoCommitController isUpdateViewAfterGetResponseComplete");
\r
200 updateLogFinalResponse(response);
\r
202 var requestStatus = UtilityService.checkUndefined(FIELD.ID.REQUEST_STATUS,
\r
203 UtilityService.checkUndefined(FIELD.ID.REQUEST,
\r
204 response.data.entity.request).requestStatus);
\r
206 var requestState = requestStatus.requestState;
\r
207 console.log("msoCommitController requestState=" + requestState);
\r
208 // look for "progress" or "pending"
\r
209 var patt1 = /progress/i;
\r
210 var patt2 = /pending/i;
\r
211 var result1 = patt1.test(requestState);
\r
212 var result2 = patt2.test(requestState)
\r
213 if (result1 || result2) {
\r
214 requestState = FIELD.STATUS.IN_PROGRESS;
\r
216 var statusMessage = requestStatus.statusMessage;
\r
217 console.log("msoCommitController statusMessage=" + statusMessage);
\r
218 if (UtilityService.hasContents(statusMessage)) {
\r
219 $scope.status = requestState + " - " + statusMessage;
\r
221 $scope.status = requestState;
\r
223 if (UtilityService.hasContents(requestStatus.percentProgress)) {
\r
224 $scope.percentProgress = requestStatus.percentProgress;
\r
227 if ( (requestState.toLowerCase() === FIELD.STATUS.FAILED.toLowerCase()) || (requestState.toLowerCase() === FIELD.STATUS.UNLOCKED.toLowerCase())) {
\r
229 type : FIELD.STATUS.MSO_FAILURE
\r
233 if (requestState.toLowerCase() === FIELD.STATUS.COMPLETE.toLowerCase()) {
\r
234 $scope.isSpinnerVisible = false;
\r
241 var updateLog = function(response) {
\r
242 $scope.log = MsoService.getFormattedCommonResponse(response)
\r
244 UtilityService.checkUndefined("entity", response.data.entity);
\r
245 UtilityService.checkUndefined("status", response.data.status);
\r
246 MsoService.checkValidStatus(response);
\r
248 var updateLogFinalResponse = function(response) {
\r
249 $scope.log = MsoService.getFormattedSingleGetOrchestrationRequestResponse(response)
\r
251 UtilityService.checkUndefined("entity", response.data.entity);
\r
252 UtilityService.checkUndefined("status", response.data.status);
\r
253 MsoService.checkValidStatus(response);
\r
255 $scope.close = function() {
\r
256 if (_this.timer !== undefined) {
\r
257 $timeout.cancel(_this.timer);
\r
259 $scope.isViewVisible = false;
\r
260 if (angular.isFunction(_this.callbackFunction)) {
\r
261 if ($scope.error === "") {
\r
262 _this.callbackFunction({
\r
263 isSuccessful : true,
\r
264 instanceId : $scope.instanceId
\r
267 _this.callbackFunction({
\r
268 isSuccessful : false
\r
270 findNextPage(_this.componentId, _this.msoRequestType, _this.isMsoError);
\r
273 $scope.popup.isVisible = false;
\r
277 var showError = function(summary, details) {
\r
278 var message = summary;
\r
279 if (UtilityService.hasContents(details)) {
\r
280 message += " (" + details + ")";
\r
282 $scope.isSpinnerVisible = false;
\r
283 $scope.isProgressVisible = false;
\r
284 $scope.error = message;
\r
285 $scope.status = FIELD.STATUS.ERROR;
\r
288 var findNextPage = function ( cid, msoRequestType, isMsoError ) {
\r
289 //console.log ("window.location.href" + window.location.href);
\r
290 //console.log ("component id " + cid);
\r
291 var originalUrl = window.location.href;
\r
292 if ( (cid === COMPONENT.SERVICE) && (msoRequestType === COMPONENT.MSO_CREATE_REQ) ) {
\r
293 var url = originalUrl;
\r
297 for ( x = 0; x < url.length; x++) {
\r
298 if ( url.charAt(x) == '/' ) {
\r
300 if ( count == 4 ) {
\r
301 firstStr = url.substring (0,x);
\r
306 // By default show the search existing service instances screen
\r
307 //var newUrl = firstStr + COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
308 var newUrl = COMPONENT.SERVICEMODELS_INSTANCES_SERVICES_PATH;
\r
310 if ( isMsoError ) {
\r
311 //Show the Browse SDC models screen
\r
312 //newUrl = firstStr + COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
313 newUrl = COMPONENT.SERVICEMODELS_MODELS_SERVICES_PATH;
\r
315 window.location.href = newUrl;
\r
320 appDS2.controller("msoCommitController", [ "COMPONENT", "FIELD", "$scope", "$http", "$timeout",
\r
321 "$window", "$log", "MsoService", "PropertyService", "UtilityService", "TestEnvironmentsService",
\r
322 msoCommitController ]);
\r