@@ -71,7 +71,8 @@ public JobService(
7171 }
7272 }
7373
74- /* Job Service API */
74+ // region Job Service API
75+
7576 /**
7677 * List Ingestion Jobs in Feast matching the given request. See CoreService protobuf documentation
7778 * for more detailed documentation.
@@ -88,24 +89,24 @@ public ListIngestionJobsResponse listJobs(ListIngestionJobsRequest request)
8889
8990 // check that filter specified and not empty
9091 if (request .hasFilter ()
91- && !(request .getFilter ().getId () == ""
92- && request .getFilter ().getStoreName () == ""
93- && request .getFilter ().hasFeatureSetReference () == false )) {
92+ && !(request .getFilter ().getId (). isEmpty ()
93+ && request .getFilter ().getStoreName (). isEmpty ()
94+ && ! request .getFilter ().hasFeatureSetReference ())) {
9495 // filter jobs based on request filter
9596 ListIngestionJobsRequest .Filter filter = request .getFilter ();
9697
9798 // for proto3, default value for missing values:
9899 // - numeric values (ie int) is zero
99100 // - strings is empty string
100- if (filter .getId () != "" ) {
101+ if (! filter .getId (). isEmpty () ) {
101102 // get by id: no more filters required: found job
102103 Optional <Job > job = this .jobRepository .findById (filter .getId ());
103104 if (job .isPresent ()) {
104105 matchingJobIds .add (filter .getId ());
105106 }
106107 } else {
107108 // multiple filters can apply together in an 'and' operation
108- if (filter .getStoreName () != "" ) {
109+ if (! filter .getStoreName (). isEmpty () ) {
109110 // find jobs by name
110111 List <Job > jobs = this .jobRepository .findByStoreName (filter .getStoreName ());
111112 Set <String > jobIds = jobs .stream ().map (Job ::getId ).collect (Collectors .toSet ());
@@ -140,7 +141,7 @@ public ListIngestionJobsResponse listJobs(ListIngestionJobsRequest request)
140141 // convert matching job models to ingestion job protos
141142 List <IngestionJobProto .IngestionJob > ingestJobs = new ArrayList <>();
142143 for (String jobId : matchingJobIds ) {
143- Job job = this .jobRepository .findById (jobId ).get ();
144+ Job job = this .jobRepository .findById (jobId ).orElseThrow ();
144145 // job that failed on start won't be converted toProto successfully
145146 // and they're irrelevant here
146147 if (job .getStatus () == JobStatus .ERROR ) {
@@ -160,21 +161,20 @@ public ListIngestionJobsResponse listJobs(ListIngestionJobsRequest request)
160161 * @param request restart ingestion job request specifying which job to stop
161162 * @throws NoSuchElementException when restart job request requests to restart a nonexistent job.
162163 * @throws UnsupportedOperationException when job to be restarted is in an unsupported status
163- * @throws InvalidProtocolBufferException on error when constructing response protobuf
164164 */
165165 @ Transactional
166- public RestartIngestionJobResponse restartJob (RestartIngestionJobRequest request )
167- throws InvalidProtocolBufferException {
168- // check job exists
169- Optional <Job > getJob = this .jobRepository .findById (request .getId ());
170- if (getJob .isEmpty ()) {
171- // FIXME: if getJob.isEmpty then constructing this error message will always throw an error...
172- throw new NoSuchElementException (
173- "Attempted to stop nonexistent job with id: " + getJob .get ().getId ());
174- }
166+ public RestartIngestionJobResponse restartJob (RestartIngestionJobRequest request ) {
167+ String jobId = request .getId ();
168+
169+ Job job =
170+ this .jobRepository
171+ .findById (jobId )
172+ .orElseThrow (
173+ () ->
174+ new NoSuchElementException (
175+ "Attempted to restart nonexistent job with id: " + jobId ));
175176
176177 // check job status is valid for restarting
177- Job job = getJob .get ();
178178 JobStatus status = job .getStatus ();
179179 if (status .isTransitional () || status .isTerminal () || status == JobStatus .UNKNOWN ) {
180180 throw new UnsupportedOperationException (
@@ -202,20 +202,20 @@ public RestartIngestionJobResponse restartJob(RestartIngestionJobRequest request
202202 * @param request stop ingestion job request specifying which job to stop
203203 * @throws NoSuchElementException when stop job request requests to stop a nonexistent job.
204204 * @throws UnsupportedOperationException when job to be stopped is in an unsupported status
205- * @throws InvalidProtocolBufferException on error when constructing response protobuf
206205 */
207206 @ Transactional
208- public StopIngestionJobResponse stopJob (StopIngestionJobRequest request )
209- throws InvalidProtocolBufferException {
210- // check job exists
211- Optional <Job > getJob = this .jobRepository .findById (request .getId ());
212- if (getJob .isEmpty ()) {
213- throw new NoSuchElementException (
214- "Attempted to stop nonexistent job with id: " + getJob .get ().getId ());
215- }
207+ public StopIngestionJobResponse stopJob (StopIngestionJobRequest request ) {
208+ String jobId = request .getId ();
209+
210+ Job job =
211+ this .jobRepository
212+ .findById (jobId )
213+ .orElseThrow (
214+ () ->
215+ new NoSuchElementException (
216+ "Attempted to stop nonexistent job with id: " + jobId ));
216217
217218 // check job status is valid for stopping
218- Job job = getJob .get ();
219219 JobStatus status = job .getStatus ();
220220 if (status .isTerminal ()) {
221221 // do nothing - job is already stopped
@@ -240,7 +240,9 @@ public StopIngestionJobResponse stopJob(StopIngestionJobRequest request)
240240 return StopIngestionJobResponse .newBuilder ().build ();
241241 }
242242
243- /* Private Utility Methods */
243+ // endregion
244+ // region Private Utility Methods
245+
244246 private <T > Set <T > mergeResults (Set <T > results , Collection <T > newResults ) {
245247 if (results .size () <= 0 ) {
246248 // no existing results: copy over new results
@@ -252,7 +254,7 @@ private <T> Set<T> mergeResults(Set<T> results, Collection<T> newResults) {
252254 return results ;
253255 }
254256
255- // converts feature set reference to a list feature set filter
257+ /** converts feature set reference to a list feature set filter */
256258 private ListFeatureSetsRequest .Filter toListFeatureSetFilter (FeatureSetReference fsReference ) {
257259 // match featuresets using contents of featureset reference
258260 String fsName = fsReference .getName ();
@@ -262,16 +264,13 @@ private ListFeatureSetsRequest.Filter toListFeatureSetFilter(FeatureSetReference
262264 // for proto3, default value for missing values:
263265 // - numeric values (ie int) is zero
264266 // - strings is empty string
265- ListFeatureSetsRequest .Filter filter =
266- ListFeatureSetsRequest .Filter .newBuilder ()
267- .setFeatureSetName ((fsName != "" ) ? fsName : "*" )
268- .setProject ((fsProject != "" ) ? fsProject : "*" )
269- .build ();
270-
271- return filter ;
267+ return ListFeatureSetsRequest .Filter .newBuilder ()
268+ .setFeatureSetName (fsName .isEmpty () ? "*" : fsName )
269+ .setProject (fsProject .isEmpty () ? "*" : fsProject )
270+ .build ();
272271 }
273272
274- // sync job status using job manager
273+ /** sync job status using job manager */
275274 private Job syncJobStatus (JobManager jobManager , Job job ) {
276275 JobStatus newStatus = jobManager .getJobStatus (job );
277276 // log job status transition
0 commit comments