X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cds-ui%2Fserver%2Fsrc%2Fcontrollers%2Fblueprint-rest.controller.ts;h=49ecb9df10f26f61c0d9a2f68811e16d191c94fa;hb=1dd0c293d8a076d0c2cabced73572f15790e8736;hp=14aba56177258971a7ac312488110b7d9b2beca7;hpb=1f08618dc6cc421c6b23c1617cef4112b39ee712;p=ccsdk%2Fcds.git diff --git a/cds-ui/server/src/controllers/blueprint-rest.controller.ts b/cds-ui/server/src/controllers/blueprint-rest.controller.ts index 14aba5617..49ecb9df1 100644 --- a/cds-ui/server/src/controllers/blueprint-rest.controller.ts +++ b/cds-ui/server/src/controllers/blueprint-rest.controller.ts @@ -48,7 +48,7 @@ import { BlueprintService } from '../services'; import * as fs from 'fs'; import * as multiparty from 'multiparty'; import * as request_lib from 'request'; -import { controllerApiConfig, processorApiConfig, appConfig } from '../config/app-config'; +import { processorApiConfig, appConfig } from '../config/app-config'; import { bluePrintManagementServiceGrpcClient } from '../clients/blueprint-management-service-grpc-client'; export class BlueprintRestController { @@ -57,7 +57,7 @@ export class BlueprintRestController { public bpservice: BlueprintService, ) { } - @get('/blueprints', { + @get('/controllerblueprint/all', { responses: { '200': { description: 'Blueprint model instance', @@ -69,7 +69,36 @@ export class BlueprintRestController { return await this.bpservice.getAllblueprints(); } - @get('/searchByTags/{tags}', { + @get('/controllerblueprint/paged', { + responses: { + '200': { + description: 'Blueprint model instance with pagination', + content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } }, + }, + }, + }) + async getPagedBlueprints( + @param.query.number('limit') limit: number, + @param.query.number('offset') offset: number, + @param.query.string('sort') sort: string) { + return await this.bpservice.getPagedBueprints(limit, offset, sort); + } + + @get('/controllerblueprint/meta-data/{keyword}', { + responses: { + '200': { + description: 'Blueprint model instance', + content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } }, + }, + }, + }) + async getAllPacakgesByKeword(@param.path.string('keyword') keyword: string) { + return await this.bpservice.getBlueprintsByKeyword(keyword); + } + + + + @get('/controllerblueprint/searchByTags/{tags}', { responses: { '200': { content: { 'application/json': {} }, @@ -80,7 +109,7 @@ export class BlueprintRestController { return await this.bpservice.getByTags(tags); } - @post('/create-blueprint') + @post('/controllerblueprint/create-blueprint') async upload( @requestBody({ description: 'multipart/form-data value.', @@ -98,18 +127,29 @@ export class BlueprintRestController { ): Promise { return new Promise((resolve, reject) => { this.getFileFromMultiPartForm(request).then(file => { - this.uploadFileToBlueprintController(file, "/blueprint-model/", response).then(resp => { - resolve(resp); - }, err => { - reject(err); - }); + // if (appConfig.action.deployBlueprint.grpcEnabled) + if (appConfig.action.grpcEnabled) + return this.uploadFileToBlueprintProcessorGrpc(file, "DRAFT", response); + else + return this.uploadFileToBlueprintController(file, "/blueprint-model/", response); }, err => { reject(err); }); }); + // return new Promise((resolve, reject) => { + // this.getFileFromMultiPartForm(request).then(file => { + // this.uploadFileToBlueprintController(file, "/blueprint-model/", response).then(resp => { + // resolve(resp); + // }, err => { + // reject(err); + // }); + // }, err => { + // reject(err); + // }); + // }); } - @post('/publish') + @post('/controllerblueprint/publish') async publish( @requestBody({ description: 'multipart/form-data value.', @@ -127,18 +167,29 @@ export class BlueprintRestController { ): Promise { return new Promise((resolve, reject) => { this.getFileFromMultiPartForm(request).then(file => { - this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response).then(resp => { - resolve(resp); - }, err => { - reject(err); - }); + // if (appConfig.action.deployBlueprint.grpcEnabled) + if (appConfig.action.grpcEnabled) + return this.uploadFileToBlueprintProcessorGrpc(file, "PUBLISH", response); + else + return this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response); }, err => { reject(err); }); }); + // return new Promise((resolve, reject) => { + // this.getFileFromMultiPartForm(request).then(file => { + // this.uploadFileToBlueprintController(file, "/blueprint-model/publish/", response).then(resp => { + // resolve(resp); + // }, err => { + // reject(err); + // }); + // }, err => { + // reject(err); + // }); + // }); } - @post('/enrich-blueprint') + @post('/controllerblueprint/enrich-blueprint') async enrich( @requestBody({ description: 'multipart/form-data value.', @@ -156,26 +207,35 @@ export class BlueprintRestController { ): Promise { return new Promise((resolve, reject) => { this.getFileFromMultiPartForm(request).then(file => { - this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response).then(resp => { - resolve(resp); - }, err => { - reject(err); - }); - }, err => { - reject(err); + if (appConfig.action.grpcEnabled) + return this.uploadFileToBlueprintProcessorGrpc(file, "ENRICH", response); + else + return this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response) + // this.uploadFileToBlueprintController(file, "/blueprint-model/enrich/", response).then(resp => { + // resolve(resp); + // }, err => { + // reject(err); + // }); + // }, err => { + // reject(err); }); }); } - @get('/download-blueprint/{name}/{version}') + @get('/controllerblueprint/download-blueprint/{name}/{version}') async download( @param.path.string('name') name: string, @param.path.string('version') version: string, @inject(RestBindings.Http.RESPONSE) response: Response, ): Promise { - return this.downloadFileFromBlueprintController("/blueprint-model/download/by-name/" + name + "/version/" + version, response); + + if (appConfig.action.grpcEnabled) + return this.downloadFileFromBlueprintProcessorGrpc(name, version, response); + else + return this.downloadFileFromBlueprintController("/blueprint-model/download/by-name/" + name + "/version/" + version, response); } + async getFileFromMultiPartForm(request: Request): Promise { return new Promise((resolve, reject) => { let form = new multiparty.Form(); @@ -191,7 +251,7 @@ export class BlueprintRestController { }) } - @post('/deploy-blueprint') + @post('/controllerblueprint/deploy-blueprint') async deploy( @requestBody({ description: 'multipart/form-data value.', @@ -209,8 +269,9 @@ export class BlueprintRestController { ): Promise { return new Promise((resolve, reject) => { this.getFileFromMultiPartForm(request).then(file => { - if (appConfig.action.deployBlueprint.grpcEnabled) - return this.uploadFileToBlueprintProcessorGrpc(file, response); + // if (appConfig.action.deployBlueprint.grpcEnabled) + if (appConfig.action.grpcEnabled) + return this.uploadFileToBlueprintProcessorGrpc(file, "PUBLISH", response); else return this.uploadFileToBlueprintProcessor(file, "/execution-service/upload/", response); }, err => { @@ -220,7 +281,7 @@ export class BlueprintRestController { } async uploadFileToBlueprintController(file: multiparty.File, uri: string, response: Response): Promise { - return this.uploadFileToBlueprintService(file, controllerApiConfig.http.url + uri, controllerApiConfig.http.authToken, response); + return this.uploadFileToBlueprintService(file, processorApiConfig.http.url + uri, processorApiConfig.http.authToken, response); } async uploadFileToBlueprintProcessor(file: multiparty.File, uri: string, response: Response): Promise { @@ -267,7 +328,7 @@ export class BlueprintRestController { } async downloadFileFromBlueprintController(uri: string, response: Response): Promise { - return this.downloadFileFromBlueprintService(controllerApiConfig.http.url + uri, controllerApiConfig.http.authToken, response); + return this.downloadFileFromBlueprintService(processorApiConfig.http.url + uri, processorApiConfig.http.authToken, response); } async downloadFileFromBlueprintService(url: string, authToken: string, response: Response): Promise { @@ -289,9 +350,9 @@ export class BlueprintRestController { }) } - async uploadFileToBlueprintProcessorGrpc(file: multiparty.File, response: Response): Promise { + async uploadFileToBlueprintProcessorGrpc(file: multiparty.File, actionName: string, response: Response): Promise { return new Promise((resolve, reject) => { - bluePrintManagementServiceGrpcClient.uploadBlueprint(file.path).then(output => { + bluePrintManagementServiceGrpcClient.uploadBlueprint(file.path, actionName).then(output => { response.send(output.status.message); resolve(response); }, err => { @@ -300,4 +361,16 @@ export class BlueprintRestController { }); }); } -} \ No newline at end of file + async downloadFileFromBlueprintProcessorGrpc(blueprintName: string, blueprintVersion: string, response: Response): Promise { + return new Promise((resolve, reject) => { + bluePrintManagementServiceGrpcClient.downloadBlueprint(blueprintName, blueprintVersion) + .then(output => { + response.send(output.status.message); + resolve(response); + }, err => { + response.status(500).send(err); + resolve(response); + }); + }); + } +}