Skip to content

Commit

Permalink
Add kafka messages consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais committed Oct 10, 2024
1 parent a011bd5 commit 998c8ae
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
8 changes: 6 additions & 2 deletions Control/lib/control-core/GrpcProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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}`;
Expand Down
3 changes: 2 additions & 1 deletion Control/test/config/apricot-grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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}`;
Expand Down
29 changes: 17 additions & 12 deletions Control/test/config/core-grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
* 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');

// 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');

Expand All @@ -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}`;
Expand All @@ -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);
},
Expand Down Expand Up @@ -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};
3 changes: 3 additions & 0 deletions Framework/Backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
updateAndSendExpressResponseFromNativeError,
} = require('./errors/updateAndSendExpressResponseFromNativeError.js');
const { Logger } = require('./log/Logger');
const {getWebUiProtoIncludeDir} = require('./protobuf/getWebUiProtoIncludeDir');

exports.ConsulService = ConsulService;

Expand Down Expand Up @@ -82,3 +83,5 @@ exports.UnauthorizedAccessError = UnauthorizedAccessError;
exports.grpcErrorToNativeError = grpcErrorToNativeError;

exports.updateAndSendExpressResponseFromNativeError = updateAndSendExpressResponseFromNativeError;

exports.getWebUiProtoIncludeDir = getWebUiProtoIncludeDir;
1 change: 1 addition & 0 deletions Framework/Backend/protobuf/getWebUiProtoIncludeDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.getWebUiProtoIncludeDir = () => __dirname;
File renamed without changes.

0 comments on commit 998c8ae

Please sign in to comment.