2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 IBM.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
25 appDS2.controller("ServiceModelController",function ($uibModal, $scope, $http, $location, COMPONENT, VIDCONFIGURATION, FIELD, DataService, vidService,
26 PropertyService, UtilityService, AsdcService, $timeout, featureFlags) {
29 var defaultViewPerPage = 10;
30 // var baseEndpoint = "vid";
31 var pathQuery = COMPONENT.SERVICES_DIST_STATUS_PATH + VIDCONFIGURATION.ASDC_MODEL_STATUS;
33 if ( VIDCONFIGURATION.ASDC_MODEL_STATUS === FIELD.STATUS.ALL) {
34 pathQuery = COMPONENT.SERVICES_PATH;
36 window.addEventListener("message", receiveMessage, false);
38 function receiveMessage(event){
39 if(event.data == 'navigateTo') {
40 $location.path('/models/services').search({});
42 $scope.rememberFilter = true;
44 if(event.data == 'navigateToInstantiationStatus') {
45 $location.path('/instantiationStatus').search({});
50 $scope.getServiceModels = function() {
51 $scope.status = FIELD.STATUS.FETCHING_SERVICE_CATALOG_ASDC;
54 .then(function (response) {
56 if (response.data && angular.isArray(response.data.services)) {
57 wholeData = response.data.services;
58 $scope.services = $scope.filterDataWithHigherVersion(wholeData);
59 $scope.viewPerPage = defaultViewPerPage;
60 $scope.totalPage=$scope.services.length/$scope.viewPerPage;
61 $scope.sortBy=COMPONENT.NAME;
62 $scope.scrollViewPerPage=2;
64 $scope.currentPageNum=1;
65 $scope.isSpinnerVisible = false;
66 $scope.isProgressVisible = false;
67 var searchKey = sessionStorage.getItem("searchKey");
68 if (searchKey != 'undefined' && searchKey!=null && ($scope.rememberFilter)) {
69 var searchKey = JSON.parse(sessionStorage.getItem("searchKey"));
70 $scope.searchString = searchKey.searchString || '';
71 $scope.viewPerPage = searchKey.viewPerPage || defaultViewPerPage;
72 $scope.totalPage = $scope.services.length / $scope.viewPerPage;
73 $timeout(function () {
74 // the table controller handles the current page once
75 // data is loaded, therefore we're delying the paging
77 $scope.currentPage = $scope.currentPageNum = searchKey.currentPage ? parseInt(searchKey.currentPage) : 1;
79 $scope.rememberFilter = false;
82 $scope.status = FIELD.STATUS.FAILED_SERVICE_MODELS_ASDC;
84 $scope.isSpinnerVisible = false;
86 $scope.deployButtonType = response.data.readOnly ? 'disabled' : 'primary';
87 }, function (response) {
88 console.log("Error: " + response);
92 $scope.isShowOrchestrationType = function() {
93 return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_SHOW_ORCHESTRATION_TYPE);
98 $scope.filterDataWithHigherVersion = function(serviceData){
100 var fiterDataServices = {};
101 for(var i=0;i<serviceData.length;i++) {
102 var index = serviceData[i].invariantUUID.trim() + delimiter + serviceData[i].name.trim();
103 if(!fiterDataServices[index]) {
104 var hasPreviousVersion = false;
105 fiterDataServices[index] = {
106 service: serviceData[i],
107 hasPreviousVersion: false
111 fiterDataServices[index].hasPreviousVersion = true;
112 if(parseFloat(serviceData[i].version.trim())>parseFloat(fiterDataServices[index].service.version.trim())) {
113 fiterDataServices[index].service = serviceData[i];
117 return Object.keys(fiterDataServices).map(function(key) {
118 var service = fiterDataServices[key].service;
119 service.hasPreviousVersion = fiterDataServices[key].hasPreviousVersion;
124 $scope.init = function() {
125 var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec();
126 PropertyService.setMsoMaxPollingIntervalMsec(msecs);
128 var polls = PropertyService.retrieveMsoMaxPolls();
129 PropertyService.setMsoMaxPolls(polls);
132 $scope.prevPage = function() {
133 $scope.currentPage--;
136 $scope.nextPage = function() {
137 $scope.currentPage++;
140 $scope.showReportWindow = function() {
142 const modalWindow = $uibModal.open({
143 templateUrl: 'app/vid/scripts/modals/report-modal/report-modal.html',
144 controller: 'reportModalController',
147 errorMsg: function () {
148 return $scope.status;
155 $scope.isShowErrorReport = function() {
156 return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_CREATE_ERROR_REPORTS);
159 $scope.createType = COMPONENT.A_LA_CARTE;
160 $scope.deployService = function(service) {
162 searchString: $scope.searchString,
163 viewPerPage: $scope.viewPerPage,
164 currentPage: $scope.currentPage
166 DataService.setHasTemplate(service.hasTemplate);
167 sessionStorage.setItem("searchKey",JSON.stringify(searchKey));
169 console.log("Instantiating SDC service " + service.uuid);
171 $http.get(COMPONENT.SERVICES_PATH + service.uuid)
172 .then(function (getServiceResponse) {
174 var serviceModel = getServiceResponse.data;
176 //VID-233 bug fix when models doesn't exists
177 if(typeof(serviceModel)==="string"){ //not an object
178 $scope.status = FIELD.STATUS.FAILED_SERVICE_MODELS_ASDC;
180 $scope.isSpinnerVisible = false;
181 $scope.isProgressVisible = true;
183 } else{ //clean error message
185 $scope.error = false;
186 $scope.isSpinnerVisible = false;
187 $scope.isProgressVisible = false;
190 DataService.setServiceName(serviceModel.service.name);
192 //VOLTE services need input list generated and macro style
193 DataService.setE2EService(false);
194 if(serviceModel.service.category === 'E2E Service') {
195 DataService.setE2EService(true);
196 DataService.setHideServiceFields(false);
197 VIDCONFIGURATION.MACRO_SERVICES.push(serviceModel.service.invariantUuid);
200 DataService.setModelInfo(COMPONENT.SERVICE, {
201 "modelInvariantId": serviceModel.service.invariantUuid,
202 "modelVersion": serviceModel.service.version,
203 "serviceType" : serviceModel.service.serviceType,
204 "serviceRole": serviceModel.service.serviceRole,
205 "modelNameVersionId": serviceModel.service.uuid,
206 "modelName": serviceModel.service.name,
207 "description": serviceModel.service.description,
208 "category":serviceModel.service.category
211 var shouldTakeTheAsyncInstantiationFlow = AsdcService.shouldTakeTheAsyncInstantiationFlow(serviceModel);
212 DataService.setShouldIncludeInAsyncInstantiationFlow(shouldTakeTheAsyncInstantiationFlow);
214 DataService.setALaCarte (true);
215 DataService.setPnf(!angular.equals(serviceModel.pnfs, {}));
216 $scope.createType = COMPONENT.A_LA_CARTE;
217 var broadcastType = COMPONENT.CREATE_COMPONENT;
218 if (AsdcService.isMacro(serviceModel) || DataService.getE2EService()) {
219 DataService.setALaCarte(false);
220 if(!shouldTakeTheAsyncInstantiationFlow){
221 $scope.createType = COMPONENT.MACRO;
222 var convertedAsdcModel = UtilityService.convertModel(serviceModel);
224 DataService.setModelInfo(COMPONENT.SERVICE, {
225 "modelInvariantId": serviceModel.service.invariantUuid,
226 "modelVersion": serviceModel.service.version,
227 "modelNameVersionId": serviceModel.service.uuid,
228 "modelName": serviceModel.service.name,
229 "description": serviceModel.service.description,
230 "category": serviceModel.service.category,
231 "serviceEcompNaming": serviceModel.service.serviceEcompNaming,
232 "inputs": serviceModel.service.inputs,
233 "serviceType": serviceModel.service.serviceType,
234 "serviceRole": serviceModel.service.serviceRole,
235 "displayInputs": convertedAsdcModel.completeDisplayInputs
240 $scope.$broadcast(broadcastType, {
241 componentId : COMPONENT.SERVICE,
242 modelNameVersionId: serviceModel.service.uuid,
243 callbackFunction : function(response) {
244 if (response.isSuccessful) {
245 vidService.setModel(serviceModel);
247 var subscriberId = FIELD.STATUS.NOT_FOUND;
248 var serviceType = FIELD.STATUS.NOT_FOUND;
250 var serviceInstanceId = response.instanceId;
252 for (var i = 0; i < response.control.length; i++) {
253 if (response.control[i].id == COMPONENT.SUBSCRIBER_NAME) {
254 subscriberId = response.control[i].value;
255 } else if (response.control[i].id == FIELD.ID.SERVICE_TYPE) {
256 serviceType = response.control[i].value;
261 $scope.refreshSubs(subscriberId,serviceType,serviceInstanceId);
266 }, function (response) {
267 console.log("Error: " + response);
273 $scope.loadPreviousVersionData=function(invariantUUID , name, version){
274 $scope.tableData =[];
276 for(var i=0;i<wholeData.length;i++){
277 if(wholeData[i].invariantUUID == invariantUUID && wholeData[i].name == name && version!=wholeData[i].version){
278 oldData.push(wholeData[i]);
281 $scope.tableData = oldData;
282 $scope.createType = "Previous Version";
283 var broadcastType = "createTableComponent";
284 $scope.componentName = name;
285 $scope.$broadcast(broadcastType, {
286 componentId : COMPONENT.OLDVERSION,
287 callbackFunction : function(response) {
292 $scope.refreshSubs = function(subscriberId, serviceType, serviceInstanceId) {
293 $scope.status = FIELD.STATUS.FETCHING_SUBSCRIBER_LIST_AAI;
295 $http.get( FIELD.ID.AAI_REFRESH_FULL_SUBSCRIBERS, {
298 timeout: $scope.responseTimeoutMsec
299 }).then(function(response){
301 if (response.data.status < 200 || response.data.status > 202) {
302 $scope.showError(FIELD.ERROR.MSO);
306 $scope.customer = response.data.customer; // get data from json
308 $scope.customerList = [];
310 $scope.serviceInstanceToCustomer = [];
312 angular.forEach($scope.customer, function(subVal, subKey) {
313 var cust = { "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID], "subscriberName": subVal[FIELD.ID.SUBNAME] };
314 $scope.customerList.push(cust);
315 if (subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS] != null) {
316 angular.forEach(subVal[FIELD.ID.SERVICE_SUBSCRIPTIONS][FIELD.ID.SERVICE_SUBSCRIPTION], function(serviceSubscription, key) {
317 $scope.serviceInstanceId = [];
318 if (serviceSubscription[FIELD.ID.SERVICETYPE] != null) {
319 $scope.serviceType = serviceSubscription[FIELD.ID.SERVICETYPE];
321 $scope.serviceType = FIELD.STATUS.NO_SERVICE_SUBSCRIPTION_FOUND;
323 if (serviceSubscription[FIELD.ID.SERVICE_INSTANCES] != null) {
324 angular.forEach(serviceSubscription[FIELD.ID.SERVICE_INSTANCES][FIELD.ID.SERVICE_INSTANCE], function(instValue, instKey) {
325 var foo = { "serviceInstanceId": instValue[FIELD.ID.SERVICE_INSTANCE_ID],
326 "globalCustomerId": subVal[FIELD.ID.GLOBAL_CUSTOMER_ID],
327 "subscriberName": subVal[FIELD.ID.SUBNAME] };
328 $scope.serviceInstanceToCustomer.push(foo);
334 DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);
335 var serviceIdList = [];
336 $http.get( FIELD.ID.AAI_GET_SERVICES, {
338 timeout: $scope.responseTimeoutMsec
339 }).then(function(response) {
340 angular.forEach(response.data, function(value, key) {
341 angular.forEach(value, function(subVal, key) {
342 var newVal = { "id" : subVal[FIELD.ID.SERVICE_ID], "description" : subVal[FIELD.ID.SERVICE_DESCRIPTION] ,"isPermitted" : subVal[FIELD.ID.IS_PERMITTED] };
343 serviceIdList.push(newVal);
344 DataService.setServiceIdList(serviceIdList);
347 "subscriberId": subscriberId,
348 "serviceType": serviceType,
349 "serviceInstanceId": serviceInstanceId,
350 "isPermitted": newVal.isPermitted.toString()
353 $location.path(COMPONENT.INSTANTIATE_PATH);
358 ["catch"]($scope.handleServerError);