@@ -170,7 +170,7 @@ private void getJobFromClusterState(String jobId, ActionListener<Job> jobListene
170170 * @param jobsListener The jobs listener
171171 */
172172 public void expandJobs (String expression , boolean allowNoJobs , ActionListener <QueryPage <Job >> jobsListener ) {
173- Map <String , Job > clusterStateJobs = expandJobsFromClusterState (expression , allowNoJobs , clusterService .state ());
173+ Map <String , Job > clusterStateJobs = expandJobsFromClusterState (expression , clusterService .state ());
174174
175175 jobConfigProvider .expandJobs (expression , allowNoJobs , ActionListener .wrap (
176176 jobBuilders -> {
@@ -197,12 +197,20 @@ public void expandJobs(String expression, boolean allowNoJobs, ActionListener<Qu
197197 ));
198198 }
199199
200- private Map <String , Job > expandJobsFromClusterState (String expression , boolean allowNoJobs , ClusterState clusterState ) {
201- Set <String > expandedJobIds = MlMetadata .getMlMetadata (clusterState ).expandJobIds (expression , allowNoJobs );
202- MlMetadata mlMetadata = MlMetadata .getMlMetadata (clusterState );
200+ private Map <String , Job > expandJobsFromClusterState (String expression , ClusterState clusterState ) {
203201 Map <String , Job > jobIdToJob = new HashMap <>();
204- for (String expandedJobId : expandedJobIds ) {
205- jobIdToJob .put (expandedJobId , mlMetadata .getJobs ().get (expandedJobId ));
202+ MlMetadata mlMetadata = MlMetadata .getMlMetadata (clusterState );
203+ try {
204+ // This call will throw if the expression is not a wild card
205+ // and the job does not exist. This is not the behaviour we
206+ // want as the job may exist in the index.
207+ // TODO jindex review the use of this function. Can it be changed not to throw in a BWC manner?
208+ Set <String > expandedJobIds = mlMetadata .expandJobIds (expression , true );
209+ for (String expandedJobId : expandedJobIds ) {
210+ jobIdToJob .put (expandedJobId , mlMetadata .getJobs ().get (expandedJobId ));
211+ }
212+ } catch (ResourceNotFoundException e ) {
213+ return jobIdToJob ;
206214 }
207215 return jobIdToJob ;
208216 }
0 commit comments