From 998c8ae6cbf4d169dd52b26391338fa08140d1fb Mon Sep 17 00:00:00 2001 From: martinboulais <31805063+martinboulais@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:01:49 +0200 Subject: [PATCH] Add kafka messages consumer --- Control/lib/control-core/GrpcProxy.js | 8 +++-- Control/test/config/apricot-grpc.js | 3 +- Control/test/config/core-grpc.js | 29 +++++++++++-------- Framework/Backend/index.js | 3 ++ .../protobuf/getWebUiProtoIncludeDir.js | 1 + .../{protos => protobuf}/protos/common.proto | 0 .../{ => protobuf}/protos/events.proto | 0 7 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 Framework/Backend/protobuf/getWebUiProtoIncludeDir.js rename Framework/Backend/{protos => protobuf}/protos/common.proto (100%) rename Framework/Backend/{ => protobuf}/protos/events.proto (100%) diff --git a/Control/lib/control-core/GrpcProxy.js b/Control/lib/control-core/GrpcProxy.js index 2c34c7d38..f80a0b37f 100644 --- a/Control/lib/control-core/GrpcProxy.js +++ b/Control/lib/control-core/GrpcProxy.js @@ -10,11 +10,12 @@ * In applying this license CERN does not waive the privileges and immunities * granted to it by virtue of its status as an Intergovernmental Organization * or submit itself to any jurisdiction. -*/ + */ // Doc: https://grpc.io/docs/languages/node/ const protoLoader = require('@grpc/proto-loader'); const grpcLibrary = require('@grpc/grpc-js'); +const {getWebUiProtoIncludeDir} = require('@aliceo2/web-ui'); const path = require('path'); const {grpcErrorToNativeError} = require('./../errors/grpcErrorToNativeError.js'); const {Status} = require(path.join(__dirname, './../../protobuf/status_pb.js')); @@ -34,7 +35,10 @@ class GrpcProxy { */ constructor(config, path) { if (this._isConfigurationValid(config, path)) { - const packageDefinition = protoLoader.loadSync(path, {longs: String, keepCase: false, arrays: true}); + const packageDefinition = protoLoader.loadSync( + path, + {longs: String, keepCase: false, arrays: true, includeDirs: [getWebUiProtoIncludeDir()]}, + ); const octlProto = grpcLibrary.loadPackageDefinition(packageDefinition); const protoService = octlProto[this._package][this._label]; const address = `${config.hostname}:${config.port}`; diff --git a/Control/test/config/apricot-grpc.js b/Control/test/config/apricot-grpc.js index 31660ccce..b892c8938 100644 --- a/Control/test/config/apricot-grpc.js +++ b/Control/test/config/apricot-grpc.js @@ -18,6 +18,7 @@ const path = require('path'); // Doc: https://grpc.io/grpc/node/grpc.html const protoLoader = require('@grpc/proto-loader'); const grpcLibrary = require('@grpc/grpc-js'); +const {getWebUiProtoIncludeDir} = require('@aliceo2/web-ui'); const PROTO_PATH = path.join(__dirname, './../../protobuf/o2apricot.proto'); @@ -28,7 +29,7 @@ const apricotGRPCServer = (config) => { let calls = {}; const server = new grpcLibrary.Server(); - const packageDefinition = protoLoader.loadSync(PROTO_PATH, {keepCase: false}); // change to camel case + const packageDefinition = protoLoader.loadSync(PROTO_PATH, {keepCase: false, includeDirs: [getWebUiProtoIncludeDir()]}); // change to camel case const octlProto = grpcLibrary.loadPackageDefinition(packageDefinition); const credentials = grpcLibrary.ServerCredentials.createInsecure(); const address = `${config.apricot.hostname}:${config.apricot.port}`; diff --git a/Control/test/config/core-grpc.js b/Control/test/config/core-grpc.js index 9648e54cd..7a6d5ba61 100644 --- a/Control/test/config/core-grpc.js +++ b/Control/test/config/core-grpc.js @@ -10,7 +10,7 @@ * In applying this license CERN does not waive the privileges and immunities * granted to it by virtue of its status as an Intergovernmental Organization * or submit itself to any jurisdiction. -*/ + */ /* eslint-disable require-jsdoc */ const path = require('path'); @@ -18,6 +18,7 @@ const path = require('path'); // Doc: https://grpc.io/grpc/node/grpc.html const protoLoader = require('@grpc/proto-loader'); const grpcLibrary = require('@grpc/grpc-js'); +const {getWebUiProtoIncludeDir} = require('@aliceo2/web-ui'); const PROTO_PATH = path.join(__dirname, './../../protobuf/o2control.proto'); @@ -29,7 +30,12 @@ const coreGRPCServer = (config) => { let calls = {}; const server = new grpcLibrary.Server(); - const packageDefinition = protoLoader.loadSync(PROTO_PATH, {keepCase: false});// change to camel case + console.log("Here: ", getWebUiProtoIncludeDir()); + const packageDefinition = protoLoader.loadSync( + PROTO_PATH, + {keepCase: false, includeDirs: [getWebUiProtoIncludeDir()]}, + );// change to camel case + console.log('Then here'); const octlProto = grpcLibrary.loadPackageDefinition(packageDefinition); const credentials = grpcLibrary.ServerCredentials.createInsecure(); const address = `${config.grpc.hostname}:${config.grpc.port}`; @@ -43,7 +49,7 @@ const coreGRPCServer = (config) => { calls['getEnvironments'] = true; const responseData = { frameworkId: '74917838-27cb-414d-bfcd-7e74f85d4926-0000', - environments: [envTest.environment] + environments: [envTest.environment], }; callback(null, responseData); }, @@ -130,37 +136,36 @@ const envTest = { mid_enabled: 'false', mid_something: 'test', dd_enabled: 'true', - run_type: 'run' + run_type: 'run', }, vars: { odc_enabled: 'true', mid_enabled: 'false', mid_something: 'test', dd_enabled: 'true', - run_type: 'run' + run_type: 'run', }, defaults: { dcs_topology: 'test', dd_enabled: 'true', - run_type: 'run' + run_type: 'run', }, - integratedServices: { - } + integratedServices: {}, }, workflow: {}, workflowTemplates: { workflowTemplates: [ { repo: 'git.cern.ch/some-user/some-repo/', - template: 'prettyreadout-1', revision: 'master', description: 'something' + template: 'prettyreadout-1', revision: 'master', description: 'something', }, - ] + ], }, listRepos: { repos: [ {name: 'git.cern.ch/some-user/some-repo/', default: true, defaultRevision: 'dev', revisions: ['master', 'dev']}, - {name: 'git.com/alice-user/alice-repo/'}] - } + {name: 'git.com/alice-user/alice-repo/'}], + }, }; module.exports = {coreGRPCServer}; diff --git a/Framework/Backend/index.js b/Framework/Backend/index.js index c72631575..86efd897d 100644 --- a/Framework/Backend/index.js +++ b/Framework/Backend/index.js @@ -37,6 +37,7 @@ const { updateAndSendExpressResponseFromNativeError, } = require('./errors/updateAndSendExpressResponseFromNativeError.js'); const { Logger } = require('./log/Logger'); +const {getWebUiProtoIncludeDir} = require('./protobuf/getWebUiProtoIncludeDir'); exports.ConsulService = ConsulService; @@ -82,3 +83,5 @@ exports.UnauthorizedAccessError = UnauthorizedAccessError; exports.grpcErrorToNativeError = grpcErrorToNativeError; exports.updateAndSendExpressResponseFromNativeError = updateAndSendExpressResponseFromNativeError; + +exports.getWebUiProtoIncludeDir = getWebUiProtoIncludeDir; diff --git a/Framework/Backend/protobuf/getWebUiProtoIncludeDir.js b/Framework/Backend/protobuf/getWebUiProtoIncludeDir.js new file mode 100644 index 000000000..7794b0b42 --- /dev/null +++ b/Framework/Backend/protobuf/getWebUiProtoIncludeDir.js @@ -0,0 +1 @@ +exports.getWebUiProtoIncludeDir = () => __dirname; diff --git a/Framework/Backend/protos/protos/common.proto b/Framework/Backend/protobuf/protos/common.proto similarity index 100% rename from Framework/Backend/protos/protos/common.proto rename to Framework/Backend/protobuf/protos/common.proto diff --git a/Framework/Backend/protos/events.proto b/Framework/Backend/protobuf/protos/events.proto similarity index 100% rename from Framework/Backend/protos/events.proto rename to Framework/Backend/protobuf/protos/events.proto