2 * Copyright (c) 2017 highstreet technologies GmbH and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 define(['app/onapAai/onapAai.module', 'app/mwtnCommons/mwtnCommons.services'], function (onapAaiApp) {
11 onapAaiApp.register.factory('$onapAai', function ($q, $http, Base64, $mwtnCommons, $mwtnDatabase, $mwtnLog, Device) {
15 var functionId = "mwtn";
16 var docType = "device";
20 var deviceLookup = {};
21 $mwtnDatabase.getAllData(functionId, docType, from, size, sort).then(
22 function successCallback(response) {
23 response.data.hits.hits.map(function(device){
24 deviceLookup[device._id] = new Device(device._source);
26 }, function errorCallback(response) {
30 service.checkModules = $mwtnCommons.checkModules;
31 service.getMwtnWebSocketUrl = $mwtnCommons.getMwtnWebSocketUrl;
32 service.gridOptions = $mwtnCommons.gridOptions;
33 service.formatData = $mwtnCommons.formatData;
34 service.formatTimeStamp = $mwtnCommons.formatTimeStamp;
35 service.deleteDocType = $mwtnDatabase.deleteDocType;
38 var transactionId = 1;
39 var getHeaders = function () {
41 'Accept': 'application/json',
42 'Content-Type': 'application/json',
43 'X-TransactionId': transactionId++
47 // create or modify a pnf in aai
48 service.createPnf = function (pnfId, doc) {
49 var base = window.location.origin;
50 var getIp = function (extension) {
51 return extension.filter(function (item) {
52 return item['value-name'] === 'neIpAddress';
53 }).map(function (item) {
58 var device = deviceLookup[pnfId];
59 if (!device) device = new Device({"id":pnfId,"name":pnfId,"mediator-ipv4":"127.0.0.1","netconf-port":"830","oam-ipv4":"127.0.0.1","site":"unknown","controller":"this","controller-site":"unknown","vendor":"unknown","type":"unknown","model":"unknown","version":"0.0"});
62 "pnf-id": doc.connect.host + ':' + doc.connect.port,
63 "equip-type": device.getType(),
64 "equip-model": device.getModel(),
65 "equip-vendor": device.getVendor(),
66 "ipaddress-v4-oam": getIp(doc['core-model:network-element'].extension) | doc.connect.host,
69 console.info('pnf', data);
72 url: base + '/aai/network/pnfs/pnf/' + pnfId, // to es config
73 // withCredentials: true,
74 headers: getHeaders(),
77 var deferred = $q.defer();
78 $http(request).then(function successCallback(response) {
79 deferred.resolve(response);
80 }, function errorCallback(response) {
81 deferred.reject(response);
84 return deferred.promise;
87 service.deletePnf = function (pnfId) {
88 // curl -X DELETE http://localhost:8282/aai/network/pnfs/pnf/Ericsson-A1 --insecure -v -u AAI:AAI -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'X-FromAppId: SDNR' -H 'X-TransactionId: 9999'
89 var base = window.location.origin;
92 url: base + '/aai/network/pnfs/pnf/' + pnfId, // to es config
93 // withCredentials: true,
96 var deferred = $q.defer();
97 $http(request).then(function successCallback(response) {
98 deferred.resolve(response);
99 }, function errorCallback(response) {
100 deferred.reject(response);
103 return deferred.promise;
106 service.getAaiPnfs = function () {
107 // curl https://10.31.1.55:8443/network/pnfs -k -v -u abc:def -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'X-FromAppId: SDNR' -H 'X-TransactionId: 9999'
109 var base = window.location.origin;
112 url: base + '/aai/network/pnfs', // to es config
113 // withCredentials: true,
114 headers: getHeaders(),
117 var deferred = $q.defer();
118 $http(request).then(function successCallback(response) {
119 deferred.resolve(response);
120 }, function errorCallback(response) {
121 deferred.reject(response);
124 return deferred.promise;
131 onapAaiApp.register.factory('Device', function () {
132 var Device = function (data) {
134 data = {id:new Date(), type: 'unknown', name:'unknonw', model: 'unkonwn', vendor:'unknonw', version:'unkonwn'};
137 this.getData = function () {
140 this.getId = function () {
141 return this.getData().id;
143 this.getType = function () {
144 return this.getData().type;
146 this.getName = function () {
147 return this.getData().name;
149 this.getModel = function () {
150 return this.getData().model;
152 this.getVendor = function () {
153 return this.getData().vendor;
155 this.getVersion = function () {
156 return this.getData().version;