mirror of
https://github.com/dadosfera/maestro.git
synced 2026-12-02 15:30:04 +00:00
maestro connection with microservices - clients and modules
This commit is contained in:
@@ -1,17 +1,22 @@
|
||||
// import { join } from 'path';
|
||||
// import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
import { PipelineProtofile } from '@victorradael/protospack';
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
|
||||
// export const PipelinesClientConfiguration: ClientOptions = {
|
||||
// transport: Transport.GRPC,
|
||||
// options: {
|
||||
// //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
|
||||
// url: `127.0.0.1:50054`,
|
||||
// package: 'pipeline',
|
||||
// protoPath: join(__dirname, '..', 'proto', 'pipeline.proto'),
|
||||
// loader: {
|
||||
// enums: String,
|
||||
// objects: true,
|
||||
// arrays: true,
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
export class PipelinesClientConfiguration {
|
||||
config(): ClientOptions {
|
||||
return {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.PIFACTORY_URL,
|
||||
package: 'pipeline',
|
||||
// credentials: credentials.createSsl(),
|
||||
protoPath: PipelineProtofile,
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,68 +1,211 @@
|
||||
// import {
|
||||
// Controller,
|
||||
// Delete,
|
||||
// Get,
|
||||
// OnModuleInit,
|
||||
// Param,
|
||||
// Post,
|
||||
// Put,
|
||||
// } from '@nestjs/common';
|
||||
// import {
|
||||
// Client,
|
||||
// ClientGrpc,
|
||||
// MessagePattern,
|
||||
// Payload,
|
||||
// } from '@nestjs/microservices';
|
||||
// import { PipelinesService } from './pipelines.service';
|
||||
// import { CreatePipelineDto } from './dto/create-pipeline.dto';
|
||||
// import { UpdatePipelineDto } from './dto/update-pipeline.dto';
|
||||
// import { GrpcClientConfiguration } from './client.config';
|
||||
import {
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Inject,
|
||||
OnModuleInit,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
Client,
|
||||
ClientGrpc,
|
||||
MessagePattern,
|
||||
Payload,
|
||||
} from '@nestjs/microservices';
|
||||
import { PipelinesServiceInterface } from '@victorradael/protospack';
|
||||
import { ICreatePipelineDto, IdRequest, IGetPipelineLogsRequest, IUpdatePipelineRequest } from './interfaces';
|
||||
|
||||
// @Controller('pipeline')
|
||||
// export class PipelinesClientService implements OnModuleInit {
|
||||
// @Client(GrpcClientConfiguration)
|
||||
// private pipelineServiceClient: ClientGrpc;
|
||||
export class PipelinesClientService implements OnModuleInit {
|
||||
private pipelineService: PipelinesServiceInterface;
|
||||
constructor(
|
||||
@Inject('PIPELINES_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||
){}
|
||||
|
||||
// private pipelineService: PipelinesService;
|
||||
onModuleInit() {
|
||||
this.pipelineService =
|
||||
this.grpcClient.getService<PipelinesServiceInterface>(
|
||||
'PipelineService',
|
||||
);
|
||||
}
|
||||
|
||||
// onModuleInit() {
|
||||
// this.pipelineService =
|
||||
// this.pipelineServiceClient.getService<PipelinesService>(
|
||||
// 'PipelineService',
|
||||
// );
|
||||
// }
|
||||
|
||||
// @Post()
|
||||
// create(@Payload() createPipelineDto: CreatePipelineDto) {
|
||||
// return this.pipelineService.create(createPipelineDto);
|
||||
// }
|
||||
async create(@Payload() createPipelineDto: ICreatePipelineDto ) {
|
||||
|
||||
// @Get()
|
||||
// list() {
|
||||
// return this.pipelineService.list();
|
||||
// }
|
||||
console.log('PipelinesClientService', 'Create');
|
||||
|
||||
// @Get(':id')
|
||||
// show(@Param() id: string) {
|
||||
// return this.pipelineService.show(id);
|
||||
// }
|
||||
const createPipelineResponse = await new Promise((resolve, reject) => {
|
||||
this.pipelineService.create(createPipelineDto).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
// @Put(':id')
|
||||
// update(@Param() id: string, @Payload() updatePipelineDto: UpdatePipelineDto) {
|
||||
// return this.pipelineService.update(id, updatePipelineDto);
|
||||
// }
|
||||
return createPipelineResponse;
|
||||
|
||||
}
|
||||
|
||||
// @Delete()
|
||||
// remove(@Param() id: string) {
|
||||
// return this.pipelineService.remove(id);
|
||||
// }
|
||||
async findAll() {
|
||||
console.log('PipelinesClientService', 'FindAll');
|
||||
|
||||
// @Post()
|
||||
// getPipelineLogsMessages(@Param() id: string, @Payload() details: string) {
|
||||
// return this.pipelineService.getPipelineLogsMessages(id, details);
|
||||
// }
|
||||
const findAllPipelineResponse = await new Promise((resolve, reject) => {
|
||||
this.pipelineService.findAll({}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
// getPipelineStatus(id: string) {
|
||||
// return this.pipelineService.getPipelineStatus(id);
|
||||
// }
|
||||
// }
|
||||
return findAllPipelineResponse;
|
||||
}
|
||||
|
||||
async findOne({id}: IdRequest) {
|
||||
console.log('PipelinesClientService', 'FindOne');
|
||||
|
||||
const findOnePipelineResponse = await new Promise((resolve, reject) => {
|
||||
this.pipelineService.findOne({id}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return findOnePipelineResponse;
|
||||
}
|
||||
|
||||
async update(UpdatePipelineRequest:IUpdatePipelineRequest) {
|
||||
console.log('PipelinesClientService', 'Update');
|
||||
|
||||
const updatePipelineResponse = await new Promise((resolve, reject) => {
|
||||
this.pipelineService.update(UpdatePipelineRequest).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return updatePipelineResponse;
|
||||
}
|
||||
|
||||
|
||||
async remove({id}:IdRequest) {
|
||||
console.log('PipelinesClientService', 'Remove');
|
||||
|
||||
const removePipelineResponse = await new Promise((resolve, reject) => {
|
||||
this.pipelineService.remove({id}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return removePipelineResponse;
|
||||
}
|
||||
|
||||
async getPipelineLogsMessages( data:IGetPipelineLogsRequest) {
|
||||
console.log('PipelinesClientService', 'GetPipelineLogsMessages');
|
||||
|
||||
const logsPipelineResponse = await new Promise((resolve, reject) => {
|
||||
this.pipelineService.getPipelineLogs(data).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return logsPipelineResponse;
|
||||
}
|
||||
|
||||
async getPipelineStatus({id}:IdRequest) {
|
||||
console.log('PipelinesClientService', 'GetPipelineStatus');
|
||||
|
||||
const statusPipelineResponse = await new Promise((resolve, reject) => {
|
||||
this.pipelineService.getPipelineStatus({id}).subscribe({
|
||||
next(x) {
|
||||
resolve(x);
|
||||
},
|
||||
error(err) {
|
||||
console.log('Observable Error');
|
||||
reject(err);
|
||||
},
|
||||
complete() {
|
||||
console.log('done');
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => res)
|
||||
.catch((err) => {
|
||||
throw new Error(err);
|
||||
});
|
||||
|
||||
return statusPipelineResponse;
|
||||
}
|
||||
}
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
|
||||
export interface ICreatePipelineDto {
|
||||
input: IdRequest;
|
||||
transformations: IdRequest[];
|
||||
output: IdRequest;
|
||||
tags: string[];
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface IdRequest {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface IUpdatePipelineRequest {
|
||||
input: IdRequest;
|
||||
transformations: IdRequest[];
|
||||
output: IdRequest;
|
||||
tags: string[];
|
||||
name: string;
|
||||
description: string;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface IGetPipelineLogsRequest {
|
||||
id: string;
|
||||
details: string;
|
||||
}
|
||||
Reference in New Issue
Block a user