Skip to content

Commit

Permalink
Add keepforever option
Browse files Browse the repository at this point in the history
Once the keepforever checkbox is selected for a build, this build will
not be removed even if we reach max # builds to keep.

Ideally, this keepforever option should only be avaliable for admin.
This should be enhanced once we have authentication added.

Signed-off-by: lanxia <[email protected]>
  • Loading branch information
llxia committed Jul 30, 2020
1 parent 51ea389 commit 651f89a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
6 changes: 4 additions & 2 deletions TestResultSummaryService/BuildMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BuildMonitor {
status = "Streaming";
logger.info(`Set build ${url} ${buildName} ${buildNum} status to Streaming `);
}
const keepForever = false;
const buildData = {
url,
buildName,
Expand All @@ -57,6 +58,7 @@ class BuildMonitor {
buildResult: allBuilds[i].result ? allBuilds[i].result : null,
timestamp: allBuilds[i].timestamp ? allBuilds[i].timestamp : null,
type: type === "FVT" ? "Test" : type,
keepForever,
status,
};
const _id = await new DataManager().createBuild(buildData);
Expand All @@ -66,6 +68,7 @@ class BuildMonitor {
url,
buildName,
buildNum,
keepForever,
status,
});
} else {
Expand Down Expand Up @@ -105,8 +108,7 @@ class BuildMonitor {
const { buildName, url } = this.getBuildInfo(buildUrl);
// keep only limited builds in DB and delete old builds
const testResults = new TestResultsDB();
const allBuildsInDB = await testResults.getData({ url, buildName }).sort({ buildNum: 1 }).toArray();

const allBuildsInDB = await testResults.getData({ url, buildName, keepForever: { $ne: true } }).sort({ buildNum: 1 }).toArray();
if (allBuildsInDB && allBuildsInDB.length > numBuildsToKeep) {
const endIndex = Math.max(0, allBuildsInDB.length - numBuildsToKeep);
await Promise.all(allBuildsInDB.slice(0, endIndex).map(async (build) => {
Expand Down
2 changes: 2 additions & 0 deletions TestResultSummaryService/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ app.get( '/getTestPerPlatform', wrap( require( "./getTestPerPlatform" ) ) );
app.get( '/getTopLevelBuildNames', wrap( require( "./getTopLevelBuildNames" ) ) );
app.get( '/getTotals', wrap( require( "./getTotals" ) ) );
app.get( '/populateDB', wrap( require( "./populateDB" ) ) );

app.get( '/updateComments', wrap( require( "./updateComments" ) ) );
app.get( '/updateKeepForever', wrap( require( "./updateKeepForever" ) ) );

// jwt
app.post( '/auth/register', wrap( require( "./jwt/register" ) ) );
Expand Down
17 changes: 17 additions & 0 deletions TestResultSummaryService/routes/updateKeepForever.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { TestResultsDB, ObjectID } = require('../Database');

/*
* updateKeepForever API updates keepForever based on _id
*/
module.exports = async (req, res) => {
const { _id, keepForever } = req.query;
if (_id && keepForever) {
const keepForeverVal = (keepForever === 'true');
const db = new TestResultsDB();
const criteria = { _id: new ObjectID(_id) };
await db.update(criteria, { $set: { keepForever: keepForeverVal } }, { upsert: false });
res.send({ error: false });
} else {
res.json({ error: true });
}
}
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 41 additions & 5 deletions test-result-summary-client/src/Build/TopLevelBuildTable.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { CheckOutlined, CloseOutlined, InfoOutlined, LoadingOutlined } from '@ant-design/icons';
import { Table, Tooltip } from 'antd';
import { CheckOutlined, CloseOutlined, InfoOutlined, LoadingOutlined, QuestionCircleOutlined } from '@ant-design/icons';
import { Table, Tooltip, Checkbox, Popconfirm } from 'antd';
import { Link } from 'react-router-dom';
import { params } from '../utils/query';
import BuildLink from './BuildLink';
Expand Down Expand Up @@ -35,11 +35,12 @@ export default class TopLevelBuildTable extends Component {
const builds = await fetchBuild.json();

const buildInfo = builds.map(build => ({
key: build.buildUrl,
key: build._id,
build: build,
date: build.timestamp ? new Date(build.timestamp).toLocaleString() : null,
startBy: build.startBy ? build.startBy : null,
jenkins: build,
keepForever: build.keepForever ? build.keepForever : false
}));
this.setState({ buildInfo });

Expand Down Expand Up @@ -71,11 +72,28 @@ export default class TopLevelBuildTable extends Component {
});
};

handleKeepForverClick = async (record) => {
const { buildInfo } = this.state;
if (record.key) {
for (let build of buildInfo) {
if (build.key === record.key) {
build.keepForever = !build.keepForever;
await fetch(`/api/updateKeepForever?_id=${build.key}&keepForever=${build.keepForever}`, {
method: 'get'
});
break;
}
}
await new Promise(r => setTimeout(r, 100));
this.setState({ buildInfo });
}
}

render() {
const { buildInfo } = this.state;
const { buildName, url, type } = this.props;
if (buildInfo) {
const renderFvTestBuild = (value, row, index) => {
const renderFvTestBuild = (value) => {
if (value && value.buildNum) {
let icon = "";
if (value.status !== "Done") {
Expand Down Expand Up @@ -209,7 +227,25 @@ export default class TopLevelBuildTable extends Component {
sorter: (a, b) => {
return a.date.localeCompare(b.date);
}
}];
}, {
title: 'Keep Forever',
dataIndex: 'keepForever',
key: 'keepForever',
render: (value, record) => {
return <Popconfirm
title={value ? "Unchecking 'keep forever' means the build results will be deleted once max # of builds to keep is reached. Uncheck?" : "Keep this build forever?"}
onConfirm={() => this.handleKeepForverClick(record)}
icon={<QuestionCircleOutlined style={{ color: 'red' }} />}
okText="Yes"
cancelText="No"
okType="default"
cancelButtonProps={{ type: 'primary' }}
>
<Checkbox checked={value}></Checkbox>
</Popconfirm>
}
}
];

return <Table
columns={columns}
Expand Down

0 comments on commit 651f89a

Please sign in to comment.