Skip to content

Commit

Permalink
Merge pull request #10 from pmandrik/dropdown_fix
Browse files Browse the repository at this point in the history
Fix dropdown bug & JSON REDIS
  • Loading branch information
pmandrik authored Apr 26, 2022
2 parents b1db86e + fec938f commit 3169ae5
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 100 deletions.
16 changes: 8 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ If there is a human error, for example if a user sometimes batch-updates runs an
sudo chmod -R 777 /srv/
forever stopall
rm -rf node
sudo wget https://nodejs.org/dist/v12.17.0/node-v12.17.0-linux-x64.tar.xz
sudo tar -xf node-v12.17.0-linux-x64.tar.xz
sudo mv node-v12.17.0-linux-x64 node
sudo rm node-v12.17.0-linux-x64.tar.xz
sudo wget https://nodejs.org/dist/v12.20.0/node-v12.20.0-linux-x64.tar.xz
sudo tar -xf node-v12.20.0-linux-x64.tar.xz
sudo mv node-v12.20.0-linux-x64 node
sudo rm node-v12.20.0-linux-x64.tar.xz
sudo chmod -R 777 /srv/
cd node && export HOME=$PWD
cd ..
Expand Down Expand Up @@ -121,10 +121,10 @@ Logs can be found by running a command: `forever logs`
sudo chmod -R 777 /srv/
forever stopall
rm -rf node
sudo wget https://nodejs.org/dist/v12.17.0/node-v12.17.0-linux-x64.tar.xz
sudo tar -xf node-v12.17.0-linux-x64.tar.xz
sudo mv node-v12.17.0-linux-x64 node
sudo rm node-v12.17.0-linux-x64.tar.xz
sudo wget https://nodejs.org/dist/v12.20.0/node-v12.20.0-linux-x64.tar.xz
sudo tar -xf node-v12.20.0-linux-x64.tar.xz
sudo mv node-v12.20.0-linux-x64 node
sudo rm node-v12.20.0-linux-x64.tar.xz
sudo chmod -R 777 /srv/
cd node && export HOME=$PWD
cd ..
Expand Down
18 changes: 18 additions & 0 deletions readme_faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,21 @@ docker push registry.cern.ch/cmsweb/runregistry-frontend:0.2-cmsweb
There is also tow images we were not able to pull from docker.com:
cmssw/runregistry-workers-oms-fetching
cmssw/runregistry-workers-json-processing

#### Redis server
REDIS server is used by BULL JS package to store configs used to generate JSONs in a queue
```
sudo yum install redis
sudo nano /etc/redis.conf
supervised no -> supervised systemd
sudo systemctl restart redis.service
```
Check:
```
redis-cli
ping
```
Set REDIS_URL to local redis server `redis://127.0.0.1:6379`



4 changes: 2 additions & 2 deletions runregistry_backend/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = {
OMS_URL: `https://cmsoms.cern.ch/agg/api/v1`,
AUTH_SERVICE_URL:
'https://auth.cern.ch/auth/realms/cern/protocol/openid-connect/token',
REDIS_URL: `redis://dev-rr-redis.runregistry.svc.cluster.local`,
REDIS_URL: `redis://127.0.0.1:6379`, // `redis://dev-rr-redis.runregistry.svc.cluster.local`,
OMS_RUNS: (number_of_runs = 10) =>
`runs?sort=-last_update&page[limit]=${number_of_runs}`,
OMS_SPECIFIC_RUN: (run_number) => `runs?filter[run_number]=${run_number}`,
Expand Down Expand Up @@ -136,7 +136,7 @@ module.exports = {
OMS_URL: `https://cmsoms.cern.ch/agg/api/v1`,
AUTH_SERVICE_URL:
'https://auth.cern.ch/auth/realms/cern/protocol/openid-connect/token',
REDIS_URL: `redis://cmsweb-test4-yvri27sszw3m-node-2:31505`,
REDIS_URL: `redis://127.0.0.1:6379`, // redis://cmsweb-test4-yvri27sszw3m-node-2:31505`,
OMS_RUNS: (number_of_runs = 10) =>
`runs?sort=-last_update&page[limit]=${number_of_runs}`,
OMS_SPECIFIC_RUN: (run_number) => `runs?filter[run_number]=${run_number}`,
Expand Down
28 changes: 27 additions & 1 deletion runregistry_backend/controllers/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
const { update_or_create_dataset } = require('./dataset');
const { create_new_version } = require('./version');
const { fill_dataset_triplet_cache } = require('./dataset_triplet_cache');
const { manually_update_a_run } = require('../cron/2.save_or_update_runs');
const { manually_update_a_run , manually_update_a_run_reset_rr_attributes } = require('../cron/2.save_or_update_runs');
const {
create_offline_waiting_datasets,
} = require('../cron_datasets/1.create_datasets');
Expand Down Expand Up @@ -578,6 +578,32 @@ exports.refreshRunClassAndComponents = async (req, res) => {
res.json(saved_run);
};

exports.resetAndRefreshRunRRatributes = async (req, res) => {
const { run_number } = req.params;
const email = req.get('email');
const previously_saved_run = await Run.findByPk(run_number);
if (previously_saved_run === null) {
throw 'Run not found';
}
if (previously_saved_run.rr_attributes.state !== 'OPEN') {
throw 'Run must be in state OPEN to be refreshed';
}

await manually_update_a_run_reset_rr_attributes(run_number, {
email,
comment: `${email} requested reset and refresh from OMS`,
});
const saved_run = await Run.findByPk(run_number, {
include: [
{
model: DatasetTripletCache,
attributes: ['triplet_summary'],
},
],
});
res.json(saved_run);
};

exports.moveRun = async (req, res) => {
const { to_state } = req.params;
const { run_number } = req.body;
Expand Down
30 changes: 29 additions & 1 deletion runregistry_backend/cron/2.save_or_update_runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,34 @@ exports.manually_update_a_run = async (
});
};

exports.manually_update_a_run_reset_rr_attributes = async (
run_number,
{ email, comment, manually_significant, atomic_version }
) => {
// get rr_attributes:
const { data: saved_run } = await axios.get(`${API_URL}/runs/${run_number}`);
const previous_rr_attributes = saved_run.rr_attributes;
if (previous_rr_attributes.state !== 'OPEN') {
throw 'Run must be in state OPEN to be refreshed';
}


// get oms_attributes:
const endpoint = `${OMS_URL}/${OMS_SPECIFIC_RUN(run_number)}`;
const {
data: { data: fetched_run },
} = await instance.get(endpoint, {
headers: {
Authorization: `Bearer ${await getToken()}`,
},
});
const empty_var = false;
const run_oms_attributes = fetched_run[0].attributes;
await exports.update_runs([run_oms_attributes], 0, {
empty_var,
email,
comment,
manually_significant,
atomic_version,
});
};

11 changes: 5 additions & 6 deletions runregistry_backend/models/permission.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// About sequelize.define
// https://sequelize.org/v3/docs/models-definition/
// To define mappings between a model and a table, use the define method. Sequelize will then automatically add the attributes createdAt and updatedAt to it.
module.exports = (sequelize, DataTypes) => {
const Permission = sequelize.define(
'Permission',
Expand All @@ -12,7 +15,7 @@ module.exports = (sequelize, DataTypes) => {
allowNull: false
},
routes: {
type: DataTypes.JSONB,
type: DataTypes.JSONB, // JSONB - JSON input text in a decomposed binary form
allowNull: false
}
},
Expand All @@ -22,11 +25,7 @@ module.exports = (sequelize, DataTypes) => {
);

Permission.associate = function(models) {
Permission.belongsToMany(models.PermissionList, {
through: models.PermissionEntries,
foreignKey: 'id',
otherKey: 'PL_id'
});
Permission.belongsToMany(models.PermissionList, { through: models.PermissionEntries, foreignKey: 'id', otherKey: 'PL_id' });
};
return Permission;
};
6 changes: 2 additions & 4 deletions runregistry_backend/routes/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ module.exports = app => {
// Shifter actions:
app.post('/runs/mark_significant', auth, catchAPI(Run.markSignificant));
app.post('/runs/move_run/:from_state/:to_state', auth, catchAPI(Run.moveRun));
app.post(
'/runs/refresh_run/:run_number',
catchAPI(Run.refreshRunClassAndComponents)
);
app.post('/runs/refresh_run/:run_number', catchAPI(Run.refreshRunClassAndComponents));
app.post('/runs/reset_and_refresh_run/:run_number', catchAPI(Run.resetAndRefreshRunRRatributes));
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { Component } from 'react';
import dynamic from 'next/dynamic';
import { connect } from 'react-redux';
import { AutoComplete, Menu, Button, Input } from 'antd';
import { AutoComplete, Menu, Button, Input, Dropdown } from 'antd';
import {
PlusCircleOutlined,
CloseCircleOutlined,
EditOutlined,
DeleteOutlined,
DownOutlined,
} from '@ant-design/icons';
import Swal from 'sweetalert2';
import {
Expand Down Expand Up @@ -288,65 +289,25 @@ class Configuration extends Component {
borderRadius: '2px',
}}
>
<div
style={{
width: '10%',
display: 'flex',
alignItems: 'center',
marginLeft: '5px',
height: '48px',
}}
>
<strong>configurations created by me:</strong>
</div>
<div style={{ width: '88%' }}>
<Menu
onClick={({ key }) => this.handleMenuChange(key)}
selectedKeys={[menu_selection]}
mode="horizontal"
>
{json_configurations_array
.filter(
({ created_by }) => created_by === this.props.email
)
.map(({ name }) => (
<Menu.Item key={name}>{name}</Menu.Item>
))}
</Menu>
</div>
</div>
<br />
<div
style={{
display: 'flex',
border: '1px solid #d9d9d9',
borderRadius: '2px',
}}
>
<div
style={{
width: '10%',
display: 'flex',
alignItems: 'center',
marginLeft: '5px',
}}
>
<strong>all configurations:</strong>
</div>
<div style={{ width: '88%' }}>
<Menu
onClick={({ key }) => this.handleMenuChange(key)}
selectedKeys={[menu_selection]}
mode="horizontal"
>
<Menu.Item key="arbitrary">
arbitrary configuration
</Menu.Item>
{json_configurations_array.map(({ name }) => (
<Menu.Item key={name}>{name}</Menu.Item>
))}
//<Menu onClick={({ key }) => this.handleMenuChange(key)} selectedKeys={[menu_selection]} mode="horizontal">
// {json_configurations_array.filter( ({ created_by }) => created_by === this.props.email).map(({ name }) => ( <Menu.Item key={name}>{name}</Menu.Item> ))}
//</Menu>

<Menu onClick={({ key }) => this.handleMenuChange(key)} selectedKeys={[menu_selection]} mode="horizontal">
<Menu.Item key="arbitrary"> New Configuration </Menu.Item>
</Menu>
</div>

<Dropdown overlay={ <Menu style={{ overflowY: 'scroll', maxHeight: '300px' }} onClick={({ key }) => this.handleMenuChange(key)} selectedKeys={[menu_selection]}>
{json_configurations_array.filter( ({ created_by }) => created_by === this.props.email).map(({ name }) => ( <Menu.Item key={name}>{name}</Menu.Item> ))}
</Menu> } destroyPopupOnHide={true}>
<a style={{ marginTop: '12px' }} className="ant-dropdown-link" onClick={e => e.preventDefault()}> My Configurations <DownOutlined /> </a>
</Dropdown>

<Dropdown overlay={ <Menu style={{ overflowY: 'scroll', maxHeight: '300px' }} onClick={({ key }) => this.handleMenuChange(key)} selectedKeys={[menu_selection]}>
{json_configurations_array.map(({ name }) => ( <Menu.Item key={name}>{name}</Menu.Item>))}
</Menu> } destroyPopupOnHide={true}>
<a style={{ marginTop: '12px' }} className="ant-dropdown-link" onClick={e => e.preventDefault()}> All Configurations <DownOutlined /> </a>
</Dropdown>
</div>
</center>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import axios from 'axios';

import EditComponent from '../../../../../components/common/editComponent/EditComponent';
import { api_url } from '../../../../../config/config';
import { refreshRun } from '../../../../../ducks/online/runs';
import { refreshRun, resetAndRefreshRun } from '../../../../../ducks/online/runs';
import { showManageRunModal } from '../../../../../ducks/online/ui';
import { addLumisectionRange } from '../../../../../ducks/online/lumisections';
import { certifiable_online_components } from '../../../../../config/config';
Expand Down Expand Up @@ -71,9 +71,7 @@ class EditRunLumisections extends Component {
reverseButtons: true,
});
if (value) {
const updated_run = await this.props.refreshRun(
run.run_number
);
const updated_run = await this.props.refreshRun( run.run_number );
await Swal(`Run updated`, '', 'success');
await this.props.showManageRunModal(updated_run);
this.fetchLumisections();
Expand All @@ -83,6 +81,28 @@ class EditRunLumisections extends Component {
>
Manually refresh component's statuses
</Button>
&nbsp;
<Button
onClick={async (evt) => {
const { value } = await Swal({
type: 'warning',
title: `If a status was previously edited by a shifter, it will not be updated, it will only change those untouched.`,
text: '',
showCancelButton: true,
confirmButtonText: 'Yes',
reverseButtons: true,
});
if (value) {
const updated_run = await this.props.resetAndRefreshRun( run.run_number );
await Swal(`Run updated`, '', 'success');
await this.props.showManageRunModal(updated_run);
this.fetchLumisections();
}
}}
type="primary"
>
Reset RR attributes and refresh
</Button>
</div>
<br />

Expand Down Expand Up @@ -213,6 +233,7 @@ const mapStateToProps = (state) => {

export default connect(mapStateToProps, {
refreshRun,
resetAndRefreshRun,
showManageRunModal,
addLumisectionRange,
})(EditRunLumisections);
18 changes: 3 additions & 15 deletions runregistry_frontend/components/ui/breadcrumb/Breadcrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,10 @@ class BreadcrumbCmp extends Component {
</div>
<div className="progresscircle_container">
<div>
<a
className="jira"
target="_blank"
href="https://its.cern.ch/jira/projects/NEWRUNREGISTRY/issues/"
>
Feedback is welcome! (JIRA)
</a>
<a className="jira" target="_blank" href="https://its.cern.ch/jira/projects/NEWRUNREGISTRY/issues/"> Feedback is welcome! (JIRA) </a>
</div>
<Dropdown overlay={online ? this.online_menu : this.offline_menu}>
<Button
style={{ marginTop: '-6px' }}
onClick={(e) => e.preventDefault()}
>
Configuration
<DownOutlined />
</Button>
<Dropdown overlay={online ? this.online_menu : this.offline_menu} destroyPopupOnHide={true}>
<Button style={{ marginTop: '-6px' }} onClick={(e) => e.preventDefault()} > Configuration <DownOutlined /> </Button>
</Dropdown>
</div>

Expand Down
12 changes: 12 additions & 0 deletions runregistry_frontend/ducks/online/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export const refreshRun = run_number =>
return run;
});

export const resetAndRefreshRun = run_number =>
error_handler(async (dispatch, getState) => {
let { data: run } = await axios.post(
`${api_url}/runs/reset_and_refresh_run/${run_number}`,
{},
auth(getState)
);
run = formatRuns([run])[0];
dispatch({ type: EDIT_RUN, payload: run });
return run;
});

// reFetch run will just refetch a run
export const reFetchRun = run_number =>
error_handler(async (dispatch, getState) => {
Expand Down

0 comments on commit 3169ae5

Please sign in to comment.