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=========================================================
22 * The Instantiation (or View/Edit) Controller controls the instantiation/removal of
23 * deployable objects (Services, VNFs, VF-Modules, Networks, and Volume-Groups)
29 "ServiceProxyConfigController", ["COMPONENT", "$log", "FIELD", "PARAMETER", "DataService",
30 "CreationService", "$scope", "$window", "$location", "AaiService", "$uibModal", "UtilityService", "$timeout",
32 function (COMPONENT, $log, FIELD, PARAMETER, DataService,
33 CreationService, $scope, $window, $location, AaiService, $uibModal, UtilityService, $timeout,
37 $scope.selectedMetadata = {};
39 $scope.serviceMetadataFields = [];
40 $scope.nodeTemplateFields = {};
42 $scope.configurationByPolicy = DataService.getConfigurationByPolicy();
44 $scope.collectorType = $scope.configurationByPolicy ? 'pnf' : 'vnf'; //default
45 $scope.collectorInstance;
46 $scope.collectorInstanceName = "";
47 $scope.collectorInstanceList = null;
48 $scope.collectorMetadata = [];
49 $scope.collectorNoResults = false;
51 $scope.sourceInstance;
52 $scope.sourceInstanceName = "";
53 $scope.sourceInstanceList = null;
54 $scope.sourceMetadata = [];
55 $scope.sourceNoResults = false;
57 $scope.errorMsg = FIELD.ERROR.INSTANCE_NAME_VALIDATE;
59 $scope.modelName = DataService.getModelInfo(COMPONENT.VNF).modelCustomizationName;
61 $scope.serviceTypes = [];
66 generateMetadata(sourceServiceProxy);
67 generateMetadata(collectorServiceProxy);
71 function setDefaultCollectorServiceType() {
72 const configServiceType = DataService.getServiceType();
73 $scope.collectorServiceType = mustFind($scope.serviceTypes, {"service-type": configServiceType});
74 loadCollectorProxies();
77 function handleGetServiceTypesResponse(response) {
78 $scope.serviceTypes = response.data;
79 setDefaultCollectorServiceType();
82 var handleGetParametersResponse = function(parameters) {
83 $scope.serviceMetadataFields = parameters.summaryList;
84 $scope.nodeTemplateFields = DataService.getPortMirroningConfigFields();
87 var mustFind = function (collection, predicate) {
88 const result = _.find(collection, predicate);
89 const description = "result for find " + JSON.stringify(predicate);
90 UtilityService.checkUndefined(description, result);
91 $log.debug(description, result);
96 $scope.back = function() {
97 $window.history.back();
101 function loadServiceTypes() {
102 const subscriberId = DataService.getGlobalCustomerId();
103 AaiService.getSubscriberServiceTypes(subscriberId)
104 .then(handleGetServiceTypesResponse)
105 .catch(function (error) {
112 $scope.create = function() {
113 $scope.disableCreate= true;
114 var portMirroringConfigFields = DataService.getPortMirroningConfigFields();
115 portMirroringConfigFields.sourceInstance = mustFind($scope.sourceInstanceList, {'id': $scope.sourceInstance});
116 portMirroringConfigFields.destinationInstance = mustFind($scope.collectorInstanceList, {'id': $scope.collectorInstance});
118 var selectedVnfsList;
120 if ($scope.configurationByPolicy) {
122 portMirroringConfigFields.sourceInstance.properties
126 portMirroringConfigFields.sourceInstance.properties,
127 portMirroringConfigFields.destinationInstance.properties
131 AaiService.getVnfVersionsByInvariantId(
132 selectedVnfsList.map(function(x) {
133 return UtilityService.checkUndefined("model-invariant-id", x['model-invariant-id']);
136 .then(function (response) {
137 $log.debug("getVnfVersionsByInvariantId: response", response);
140 .map(function (inOutProperties) {
141 const model = mustFind(response.data.model, {'model-invariant-id': inOutProperties['model-invariant-id']});
143 const modelVer = mustFind(model["model-vers"]["model-ver"], {'model-version-id': inOutProperties['model-version-id']});
145 inOutProperties['model-version'] = modelVer['model-version'];
146 inOutProperties['model-name'] = modelVer['model-name'];
147 UtilityService.checkUndefined("model-version", modelVer);
152 var requestParams = {
153 configurationModelInfo: DataService.getModelInfo(COMPONENT.VNF),
154 relatedTopModelsInfo: DataService.getModelInfo(COMPONENT.SERVICE),
155 portMirroringConfigFields:portMirroringConfigFields,
156 attuuid: DataService.getLoggedInUserId(),
157 topServiceInstanceId: DataService.getServiceInstanceId(),
158 configurationByPolicy: $scope.configurationByPolicy,
159 callbackFunction: updateViewCallbackFunction
162 modalInstance = $uibModal.open({
163 templateUrl: 'app/vid/scripts/modals/mso-commit/mso-commit.html',
164 controller : "msoCommitModalController",
167 msoType: function () {
168 return COMPONENT.MSO_CREATE_CONFIGURATION_REQ;
170 requestParams: function () {
171 return requestParams;
173 configuration: function () {
179 .catch(function (error) {
180 $log.error("error while configuration create", error);
181 $scope.disableCreate= false;
185 $scope.openMetadataModal = function(name) {
186 $scope.selectedMetadata = $scope[name];
187 modalInstance = $uibModal.open({
188 templateUrl: 'app/vid/scripts/modals/service-metadata/service-metadata.html',
196 $scope.cancel = function() {
197 modalInstance.dismiss('cancel');
200 var updateViewCallbackFunction = function(response) {
201 $scope.callbackResults = "";
202 var color = FIELD.ID.COLOR_NONE;
203 $scope.callbackStyle = {
204 "background-color" : color
208 * This 1/2 delay was only added to visually highlight the status
209 * change. Probably not needed in the real application code.
211 $timeout(function() {
212 $scope.callbackResults = UtilityService.getCurrentTime()
213 + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
214 if (response.isSuccessful) {
215 color = FIELD.ID.COLOR_8F8;
216 $window.history.go(-2);
218 $scope.disableCreate=false;
219 color = FIELD.ID.COLOR_F88;
221 $scope.callbackStyle = {
222 "background-color" : color
227 CreationService.initializeComponent(COMPONENT.VNF);
228 CreationService.initializeComponent(COMPONENT.SERVICE);
229 CreationService.getParameters(handleGetParametersResponse);
231 var sourceServiceProxies = DataService.getSourceServiceProxies();
232 var collectorServiceProxies = DataService.getCollectorServiceProxies();
233 var serviceProxiesList = DataService.getServiceProxies();
235 var sourceServiceProxy = {
236 serviceList: sourceServiceProxies,
237 instanceListScopePropertyName: "sourceInstanceList",
238 name: "sourceInstanceName",
239 metadata: "sourceMetadata",
240 noResults: "sourceNoResults"
243 var collectorServiceProxy = {
244 serviceList: collectorServiceProxies,
245 instanceListScopePropertyName: "collectorInstanceList",
246 name: "collectorInstanceName",
247 metadata: "collectorMetadata",
248 noResults: "collectorNoResults"
251 $scope.onSourceServiceTypeSelected = function() {
252 clearSourceProxySelection();
256 $scope.onCollectorServiceTypeSelected = function() {
257 clearCollectorProxySelection();
258 loadCollectorProxies();
261 $scope.shouldLetSelectingCollectorType = function() {
262 return $scope.collectorType === 'vnf' || featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_1810_CR_LET_SELECTING_COLLECTOR_TYPE_UNCONDITIONALLY);
265 function clearSourceProxySelection() {
266 $scope.sourceInstance = undefined;
269 function clearCollectorProxySelection() {
270 $scope.collectorInstance = undefined;
273 function loadSourceProxies() {
274 var serviceProxy = serviceProxiesList[(sourceServiceProxy.serviceList)[0]];
275 var selectedServiceType = $scope.sourceServiceType['service-type'];
276 loadProxyInstances(sourceServiceProxy, selectedServiceType, serviceProxy);
279 function loadCollectorProxies() {
280 var serviceProxy = serviceProxiesList[(collectorServiceProxy.serviceList)[0]];
281 var selectedServiceType = $scope.collectorServiceType['service-type'];
282 loadProxyInstances(collectorServiceProxy, selectedServiceType, serviceProxy);
285 function loadProxyInstances(service, serviceType, serviceProxy) {
286 $scope[service.instanceListScopePropertyName] = null;
287 var configNodeTemplateFields = DataService.getPortMirroningConfigFields();
288 if (service.name === 'collectorInstanceName' && $scope.configurationByPolicy) {
289 var configurationModel = DataService.getModelInfo(COMPONENT.VNF);
290 AaiService.getPnfInstancesList(
291 DataService.getGlobalCustomerId(),
293 serviceProxy.sourceModelUuid,
294 serviceProxy.sourceModelInvariant,
295 configNodeTemplateFields.lcpRegion.value,
296 configurationModel.properties.equip_vendor,
297 configurationModel.properties.equip_model
299 .then(function (response) {
300 var results = response.results || [];
301 $scope[service.instanceListScopePropertyName] = results;
302 $scope[service.noResults] = (results.length === 0);
304 .catch(function (error) {
305 $scope[service.noResults] = true;
306 $log.error('No pnf instance found for ' + service.name, error);
309 AaiService.getVnfInstancesList(
310 DataService.getGlobalCustomerId(),
312 serviceProxy.sourceModelUuid,
313 serviceProxy.sourceModelInvariant,
314 configNodeTemplateFields.lcpRegion.value
316 .then(function (response) {
317 var results = response.results || [];
318 $scope[service.instanceListScopePropertyName] = results;
319 $scope[service.noResults] = (results.length === 0);
321 .catch(function (error) {
322 $scope[service.noResults] = true;
323 $log.error("No vnf instance found for " + service.name, error);
328 function generateMetadata(service) {
329 const serviceProxy = serviceProxiesList[(service.serviceList)[0]];
330 $scope[service.name] = serviceProxy.name;
332 $scope[service.metadata] = [
333 {"name" :"Name" ,"value" : serviceProxy.name},
334 {"name" :"Version",value : serviceProxy.version},
335 {"name" :"Description", value : serviceProxy.description},
336 {"name" :"Type", value : serviceProxy.type},
337 {"name" :"Invariant UUID", value : serviceProxy.invariantUuid},
338 {"name" :"UUID", value : serviceProxy.uuid},
339 {"name" :"Customization UUID", value : serviceProxy.customizationUuid},
340 {"name" :"Source Model Uuid", value : serviceProxy.sourceModelUuid},
341 {"name" :"Source Model Invariant", value : serviceProxy.sourceModelInvariant},
342 {"name" :"Source Model Name", value : serviceProxy.sourceModelName}
347 $scope.$on('$routeChangeStart', function (event, next, current) {
348 if(next.$$route.originalPath!=="/addNetworkNode"){
349 DataService.setPortMirroningConfigFields(null);