mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-10 10:09:08 +00:00
Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c8a4c1aae6 | ||
|
|
f48a35c7ce | ||
|
|
831a03402e | ||
|
|
856f913ce6 | ||
|
|
dc617b6925 | ||
|
|
3f80062672 | ||
|
|
07eb423814 | ||
|
|
721232448e | ||
|
|
0b0d261aae | ||
|
|
87a8d741d7 |
@@ -4787,6 +4787,41 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/catalog/register-dataset": {
|
||||||
|
"post": {
|
||||||
|
"operationId": "CatalogController_registerDatasetWithMetadataRequest",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "dadosfera-lang",
|
||||||
|
"in": "header",
|
||||||
|
"required": false,
|
||||||
|
"schema": {
|
||||||
|
"enum": [
|
||||||
|
"pt-br",
|
||||||
|
"en-us"
|
||||||
|
],
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"description": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": [
|
||||||
|
"Catalog"
|
||||||
|
],
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"access-token": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/terms-of-use/token": {
|
"/terms-of-use/token": {
|
||||||
"get": {
|
"get": {
|
||||||
"operationId": "TermsOfUseController_getToken",
|
"operationId": "TermsOfUseController_getToken",
|
||||||
|
|||||||
@@ -18,3 +18,5 @@ charts:
|
|||||||
value: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
|
value: f239718a-a271-4ef9-ae7e-02a2f0f3aa6e
|
||||||
- name: maestro.open_group_id
|
- name: maestro.open_group_id
|
||||||
value: 401573bb-334f-44b2-b30e-88d4cea31ae9
|
value: 401573bb-334f-44b2-b30e-88d4cea31ae9
|
||||||
|
- name: replicaCount
|
||||||
|
value: 2
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ spec:
|
|||||||
- key: application
|
- key: application
|
||||||
operator: In
|
operator: In
|
||||||
values:
|
values:
|
||||||
- backend
|
- general
|
||||||
|
|
||||||
tolerations:
|
tolerations:
|
||||||
- key: "kubernetes.azure.com/scalesetpriority"
|
- key: "kubernetes.azure.com/scalesetpriority"
|
||||||
operator: "Equal"
|
operator: "Equal"
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
# Declare variables to be passed into your templates.
|
# Declare variables to be passed into your templates.
|
||||||
|
|
||||||
replicaCount: 3
|
replicaCount: 3
|
||||||
hostname: maestro-temp.dadosfera.ai
|
hostname: maestro.dadosfera.ai
|
||||||
image:
|
image:
|
||||||
repository: 611330257153.dkr.ecr.us-east-1.amazonaws.com/microservices/maestro_prd
|
repository: 611330257153.dkr.ecr.us-east-1.amazonaws.com/microservices/maestro_prd
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
|
|||||||
Generated
+1617
-1401
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -30,7 +30,7 @@
|
|||||||
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
"@aws-sdk/client-secrets-manager": "^3.414.0",
|
||||||
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
"@dadosfera/dadosfera-logs": "^1.0.0-beta.4",
|
||||||
"@dadosfera/protospack": "2.5.3",
|
"@dadosfera/protospack": "2.5.3",
|
||||||
"@dadosfera/protospack-v2": "3.37.0-beta.5",
|
"@dadosfera/protospack-v2": "3.37.0-beta.7",
|
||||||
"@grpc/grpc-js": "^1.9.3",
|
"@grpc/grpc-js": "^1.9.3",
|
||||||
"@grpc/proto-loader": "^0.7.9",
|
"@grpc/proto-loader": "^0.7.9",
|
||||||
"@nestjs/cli": "^9.5.0",
|
"@nestjs/cli": "^9.5.0",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
} from '@nestjs/microservices';
|
} from '@nestjs/microservices';
|
||||||
import { credentials } from '@grpc/grpc-js';
|
import { credentials } from '@grpc/grpc-js';
|
||||||
import { Catalog } from '@dadosfera/protospack-v2';
|
import { Catalog } from '@dadosfera/protospack-v2';
|
||||||
|
import { PlatformInterfaces } from '@dadosfera/protospack-v2';
|
||||||
|
|
||||||
const isLocalConnection =
|
const isLocalConnection =
|
||||||
process.env.PIFACTORY_URL.startsWith('pi-factory:') ||
|
process.env.PIFACTORY_URL.startsWith('pi-factory:') ||
|
||||||
@@ -19,11 +20,13 @@ export class CatalogClientConfiguration {
|
|||||||
package: [
|
package: [
|
||||||
Catalog.ProtoPackages.ReadPackage,
|
Catalog.ProtoPackages.ReadPackage,
|
||||||
Catalog.ProtoPackages.WritePackage,
|
Catalog.ProtoPackages.WritePackage,
|
||||||
|
PlatformInterfaces.ProtoPackages.WritePackage
|
||||||
],
|
],
|
||||||
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
credentials: isLocalConnection ? undefined : credentials.createSsl(),
|
||||||
protoPath: [
|
protoPath: [
|
||||||
Catalog.ProtoPaths.ReadFilePath,
|
Catalog.ProtoPaths.ReadFilePath,
|
||||||
Catalog.ProtoPaths.WriteFilePath,
|
Catalog.ProtoPaths.WriteFilePath,
|
||||||
|
PlatformInterfaces.ProtoPaths.WriteFilePath
|
||||||
],
|
],
|
||||||
loader: {
|
loader: {
|
||||||
keepCase: true,
|
keepCase: true,
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import {
|
|||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
UseFilters,
|
UseFilters,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
ApiCreatedResponse,
|
ApiCreatedResponse,
|
||||||
@@ -30,6 +32,7 @@ import { CatalogService } from './catalog.service';
|
|||||||
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
import { DadosferaLogger } from '@dadosfera/dadosfera-logs';
|
||||||
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
import { PackTheMetadata } from 'src/utils/ PackTheMetadata';
|
||||||
import { RequestUser, User } from 'src/decorators/user.decorator';
|
import { RequestUser, User } from 'src/decorators/user.decorator';
|
||||||
|
import { lastValueFrom } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
BatchRemoveRlsRulesRequest,
|
BatchRemoveRlsRulesRequest,
|
||||||
GetDatasetCatalogTaskRes,
|
GetDatasetCatalogTaskRes,
|
||||||
@@ -54,6 +57,7 @@ import {
|
|||||||
AddRlsRuleRequest,
|
AddRlsRuleRequest,
|
||||||
GetNimbusDashboardsRequest,
|
GetNimbusDashboardsRequest,
|
||||||
GetRlsRulesRequest,
|
GetRlsRulesRequest,
|
||||||
|
RegisterDatasetWithMetatadaRequest,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
} from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
||||||
|
|
||||||
@ApiTags('Catalog')
|
@ApiTags('Catalog')
|
||||||
@@ -743,4 +747,94 @@ export class CatalogController {
|
|||||||
|
|
||||||
return JSON.parse(dashboards);
|
return JSON.parse(dashboards);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Post('register-dataset')
|
||||||
|
@RequireSomePermission(
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.CREATE,
|
||||||
|
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER
|
||||||
|
)
|
||||||
|
async registerDatasetWithMetadataRequest(
|
||||||
|
@Body() body: RegisterDatasetWithMetatadaRequest,
|
||||||
|
@User() user: RequestUser,
|
||||||
|
) {
|
||||||
|
const { customer_id, customer_name, user_id, username } = user;
|
||||||
|
const logMetadata = {
|
||||||
|
customer_name: customer_name,
|
||||||
|
user_id: user_id,
|
||||||
|
method: 'POST',
|
||||||
|
path: '/catalog/register-dataset',
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
|
||||||
|
const metadata = PackTheMetadata({
|
||||||
|
customer_id,
|
||||||
|
customer_name,
|
||||||
|
user_id,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.logger.log(`Request from user ${user_id} for customer ${customer_name}`, logMetadata);
|
||||||
|
|
||||||
|
// Create table metadata
|
||||||
|
const tableMetadataBody = {
|
||||||
|
table_metadata: body.table_metadata,
|
||||||
|
info: {
|
||||||
|
customer: customer_name,
|
||||||
|
|
||||||
|
},
|
||||||
|
logMetadata: logMetadata
|
||||||
|
};
|
||||||
|
|
||||||
|
const table_metadata_id = await this.catalogService.createTableMetadata(
|
||||||
|
tableMetadataBody,
|
||||||
|
);
|
||||||
|
this.logger.info(`table_metadata_id: ${table_metadata_id}`, logMetadata);
|
||||||
|
|
||||||
|
// Create column metadata
|
||||||
|
const columnMetadataBody = {
|
||||||
|
column_metadata: body.column_metadata,
|
||||||
|
info: {
|
||||||
|
customer: customer_name,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.logger.info(`Creating column metadata for table ${table_metadata_id}`, logMetadata);
|
||||||
|
const column_metadata_ids = await this.catalogService.createColumnMetadata(columnMetadataBody)
|
||||||
|
|
||||||
|
// Create data preview
|
||||||
|
const dataPreviewBody = {
|
||||||
|
data_preview: body.data_preview,
|
||||||
|
info: {
|
||||||
|
customer: customer_name,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.logger.debug(`Creating data preview for table ${table_metadata_id}`, logMetadata);
|
||||||
|
const data_preview_id = await this.catalogService.createDataPreview(
|
||||||
|
dataPreviewBody,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Catalog dataset item
|
||||||
|
this.logger.info(`Cataloging dataset item for table ${table_metadata_id}`, logMetadata);
|
||||||
|
await this.catalogService.catalogDatasetItem(table_metadata_id, metadata);
|
||||||
|
this.logger.info(`Dataset registration completed successfully for table ${table_metadata_id}`, logMetadata);
|
||||||
|
return {
|
||||||
|
message: 'Dataset registered successfully',
|
||||||
|
table_metadata_id: table_metadata_id,
|
||||||
|
column_metadata_ids: column_metadata_ids,
|
||||||
|
data_preview_id: data_preview_id,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(`Failed to register dataset. The following error occurred: ${error.response.data}`, logMetadata);
|
||||||
|
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
message: 'Ocorreu um erro ao registrar o dataset',
|
||||||
|
error: error.message,
|
||||||
|
code: 'REGISTRATION_FAILED',
|
||||||
|
details: error.message,
|
||||||
|
},
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import {
|
|||||||
ProtoServices,
|
ProtoServices,
|
||||||
Messages,
|
Messages,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
} from '@dadosfera/protospack-v2/dist/lib/Catalog';
|
||||||
|
import {
|
||||||
|
Messages as PlatformInterfaceMessages,
|
||||||
|
WriteService as PlatformInterfaceWriteService,
|
||||||
|
ProtoServices as PlatformInterfacesProtoServices,
|
||||||
|
} from '@dadosfera/protospack-v2/dist/lib/PlatformInterfaces';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
HttpException,
|
HttpException,
|
||||||
@@ -33,6 +38,7 @@ import {
|
|||||||
class CatalogService implements OnModuleInit {
|
class CatalogService implements OnModuleInit {
|
||||||
catalogReadService: ReadService.CatalogReadServices;
|
catalogReadService: ReadService.CatalogReadServices;
|
||||||
catalogWriteService: WriteService.CatalogWriteServices;
|
catalogWriteService: WriteService.CatalogWriteServices;
|
||||||
|
platformWriteService: PlatformInterfaceWriteService.PlatformInterfacesWriteServices;
|
||||||
logger: any;
|
logger: any;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DadosferaLogger)
|
@Inject(DadosferaLogger)
|
||||||
@@ -54,9 +60,14 @@ class CatalogService implements OnModuleInit {
|
|||||||
this.grpcClient.getService<WriteService.CatalogWriteServices>(
|
this.grpcClient.getService<WriteService.CatalogWriteServices>(
|
||||||
ProtoServices.CatalogWriteServices,
|
ProtoServices.CatalogWriteServices,
|
||||||
);
|
);
|
||||||
|
this.platformWriteService =
|
||||||
|
this.grpcClient.getService<PlatformInterfaceWriteService.PlatformInterfacesWriteServices>(
|
||||||
|
PlatformInterfacesProtoServices.PlatformInterfacesWriteServices,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_getNimbusUrl(body) {
|
_getNimbusUrl(body) {
|
||||||
|
this.logger.debug(`Body: ${JSON.stringify(body)}`);
|
||||||
const customer = body.info.customer.toLowerCase();
|
const customer = body.info.customer.toLowerCase();
|
||||||
|
|
||||||
if (process.env.ENV === 'prd') {
|
if (process.env.ENV === 'prd') {
|
||||||
@@ -420,6 +431,112 @@ class CatalogService implements OnModuleInit {
|
|||||||
);
|
);
|
||||||
return res.dashboards;
|
return res.dashboards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async createTableMetadata(body: any): Promise<number> {
|
||||||
|
const nimbusUrl = this._getNimbusUrl(body);
|
||||||
|
this.logger.info(`Nimbus URL: ${nimbusUrl}`, {...body.logMetadata});
|
||||||
|
|
||||||
|
const endpoint = `${nimbusUrl}/api/catalog/table-metadata/`;
|
||||||
|
|
||||||
|
this.logger.info(`Creating table metadata for table ${body.table_metadata.table_name}`, {...body.logMetadata});
|
||||||
|
this.logger.info(`Using endpoint: ${endpoint}`, {...body.logMetadata});
|
||||||
|
this.logger.debug(`Payload: ${JSON.stringify(body.table_metadata)}`, {...body.logMetadata});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data, status } = await axios.post(endpoint, {...body.table_metadata});
|
||||||
|
|
||||||
|
this.logger.info(
|
||||||
|
`Table metadata created successfully with status ${status} for table ${body.table_metadata.table_name}`,
|
||||||
|
{...body.logMetadata},
|
||||||
|
);
|
||||||
|
return data.id;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to create table metadata for table ${body.table_metadata.table_name} failed with status ${
|
||||||
|
error.response?.status
|
||||||
|
} because of ${JSON.stringify(error.response?.data) || error.message}`, {...body.logMetadata});
|
||||||
|
throw new Error(error.response?.data?.message || error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async createColumnMetadata(body: any): Promise<number[]> {
|
||||||
|
const nimbusUrl = this._getNimbusUrl(body);
|
||||||
|
this.logger.info(`Nimbus URL: ${nimbusUrl}`, body.logMetadata);
|
||||||
|
const endpoint = `${nimbusUrl}/api/catalog/column-metadata/`;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.logger.info(`Creating column metadata for table ${body.column_metadata.table_name}`, {...body.logMetadata});
|
||||||
|
this.logger.info(`Using endpoint: ${endpoint}`, {...body.logMetadata});
|
||||||
|
this.logger.debug(`Payload: ${JSON.stringify(body.column_metadata)}`, {...body.logMetadata});
|
||||||
|
const { data, status } = await axios.post(endpoint, body.column_metadata);
|
||||||
|
|
||||||
|
this.logger.info(
|
||||||
|
`Column metadata created successfully with status ${status} for table ${body.column_metadata.table_name}`,
|
||||||
|
{...body.logMetadata},
|
||||||
|
);
|
||||||
|
return data.map((column) => column.id);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to create column metadata failed with status for table ${body.column_metadata.table_name} ${
|
||||||
|
error.response?.status
|
||||||
|
} because of ${error.response?.data || error.message}`, {...body.logMetadata});
|
||||||
|
throw new Error(error.response?.data?.message || error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async createDataPreview(body: any): Promise<number> {
|
||||||
|
const nimbusUrl = this._getNimbusUrl(body);
|
||||||
|
this.logger.info(`Nimbus URL: ${nimbusUrl}`, {...body.logMetadata});
|
||||||
|
const endpoint = `${nimbusUrl}/api/catalog/data-preview/`;
|
||||||
|
|
||||||
|
this.logger.info(`Creating data preview for table ${body.data_preview.table_name}`, {...body.logMetadata});
|
||||||
|
this.logger.info(`Using endpoint: ${endpoint}`, {...body.logMetadata});
|
||||||
|
this.logger.debug(`Payload: ${JSON.stringify(body.data_preview)}`, {...body.logMetadata});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { data, status } = await axios.post(endpoint, body.data_preview);
|
||||||
|
|
||||||
|
this.logger.info(
|
||||||
|
`Data preview created successfully with status ${status} for table ${body.data_preview.table_name}`,
|
||||||
|
{...body.logMetadata},
|
||||||
|
);
|
||||||
|
return data.id;
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(
|
||||||
|
`Failed to create data preview for table ${body.data_preview.table_name} failed with status ${
|
||||||
|
error.response?.status
|
||||||
|
} because of ${error.response?.data || error.message}`,
|
||||||
|
{...body.logMetadata},
|
||||||
|
);
|
||||||
|
throw new Error(error.response?.data?.message || error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async catalogDatasetItem(table_metadata_id: number, metadata: Metadata) {
|
||||||
|
const customer_name_raw = metadata.get('customer_name');
|
||||||
|
|
||||||
|
const customer_name = customer_name_raw?.[0]?.toString();
|
||||||
|
if (!customer_name) {
|
||||||
|
throw new BadRequestException('Customer name not found in metadata');
|
||||||
|
}
|
||||||
|
const res = await lastValueFrom(
|
||||||
|
this.platformWriteService.CatalogDataAssets(
|
||||||
|
{
|
||||||
|
data_assets: [
|
||||||
|
{
|
||||||
|
data_asset_id: table_metadata_id.toString(),
|
||||||
|
customer_name: customer_name,
|
||||||
|
data_asset_type: 'dataset',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
metadata,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { CatalogService };
|
export { CatalogService };
|
||||||
|
|||||||
@@ -41,9 +41,6 @@ export class OpenDataController {
|
|||||||
@Req()
|
@Req()
|
||||||
request: Request,
|
request: Request,
|
||||||
) {
|
) {
|
||||||
if (!request.headers['user-agent'].includes('WordPress/6.7.1; https://devsbm.dadosfera.io')) {
|
|
||||||
throw new ForbiddenException();
|
|
||||||
}
|
|
||||||
this.logger.info('createUser for open data');
|
this.logger.info('createUser for open data');
|
||||||
|
|
||||||
this.logger.info('user-agent', request.headers['user-agent']);
|
this.logger.info('user-agent', request.headers['user-agent']);
|
||||||
|
|||||||
Reference in New Issue
Block a user