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;
170 .catch(function (error) {
171 $log.error("error while configuration create", error);
172 $scope.disableCreate= false;
176 $scope.openMetadataModal = function(name) {
177 $scope.selectedMetadata = $scope[name];
178 modalInstance = $uibModal.open({
179 templateUrl: 'app/vid/scripts/modals/service-metadata/service-metadata.html',
187 $scope.cancel = function() {
188 modalInstance.dismiss('cancel');
191 var updateViewCallbackFunction = function(response) {
192 $scope.callbackResults = "";
193 var color = FIELD.ID.COLOR_NONE;
194 $scope.callbackStyle = {
195 "background-color" : color
199 * This 1/2 delay was only added to visually highlight the status
200 * change. Probably not needed in the real application code.
202 $timeout(function() {
203 $scope.callbackResults = UtilityService.getCurrentTime()
204 + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
205 if (response.isSuccessful) {
206 color = FIELD.ID.COLOR_8F8;
207 $window.history.go(-2);
209 $scope.disableCreate=false;
210 color = FIELD.ID.COLOR_F88;
212 $scope.callbackStyle = {
213 "background-color" : color
218 CreationService.initializeComponent(COMPONENT.VNF);
219 CreationService.initializeComponent(COMPONENT.SERVICE);
220 CreationService.getParameters(handleGetParametersResponse);
222 var sourceServiceProxies = DataService.getSourceServiceProxies();
223 var collectorServiceProxies = DataService.getCollectorServiceProxies();
224 var serviceProxiesList = DataService.getServiceProxies();
226 var sourceServiceProxy = {
227 serviceList: sourceServiceProxies,
228 instanceListScopePropertyName: "sourceInstanceList",
229 name: "sourceInstanceName",
230 metadata: "sourceMetadata",
231 noResults: "sourceNoResults"
234 var collectorServiceProxy = {
235 serviceList: collectorServiceProxies,
236 instanceListScopePropertyName: "collectorInstanceList",
237 name: "collectorInstanceName",
238 metadata: "collectorMetadata",
239 noResults: "collectorNoResults"
242 $scope.onSourceServiceTypeSelected = function() {
243 clearSourceProxySelection();
247 $scope.onCollectorServiceTypeSelected = function() {
248 clearCollectorProxySelection();
249 loadCollectorProxies();
252 function clearSourceProxySelection() {
253 $scope.sourceInstance = undefined;
256 function clearCollectorProxySelection() {
257 $scope.collectorInstance = undefined;
260 function loadSourceProxies() {
261 var serviceProxy = serviceProxiesList[(sourceServiceProxy.serviceList)[0]];
262 var selectedServiceType = $scope.sourceServiceType['service-type'];
263 loadProxyInstances(sourceServiceProxy, selectedServiceType, serviceProxy);
266 function loadCollectorProxies() {
267 var serviceProxy = serviceProxiesList[(collectorServiceProxy.serviceList)[0]];
268 var selectedServiceType = $scope.collectorServiceType['service-type'];
269 loadProxyInstances(collectorServiceProxy, selectedServiceType, serviceProxy);
272 function loadProxyInstances(service, serviceType, serviceProxy) {
273 $scope[service.instanceListScopePropertyName] = null;
274 // $scope.collectorType = $scope.configurationByPolicy ? 'pnf' : 'vnf';
275 var configNodeTemplateFields = DataService.getPortMirroningConfigFields();
276 if (service.name == "collectorInstanceName" && $scope.configurationByPolicy) {
277 var configurationModel = DataService.getModelInfo(COMPONENT.VNF);
278 AaiService.getPnfInstancesList(
279 DataService.getGlobalCustomerId(),
281 serviceProxy.sourceModelUuid,
282 serviceProxy.sourceModelInvariant,
283 configNodeTemplateFields.lcpRegion.value,
284 configurationModel.properties.equip_vendor,
285 configurationModel.properties.equip_model
287 .then(function (response) {
288 var results = response.results || [];
289 $scope[service.instanceListScopePropertyName] = results;
290 $scope[service.noResults] = (results.length === 0);
292 .catch(function (error) {
293 $scope[service.noResults] = true;
294 $log.error("No pnf instance found for " + service.name, error);
297 AaiService.getVnfInstancesList(
298 DataService.getGlobalCustomerId(),
300 serviceProxy.sourceModelUuid,
301 serviceProxy.sourceModelInvariant,
302 configNodeTemplateFields.lcpRegion.value
304 .then(function (response) {
305 var results = response.results || [];
306 $scope[service.instanceListScopePropertyName] = results;
307 $scope[service.noResults] = (results.length === 0);
309 .catch(function (error) {
310 $scope[service.noResults] = true;
311 $log.error("No vnf instance found for " + service.name, error);
316 function generateMetadata(service) {
317 const serviceProxy = serviceProxiesList[(service.serviceList)[0]];
318 $scope[service.name] = serviceProxy.name;
320 $scope[service.metadata] = [
321 {"name" :"Name" ,"value" : serviceProxy.name},
322 {"name" :"Version",value : serviceProxy.version},
323 {"name" :"Description", value : serviceProxy.description},
324 {"name" :"Type", value : serviceProxy.type},
325 {"name" :"Invariant UUID", value : serviceProxy.invariantUuid},
326 {"name" :"UUID", value : serviceProxy.uuid},
327 {"name" :"Customization UUID", value : serviceProxy.customizationUuid},
328 {"name" :"Source Model Uuid", value : serviceProxy.sourceModelUuid},
329 {"name" :"Source Model Invariant", value : serviceProxy.sourceModelInvariant},
330 {"name" :"Source Model Name", value : serviceProxy.sourceModelName}
335 $scope.$on('$routeChangeStart', function (event, next, current) {
336 if(next.$$route.originalPath!=="/addNetworkNode"){
337 DataService.setPortMirroningConfigFields(null);