Skip to content

Commit

Permalink
Fix warnings and errors that can be auto-fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
graduta committed Jul 23, 2024
1 parent 9503f20 commit a5065bd
Show file tree
Hide file tree
Showing 166 changed files with 3,300 additions and 3,361 deletions.
10 changes: 5 additions & 5 deletions Control/config-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ module.exports = {
// key: './cert/key.pem',
// cert: './cert/cert.pem',
tls: false,
limit: '1Mb'
limit: '1Mb',
},
grpc: {
hostname: 'localhost',
port: 9090,
timeout: 20000, // ms, gRPC deadline for service calls
maxMessageLength: 50, // MB, gRPC receive message limit
label: 'Control',
package: 'o2control'
package: 'o2control',
},
apricot: {
hostname: 'localhost',
port: 9090,
timeout: 20000, // ms, gRPC deadline for service calls
maxMessageLength: 50, // MB, gRPC receive message limit
label: 'Apricot',
package: 'apricot'
package: 'apricot',
},
grafana: {
url: 'http://localhost:3000'
url: 'http://localhost:3000',
},
bookkeeping: {
url: 'http://localhost:4000',
Expand All @@ -51,7 +51,7 @@ module.exports = {
url: 'localhost:8083',
},
qcGui: {
url: 'qcg.cern.ch'
url: 'qcg.cern.ch',
},
utils: {
refreshTask: 10000, // how often should task list page should refresh its content
Expand Down
8 changes: 4 additions & 4 deletions Control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
* 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 path = require('path');
const {HttpServer, WebSocket} = require('@aliceo2/web-ui');
const { HttpServer, WebSocket } = require('@aliceo2/web-ui');

const config = require('./lib/config/configProvider.js');
const {buildPublicConfig} = require('./lib/config/publicConfigProvider.js');
const { buildPublicConfig } = require('./lib/config/publicConfigProvider.js');
const api = require('./lib/api.js');

// -------------------------------------------------------

buildPublicConfig(config);

config.http.iframeCsp = (config?.grafana?.url) ? [ config.grafana.url ] : [];
config.http.iframeCsp = config?.grafana?.url ? [config.grafana.url] : [];
const http = new HttpServer(config.http, config.jwt, config.openId);
const ws = new WebSocket(http);
http.addStaticPath(path.join(__dirname, 'public'));
Expand Down
103 changes: 53 additions & 50 deletions Control/lib/adapters/EnvironmentInfoAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
* or submit itself to any jurisdiction.
*/

const {TaskState} = require('./../common/taskState.enum.js');
const { TaskState } = require('./../common/taskState.enum.js');

const QC_NODES_NAME_REGEX = /alio2-cr1-q(c|me|ts)[0-9]{2}/;

/**
* Enum with potential sources of tasks for AliECS environment
* @readonly
* @enum {String}
* @enum {string}
*/
const TASKS_SOURCE = {
EPN: 'EPN',
FLP: 'FLP',
TRG: 'TRG',
QC: 'QC',
}
};

/**
* EnvironmentInfoAdapter - Given an AliECS Environment, construct an EnvironmentInfo object for GUI purposes
Expand All @@ -38,10 +39,10 @@ class EnvironmentInfoAdapter {

/**
* Converts the given proto object (o2control.proto) to an entity overview object.
*
* @param {EnvironmentInfoProto} protoObject - object to convert

Check warning on line 42 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Expected @param names to be "environment, detectorsAll, hostsByDetector". Got "protoObject, environment, detectorsAll, hostsByDetector"

Check warning on line 42 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Expected @param names to be "environment, detectorsAll, hostsByDetector". Got "protoObject, environment, detectorsAll, hostsByDetector"
* @param {Array<String>} detectorsAll - list of all detectors in the current AliECS deployment
* @param {Map<String, Array<String>>} hostsByDetector - object with list of hosts grouped by detector
* @param environment

Check warning on line 43 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Missing JSDoc @param "environment" description

Check warning on line 43 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Missing JSDoc @param "environment" type

Check warning on line 43 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Missing JSDoc @param "environment" description

Check warning on line 43 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Missing JSDoc @param "environment" type
* @param {Array<string>} detectorsAll - list of all detectors in the current AliECS deployment
* @param {Map<string, Array<string>>} hostsByDetector - object with list of hosts grouped by detector
* @returns {EnvironmentInfo} entity of environment with needed information
*/
static toOverviewEntity(environment, detectorsAll, hostsByDetector) {
Expand Down Expand Up @@ -93,51 +94,49 @@ class EnvironmentInfoAdapter {
/**

Check warning on line 94 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Missing JSDoc @returns declaration

Check warning on line 94 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Missing JSDoc @returns declaration
* Method to build an environment info with tasks from specified source
* @param {EnvironmentInfoProto} environment - environment as from AliECS
* @param {String} taskSource - source of tasks
* @param {Array<String>} detectorsAll - list of all detectors in the current AliECS deployment
* @param {Map<String, Array<String>>} hostsByDetectors - object with list of hosts grouped by detector
* @param {string} taskSource - source of tasks
* @param {Array<string>} detectorsAll - list of all detectors in the current AliECS deployment
* @param {Map<string, Array<string>>} hostsByDetectors - object with list of hosts grouped by detector
*/
static toEntity(environment, taskSource = '', detectorsAll, hostsByDetectors) {
taskSource = taskSource.toLocaleUpperCase();

const environmentInfo = EnvironmentInfoAdapter.toOverviewEntity(environment, detectorsAll, hostsByDetectors);
if (taskSource === TASKS_SOURCE.EPN) {
const {integratedServicesData: {odc = '{}'}} = environment;
const {devices = []} = JSON.parse(odc);
const { integratedServicesData: { odc = '{}' } } = environment;
const { devices = [] } = JSON.parse(odc);

environmentInfo.tasks = Array.from(
Object.values(devices).map((device) => {
device.epnState = device.state;
device.state = device.ecsState;
delete device.ecsState;
return device;
})
);
environmentInfo.tasks = Array.from(Object.values(devices).map((device) => {
device.epnState = device.state;
device.state = device.ecsState;
delete device.ecsState;
return device;
}));
} else if (taskSource === TASKS_SOURCE.FLP) {
const {tasks = [], includedDetectors} = environment;
const { tasks = [], includedDetectors } = environment;
environmentInfo.tasks = [];
for (const task of tasks) {
const {deploymentInfo: {hostname = ''} = {}} = task;
const { deploymentInfo: { hostname = '' } = {} } = task;
const keyDetector = Object.keys(Object.fromEntries(hostsByDetectors))

Check failure on line 120 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Use array destructuring

Check failure on line 120 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Use array destructuring
.filter((detector) => hostsByDetectors.get(detector).includes(hostname))[0];
if (!hostname.match(QC_NODES_NAME_REGEX) && includedDetectors.includes(keyDetector)) {
environmentInfo.tasks.push(task);
}
}
} else if (taskSource === TASKS_SOURCE.QC) {
const {tasks = []} = environment;
const { tasks = [] } = environment;
environmentInfo.tasks = [];
for (const task of tasks) {
const {deploymentInfo: {hostname = ''} = {}} = task;
const { deploymentInfo: { hostname = '' } = {} } = task;
if (hostname.match(QC_NODES_NAME_REGEX)) {
environmentInfo.tasks.push(task);
}
}
} else if (taskSource === TASKS_SOURCE.TRG) {
const {tasks = [], includedDetectors} = environment;
const { tasks = [], includedDetectors } = environment;
environmentInfo.tasks = [];
for (const task of tasks) {
const {deploymentInfo: {hostname = ''} = {}} = task;
const { deploymentInfo: { hostname = '' } = {} } = task;
const keyDetector = Object.keys(Object.fromEntries(hostsByDetectors))

Check failure on line 140 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Use array destructuring

Check failure on line 140 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Use array destructuring
.filter((detector) => hostsByDetectors.get(detector).includes(hostname))[0];
if (!hostname.match(QC_NODES_NAME_REGEX) && !includedDetectors.includes(keyDetector)) {
Expand All @@ -151,7 +150,7 @@ class EnvironmentInfoAdapter {
/**
* Given an environment, group its tasks by the 3 main categories: FLP, QC Nodes and CTP Readout
* @param {EnvironmentInfo} environment - DTO representing an environment
* @param {Map<String, Array<String>>} hostsByDetectors - hosts grouped by the detectors
* @param {Map<string, Array<string>>} hostsByDetectors - hosts grouped by the detectors
* @returns {object{tasks: Array<TaskInfo>, hosts: Set}} - Object with groups of tasks and set of unique hosts

Check warning on line 154 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Syntax error in type: object{tasks: Array<TaskInfo>, hosts: Set}

Check warning on line 154 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Syntax error in type: object{tasks: Array<TaskInfo>, hosts: Set}
*/
static _getHardwareCountersPerComponent(environment, hostsByDetectors) {
Expand All @@ -171,31 +170,31 @@ class EnvironmentInfoAdapter {
const trgStates = {};
const trgStatuses = {};

const {tasks = [], includedDetectors = []} = environment;
const { tasks = [], includedDetectors = [] } = environment;

for (const task of tasks) {
const {critical = false, status = 'NOT-KNOWN', deploymentInfo: {hostname = ''} = {}} = task;
let {state = TaskState.UNKNOWN} = task;
const { critical = false, status = 'NOT-KNOWN', deploymentInfo: { hostname = '' } = {} } = task;
let { state = TaskState.UNKNOWN } = task;

if (state === TaskState.ERROR && critical) {
state = TaskState.ERROR_CRITICAL;
}

if (hostname.match(QC_NODES_NAME_REGEX)) {
qcTasksTotal++;
qcStates[state] = (qcStates[state] + 1) || 1;
qcStatuses[status] = (qcStatuses[status] + 1) || 1;
qcStates[state] = qcStates[state] + 1 || 1;
qcStatuses[status] = qcStatuses[status] + 1 || 1;
qcHosts.add(hostname);
} else {
const {userVars: {ctp_readout_enabled = 'false'} = {}} = environment;
const { userVars: { ctp_readout_enabled = 'false' } = {} } = environment;
const isReadoutEnabled = ctp_readout_enabled === 'true';

const keyDetector = Object.keys(Object.fromEntries(hostsByDetectors))

Check failure on line 192 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Use array destructuring

Check failure on line 192 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Use array destructuring
.filter((detector) => hostsByDetectors.get(detector).includes(hostname))[0];
if (includedDetectors.includes(keyDetector)) {
flpTasksTotal++;
flpStates[state] = (flpStates[state] + 1) || 1;
flpStatuses[status] = (flpStatuses[status] + 1) || 1;
flpStates[state] = flpStates[state] + 1 || 1;
flpStatuses[status] = flpStatuses[status] + 1 || 1;
if (!flpDetectors[keyDetector]) {
flpDetectors[keyDetector] = {
total: 0,
Expand All @@ -204,14 +203,14 @@ class EnvironmentInfoAdapter {
};
}
flpDetectors[keyDetector].total++;
flpDetectors[keyDetector].states[state] = (flpDetectors[keyDetector].states[state] + 1) || 1;
flpDetectors[keyDetector].statuses[status] = (flpDetectors[keyDetector].statuses[status] + 1) || 1;
flpDetectors[keyDetector].states[state] = flpDetectors[keyDetector].states[state] + 1 || 1;
flpDetectors[keyDetector].statuses[status] = flpDetectors[keyDetector].statuses[status] + 1 || 1;

flpHosts.add(hostname);
} else if (isReadoutEnabled) {
trgTasksTotal++;
trgStates[state] = (trgStates[state] + 1) || 1;
trgStatuses[status] = (trgStatuses[status] + 1) || 1;
trgStates[state] = trgStates[state] + 1 || 1;
trgStatuses[status] = trgStatuses[status] + 1 || 1;
trgHosts.add(hostname);
}
}
Expand All @@ -234,42 +233,44 @@ class EnvironmentInfoAdapter {
},
hosts: flpHosts.size,
detectorCounters: flpDetectors,
}, trg: {
},
trg: {
tasks: {
total: trgTasksTotal,
states: trgStates,
statuses: trgStatuses,
},
hosts: trgHosts.size,
}
},
};
}

/**

Check warning on line 248 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Missing JSDoc @returns declaration

Check warning on line 248 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Missing JSDoc @returns declaration
* Prepare an ODC object with hardware information based
* @param {Map<String, Object>} integratedServicesData - object with details of the integrated services
* @param {Map<string, object>} integratedServicesData - object with details of the integrated services

Check warning on line 250 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Expected @param names to be "odc". Got "integratedServicesData, odc"

Check warning on line 250 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Expected @param names to be "odc". Got "integratedServicesData, odc"
* @param odc

Check warning on line 251 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Missing JSDoc @param "odc" description

Check warning on line 251 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Missing JSDoc @param "odc" type

Check warning on line 251 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Missing JSDoc @param "odc" description

Check warning on line 251 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Missing JSDoc @param "odc" type
*/
static _getOdcCounters(odc = {}) {
try {
/**
* @type {Array<DeviceInfo>} devices
*/
const {devices = [], ddsSessionId = '', ddsSessionStatus = '', state = ''} = JSON.parse(odc);
const { devices = [], ddsSessionId = '', ddsSessionStatus = '', state = '' } = JSON.parse(odc);
const states = {};
const hosts = new Set();

Object.values(devices).forEach((device) => {
const {ecsState, host} = device;
const { ecsState, host } = device;
hosts.add(host);
states[ecsState] = (states[ecsState] + 1) || 1;
states[ecsState] = states[ecsState] + 1 || 1;
});
return {
tasks: {
total: Object.keys(devices).length,
states
states,
},
hosts: hosts.size,
info: {ddsSessionId, ddsSessionStatus, state}
info: { ddsSessionId, ddsSessionStatus, state },
};
} catch (error) {

Check failure on line 275 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

'error' is defined but never used

Check failure on line 275 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

'error' is defined but never used
return {
Expand All @@ -278,7 +279,7 @@ class EnvironmentInfoAdapter {
states: {},
},
hosts: 0,
info: {ddsSessionId: '-', ddsSessionStatus: '-', state: '-'}
info: { ddsSessionId: '-', ddsSessionStatus: '-', state: '-' },
};
}
}
Expand All @@ -289,18 +290,20 @@ class EnvironmentInfoAdapter {
* * remove any variables that are a detector variable but are not part of the included detector
* @param {JSON} objectToFilterFrom - object from which var
* @param {string} label

Check warning on line 292 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

Expected @param names to be "objectToFilterFrom, includedDetectors, detectors". Got "objectToFilterFrom, label, includedDetectors, detectors"

Check warning on line 292 in Control/lib/adapters/EnvironmentInfoAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

Expected @param names to be "objectToFilterFrom, includedDetectors, detectors". Got "objectToFilterFrom, label, includedDetectors, detectors"
* @return {JSON}
* @param includedDetectors
* @param detectors
* @returns {JSON}
*/
static _filterOutDetectorsVariables(objectToFilterFrom, includedDetectors, detectors) {
const data = JSON.parse(JSON.stringify(objectToFilterFrom));
for (const key of Object.keys(data)) {
const prefixUpper = key.split('_')[0].toLocaleUpperCase();
const isVariableDetector =
detectors.findIndex((det) => det.toLocaleUpperCase() === prefixUpper) !== -1
detectors.findIndex((det) => det.toLocaleUpperCase() === prefixUpper) !== -1;
const isVariableIncludedDetector =
includedDetectors.findIndex((det) => det.toLocaleUpperCase() === prefixUpper) !== -1;
if (isVariableDetector && !isVariableIncludedDetector) {
delete data[key]
delete data[key];
}
}
return data;
Expand Down
2 changes: 1 addition & 1 deletion Control/lib/adapters/EnvironmentTransitionResultAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EnvironmentTransitionResultAdapter {
* Converts the given object to an entity object.
* @static
* @param {ControlEnvironmentReply} transitionResult - as from AliECS
* @return {EnvironmentTransitionResult} information on the transition result of the environment
* @returns {EnvironmentTransitionResult} information on the transition result of the environment
*/
static toEntity(transitionResult) {
const {
Expand Down
5 changes: 2 additions & 3 deletions Control/lib/adapters/RunSummaryAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ class RunSummaryAdapter {

/**
* Converts the given object to an entity object.
*
* @param {Object} run - Run Entity as per Bookkeeping https://github.com/AliceO2Group/Bookkeeping/blob/main/lib/domain/entities/Run.js
* @param {object} run - Run Entity as per Bookkeeping https://github.com/AliceO2Group/Bookkeeping/blob/main/lib/domain/entities/Run.js

Check failure on line 26 in Control/lib/adapters/RunSummaryAdapter.js

View workflow job for this annotation

GitHub Actions / Tests & coverage on ubuntu-latest

This line has a length of 137. Maximum allowed is 120

Check failure on line 26 in Control/lib/adapters/RunSummaryAdapter.js

View workflow job for this annotation

GitHub Actions / Tests on macos-latest

This line has a length of 137. Maximum allowed is 120
* @returns {RunSummary} entity of a task with needed information
*/
static toEntity(run) {
Expand All @@ -40,7 +39,7 @@ class RunSummaryAdapter {
endTime,
} = run;

let {detectors = []} = run;
let { detectors = [] } = run;
if (typeof detectors === 'string') {
detectors = detectors.split(',');
}
Expand Down
3 changes: 1 addition & 2 deletions Control/lib/adapters/TaskInfoAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class TaskInfoAdapter {

/**
* Converts the given proto object (o2control.proto) to an entity object.
*
* @param {TaskInfoProto} task - object to convert
* @returns {TaskInfo} entity of a task with needed information
*/
Expand Down Expand Up @@ -62,7 +61,7 @@ class TaskInfoAdapter {
* @returns {string} short name of the task
*/
static getShortName(taskName) {
const regex = new RegExp(`tasks/.*@`);
const regex = new RegExp('tasks/.*@');
const matchedTaskName = taskName.match(regex);
if (matchedTaskName) {
taskName = matchedTaskName[0].replace('tasks/', '').replace('@', '');
Expand Down
Loading

0 comments on commit a5065bd

Please sign in to comment.