Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rollup Jobs API to accommodate change to ES that allows starting a started job and stopping a stopped job. #38168

Merged
merged 4 commits into from
Jun 10, 2019
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
11 changes: 1 addition & 10 deletions x-pack/plugins/rollup/server/routes/api/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ export function registerJobsRoute(server) {
return await Promise.all(jobIds.map(id => callWithRequest('rollup.startJob', { id })))
.then(() => ({ success: true }));
} catch(err) {
// There is an issue opened on ES to handle the following error correctly
// https://github.com/elastic/elasticsearch/issues/39845
// Until then we'll modify the response here.
if (err.message.includes('Cannot start task for Rollup Job')) {
err.status = 400;
err.statusCode = 400;
err.body.error.status = 400;
err.displayName = 'Bad request';
}

if (isEsError(err)) {
return wrapEsError(err);
Expand Down Expand Up @@ -144,7 +135,7 @@ export function registerJobsRoute(server) {
.then(() => ({ success: true }));
} catch(err) {
// There is an issue opened on ES to handle the following error correctly
// https://github.com/elastic/elasticsearch/issues/39845
// https://github.com/elastic/elasticsearch/issues/42908
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to create a new issue here because it looks like the old one didn't capture this case.

// Until then we'll modify the response here.
if (err.response && err.response.includes('Job must be [STOPPED] before deletion')) {
err.status = 400;
Expand Down
32 changes: 20 additions & 12 deletions x-pack/test/api_integration/apis/management/rollup/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default function ({ getService }) {
});
});

describe.skip('actions', () => {
describe('actions', () => {
describe('start', () => {
let job;

Expand All @@ -237,32 +237,40 @@ export default function ({ getService }) {
expect(job.status.job_state).to.eql('started');
});

it('should throw a 400 Bad request if the job is already started', async () => {
it('should return 200 if the job is already started', async () => {
await startJob(job.config.id); // Start the job

const { body } = await startJob(job.config.id).expect(400);
expect(body.error).to.eql('Bad Request');
expect(body.message).to.contain('Cannot start task for Rollup Job');
await startJob(job.config.id).expect(200);
});
});

describe('stop', () => {
it('should stop the job', async () => {
let job;

beforeEach(async () => {
const indexName = await createIndexWithMappings();
const payload = getJobPayload(indexName);
const { id: jobId } = payload.job;

await createJob(payload);
await startJob(jobId);
const { body } = await stopJob(jobId).expect(200);

const { body: { jobs } } = await loadJobs();
job = jobs.find(job => job.config.id === payload.job.id);
});

it('should stop the job', async () => {
await startJob(job.config.id);
const { body } = await stopJob(job.config.id).expect(200);

expect(body).to.eql({ success: true });

// Fetch the job to make sure it has been stopped
const jobId = job.config.id;
const { body: { jobs } } = await loadJobs();
const job = jobs.find(job => job.config.id === jobId);
job = jobs.find(job => job.config.id === jobId);
expect(job.status.job_state).to.eql('stopped');
});

it('should return 200 if the job is already stopped', async () => {
await stopJob(job.config.id).expect(200);
});
});
});
});
Expand Down