mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-17 19:49:08 +00:00
maestro connection with microservices - clients and modules
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
// import { join } from 'path';
|
||||
// import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
import { credentials } from '@grpc/grpc-js';
|
||||
import { ClientOptions, Transport } from '@nestjs/microservices';
|
||||
|
||||
// export const InputsClientConfiguration: ClientOptions = {
|
||||
// transport: Transport.GRPC,
|
||||
// options: {
|
||||
// //url: `${process.env.USERS_SVC_URL}:${process.env.USERS_SVC_PORT}`,
|
||||
// url: `127.0.0.1:50052`,
|
||||
// package: 'input',
|
||||
// protoPath: join(__dirname, '..', 'proto', 'input.proto'),
|
||||
// loader: {
|
||||
// enums: String,
|
||||
// objects: true,
|
||||
// arrays: true,
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
import { InputProtofile } from '@victorradael/protospack';
|
||||
|
||||
export class InputsClientConfiguration {
|
||||
config(): ClientOptions {
|
||||
return {
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
url: process.env.INFACTORY_URL,
|
||||
package: 'input',
|
||||
// credentials: credentials.createSsl(),
|
||||
protoPath: InputProtofile,
|
||||
loader: {
|
||||
enums: String,
|
||||
objects: true,
|
||||
arrays: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,64 +1,185 @@
|
||||
// import {
|
||||
// Get,
|
||||
// Post,
|
||||
// Controller,
|
||||
// Delete,
|
||||
// OnModuleInit,
|
||||
// Put,
|
||||
// Param,
|
||||
// } from '@nestjs/common';
|
||||
// import { Client, ClientGrpc, Payload } from '@nestjs/microservices';
|
||||
// import { CreateInputGrpcClientDto } from './dto/create-input-grpc-client.dto';
|
||||
// import { UpdateInputGrpcClientDto } from './dto/update-input-grpc-client.dto';
|
||||
// import { InputGrpcClientService } from './input-grpc-client.service';
|
||||
// import { GrpcClientConfiguration } from './client.config';
|
||||
// import { TestConnectionDTO } from './dto/test-connection-grpc-client.dto';
|
||||
// import { ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
OnModuleInit,
|
||||
Inject,
|
||||
} from '@nestjs/common';
|
||||
import { ClientGrpc } from '@nestjs/microservices';
|
||||
import { InputService } from '@victorradael/protospack';
|
||||
import { ICreateInputRequest, IIdRequest, ITestConnectionRequest, UpdateInputRequest } from './interfaces';
|
||||
|
||||
// @Controller('grpc/input')
|
||||
// export class InputsClientService implements OnModuleInit {
|
||||
// @Client(GrpcClientConfiguration)
|
||||
// private inputServiceClient: ClientGrpc;
|
||||
export class InputsClientService implements OnModuleInit {
|
||||
private inputService: InputService;
|
||||
constructor(
|
||||
@Inject('INPUTS_PACKAGE') private readonly grpcClient: ClientGrpc,
|
||||
) {}
|
||||
|
||||
// private inputService: InputGrpcClientService;
|
||||
|
||||
onModuleInit() {
|
||||
this.inputService =
|
||||
this.grpcClient.getService<InputService>(
|
||||
'InputService',
|
||||
);
|
||||
}
|
||||
|
||||
// onModuleInit() {
|
||||
// this.inputService =
|
||||
// this.inputServiceClient.getService<InputGrpcClientService>(
|
||||
// 'InputService',
|
||||
// );
|
||||
// }
|
||||
async create(createInputDto: ICreateInputRequest ) {
|
||||
console.log('InputClientService', 'Create');
|
||||
|
||||
// @Post()
|
||||
// async create(@Payload() createInputDto: CreateInputGrpcClientDto) {
|
||||
// return this.inputService.create(createInputDto);
|
||||
// }
|
||||
const createInputResponse = await new Promise((resolve, reject) => {
|
||||
this.inputService.Create(createInputDto).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);
|
||||
});
|
||||
|
||||
// @Get()
|
||||
// list() {
|
||||
// return this.inputService.list();
|
||||
// }
|
||||
return createInputResponse;
|
||||
|
||||
}
|
||||
|
||||
// @Get(':id')
|
||||
// show(@Param() id: string) {
|
||||
// return this.inputService.show(id);
|
||||
// }
|
||||
|
||||
// @Put(':id')
|
||||
// update(
|
||||
// @Payload() updateInputDto: UpdateInputGrpcClientDto,
|
||||
// @Param() id: string,
|
||||
// ) {
|
||||
// return this.inputService.update(id, updateInputDto);
|
||||
// }
|
||||
async findOne(data: IIdRequest ) {
|
||||
console.log('InputClientService', 'FindOne');
|
||||
|
||||
// @Delete(':id')
|
||||
// remove(@Param() id: string) {
|
||||
// return this.inputService.remove(id);
|
||||
// }
|
||||
const { id } = data
|
||||
|
||||
// @Get('/test-connection')
|
||||
// testConnection(@Payload() testConnectionDTO: TestConnectionDTO) {
|
||||
// return this.inputService.testConnection(testConnectionDTO);
|
||||
// }
|
||||
// }
|
||||
const findOneInputResponse = await new Promise((resolve, reject) => {
|
||||
this.inputService.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 findOneInputResponse;
|
||||
|
||||
}
|
||||
|
||||
|
||||
async findAll(data) {
|
||||
console.log('InputClientService', 'FindAll');
|
||||
|
||||
const findAllInputResponse = await new Promise((resolve, reject) => {
|
||||
this.inputService.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);
|
||||
});
|
||||
|
||||
return findAllInputResponse;
|
||||
|
||||
}
|
||||
|
||||
|
||||
async update(updateInputDTO:UpdateInputRequest) {
|
||||
console.log('InputClientService', 'Update');
|
||||
console.log(updateInputDTO)
|
||||
const updateInputResponse = await new Promise((resolve, reject) => {
|
||||
this.inputService.Update(updateInputDTO).subscribe({
|
||||
next(x) {
|
||||
console.log(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 updateInputResponse;
|
||||
|
||||
}
|
||||
|
||||
async remove(idRequest:IIdRequest) {
|
||||
console.log('InputClientService', 'Remove');
|
||||
|
||||
const removeInputResponse = await new Promise((resolve, reject) => {
|
||||
this.inputService.Remove(idRequest).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 removeInputResponse;
|
||||
|
||||
}
|
||||
|
||||
async testConnection(data:ITestConnectionRequest) {
|
||||
console.log('InputClientService', 'TestCOnnection');
|
||||
|
||||
const testConnectionResponse = await new Promise((resolve, reject) => {
|
||||
this.inputService.TestConnection(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 testConnectionResponse;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
interface Values {
|
||||
jdbc_user: string;
|
||||
jdbc_password: string;
|
||||
database: string;
|
||||
endpoint: string;
|
||||
tables: string[];
|
||||
port: string;
|
||||
engine: string;
|
||||
schema: string;
|
||||
}
|
||||
|
||||
interface Cron {
|
||||
hours: string[];
|
||||
hour_interval: boolean;
|
||||
hour_resourse: boolean;
|
||||
hour_resourse_value: number;
|
||||
month_day: string[];
|
||||
month_day_interval: boolean;
|
||||
month_day_resourse: boolean;
|
||||
month_day_resourse_value: number;
|
||||
month: string[];
|
||||
month_interval: boolean;
|
||||
month_resourse: boolean;
|
||||
month_resourse_value: number;
|
||||
week_days: string[];
|
||||
week_days_interval: boolean;
|
||||
week_days_resourse: boolean;
|
||||
week_days_resourse_value: number;
|
||||
}
|
||||
|
||||
export interface ICreateInputRequest {
|
||||
|
||||
cron: Cron;
|
||||
name: string;
|
||||
plugin: string;
|
||||
values: Values;
|
||||
operation: string;
|
||||
|
||||
}
|
||||
export interface IIdRequest{
|
||||
id:string;
|
||||
}
|
||||
|
||||
interface UpdateInputRequest {
|
||||
id: string;
|
||||
cron: Cron;
|
||||
name: string;
|
||||
plugin: string;
|
||||
values: Values;
|
||||
operation: string;
|
||||
}
|
||||
|
||||
export interface ITestConnectionRequest {
|
||||
plugin: string;
|
||||
values: Values;
|
||||
}
|
||||
Reference in New Issue
Block a user