Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ENV_MODE=test
RUNNING_ENV=DOCKER

## logger
RCT_LOG_FILENAME=reports/rctlogs.txt
RCT_LOG_FILE_LOGLEV=${RCT_LOG_FILE_LOGLEV:-warn}
RCT_LOG_CONSOLE_LOGLEV=${RCT_LOG_CONSOLE_LOGLEV:-debug}
RCT_LOG_CONSOLE_SYSD=${RCT_LOG_CONSOLE_SYSD:-}

## http server
RCT_HTTP_PORT=8081
RCT_HOSTNAME=localhost
RCT_TLS_ENABLED=false

RCT_JWT_SECRET=secret
RCT_JWT_EXPIRATION=12h

## external services connections
CERN_SOCKS=false
RCT_SYNC_TASK_AT_START=false

## database configuration
### general
RCT_DB_HOST=database
RCT_DB_NAME=rct-db
RCT_DB_PORT=5432
RCT_DB_USERNAME=rct-user
RCT_DB_PASSWORD=rct-passwd
MOCK_DB=${MOCK_DB:-true}

### docker container postgres configuration
POSTGRES_PASSWORD=postgres
POSTGRES_USER=postgres
POSTGRES_DB=postgres
PGDATA=/var/lib/postgresql/data/pgdata
POSTGRES_HOST_AUTH_METHOD=md5

### endpoints
_DEF_BK_HOST=ali-bookkeeping.cern.ch
_DEF_ML_HOST=alimonitor.cern.ch
_DEF_ML_PROT=https

### bkp
RCT_EP_BK_RUNS_PROT=https
RCT_EP_BK_RUNS_HOST=$_DEF_BK_HOST
RCT_EP_BK_RUNS_PATH=${RCT_EP_BK_RUNS_PATH:-/api/runs?filter[definitions]=PHYSICS}


### data passes
RCT_EP_ML_DP_RAW_PROT=$_DEF_ML_PROT
RCT_EP_ML_DP_RAW_HOST=$_DEF_ML_HOST
RCT_EP_ML_DP_RAW_PATH=${RCT_EP_ML_DP_RAW_PATH:-/production/raw.jsp?res_path=json}


RCT_EP_ML_DP_DET_PROT=$_DEF_ML_PROT
RCT_EP_ML_DP_DET_HOST=$_DEF_ML_HOST
RCT_EP_ML_DP_DET_PATH=${RCT_EP_ML_DP_DET_PATH:-/raw/raw_details.jsp?timesel=0&res_path=json}


### simulation passes
RCT_EP_ML_MC_RAW_PROT=$_DEF_ML_PROT
RCT_EP_ML_MC_RAW_HOST=$_DEF_ML_HOST
RCT_EP_ML_MC_RAW_PATH=${RCT_EP_ML_MC_RAW_PATH:-/MC/?res_path=json}

RCT_EP_ML_MC_DET_PROT=$_DEF_ML_PROT
RCT_EP_ML_MC_DET_HOST=$_DEF_ML_HOST
RCT_EP_ML_MC_DET_PATH=${RCT_EP_ML_MC_DET_PATH:-/job_events.jsp?timesel=0&res_path=json}

RCT_EP_ML_MC_TAG_PROT=$_DEF_ML_PROT
RCT_EP_ML_MC_TAG_HOST=$_DEF_ML_HOST
RCT_EP_ML_MC_TAG_PATH=${RCT_EP_ML_MC_TAG_PATH:-/MC/prodDetails.jsp?res_path=json}
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Check released tag matches ALICE O2 naming pattern
run: |
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: Install production dependencies
run: npm install --only=production
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ jobs:
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
- run: npm ci
- run: npm run docker:test
# - run: ./node_modules/.bin/nyc report --reporter=text-lcov > coverage.lcov
- name: Send codecov report for RunConditionTable
uses: codecov/codecov-action@v2
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
Expand All @@ -34,11 +34,28 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '18.x'
- name: Installing dependencies
run: npm ci
- name: Running static analysis
run: npm run static

test:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install mocha
run: npm install -g mocha
- name: Installing dependencies
run: npm ci
- name: Running tests
run: npm run test:mocha
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ database**/cached/
*__pycache__
security
scratch
.env
env_file
database/cache
notes
64 changes: 15 additions & 49 deletions app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@
* or submit itself to any jurisdiction.
*/
// RCT
const { HttpServer, Log } = require('@aliceo2/web-ui');
const { Log } = require('@aliceo2/web-ui');
const config = require('./lib/config/configProvider.js');
const { buildPublicConfig } = require('./lib/config/publicConfigProvider.js');

// IO
const path = require('path');
const readline = require('readline');
const Utils = require('./lib/Utils.js');
const { Console } = require('node:console');

// Services
const DatabaseService = require('./lib/database/DatabaseService.js');
const BookkeepingService = require('./lib/alimonitor-services/BookkeepingService.js');
const MonalisaService = require('./lib/alimonitor-services/MonalisaService.js');
const MonalisaServiceMC = require('./lib/alimonitor-services/MonalisaServiceMC.js');
const AuthControlManager = require('./lib/other/AuthControlManager.js');
const services = require('./lib/alimonitor-services');

// Database
const database = require('./lib/database');

// Server
const { webUiServer } = require('./server/index.js');

// Extract important
const EP = config.public.endpoints;
Expand All @@ -42,24 +43,15 @@ class RunConditionTableApplication {

this.logger = new Log(RunConditionTableApplication.name);

this.buildServer();
this.buildServices();
this.defineStaticRoutes();
this.webUiServer = webUiServer;
this.databaseService = database.databaseService;
this.services = services;
this.defineEndpoints();
this.buildAuthControl();

buildPublicConfig(config);
this.buildCli();
}

buildServer() {
if (!config.openId) {
this.httpServer = new HttpServer(config.http, config.jwt);
} else {
this.httpServer = new HttpServer(config.http, config.jwt, config.openId);
}
}

buildCli() {
this.rl = readline.createInterface({
input: process.stdin,
Expand Down Expand Up @@ -138,13 +130,6 @@ class RunConditionTableApplication {
return () => this.con.log('incorrect command');
}

defineStaticRoutes() {
const { httpServer } = this;

httpServer.addStaticPath(path.join(__dirname, 'public'));
httpServer.addStaticPath(path.join(__dirname, '..', 'node_modules', 'less/dist'), '/scripts');
}

defineEndpoints() {
const { httpServer } = this;
const { databaseService } = this;
Expand All @@ -154,26 +139,7 @@ class RunConditionTableApplication {
httpServer.get(EP.rctData, (req, res) => databaseService.pgExecFetchData(req, res));
httpServer.post(EP.insertData, (req, res) => databaseService.pgExecDataInsert(req, res));
httpServer.get(EP.date, (req, res) => databaseService.getDate(req, res));
httpServer.get(EP.sync, async (req, res) => this.syncAll());
}

buildAuthControl() {
this.authControlManager = new AuthControlManager(this.httpServer);
this.authControlManager.bindToTokenControl(EP.authControl);
}

buildServices() {
this.databaseService = new DatabaseService();

const monalisaService = new MonalisaService();
const monalisaServiceMC = new MonalisaServiceMC();
this.services = {
bookkeepingService: new BookkeepingService(),
monalisaService: monalisaService,
monalisaServiceDetails: monalisaService.monalisaServiceDetails,
monalisaServiceMC: monalisaServiceMC,
monalisaServiceMCDetails: monalisaServiceMC.monalisaServiceMCDetails,
};
httpServer.get(EP.sync, async (_req, _res) => this.syncAll());
}

async syncAll() {
Expand Down Expand Up @@ -269,9 +235,9 @@ class RunConditionTableApplication {
return process.env.ENV_MODE;
}

getAddress() {
return this.httpServer.address();
get httpServer() {
return this.webUiServer.httpServer;
}
}

module.exports = RunConditionTableApplication;
module.exports = new RunConditionTableApplication();
2 changes: 1 addition & 1 deletion app/lib/alimonitor-services/BookkeepingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,4 @@ class BookkeepingService extends AbstractServiceSynchronizer {
}
}

module.exports = BookkeepingService;
module.exports = new BookkeepingService();
2 changes: 1 addition & 1 deletion app/lib/alimonitor-services/MonalisaService.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ class MonalisaService extends AbstractServiceSynchronizer {
}
}

module.exports = MonalisaService;
module.exports = new MonalisaService();
2 changes: 1 addition & 1 deletion app/lib/alimonitor-services/MonalisaServiceMC.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ class MonalisaServiceMC extends AbstractServiceSynchronizer {
}
}

module.exports = MonalisaServiceMC;
module.exports = new MonalisaServiceMC();
28 changes: 28 additions & 0 deletions app/lib/alimonitor-services/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* 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.
*/

const monalisaService = require('./MonalisaService');
const monalisaServiceMC = require('./MonalisaServiceMC');
const bookkeepingService = require('./BookkeepingService');

const { monalisaServiceDetails } = monalisaService;
const { monalisaServiceMCDetails } = monalisaServiceMC;

module.exports = {
bookkeepingService,
monalisaService,
monalisaServiceDetails,
monalisaServiceMC,
monalisaServiceMCDetails,
};
4 changes: 1 addition & 3 deletions app/lib/database/DatabaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ class DatabaseService {
res.status(status).json({ message: message });
}



async disconnect() {
const promises = Object.entries(this.loggedUsers.tokenToUserData).map(([_, data]) => {
this.logger.info(`ending for ${data.name}`);
Expand Down Expand Up @@ -203,4 +201,4 @@ class DatabaseService {

}

module.exports = DatabaseService;
module.exports = new DatabaseService();
2 changes: 1 addition & 1 deletion app/lib/database/QueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class QueryBuilder {
to: ''
}
// assert correctness of previous
// Mapping search params to categoraized key, value pairs
// Mapping search params to categorized { key, value } pairs
const filterTypesRegex= new RegExp(filterTypes.map((t) => `(.*-${t})`).join('|'));
const filterParams = Object.entries(params).filter(([k, v]) => k.match(filterTypesRegex));

Expand Down
19 changes: 19 additions & 0 deletions app/lib/database/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* 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.
*/

const databaseService = require('./DatabaseService');

module.exports = {
databaseService
}
17 changes: 14 additions & 3 deletions app/lib/database/views/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@

/**
* @license
* Copyright 2019-2020 CERN and copyright holders of ALICE O2.
* See http://alice-o2.web.cern.ch/copyright for details of the copyright holders.
* All rights not expressly granted are reserved.
*
* This software is distributed under the terms of the GNU General Public
* License v3 (GPL Version 3), copied verbatim in the file "COPYING".
*
* 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.
*/

const periods_view = require('./periods_view.js');
const {runs_per_period_view, runs_per_data_pass_view} = require('./runs_views.js');
Expand All @@ -8,7 +20,6 @@ const anchored_per_mc_view = require('./anchored_per_mc_view.js');
const anchorage_per_data_pass_view = require('./anchorage_per_data_pass_view.js');
const flags_view = require('./flags_view.js');


module.exports = {
periods_view,
runs_per_data_pass_view,
Expand All @@ -18,4 +29,4 @@ module.exports = {
anchored_per_mc_view,
anchorage_per_data_pass_view,
flags_view
}
}
3 changes: 1 addition & 2 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
* or submit itself to any jurisdiction.
*/

const RunConditionTableApplication = require('./application.js');
const runConditionTableApplication = require('./application.js');

const runConditionTableApplication = new RunConditionTableApplication();
runConditionTableApplication.run();

/**
Expand Down
Loading