update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / framework / core / modules / api / descriptorModelMetaAPI.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 // DescriptorModelMeta API (NSD + VNFD)
19
20
21 var ModelMeta = {};
22 var Promise = require('bluebird');
23 var rp = require('request-promise');
24 var Promise = require('promise');
25 var constants = require('../../api_utils/constants');
26 var utils = require('../../api_utils/utils');
27 var _ = require('lodash');
28
29 ModelMeta.get = function(req) {
30 var self = this;
31 var api_server = req.query['api_server'];
32
33 return new Promise(function(resolve, reject) {
34 Promise.all([
35 rp({
36 uri: utils.confdPort(api_server) + '/api/schema/nsd-catalog/nsd',
37 method: 'GET',
38 headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, {
39 'Authorization': req.session && req.session.authorization
40 }),
41 forever: constants.FOREVER_ON,
42 rejectUnauthorized: false,
43 resolveWithFullResponse: true
44 }),
45 rp({
46 uri: utils.confdPort(api_server) + '/api/schema/vnfd-catalog/vnfd',
47 method: 'GET',
48 headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, {
49 'Authorization': req.session && req.session.authorization
50 }),
51 forever: constants.FOREVER_ON,
52 rejectUnauthorized: false,
53 resolveWithFullResponse: true
54 })
55 ]).then(function(result) {
56 var response = {};
57 response['data'] = {};
58 if (result[0].body && result[1].body) {
59 response['data']['nsd'] = JSON.parse(result[0].body)['nsd'];
60 response['data']['vnfd'] = JSON.parse(result[1].body)['vnfd'];
61 }
62 response.statusCode = constants.HTTP_RESPONSE_CODES.SUCCESS.OK
63
64 resolve(response);
65 }).catch(function(error) {
66 var response = {};
67 console.log('Problem with ModelMeta.get', error);
68 response.statusCode = error.statusCode || 500;
69 response.errorMessage = {
70 error: 'Failed to get descriptorModelMeta' + error
71 };
72 reject(response);
73 });
74 });
75 };
76
77 module.exports = ModelMeta;