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 MsoService = function($http, $log, PropertyService, UtilityService) {
28 * Common function to handle both create and delete instance requests
30 var requestInstanceUpdate = function(request, successCallbackFunction) {
31 $log.debug("MsoService:requestInstanceUpdate: request:");
33 $http.post(PropertyService.getMsoBaseUrl() + "/" + request.url, {
34 requestDetails : request.requestDetails
36 timeout : PropertyService.getServerResponseTimeoutMsec()
37 }).then(successCallbackFunction)["catch"]
38 (UtilityService.runHttpErrorHandler);
41 var checkValidStatus = function(response) {
42 if (response.data.status < 200 || response.data.status > 202) {
49 var addListEntry = function(name, value) {
50 var entry = '"' + name + '": ';
51 if (value === undefined) {
52 return entry + "undefined";
54 return entry + '"' + value + '"';
59 createInstance : requestInstanceUpdate,
60 deleteInstance : requestInstanceUpdate,
61 getOrchestrationRequest : function(requestId, successCallbackFunction) {
62 $log.debug("MsoService:getOrchestrationRequest: requestId: "
65 PropertyService.getMsoBaseUrl() + "/mso_get_orch_req/"
66 + requestId + "?r=" + Math.random(),
68 timeout : PropertyService
69 .getServerResponseTimeoutMsec()
70 }).then(successCallbackFunction)["catch"]
71 (UtilityService.runHttpErrorHandler);
73 getOrchestrationRequests : function(filterString,
74 successCallbackFunction) {
75 $log.debug("MsoService:getOrchestrationRequests: filterString: "
78 PropertyService.getMsoBaseUrl() + "/mso_get_orch_reqs/"
79 + encodeURIComponent(filterString) + "?r="
82 timeout : PropertyService
83 .getServerResponseTimeoutMsec()
84 }).then(successCallbackFunction)["catch"]
85 (UtilityService.runHttpErrorHandler);
87 getFormattedCommonResponse : function(response) {
88 return UtilityService.getCurrentTime() + " HTTP Status: "
89 + UtilityService.getHttpStatusText(response.data.status)
90 + "\n" + angular.toJson(response.data.entity, true)
93 checkValidStatus : checkValidStatus,
94 getFormattedGetOrchestrationRequestsResponse : function(response) {
95 UtilityService.checkUndefined("entity", response.data.entity);
96 UtilityService.checkUndefined("status", response.data.status);
97 checkValidStatus(response);
99 var list = response.data.entity.requestList
100 UtilityService.checkUndefined("requestList", list);
104 for (var i = 0; i < list.length; i++) {
105 var request = list[i].request;
106 message += addListEntry("requestId", request.requestId) + ",\n";
107 message += addListEntry("requestType", request.requestType)
109 var status = request.requestStatus;
110 if (status === undefined) {
111 message += addListEntry("requestStatus", undefined) + "\n";
113 message += addListEntry("timestamp", status.timestamp)
115 message += addListEntry("requestState", status.requestState)
117 message += addListEntry("statusMessage",
118 status.statusMessage)
120 message += addListEntry("percentProgress",
121 status.percentProgress)
124 if (i < (list.length - 1)) {
130 showResponseContentError : function(error, showFunction) {
131 switch (error.type) {
132 case "undefinedObject":
133 showFunction("System failure", error.message);
136 showFunction("MSO failure", "see log below for details")
139 showFunction("System failure");
145 app.factory("MsoService", [ "$http", "$log", "PropertyService",
146 "UtilityService", MsoService ]);