2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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 = [];
63 $scope.isSourceSubscriberEnabled = function() {
64 return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_2006_PORT_MIRRORING_LET_SELECTING_SOURCE_SUBSCRIBER)
65 && !$scope.configurationByPolicy;
69 if ($scope.isSourceSubscriberEnabled()) {
70 loadSourceSubscriber();
72 loadServiceTypes(DataService.getGlobalCustomerId(), handleGetSourceAndCollectorServiceTypesResponse);
73 generateMetadata(sourceServiceProxy);
74 generateMetadata(collectorServiceProxy);
78 function loadSourceSubscriber() {
79 AaiService.getSubList(function (response) {
80 $scope.sourceSubscribers = response;
81 $scope.sourceSubscriber = response.find((subscriber)=>{
82 return subscriber.globalCustomerId === DataService.getGlobalCustomerId();
84 }, function (response) { // failure
85 $scope.sourceSubscribers = [];
89 function getSourceSubscriberId() {
90 return $scope.isSourceSubscriberEnabled()
91 ? $scope.sourceSubscriber && $scope.sourceSubscriber.globalCustomerId
92 : DataService.getGlobalCustomerId()
95 function setDefaultCollectorServiceType() {
96 const configServiceType = DataService.getServiceType();
97 $scope.collectorServiceType = mustFind($scope.serviceTypes, {"service-type": configServiceType});
98 loadCollectorProxies();
101 function handleGetSourceAndCollectorServiceTypesResponse(response) {
102 handleGetSourceServiceTypesResponse(response)
103 handleGetCollectorServiceTypesResponse(response)
106 function handleGetCollectorServiceTypesResponse(response) {
107 $scope.serviceTypes = response.data;
108 setDefaultCollectorServiceType();
111 function handleGetSourceServiceTypesResponse(response) {
112 $scope.sourceServiceTypes = response.data;
115 var handleGetParametersResponse = function(parameters) {
116 $scope.serviceMetadataFields = parameters.summaryList;
117 $scope.nodeTemplateFields = DataService.getPortMirroningConfigFields();
120 var mustFind = function (collection, predicate) {
121 const result = _.find(collection, predicate);
122 const description = "result for find " + JSON.stringify(predicate);
123 UtilityService.checkUndefined(description, result);
124 $log.debug(description, result);
129 $scope.back = function() {
130 $window.history.back();
133 $scope.onSourceSubscriberChange = function(selectedSubscriber) {
134 $scope.sourceSubscriber = selectedSubscriber
135 loadServiceTypes(selectedSubscriber.globalCustomerId, handleGetSourceServiceTypesResponse)
138 function loadServiceTypes(subscriberId, handleGetServiceTypesResponseCallback) {
139 AaiService.getSubscriberServiceTypes(subscriberId)
140 .then(handleGetServiceTypesResponseCallback)
141 .catch(function (error) {
148 $scope.create = function() {
149 $scope.disableCreate= true;
150 var portMirroringConfigFields = DataService.getPortMirroningConfigFields();
151 portMirroringConfigFields.sourceInstance = mustFind($scope.sourceInstanceList, {'id': $scope.sourceInstance});
152 portMirroringConfigFields.destinationInstance = mustFind($scope.collectorInstanceList, {'id': $scope.collectorInstance});
154 var selectedVnfsList;
156 if ($scope.configurationByPolicy) {
158 portMirroringConfigFields.sourceInstance.properties
162 portMirroringConfigFields.sourceInstance.properties,
163 portMirroringConfigFields.destinationInstance.properties
167 AaiService.getVnfVersionsByInvariantId(
168 selectedVnfsList.map(function(x) {
169 return UtilityService.checkUndefined("model-invariant-id", x['model-invariant-id']);
172 .then(function (response) {
173 $log.debug("getVnfVersionsByInvariantId: response", response);
176 .map(function (inOutProperties) {
177 const model = mustFind(response.data.model, {'model-invariant-id': inOutProperties['model-invariant-id']});
179 const modelVer = mustFind(model["model-vers"]["model-ver"], {'model-version-id': inOutProperties['model-version-id']});
181 inOutProperties['model-version'] = modelVer['model-version'];
182 inOutProperties['model-name'] = modelVer['model-name'];
183 UtilityService.checkUndefined("model-version", modelVer);
188 var requestParams = {
189 configurationModelInfo: DataService.getModelInfo(COMPONENT.VNF),
190 relatedTopModelsInfo: DataService.getModelInfo(COMPONENT.SERVICE),
191 portMirroringConfigFields:portMirroringConfigFields,
192 attuuid: DataService.getLoggedInUserId(),
193 topServiceInstanceId: DataService.getServiceInstanceId(),
194 configurationByPolicy: $scope.configurationByPolicy,
195 callbackFunction: updateViewCallbackFunction
198 modalInstance = $uibModal.open({
199 templateUrl: 'app/vid/scripts/modals/mso-commit/mso-commit.html',
200 controller : "msoCommitModalController",
203 msoType: function () {
204 return COMPONENT.MSO_CREATE_CONFIGURATION_REQ;
206 requestParams: function () {
207 return requestParams;
209 configuration: function () {
215 .catch(function (error) {
216 $log.error("error while configuration create", error);
217 $scope.disableCreate= false;
221 $scope.openMetadataModal = function(name) {
222 $scope.selectedMetadata = $scope[name];
223 modalInstance = $uibModal.open({
224 templateUrl: 'app/vid/scripts/modals/service-metadata/service-metadata.html',
232 $scope.cancel = function() {
233 modalInstance.dismiss('cancel');
236 var updateViewCallbackFunction = function(response) {
237 $scope.callbackResults = "";
238 var color = FIELD.ID.COLOR_NONE;
239 $scope.callbackStyle = {
240 "background-color" : color
244 * This 1/2 delay was only added to visually highlight the status
245 * change. Probably not needed in the real application code.
247 $timeout(function() {
248 $scope.callbackResults = UtilityService.getCurrentTime()
249 + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
250 if (response.isSuccessful) {
251 color = FIELD.ID.COLOR_8F8;
252 $window.history.go(-2);
254 $scope.disableCreate=false;
255 color = FIELD.ID.COLOR_F88;
257 $scope.callbackStyle = {
258 "background-color" : color
263 CreationService.initializeComponent(COMPONENT.VNF);
264 CreationService.initializeComponent(COMPONENT.SERVICE);
265 CreationService.getParameters(handleGetParametersResponse);
267 var sourceServiceProxies = DataService.getSourceServiceProxies();
268 var collectorServiceProxies = DataService.getCollectorServiceProxies();
269 var serviceProxiesList = DataService.getServiceProxies();
271 var sourceServiceProxy = {
272 serviceList: sourceServiceProxies,
273 instanceListScopePropertyName: "sourceInstanceList",
274 name: "sourceInstanceName",
275 metadata: "sourceMetadata",
276 noResults: "sourceNoResults"
279 var collectorServiceProxy = {
280 serviceList: collectorServiceProxies,
281 instanceListScopePropertyName: "collectorInstanceList",
282 name: "collectorInstanceName",
283 metadata: "collectorMetadata",
284 noResults: "collectorNoResults"
287 $scope.onSourceServiceTypeSelected = function() {
288 clearSourceProxySelection();
292 $scope.onCollectorServiceTypeSelected = function() {
293 clearCollectorProxySelection();
294 loadCollectorProxies();
297 $scope.shouldLetSelectingCollectorType = function() {
298 return $scope.collectorType === 'vnf' || featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_1810_CR_LET_SELECTING_COLLECTOR_TYPE_UNCONDITIONALLY);
301 function clearSourceProxySelection() {
302 $scope.sourceInstance = undefined;
305 function clearCollectorProxySelection() {
306 $scope.collectorInstance = undefined;
309 function loadSourceProxies() {
310 var serviceProxy = serviceProxiesList[(sourceServiceProxy.serviceList)[0]];
311 var selectedServiceType = $scope.sourceServiceType['service-type'];
312 loadProxyInstances(sourceServiceProxy, selectedServiceType, serviceProxy);
315 function loadCollectorProxies() {
316 var serviceProxy = serviceProxiesList[(collectorServiceProxy.serviceList)[0]];
317 var selectedServiceType = $scope.collectorServiceType['service-type'];
318 loadProxyInstances(collectorServiceProxy, selectedServiceType, serviceProxy);
321 function loadProxyInstances(service, serviceType, serviceProxy) {
322 $scope[service.instanceListScopePropertyName] = null;
323 var configNodeTemplateFields = DataService.getPortMirroningConfigFields();
324 if (service.name === 'collectorInstanceName' && $scope.configurationByPolicy) {
325 var configurationModel = DataService.getModelInfo(COMPONENT.VNF);
326 AaiService.getPnfInstancesList(
327 getSourceSubscriberId(),
329 serviceProxy.sourceModelUuid,
330 serviceProxy.sourceModelInvariant,
331 configNodeTemplateFields.cloudRegionId,
332 configurationModel.properties.equip_vendor,
333 configurationModel.properties.equip_model
335 .then(function (response) {
336 var results = response.results || [];
337 $scope[service.instanceListScopePropertyName] = results;
338 $scope[service.noResults] = (results.length === 0);
340 .catch(function (error) {
341 $scope[service.noResults] = true;
342 $log.error('No pnf instance found for ' + service.name, error);
345 AaiService.getVnfInstancesList(
346 getSourceSubscriberId(),
348 serviceProxy.sourceModelUuid,
349 serviceProxy.sourceModelInvariant,
350 configNodeTemplateFields.cloudRegionId
352 .then(function (response) {
353 var results = response.results || [];
354 $scope[service.instanceListScopePropertyName] = results;
355 $scope[service.noResults] = (results.length === 0);
357 .catch(function (error) {
358 $scope[service.noResults] = true;
359 $log.error("No vnf instance found for " + service.name, error);
364 function generateMetadata(service) {
365 const serviceProxy = serviceProxiesList[(service.serviceList)[0]];
366 $scope[service.name] = serviceProxy.name;
368 $scope[service.metadata] = [
369 {"name" :"Name" ,"value" : serviceProxy.name},
370 {"name" :"Version",value : serviceProxy.version},
371 {"name" :"Description", value : serviceProxy.description},
372 {"name" :"Type", value : serviceProxy.type},
373 {"name" :"Invariant UUID", value : serviceProxy.invariantUuid},
374 {"name" :"UUID", value : serviceProxy.uuid},
375 {"name" :"Customization UUID", value : serviceProxy.customizationUuid},
376 {"name" :"Source Model Uuid", value : serviceProxy.sourceModelUuid},
377 {"name" :"Source Model Invariant", value : serviceProxy.sourceModelInvariant},
378 {"name" :"Source Model Name", value : serviceProxy.sourceModelName}
383 $scope.$on('$routeChangeStart', function (event, next, current) {
384 if(next.$$route.originalPath!=="/addNetworkNode"){
385 DataService.setPortMirroningConfigFields(null);