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)
28 appDS2.controller("ServiceProxyConfigController", ["COMPONENT", "$log", "FIELD", "PARAMETER", "DataService", "CreationService", "$scope", "$window", "$location", "AaiService", "$uibModal", "UtilityService", "$timeout",
29 function (COMPONENT, $log, FIELD, PARAMETER, DataService, CreationService, $scope, $window, $location, AaiService, $uibModal, UtilityService, $timeout) {
31 $scope.selectedMetadata = {};
33 $scope.serviceMetadataFields = [];
34 $scope.nodeTemplateFields = {};
36 $scope.configurationByPolicy = DataService.getConfigurationByPolicy();
38 $scope.collectorType = $scope.configurationByPolicy ? 'pnf' : 'vnf'; //default
39 $scope.collectorInstance;
40 $scope.collectorInstanceName = "";
41 $scope.collectorInstanceList = null;
42 $scope.collectorMetadata = [];
43 $scope.collectorNoResults = false;
45 $scope.sourceInstance;
46 $scope.sourceInstanceName = "";
47 $scope.sourceInstanceList = null;
48 $scope.sourceMetadata = [];
49 $scope.sourceNoResults = false;
51 $scope.errorMsg = FIELD.ERROR.INSTANCE_NAME_VALIDATE;
53 $scope.modelName = DataService.getModelInfo(COMPONENT.VNF).modelCustomizationName;
55 $scope.serviceTypes = [];
60 generateMetadata(sourceServiceProxy);
61 generateMetadata(collectorServiceProxy);
65 function setDefaultCollectorServiceType() {
66 const configServiceType = DataService.getServiceType();
67 $scope.collectorServiceType = mustFind($scope.serviceTypes, {"service-type": configServiceType});
68 loadCollectorProxies();
71 function handleGetServiceTypesResponse(response) {
72 $scope.serviceTypes = response.data;
73 setDefaultCollectorServiceType();
76 var handleGetParametersResponse = function(parameters) {
77 $scope.serviceMetadataFields = parameters.summaryList;
78 $scope.nodeTemplateFields = DataService.getPortMirroningConfigFields();
81 var mustFind = function (collection, predicate) {
82 const result = _.find(collection, predicate);
83 const description = "result for find " + JSON.stringify(predicate);
84 UtilityService.checkUndefined(description, result);
85 $log.debug(description, result);
90 $scope.back = function() {
91 $window.history.back();
95 function loadServiceTypes() {
96 const subscriberId = DataService.getGlobalCustomerId();
97 AaiService.getSubscriberServiceTypes(subscriberId)
98 .then(handleGetServiceTypesResponse)
99 .catch(function (error) {
106 $scope.create = function() {
107 $scope.disableCreate= true;
108 var portMirroringConfigFields = DataService.getPortMirroningConfigFields();
109 portMirroringConfigFields.sourceInstance = mustFind($scope.sourceInstanceList, {'id': $scope.sourceInstance});
110 portMirroringConfigFields.destinationInstance = mustFind($scope.collectorInstanceList, {'id': $scope.collectorInstance});
112 var selectedVnfsList;
114 if ($scope.configurationByPolicy) {
116 portMirroringConfigFields.sourceInstance.properties
120 portMirroringConfigFields.sourceInstance.properties,
121 portMirroringConfigFields.destinationInstance.properties
125 AaiService.getVnfVersionsByInvariantId(
126 selectedVnfsList.map(function(x) {
127 return UtilityService.checkUndefined("model-invariant-id", x['model-invariant-id']);
130 .then(function (response) {
131 $log.debug("getVnfVersionsByInvariantId: response", response);
134 .map(function (inOutProperties) {
135 const model = mustFind(response.data.model, {'model-invariant-id': inOutProperties['model-invariant-id']});
137 const modelVer = mustFind(model["model-vers"]["model-ver"], {'model-version-id': inOutProperties['model-version-id']});
139 inOutProperties['model-version'] = modelVer['model-version'];
140 inOutProperties['model-name'] = modelVer['model-name'];
141 UtilityService.checkUndefined("model-version", modelVer);
146 var requestParams = {
147 configurationModelInfo: DataService.getModelInfo(COMPONENT.VNF),
148 relatedTopModelsInfo: DataService.getModelInfo(COMPONENT.SERVICE),
149 portMirroringConfigFields:portMirroringConfigFields,
150 attuuid: DataService.getLoggedInUserId(),
151 topServiceInstanceId: DataService.getServiceInstanceId(),
152 configurationByPolicy: $scope.configurationByPolicy,
153 callbackFunction: updateViewCallbackFunction
156 modalInstance = $uibModal.open({
157 templateUrl: 'app/vid/scripts/modals/mso-commit/mso-commit.html',
158 controller : "msoCommitModalController",
161 msoType: function () {
162 return COMPONENT.MSO_CREATE_REQ;
164 requestParams: function () {
165 return requestParams;
167 configuration: function () {
173 .catch(function (error) {
174 $log.error("error while configuration create", error);
175 $scope.disableCreate= false;
179 $scope.openMetadataModal = function(name) {
180 $scope.selectedMetadata = $scope[name];
181 modalInstance = $uibModal.open({
182 templateUrl: 'app/vid/scripts/modals/service-metadata/service-metadata.html',
190 $scope.cancel = function() {
191 modalInstance.dismiss('cancel');
194 var updateViewCallbackFunction = function(response) {
195 $scope.callbackResults = "";
196 var color = FIELD.ID.COLOR_NONE;
197 $scope.callbackStyle = {
198 "background-color" : color
202 * This 1/2 delay was only added to visually highlight the status
203 * change. Probably not needed in the real application code.
205 $timeout(function() {
206 $scope.callbackResults = UtilityService.getCurrentTime()
207 + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
208 if (response.isSuccessful) {
209 color = FIELD.ID.COLOR_8F8;
210 $window.history.go(-2);
212 $scope.disableCreate=false;
213 color = FIELD.ID.COLOR_F88;
215 $scope.callbackStyle = {
216 "background-color" : color
221 CreationService.initializeComponent(COMPONENT.VNF);
222 CreationService.initializeComponent(COMPONENT.SERVICE);
223 CreationService.getParameters(handleGetParametersResponse);
225 var sourceServiceProxies = DataService.getSourceServiceProxies();
226 var collectorServiceProxies = DataService.getCollectorServiceProxies();
227 var serviceProxiesList = DataService.getServiceProxies();
229 var sourceServiceProxy = {
230 serviceList: sourceServiceProxies,
231 instanceListScopePropertyName: "sourceInstanceList",
232 name: "sourceInstanceName",
233 metadata: "sourceMetadata",
234 noResults: "sourceNoResults"
237 var collectorServiceProxy = {
238 serviceList: collectorServiceProxies,
239 instanceListScopePropertyName: "collectorInstanceList",
240 name: "collectorInstanceName",
241 metadata: "collectorMetadata",
242 noResults: "collectorNoResults"
245 $scope.onSourceServiceTypeSelected = function() {
246 clearSourceProxySelection();
250 $scope.onCollectorServiceTypeSelected = function() {
251 clearCollectorProxySelection();
252 loadCollectorProxies();
255 function clearSourceProxySelection() {
256 $scope.sourceInstance = undefined;
259 function clearCollectorProxySelection() {
260 $scope.collectorInstance = undefined;
263 function loadSourceProxies() {
264 var serviceProxy = serviceProxiesList[(sourceServiceProxy.serviceList)[0]];
265 var selectedServiceType = $scope.sourceServiceType['service-type'];
266 loadProxyInstances(sourceServiceProxy, selectedServiceType, serviceProxy);
269 function loadCollectorProxies() {
270 var serviceProxy = serviceProxiesList[(collectorServiceProxy.serviceList)[0]];
271 var selectedServiceType = $scope.collectorServiceType['service-type'];
272 loadProxyInstances(collectorServiceProxy, selectedServiceType, serviceProxy);
275 function loadProxyInstances(service, serviceType, serviceProxy) {
276 $scope[service.instanceListScopePropertyName] = null;
277 // $scope.collectorType = $scope.configurationByPolicy ? 'pnf' : 'vnf';
278 var configNodeTemplateFields = DataService.getPortMirroningConfigFields();
279 if (service.name == "collectorInstanceName" && $scope.configurationByPolicy) {
280 var configurationModel = DataService.getModelInfo(COMPONENT.VNF);
281 AaiService.getPnfInstancesList(
282 DataService.getGlobalCustomerId(),
284 serviceProxy.sourceModelUuid,
285 serviceProxy.sourceModelInvariant,
286 configNodeTemplateFields.lcpRegion.value,
287 configurationModel.properties.equip_vendor,
288 configurationModel.properties.equip_model
290 .then(function (response) {
291 var results = response.results || [];
292 $scope[service.instanceListScopePropertyName] = results;
293 $scope[service.noResults] = (results.length === 0);
295 .catch(function (error) {
296 $scope[service.noResults] = true;
297 $log.error("No pnf instance found for " + service.name, error);
300 AaiService.getVnfInstancesList(
301 DataService.getGlobalCustomerId(),
303 serviceProxy.sourceModelUuid,
304 serviceProxy.sourceModelInvariant,
305 configNodeTemplateFields.lcpRegion.value
307 .then(function (response) {
308 var results = response.results || [];
309 $scope[service.instanceListScopePropertyName] = results;
310 $scope[service.noResults] = (results.length === 0);
312 .catch(function (error) {
313 $scope[service.noResults] = true;
314 $log.error("No vnf instance found for " + service.name, error);
319 function generateMetadata(service) {
320 const serviceProxy = serviceProxiesList[(service.serviceList)[0]];
321 $scope[service.name] = serviceProxy.name;
323 $scope[service.metadata] = [
324 {"name" :"Name" ,"value" : serviceProxy.name},
325 {"name" :"Version",value : serviceProxy.version},
326 {"name" :"Description", value : serviceProxy.description},
327 {"name" :"Type", value : serviceProxy.type},
328 {"name" :"Invariant UUID", value : serviceProxy.invariantUuid},
329 {"name" :"UUID", value : serviceProxy.uuid},
330 {"name" :"Customization UUID", value : serviceProxy.customizationUuid},
331 {"name" :"Source Model Uuid", value : serviceProxy.sourceModelUuid},
332 {"name" :"Source Model Invariant", value : serviceProxy.sourceModelInvariant},
333 {"name" :"Source Model Name", value : serviceProxy.sourceModelName}
338 $scope.$on('$routeChangeStart', function (event, next, current) {
339 if(next.$$route.originalPath!=="/addNetworkNode"){
340 DataService.setPortMirroningConfigFields(null);