diff options
Diffstat (limited to 'cds-ui/server')
8 files changed, 311 insertions, 55 deletions
diff --git a/cds-ui/server/src/controllers/blueprint-rest.controller.ts b/cds-ui/server/src/controllers/blueprint-rest.controller.ts index c1f7f9640..38abad80c 100644 --- a/cds-ui/server/src/controllers/blueprint-rest.controller.ts +++ b/cds-ui/server/src/controllers/blueprint-rest.controller.ts @@ -51,12 +51,11 @@ import * as request_lib from 'request'; const REST_BLUEPRINT_CONTROLLER_BASE_URL = process.env.REST_BLUEPRINT_CONTROLLER_BASE_URL || "http://localhost:8080/api/v1"; const REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER = process.env.REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER || "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="; -const REST_BLUEPRINT_PROCESSOR_BASE_URL= "http://localhost:8081/api/v1"; +const REST_BLUEPRINT_PROCESSOR_BASE_URL= process.env.REST_BLUEPRINT_PROCESSOR_BASE_URL ||"http://localhost:8081/api/v1"; +const MULTIPART_FORM_UPLOAD_DIR = process.env.MULTIPART_FORM_UPLOAD_DIR || "/tmp"; export class BlueprintRestController { constructor( - // @repository(BlueprintRepository) - // public blueprintRepository : BlueprintRepository, @inject('services.BlueprintService') public bpservice: BlueprintService, ) {} @@ -71,7 +70,6 @@ export class BlueprintRestController { }) async getall() { return await this.bpservice.getAllblueprints(REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER); - } @post('/create-blueprint') @@ -89,12 +87,39 @@ export class BlueprintRestController { }) request: Request, @inject(RestBindings.Http.RESPONSE) response: Response, - ): Promise<object> { + ): Promise<Response> { return new Promise((resolve, reject) => { this.getFileFromMultiPartForm(request).then(file=>{ - this.uploadFileToBlueprintController(file, "/blueprint-model/").then(resp=>{ - response.setHeader("X-ONAP-RequestID", resp.headers['x-onap-requestid']); - resolve(JSON.parse(resp.body)); + this.uploadFileToBlueprintController(file, REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/", response).then(resp=>{ + resolve(resp); + }, err=>{ + reject(err); + }); + }, err=>{ + reject(err); + }); + }); + } + @post('/publish') + async publish( + @requestBody({ + description: 'multipart/form-data value.', + required: true, + content: { + 'multipart/form-data': { + // Skip body parsing + 'x-parser': 'stream', + schema: {type: 'object'}, + }, + }, + }) + request: Request, + @inject(RestBindings.Http.RESPONSE) response: Response, + ): Promise<Response> { + return new Promise((resolve, reject) => { + this.getFileFromMultiPartForm(request).then(file=>{ + this.uploadFileToBlueprintController(file, REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/publish/", response).then(resp=>{ + resolve(resp); }, err=>{ reject(err); }); @@ -103,7 +128,6 @@ export class BlueprintRestController { }); }); } - @post('/enrich-blueprint') async enrich( @requestBody({ @@ -119,13 +143,11 @@ export class BlueprintRestController { }) request: Request, @inject(RestBindings.Http.RESPONSE) response: Response, - ): Promise<any> { + ): Promise<Response> { return new Promise((resolve, reject) => { this.getFileFromMultiPartForm(request).then(file=>{ - this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/").then(resp=>{ - response.setHeader("X-ONAP-RequestID", resp.headers['x-onap-requestid']); - response.setHeader("Content-Disposition", resp.headers['content-disposition']); - resolve(resp.body); + this.uploadFileToBlueprintController(file, REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/enrich/", response).then(resp=>{ + resolve(resp); }, err=>{ reject(err); }); @@ -139,25 +161,13 @@ export class BlueprintRestController { async download( @param.path.string('name') name: string, @param.path.string('version') version:string, - // @inject(RestBindings.Http.REQUEST) request: Request, @inject(RestBindings.Http.RESPONSE) response: Response, - ): Promise<any> { - return new Promise((resolve, reject) => { - this.downloadFileFromBlueprintController("/blueprint-model/download/by-name/"+name+"/version/"+version).then(resp=>{ - response.setHeader("X-ONAP-RequestID", resp.headers['x-onap-requestid']); - response.setHeader("Content-Disposition", resp.headers['content-disposition']); - resolve(resp.body); - }, err=>{ - reject(err); - }); - }); + ): Promise<Response> { + return this.downloadFileFromBlueprintController(REST_BLUEPRINT_CONTROLLER_BASE_URL+"/blueprint-model/download/by-name/"+name+"/version/"+version, response); } - async getFileFromMultiPartForm(request: Request): Promise<any>{ + async getFileFromMultiPartForm(request: Request): Promise<multiparty.File>{ return new Promise((resolve, reject) => { - // let options = { - // uploadDir: MULTIPART_FORM_UPLOAD_DIR - // } let form = new multiparty.Form(); form.parse(request, (err: any, fields: any, files: { [x: string]: any[]; }) => { if (err) reject(err); @@ -171,9 +181,38 @@ export class BlueprintRestController { }) } - async uploadFileToBlueprintController(file: any, uri: string): Promise<any>{ + @post('/deploy-blueprint') + async deploy( + @requestBody({ + description: 'multipart/form-data value.', + required: true, + content: { + 'multipart/form-data': { + // Skip body parsing + 'x-parser': 'stream', + schema: {type: 'object'}, + }, + }, + }) + request: Request, + @inject(RestBindings.Http.RESPONSE) response: Response, + ): Promise<Response> { + return new Promise((resolve, reject) => { + this.getFileFromMultiPartForm(request).then(file=>{ + this.uploadFileToBlueprintController(file, REST_BLUEPRINT_PROCESSOR_BASE_URL+"/execution-service/upload/", response).then(resp=>{ + resolve(resp); + }, err=>{ + reject(err); + }); + }, err=>{ + reject(err); + }); + }); + } + async uploadFileToBlueprintController(file: multiparty.File, uri: string, response: Response): Promise<Response>{ let options = { - url: REST_BLUEPRINT_CONTROLLER_BASE_URL + uri, + // url: REST_BLUEPRINT_CONTROLLER_BASE_URL + uri, + url:uri, headers: { Authorization: REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER, 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' @@ -189,40 +228,43 @@ export class BlueprintRestController { } }; - return new Promise((resolve, reject) => { - request_lib.post(options, (err: any, resp: any, body: any) => { + var removeTempFile = () => { + fs.unlink(file.path, (err: any) => { if (err) { - //delete tmp file - fs.unlink(file.path, (err: any) => { - if (err) { - console.error(err); - return - } - }) + console.error(err); + } + }); + } + + return new Promise((resolve, reject) => { + request_lib.post(options) + .on("error", err => { reject(err); - }else{ - resolve(resp); - } - }) + }) + .pipe(response) + .once("finish", () => { + removeTempFile(); + resolve(response); + }); }) } - - async downloadFileFromBlueprintController(uri: string): Promise<any> { + async downloadFileFromBlueprintController(uri: string, response: Response): Promise<Response> { let options = { - url: REST_BLUEPRINT_CONTROLLER_BASE_URL + uri, + url: uri, + // REST_BLUEPRINT_CONTROLLER_BASE_URL + uri, headers: { Authorization: REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER, } }; - return new Promise((resolve, reject) => { - request_lib.get(options, (err: any, resp: any, body: any) => { - if (err) { + request_lib.get(options) + .on("error", err => { reject(err); - }else{ - resolve(resp); - } - }) + }) + .pipe(response) + .once("finish", () => { + resolve(response); + }); }) -} + } }
\ No newline at end of file diff --git a/cds-ui/server/src/controllers/data-dictionary.controller.ts b/cds-ui/server/src/controllers/data-dictionary.controller.ts new file mode 100644 index 000000000..36efe6e8a --- /dev/null +++ b/cds-ui/server/src/controllers/data-dictionary.controller.ts @@ -0,0 +1,85 @@ +// Uncomment these imports to begin using these cool features! + +// import {inject} from '@loopback/context'; +import { + post, + param, + get, + getFilterSchemaFor, + getWhereSchemaFor, + patch, + put, + del, + requestBody, + Request, + Response, + RestBindings, +} from '@loopback/rest'; +import { inject } from '@loopback/core'; +import { ResourceDictionaryService } from '../services'; + +const REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER = process.env.REST_BLUEPRINT_CONTROLLER_BASIC_AUTH_HEADER || "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="; +export class DataDictionaryController { + constructor( + @inject('services.ResourceDictionaryService') + public rdservice: ResourceDictionaryService, + ) { } + + @get('/resourcedictionary/{name}', { + responses: { + '200': { + content: { 'application/json': {} }, + }, + }, + }) + async getByName(@param.path.string('name') name: string) { + return await this.rdservice.getByName(name, REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER); + } + @get('/resourcedictionary/{tags}', { + responses: { + '200': { + content: { 'application/json': {} }, + }, + }, + }) + async getByTags(@param.path.string('tags') tags: string) { + return await this.rdservice.getByTags(tags, REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER); + } + + @get('/resourcedictionary/source-mapping', { + responses: { + '200': { + content: { 'application/json': {} }, + }, + }, + }) + async getSourceMapping() { + return await this.rdservice.getSourceMapping(REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER); + } + @post('/resourcedictionary/save', { + responses: { + '200': { + content: { 'application/json': {} } + } + }, + }) + async save(@requestBody({ + content: { 'application/json': { schema: { 'x-ts-type': JSON } } }, + accepts: { 'application/json': { schema: { 'x-ts-type': JSON } } } + }) resourceDictionary: JSON): Promise<any> { + return await this.rdservice.save(REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER, resourceDictionary); + } + @post('/resourcedictionary/search/by-names', { + responses: { + '200': { + content: { 'application/json': {} } + } + }, + }) + async searchByNames(@requestBody({ + content: { 'application/json': { schema: { 'x-ts-type': JSON } } }, + accepts: { 'application/json': { schema: { 'x-ts-type': JSON } } } + }) resourceDictionaryList: JSON): Promise<any> { + return await this.rdservice.searchbyNames(REST_RESOURCE_DICTIONARY_BASIC_AUTH_HEADER, resourceDictionaryList); + } +} diff --git a/cds-ui/server/src/controllers/index.ts b/cds-ui/server/src/controllers/index.ts index bf2bd6fb7..59f635149 100644 --- a/cds-ui/server/src/controllers/index.ts +++ b/cds-ui/server/src/controllers/index.ts @@ -20,3 +20,4 @@ limitations under the License. */ export * from './ping.controller'; +export * from './data-dictionary.controller'; diff --git a/cds-ui/server/src/datasources/index.ts b/cds-ui/server/src/datasources/index.ts index f7a934cd8..7ed2c9121 100644 --- a/cds-ui/server/src/datasources/index.ts +++ b/cds-ui/server/src/datasources/index.ts @@ -22,3 +22,4 @@ limitations under the License. export * from './db.datasource'; export * from './blueprint.datasource'; +export * from './resource-dictionary.datasource'; diff --git a/cds-ui/server/src/datasources/resource-dictionary.datasource.json b/cds-ui/server/src/datasources/resource-dictionary.datasource.json new file mode 100644 index 000000000..9bf5f30c4 --- /dev/null +++ b/cds-ui/server/src/datasources/resource-dictionary.datasource.json @@ -0,0 +1,89 @@ +{ + "name": "resourceDictionary", + "connector": "rest", + "baseURL": "http://localhost:8080/api/v1/dictionary", + "crud": false, + "operations": [{ + "template": { + "method": "GET", + "url": "http://localhost:8080/api/v1/dictionary/{name}", + "headers": { + "accepts": "application/json", + "content-type": "application/json", + "authorization": "{authtoken}" + }, + "responsePath": "$.*" + }, + "functions": { + "getByName": ["name", "authtoken"] + + } + }, + { + "template": { + "method": "GET", + "url": "http://localhost:8080/api/v1/dictionary/source-mapping", + "headers": { + "accepts": "application/json", + "content-type": "application/json", + "authorization": "{authtoken}" + }, + "responsePath": "$.*" + }, + "functions": { + "getSourceMapping": ["authtoken"] + + } + }, + { + "template": { + "method": "GET", + "url": "http://localhost:8080/api/v1/dictionary/search/{tags}", + "headers": { + "accepts": "application/json", + "content-type": "application/json", + "authorization": "{authtoken}" + }, + "responsePath": "$.*" + }, + "functions": { + "getByTags": ["tags", "authtoken"] + + } + }, + { + "template": { + "method": "POST", + "url": "http://localhost:8080/api/v1/dictionary", + "headers": { + "accepts": "application/json", + "content-type": "application/json", + "authorization": "{authtoken}" + }, + "body": "{resourceDictionary}", + "responsePath": "$.*" + }, + "functions": { + "save": ["authtoken", "resourceDictionary"] + + } + }, + { + "template": { + "method": "POST", + "url": "http://localhost:8080/api/v1/dictionary/by-names", + "headers": { + "accepts": "application/json", + "content-type": "application/json", + "authorization": "{authtoken}" + }, + "body": "{resourceDictionaryList}", + "responsePath": "$.*" + }, + "functions": { + "searchbyNames": ["authtoken", "resourceDictionaryList"] + + } + } + ] +}
\ No newline at end of file diff --git a/cds-ui/server/src/datasources/resource-dictionary.datasource.ts b/cds-ui/server/src/datasources/resource-dictionary.datasource.ts new file mode 100644 index 000000000..381ab9a78 --- /dev/null +++ b/cds-ui/server/src/datasources/resource-dictionary.datasource.ts @@ -0,0 +1,14 @@ +import {inject} from '@loopback/core'; +import {juggler} from '@loopback/repository'; +import * as config from './resource-dictionary.datasource.json'; + +export class ResourceDictionaryDataSource extends juggler.DataSource { + static dataSourceName = 'resourceDictionary'; + + constructor( + @inject('datasources.config.resourceDictionary', {optional: true}) + dsConfig: object = config, + ) { + super(dsConfig); + } +} diff --git a/cds-ui/server/src/services/index.ts b/cds-ui/server/src/services/index.ts index 26b01ed0b..8a82e3231 100644 --- a/cds-ui/server/src/services/index.ts +++ b/cds-ui/server/src/services/index.ts @@ -1 +1,2 @@ export * from './blueprint.service'; +export * from './resource-dictionary.service'; diff --git a/cds-ui/server/src/services/resource-dictionary.service.ts b/cds-ui/server/src/services/resource-dictionary.service.ts new file mode 100644 index 000000000..44ba1a347 --- /dev/null +++ b/cds-ui/server/src/services/resource-dictionary.service.ts @@ -0,0 +1,23 @@ +import {getService} from '@loopback/service-proxy'; +import {inject, Provider} from '@loopback/core'; +import {ResourceDictionaryDataSource} from '../datasources'; + +export interface ResourceDictionaryService { + getByName(name: string, authtoken: string): Promise<JSON>; + getSourceMapping(authtoken: string): Promise<JSON>; + getByTags(tags: string, authtoken: string): Promise<JSON>; + save(authtoken: string, resourceDictionary: JSON): Promise<JSON>; + searchbyNames(authtoken: string, resourceDictionaryList: JSON): Promise<JSON>; +} + +export class ResourceDictionaryServiceProvider implements Provider<ResourceDictionaryService> { + constructor( + // resourceDictionary must match the name property in the datasource json file + @inject('datasources.resourceDictionary') + protected dataSource: ResourceDictionaryDataSource = new ResourceDictionaryDataSource(), + ) {} + + value(): Promise<ResourceDictionaryService> { + return getService(this.dataSource); + } +} |