Skip to content

Commit

Permalink
Fix handling of null job
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle committed Dec 14, 2018
1 parent 666f99b commit 529d472
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* on that rather than the clusterstate.
*
* The number of configs indexed in each bulk operation is limited by {@link #MAX_BULK_WRITE_SIZE}
* pairs of datafeeds adn jobs are migrated together.
* pairs of datafeeds and jobs are migrated together.
*/
public class MlConfigMigrator {

Expand Down Expand Up @@ -376,7 +376,7 @@ public int totalCount() {

/**
* Return at most {@link #MAX_BULK_WRITE_SIZE} configs favouring
* datafeed and job pairs so if a datafeed is choosen so is its job.
* datafeed and job pairs so if a datafeed is chosen so is its job.
*
* @param datafeedsToMigrate Datafeed configs
* @param jobsToMigrate Job configs
Expand All @@ -396,11 +396,11 @@ public static JobsAndDatafeeds limitWrites(Collection<DatafeedConfig> datafeedsT
// prioritise datafeed and job pairs
for (DatafeedConfig datafeedConfig : datafeedsToMigrate) {
if (count < MAX_BULK_WRITE_SIZE) {
Job datafeedsJob = jobsToMigrate.remove(datafeedConfig.getJobId());
jobsAndDatafeeds.jobs.add(datafeedsJob);
jobsAndDatafeeds.datafeedConfigs.add(datafeedConfig);
count++;
Job datafeedsJob = jobsToMigrate.remove(datafeedConfig.getJobId());
if (datafeedsJob != null) {
jobsAndDatafeeds.datafeedConfigs.add(datafeedConfig);
jobsAndDatafeeds.jobs.add(datafeedsJob);
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,14 @@ public void testLimitWrites_GivenMoreJobsThanDatafeeds() {
assertTrue(selectedJobIds.containsAll(datafeedJobIds));
}

public void testLimitWrites_GivenNullJob() {
List<DatafeedConfig> datafeeds = Collections.singletonList(createCompatibleDatafeed("no-job-for-this-datafeed"));
MlConfigMigrator.JobsAndDatafeeds jobsAndDatafeeds = MlConfigMigrator.limitWrites(datafeeds, Collections.emptyMap());

assertThat(jobsAndDatafeeds.datafeedConfigs, hasSize(1));
assertThat(jobsAndDatafeeds.jobs, empty());
}

private DatafeedConfig createCompatibleDatafeed(String jobId) {
// create a datafeed without aggregations or anything
// else that may cause validation errors
Expand Down

0 comments on commit 529d472

Please sign in to comment.