X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cds-ui%2Fserver%2Fsrc%2Fcontrollers%2Fblueprint-rest.controller.ts;h=870f9793fa7a531c153c93635e937026b5ab8d39;hb=refs%2Fchanges%2F32%2F109632%2F1;hp=789589837baf9570ef52cb8ef08201082f7a8c96;hpb=6c6ec71317d746bd744cd510a5da79956b8d176c;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 789589837..870f9793f 100644 --- a/cds-ui/server/src/controllers/blueprint-rest.controller.ts +++ b/cds-ui/server/src/controllers/blueprint-rest.controller.ts @@ -20,42 +20,23 @@ limitations under the License. */ - -import { - Count, - CountSchema, - Filter, - repository, - Where, -} from '@loopback/repository'; -import { - post, - param, - get, - getFilterSchemaFor, - getWhereSchemaFor, - patch, - put, - del, - requestBody, - Request, - Response, - RestBindings, -} from '@loopback/rest'; +import { get, param, post, Request, requestBody, Response, RestBindings, del } from '@loopback/rest'; import { Blueprint } from '../models'; import { inject } from '@loopback/core'; import { BlueprintService } from '../services'; import * as fs from 'fs'; import * as multiparty from 'multiparty'; import * as request_lib from 'request'; -import { processorApiConfig, appConfig } from '../config/app-config'; +import { appConfig, processorApiConfig } from '../config/app-config'; import { bluePrintManagementServiceGrpcClient } from '../clients/blueprint-management-service-grpc-client'; +import { BlueprintDetail } from '../models/blueprint.detail.model'; export class BlueprintRestController { constructor( @inject('services.BlueprintService') public bpservice: BlueprintService, - ) { } + ) { + } @get('/controllerblueprint/all', { responses: { @@ -69,6 +50,88 @@ export class BlueprintRestController { return await this.bpservice.getAllblueprints(); } + @get('/controllerblueprint/{id}', { + responses: { + '200': { + description: 'Blueprint model instance', + content: { 'application/json': { schema: { 'x-ts-type': BlueprintDetail } } }, + }, + }, + }) + async getOneBluePrint(@param.path.string('id') id: string) { + return await this.bpservice.getOneBluePrint(id); + } + + @del('/controllerblueprint/{id}', { + responses: { + '200': { + description: 'Blueprint model instance', + content: { 'application/json': { schema: { 'x-ts-type': BlueprintDetail } } }, + }, + }, + }) + async deleteBluePrint(@param.path.string('id') id: string) { + return await this.bpservice.deleteBluePrint(id); + } + + + @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, + @param.query.string('sortType') sortType: string) { + return await this.bpservice.getPagedBueprints(limit, offset, sort, sortType); + } + + @get('/controllerblueprint/metadata/paged/{keyword}', { + responses: { + '200': { + description: 'Blueprint model instance with pagination', + content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } }, + }, + }, + }) + async getMetaDataPagedBlueprints( + @param.path.string('keyword') keyword: string, + @param.query.number('limit') limit: number, + @param.query.number('offset') offset: number, + @param.query.string('sort') sort: string, + @param.query.string('sortType') sortType: string) { + return await this.bpservice.getMetaDataPagedBlueprints(limit, offset, sort, keyword, sortType); + } + + @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/by-name/{name}/version/{version}', { + responses: { + '200': { + description: 'Blueprint model instance', + content: { 'application/json': { schema: { 'x-ts-type': Blueprint } } }, + }, + }, + }) + async getPacakgesByNameAndVersion(@param.path.string('name') name: string, @param.path.string('version') version: string) { + return await this.bpservice.getBlueprintByNameAndVersion(name, version); + } + @get('/controllerblueprint/searchByTags/{tags}', { responses: { '200': { @@ -98,15 +161,26 @@ 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('/controllerblueprint/publish') @@ -127,15 +201,26 @@ 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('/controllerblueprint/enrich-blueprint') @@ -156,13 +241,17 @@ 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); }); }); } @@ -173,9 +262,14 @@ export class BlueprintRestController { @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(); @@ -188,7 +282,7 @@ export class BlueprintRestController { resolve(file); } }); - }) + }); } @post('/controllerblueprint/deploy-blueprint') @@ -209,10 +303,11 @@ 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); + return this.uploadFileToBlueprintProcessor(file, '/execution-service/upload/', response); }, err => { reject(err); }); @@ -232,17 +327,17 @@ export class BlueprintRestController { url: url, headers: { Authorization: authToken, - 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' + 'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW', }, formData: { file: { value: fs.createReadStream(file.path), options: { filename: 'cba.zip', - contentType: 'application/zip' - } - } - } + contentType: 'application/zip', + }, + }, + }, }; var removeTempFile = () => { @@ -251,19 +346,19 @@ export class BlueprintRestController { console.error(err); } }); - } + }; return new Promise((resolve, reject) => { request_lib.post(options) - .on("error", err => { + .on('error', err => { reject(err); }) .pipe(response) - .once("finish", () => { + .once('finish', () => { removeTempFile(); resolve(response); }); - }) + }); } async downloadFileFromBlueprintController(uri: string, response: Response): Promise { @@ -275,23 +370,23 @@ export class BlueprintRestController { url: url, headers: { Authorization: authToken, - } + }, }; return new Promise((resolve, reject) => { request_lib.get(options) - .on("error", err => { + .on('error', err => { reject(err); }) .pipe(response) - .once("finish", () => { + .once('finish', () => { resolve(response); }); - }) + }); } - 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 +395,17 @@ 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); + }); + }); + } +}