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
Show all changes
85 commits
Select commit Hold shift + click to select a range
5f43247
Runs model refactor
xsalonx Jul 18, 2023
07c70d2
Run model refacotr
xsalonx Jul 18, 2023
b6ecc1a
run model file rename
xsalonx Jul 18, 2023
f9ad4ce
added index to models
xsalonx Jul 18, 2023
6153042
added DatabaseManager
xsalonx Jul 18, 2023
c31e42b
added psql client to app contatiner
xsalonx Jul 18, 2023
cdefd1b
Run model compatible with db
xsalonx Jul 18, 2023
5f45c52
basics of repository added
xsalonx Jul 19, 2023
8173c47
db utitlities added
xsalonx Jul 19, 2023
e6ff7ba
refactor(renaming)
xsalonx Jul 19, 2023
0278cad
Merge branch 'master' into improvement/ORCT-117/sequelize-minimal-mod…
xsalonx Jul 19, 2023
c0e6010
repository addition
xsalonx Jul 19, 2023
c138851
basics for routers and controllers
xsalonx Jul 19, 2023
7022d19
init of Run controller
xsalonx Jul 19, 2023
0b005ea
added routes creator
xsalonx Jul 19, 2023
36e26fd
routes parsing
xsalonx Jul 19, 2023
e0f8907
routes parsing added
xsalonx Jul 20, 2023
5f5e436
added binding of endpoints, public api in env mode
xsalonx Jul 20, 2023
14b0659
master merged
xsalonx Jul 20, 2023
8856edb
cleanup
xsalonx Jul 20, 2023
87d83e7
cleanup
xsalonx Jul 20, 2023
6ead4c6
refator; cleanup
xsalonx Jul 20, 2023
d440e82
user privileges over db
xsalonx Jul 20, 2023
3a0748a
refator; cleanup
xsalonx Jul 20, 2023
7d1f211
cleanup
xsalonx Jul 20, 2023
2e2836d
basic tests for server
xsalonx Jul 20, 2023
305ba28
repository rename
xsalonx Jul 20, 2023
0de42ad
abstraction for routes dependencies added
xsalonx Jul 20, 2023
b9f09af
refactor
xsalonx Jul 20, 2023
fe323ff
refactor
xsalonx Jul 20, 2023
f4479fc
refactor
xsalonx Jul 20, 2023
f4eba37
refactor
xsalonx Jul 20, 2023
2cbae97
docs
xsalonx Jul 20, 2023
aa11d91
restored previous privileges on db
xsalonx Jul 20, 2023
c3e59ed
code styling
xsalonx Jul 20, 2023
ec140f9
next added
xsalonx Jul 21, 2023
de3a387
refactor
xsalonx Jul 21, 2023
c6b2042
database manager used in application
xsalonx Jul 21, 2023
2c2bb36
tets
xsalonx Jul 21, 2023
d1b56c9
db host name fix in test env
xsalonx Jul 21, 2023
d8a1768
rename
xsalonx Jul 21, 2023
9578350
taking advantage of routesAbstractionController singleton
xsalonx Jul 24, 2023
9b17c14
only repositories in DatabaseManager
xsalonx Jul 24, 2023
44699c7
renaming
xsalonx Jul 24, 2023
39112a4
docks refacot
xsalonx Jul 24, 2023
c111372
refactor
xsalonx Jul 24, 2023
a5e07c1
singleton removed
xsalonx Jul 24, 2023
01e44bb
endpoint rename
xsalonx Jul 24, 2023
0fc85cd
routes controller renamed
xsalonx Jul 24, 2023
44b1f8f
setup db cleanup
xsalonx Jul 24, 2023
12a122e
basic adapter and usecase for runs
xsalonx Jul 24, 2023
3c533bd
joi dependencie added
xsalonx Jul 24, 2023
f6017d2
add dtos commons
xsalonx Jul 24, 2023
ee76aff
basic dtos for runs
xsalonx Jul 24, 2023
b5f9019
dto validation function added
xsalonx Jul 24, 2023
40f60ab
Allruns usecase with dto implementation
xsalonx Jul 24, 2023
1935dc9
refactor of common DTOs
xsalonx Jul 24, 2023
0152862
cleanup
xsalonx Jul 24, 2023
556053c
DTO for api-docs endpoint
xsalonx Jul 24, 2023
6197bca
Run entitty type def
xsalonx Jul 24, 2023
a6274f0
SequlizeRun typdef added
xsalonx Jul 24, 2023
f0d22f3
usage of Run typdefs
xsalonx Jul 24, 2023
3d3f0fa
repository refactor
xsalonx Jul 24, 2023
91353df
repositories factor refactored; models accessible from databaseManager
xsalonx Jul 25, 2023
f7ce348
specificallyDefinedRepositories validation, java-docs
xsalonx Jul 25, 2023
6c07ae1
parantheses refactor
xsalonx Jul 25, 2023
f2ea80b
rename
xsalonx Jul 25, 2023
8e2d049
temporary casting of big numbers in Run model
xsalonx Jul 25, 2023
51cef97
domain layer separation, refactor
xsalonx Jul 25, 2023
63ba8e4
java-docs
xsalonx Jul 25, 2023
8bbf530
Adapter - no shortcut
xsalonx Jul 25, 2023
7c7303f
renaming
xsalonx Jul 25, 2023
ea9b96e
rctmake allow to expose db container port to host
xsalonx Jul 25, 2023
be183b4
umzug applied, sequelize migration instead on sync
xsalonx Jul 25, 2023
30d888d
db util update due to seuqlize creating table with uppercases
xsalonx Jul 25, 2023
09803fb
ENV_MODE env var target name for dev changed
xsalonx Jul 25, 2023
9f71507
synced removed from databaseManager
xsalonx Jul 25, 2023
204164b
excessive argument removed
xsalonx Jul 26, 2023
58b7586
RunService instead of usecase
xsalonx Jul 26, 2023
191cdeb
refactor
xsalonx Jul 26, 2023
dbe5086
databaseMAnager tests
xsalonx Jul 26, 2023
defcfa9
no default export
xsalonx Jul 26, 2023
ecedfa6
no null return in RunService.getAll
xsalonx Jul 26, 2023
05e8911
typo
xsalonx Jul 26, 2023
7d9d329
index.js removed from database module
xsalonx Jul 26, 2023
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
9 changes: 6 additions & 3 deletions app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const { buildPublicConfig } = require('./lib/config/publicConfigProvider.js');
// Services
const alimonitorServices = require('./lib/alimonitor-services');
// Database
const database = require('./lib/database');
const { databaseManager } = require('./lib/database/DatabaseManager.js');
const { databaseService } = require('./lib/database/DatabaseService.js');

// Server
const { webUiServer } = require('./lib/server');
Expand All @@ -43,7 +44,8 @@ class RunConditionTableApplication {
this.logger = new Log(RunConditionTableApplication.name);

this.webUiServer = webUiServer;
this.databaseService = database.databaseService;
this.databaseService = databaseService;
this.databaseManager = databaseManager;
this.databaseService.healthcheckInsertData();
this.syncManager = alimonitorServices.syncManager;
this.defineEndpoints();
Expand Down Expand Up @@ -72,6 +74,7 @@ class RunConditionTableApplication {
async run() {
this.logger.info('Starting RCT app...');
try {
await this.databaseManager.migrate();
await this.httpServer.listen();
} catch (error) {
this.logger.error(`Error while starting RCT app: ${error}`);
Expand Down Expand Up @@ -103,7 +106,7 @@ class RunConditionTableApplication {
}

static isInDevMode() {
return process.env.ENV_MODE === 'development';
return process.env.ENV_MODE === 'dev';
}

static getEnvMode() {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/alimonitor-services/SyncManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* or submit itself to any jurisdiction.
*/
const { Log } = require('@aliceo2/web-ui');
const { databaseService } = require('../database');
const { databaseService } = require('../database/DatabaseService.js');
const config = require('../../config');

const monalisaService = require('./MonalisaService');
Expand Down
98 changes: 98 additions & 0 deletions app/lib/database/DatabaseManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* 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 { Sequelize } = require('sequelize');
const { Log } = require('@aliceo2/web-ui')
const { Umzug, SequelizeStorage, memoryStorage } = require('umzug');
const path = require('path')
const config = require('../../config');
const modelsFactory = require('./models');
const repositoriesFactory = require('./repositories');

/**
* Sequelize implementation of the Database.
*/
class DatabaseManager {
constructor() {
this.logger = new Log(DatabaseManager.name);
this.schema = 'public';

this.sequelize = new Sequelize({
...config.database,
username: config.database.user, // TEMPORARILY
logging: config.database.logging ? this.logger.debug.bind(this.logger) : false,
dialect: 'postgres',
define: {
underscored: false,
schema: this.schema,
},
});
this.models = modelsFactory(this.sequelize);
this.repositories = repositoriesFactory(this.models);
}

/**
* Executes every *pending* migrations.
*
* @returns {Promise} Promise object represents the outcome.
*/
async migrate() {
this.logger.info('Executing pending migrations...');

try {
const umzug = this.getUmzug(
path.join(__dirname, 'migrations'),
new SequelizeStorage({
sequelize: this.sequelize,
}),
);

await umzug.up();
} catch (error) {
this.logger.error(`Error while executing migrations: ${error}`);
return Promise.reject(error);
}

this.logger.info('Executed pending migrations');
}

/**
* Returns a new Umzug instance for the given migration directory and storage
*
* @param {string} migrationsDirectory the path to the migrations directory
* @param {string} storage the data storage to use
* @return {Umzug} the Umzug instance
*/
getUmzug(migrationsDirectory, storage) {
return new Umzug({
migrations: {
glob: `${migrationsDirectory}/*.js`,
resolve: ({ name, path: migrationPath, context }) => {
const migration = require(migrationPath || '');

return {
name,
up: async () => migration.up(context, Sequelize),
down: async () => migration.down(context, Sequelize),
};
},
},
context: this.sequelize.getQueryInterface(),
storage,
});
}
}

module.exports = {
databaseManager: new DatabaseManager(),
};
12 changes: 7 additions & 5 deletions app/lib/database/DatabaseService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
*/

const { Log } = require('@aliceo2/web-ui');
const { Client, Pool } = require('pg');
const QueryBuilder = require('./QueryBuilder.js');
const { Pool } = require('pg');
const { PGQueryBuilder } = require('./utilities');
const config = require('./../config/configProvider.js');
const {distinct} = require('../utils')

Expand Down Expand Up @@ -151,7 +151,7 @@ class DatabaseService {
}

try {
const query = QueryBuilder.buildSelect(params);
const query = PGQueryBuilder.buildSelect(params);
await this.pgExec(query, connectErrorHandler, dbResponseHandler, dbResErrorHandler);
} catch (e) {
this.logger.error(e.stack)
Expand All @@ -176,7 +176,7 @@ class DatabaseService {

try {
await this.pgExec(
QueryBuilder.buildInsert(params),
PGQueryBuilder.buildInsert(params),
connectErrorHandler,
dbResponseHandler,
dbResErrorHandler);
Expand Down Expand Up @@ -207,4 +207,6 @@ class DatabaseService {

}

module.exports = new DatabaseService();
module.exports = {
databaseService: new DatabaseService()
};
90 changes: 90 additions & 0 deletions app/lib/database/adapters/RunAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* 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.
*/


/**
* RunAdapter
*/
class RunAdapter {
/**
* Converts the given database object to an entity object.
*
* @param {SequelizeRun} databaseObject Object to convert.
* @returns {Run} Converted entity object.
*/
toEntity(databaseObject) {
const {
runNumber,
timeO2Start,
timeO2End,
timeTrgStart,
timeTrgEnd,
startTime,
endTime,
runDuration,
fillNumber,
lhcBeamEnergy,
l3CurrentVal,
dipoleCurrentVal,
} = databaseObject;

return {
runNumber,
timeO2Start,
timeO2End,
timeTrgStart,
timeTrgEnd,
startTime,
endTime,
runDuration,
fillNumber,
lhcBeamEnergy,
l3CurrentVal,
dipoleCurrentVal,
}
}

/**
* Converts the given entity object to database object.
*
* @param {Run} databaseObject Object to convert.
* @returns {SequelizeRun} Converted entity object.
*/
toDatabase(entityObject) {
const {
runNumber,
timeO2Start,
timeO2End,
timeTrgStart,
timeTrgEnd,
fillNumber,
lhcBeamEnergy,
l3CurrentVal,
dipoleCurrentVal,
} = entityObject;

return {
runNumber,
timeO2Start,
timeO2End,
timeTrgStart,
timeTrgEnd,
fillNumber,
lhcBeamEnergy,
l3CurrentVal,
dipoleCurrentVal,
}
}
}

module.exports = RunAdapter;
20 changes: 20 additions & 0 deletions app/lib/database/adapters/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* 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 RunAdapter = require('./RunAdapter');

const runAdapter = new RunAdapter();

module.exports = {
runAdapter,
}
21 changes: 0 additions & 21 deletions app/lib/database/index.js

This file was deleted.

Loading