Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1e1abb1
Added protobuf definitions for a Job Management API
Mar 11, 2020
bd04076
Added query methods to JobRepository to query jobs by store and featu…
Mar 12, 2020
643f042
Added hashCode() & equals() to Job model compare and hash jobs
Mar 12, 2020
f4b417e
Added toIngestionProto() to Job object to convert Job model to ingest…
Mar 16, 2020
9d62a38
Added query methods to FeatureSetRepository to query by exact (name, …
Mar 16, 2020
32a0bb5
Added listJobs() to JobService to handle request list ingestion jobs …
Mar 16, 2020
4f55012
Added missing filter field in ListIngestionJobsRequest protobuf
Mar 17, 2020
b3aa72a
Added code to setup mockups for testing JobService
Mar 17, 2020
06b84df
Revert "Added hashCode() & equals() to Job model compare and hash jobs"
Mar 17, 2020
c4b901a
Added JobServiceTest unit tests for JobService's listJobs()
Mar 17, 2020
cd0bde2
Added stopJobs() to JobService to handle requests to stop jobs
Mar 18, 2020
c59035f
Added getTransitionalStates() to JobStatus to return collection of tr…
Mar 20, 2020
898045c
Changed stopJobs() to throw unsupported error on transitional job sta…
Mar 20, 2020
f4711cd
Moved conversion of JobStatus to IngestionJobStatus proto to JobStatus.
Mar 20, 2020
fe744ea
Make findFeatureSet() match only one featureset.
Mar 20, 2020
a79f8b4
Added matchFeatureSets() to SpecService to match Feature Sets from Re…
Mar 20, 2020
5b25929
Refactor JobService listJobs() to use SpecService to provide features…
Mar 20, 2020
1997bb1
Revert findBy methods added to FeatureSetRepository as no longer used.
Mar 20, 2020
f320e38
Added restartJob() to JobManagers to restart ingestion/import jobs
Mar 20, 2020
0ec5afb
Added restartJob() to JobService to restart ingestion jobs
Mar 23, 2020
83cc4c7
Update job model (due to new extId) when restartJob() in JobService
Mar 23, 2020
cf6a9c4
Use assertThat() & equalTo() instead of assertEquals() in JobService
Mar 23, 2020
8088b33
Revert "Use assertThat() & equalTo() instead of assertEquals() in Job…
Mar 23, 2020
bdc2803
Use hamcrest’s assertThat() and equalTo() instead of Junit's assertEq…
Mar 23, 2020
fafcd11
Hook up JobService list, stop, restart job methods to CoreServiceImpl.
Mar 23, 2020
7a97e1f
Throw InvalidArgumentException instead when calling listJobs() with i…
Mar 23, 2020
d277f93
Fixed typos in javadocs: InvalidArgumentException should be IllegalAr…
Mar 23, 2020
255946b
Fixed in findByFeatureSetsIn() query in JobRepository
Mar 23, 2020
09e9ddc
Renamed toIngestionProto() methods to toProto() to follow code conven…
Mar 23, 2020
c85da17
Make JobService's listJobs() a transaction to prevent DB data race co…
Mar 23, 2020
c876e40
Moved matchFeatureSets() in SpecService to private method in JobService
Mar 23, 2020
1799c3a
Make the map that maps between JobStatus and IngestionJobStatus static
Mar 23, 2020
1bead61
Make JobService's listJobs() to return all ingestion jobs on empty fi…
Mar 25, 2020
19994ea
Fixed issue where the jobManager map that JobService built used wrong…
Mar 25, 2020
ff73b5f
Fix issue where actual Job Status is not synced with database.
Mar 26, 2020
c207f1a
Log stopJob() & restartJob() operations to make debugging easier
Mar 26, 2020
c64039a
Use Runner.name() instead of runner.toString() to build JobManager map
Mar 27, 2020
ed4dae9
Move documentation on JobService operations to CoreService protobuf d…
Mar 28, 2020
24c09be
Added IngestJob to python sdk as native representation of IngestionJo…
Mar 30, 2020
2930388
Make empty filter on JobService's listJobs() select all ingestion jobs
Mar 30, 2020
5cc8abe
Added bindings for Job management API to python sdk client.
Mar 30, 2020
d86cb66
Fixed __connect_core() to connect to Feast CoreService when calling o…
Mar 30, 2020
d9874f2
Auto reload IngestJob.status and IngestJob.external_id on get property.
Mar 30, 2020
19620b2
Added IngestJob.wait() to wait for job status to transtion
Mar 30, 2020
6b47ecb
Added basic job api e2e test to exercise job api
Mar 30, 2020
f3471ac
Reorder the operations e2etest to make sure that jobs are running aft…
Mar 30, 2020
1707401
Added e2e test for all types exercising job api
Mar 31, 2020
9999db5
Fixed typo in function arguments
Mar 31, 2020
f012623
Added unit tests for Ingestion Job API additions in python sdk
Mar 31, 2020
2e819b2
Rename "ingestion" to "ingest" for more consistent naming
Mar 31, 2020
ba08c8a
Disable support for restarting Job in a terminal state due to possibl…
Apr 3, 2020
5fb774c
Added __str__ and __repr__ to IngestJob to render ingestjob in human …
Apr 3, 2020
80ef3c9
Added FeatureSetRef to represent references to featursets
Apr 4, 2020
d3c9a3d
Admend client's list_ingest_jobs() to accept feature references directly
Apr 6, 2020
0cfc32a
Fixed typo in IngestJob.store property
Apr 6, 2020
a540157
Fixed issue with FeatureSetRef.from_str not converting version to int
Apr 6, 2020
355b571
Make the grpc error message more apparent on stop_ingest_job() and re…
Apr 6, 2020
05b33a6
Added feast ingest-job list, describe, stop, restart to CLI
Apr 6, 2020
3b8198a
Rename Job to RetrievalJob to prevent confusion with IngestJob
Apr 6, 2020
19bd141
Updated e2e tests to use FeatureSetRef in list_ingest_jobs()
Apr 6, 2020
9f6cf6a
Fixed due e2e tests to cater to new limitations on stop_ingest_job()
Apr 6, 2020
87054b9
Increase timeout on test_all_types_ingest_jobs() e2e test.
Apr 6, 2020
1848dd4
Configure IngestJob.wait() to backoff with a exponentially larger wai…
Apr 7, 2020
146fb2b
Added print statements to debug e2e test failure.
Apr 7, 2020
0fa6b93
Revert "Added print statements to debug e2e test failure."
Apr 7, 2020
66d3f77
Fixed issue of test waiting for aborted job to become running causing…
Apr 7, 2020
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
Prev Previous commit
Next Next commit
Added stopJobs() to JobService to handle requests to stop jobs
  • Loading branch information
Zhu Zhanyan committed Apr 6, 2020
commit cd0bde2f5399bd68ffa79596b1d1cea6bbfd9346
3 changes: 1 addition & 2 deletions core/src/main/java/feast/core/model/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public String getSinkName() {
*
* @return Ingestion Job proto derieved from the given job
*/
public IngestionJobProto.IngestionJob toIngestionProto()
throws InvalidProtocolBufferException {
public IngestionJobProto.IngestionJob toIngestionProto() throws InvalidProtocolBufferException {
// maps job models job status to ingestion job status
Map<JobStatus, IngestionJobProto.IngestionJobStatus> statusMap =
Map.of(
Expand Down
59 changes: 46 additions & 13 deletions core/src/main/java/feast/core/service/JobService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@
import com.google.protobuf.InvalidProtocolBufferException;
import feast.core.CoreServiceProto.ListIngestionJobsRequest;
import feast.core.CoreServiceProto.ListIngestionJobsResponse;
import feast.core.CoreServiceProto.StopIngestionJobRequest;
import feast.core.CoreServiceProto.StopIngestionJobResponse;
import feast.core.FeatureSetReferenceProto.FeatureSetReference;
import feast.core.IngestionJobProto;
import feast.core.dao.FeatureSetRepository;
import feast.core.dao.JobRepository;
import feast.core.job.JobManager;
import feast.core.job.Runner;
import feast.core.model.FeatureSet;
import feast.core.model.Job;
import feast.core.model.JobStatus;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -43,7 +47,7 @@
public class JobService {
private JobRepository jobRepository;
private FeatureSetRepository featureSetRepository;
private Map<Runner, JobManager> jobManagers;
private Map<String, JobManager> jobManagers;

@Autowired
public JobService(
Expand All @@ -53,12 +57,13 @@ public JobService(
this.jobRepository = jobRepository;
this.featureSetRepository = featureSetRepository;

this.jobManagers = new HashMap<>();
for (JobManager manager : jobManagerList) {
this.jobManagers.put(manager.getRunnerType(), manager);
this.jobManagers.put(manager.getRunnerType().getName(), manager);
}
}

/* Service API */
/* Job Service API */
/**
* List Ingestion Jobs in feast matching the given request
*
Expand Down Expand Up @@ -126,21 +131,49 @@ public ListIngestionJobsResponse listJobs(ListIngestionJobsRequest request)
// pack jobs into response
return ListIngestionJobsResponse.newBuilder().addAllJobs(ingestJobs).build();
}
//TODO: restart ingestion job

// TODO: restart ingestion job

/**
* Stops the ingestion job matching the given request
*
* Stops (Aborts) the ingestion job matching the given request. Does nothing if the target job to
* be stopped is already stopped or stopping
*
* @param request stop ingestion job request specifying which job to stop
* @throw InvalidProtocolBufferException whe
* */
/*
* @throws NoSuchElementException when stop job request requests to stop a nonexistent job.
* @throws UnsupportedOperationException when job to be stopped is in an unknown status
* @throws InvalidProtocolBufferException on error when constructing response protobuf
*/
public StopIngestionJobResponse stopJob(StopIngestionJobRequest request)
throws InvalidProtocolBufferException {
throws InvalidProtocolBufferException {
// check job exists
Optional<Job> getJob = this.jobRepository.findById(request.getId());
if (getJob.isEmpty()) {
throw new NoSuchElementException(
"Attempted to stop nonexistent job with id: " + getJob.get().getId());
}

// check job status is valid for stopping
Job job = getJob.get();
JobStatus status = job.getStatus();
if (status.equals(JobStatus.ABORTED)
Comment thread
mrzzy marked this conversation as resolved.
Outdated
|| status.equals(JobStatus.ABORTING)
|| status.equals(JobStatus.SUSPENDED)
|| status.equals(JobStatus.SUSPENDING)
|| status.equals(JobStatus.COMPLETED)
|| status.equals(JobStatus.ERROR)) {
// do nothing - job is already stopped or stopping
return StopIngestionJobResponse.newBuilder().build();
} else if (status.equals(JobStatus.UNKNOWN)) {
throw new UnsupportedOperationException(
"Stopping a job with an unknown status is unsupported");
}

// stop job with job manager
JobManager jobManager = this.jobManagers.get(job.getRunner());
jobManager.abortJob(job.getExtId());

return StopIngestionJobResponse.newBuilder().build();
}
*/

/* Private Utility Methods */
/**
Expand Down
99 changes: 88 additions & 11 deletions core/src/test/java/feast/core/service/JobServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import com.google.protobuf.InvalidProtocolBufferException;
import feast.core.CoreServiceProto.ListIngestionJobsRequest;
import feast.core.CoreServiceProto.ListIngestionJobsResponse;
import feast.core.CoreServiceProto.StopIngestionJobRequest;
import feast.core.CoreServiceProto.StopIngestionJobResponse;
import feast.core.FeatureSetProto.FeatureSetStatus;
import feast.core.FeatureSetReferenceProto.FeatureSetReference;
import feast.core.IngestionJobProto.IngestionJob;
Expand All @@ -43,7 +47,6 @@
import feast.core.model.Store;
import feast.types.ValueProto.ValueType.Enum;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand All @@ -56,7 +59,7 @@ public class JobServiceTest {
// mocks
@Mock private FeatureSetRepository featureSetRepository;
@Mock private JobRepository jobRepository;
@Mock private List<JobManager> jobManagers;
@Mock private JobManager jobManager;
// fake models
private Source dataSource;
private Store dataStore;
Expand Down Expand Up @@ -98,15 +101,15 @@ public void setup() {
e.printStackTrace();
}

// setup mock repositories
// setup mock objects
this.setupFeatureSetRepository();
this.setupJobRepository();
this.setupJobManager();

// TODO: init fake job managers
this.jobManagers = new ArrayList<>();

// create test target
this.jobService =
new JobService(this.jobRepository, this.featureSetRepository, this.jobManagers);
new JobService(
this.jobRepository, this.featureSetRepository, Arrays.asList(this.jobManager));
}

// setup fake feature set repository
Expand All @@ -128,9 +131,11 @@ public void setupJobRepository() {
when(this.jobRepository.findByFeatureSetIn(Arrays.asList(this.featureSet)))
.thenReturn(Arrays.asList(this.job));
}

// TODO: setup fake job manager

// TODO: setup fake job manager
public void setupJobManager() {
when(this.jobManager.getRunnerType()).thenReturn(Runner.DATAFLOW);
}

// dummy model constructorss
private FeatureSet newDummyFeatureSet(String name, int version, String project) {
Expand Down Expand Up @@ -167,11 +172,11 @@ private ListIngestionJobsResponse tryListJobs(ListIngestionJobsRequest request)
ListIngestionJobsResponse response = null;
try {
response = this.jobService.listJobs(request);
} catch(InvalidProtocolBufferException e){
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
fail("Caught Unexpected exception");
}

return response;
}

Expand Down Expand Up @@ -229,4 +234,76 @@ public void testListIngestionJobByFeatureSetReference() {
request = ListIngestionJobsRequest.newBuilder().setFilter(filter).build();
assertEquals(this.tryListJobs(request).getJobs(0), this.ingestionJob);
}

// stop jobs
private StopIngestionJobResponse tryStopJob(
StopIngestionJobRequest request, boolean expectError) {
StopIngestionJobResponse response = null;
try {
response = this.jobService.stopJob(request);
// expected exception, but none was thrown
if (expectError) {
fail("Expected exception, but none was thrown");
}
} catch (Exception e) {
if (expectError != true) {
// unexpected exception
e.printStackTrace();
fail("Caught Unexpected exception");
}
}

return response;
}

@Test
public void testStopJobForId() {
JobStatus prevStatus = this.job.getStatus();
this.job.setStatus(JobStatus.RUNNING);

StopIngestionJobRequest request =
StopIngestionJobRequest.newBuilder().setId(this.job.getId()).build();
this.tryStopJob(request, false);
verify(this.jobManager).abortJob(this.job.getExtId());

this.job.setStatus(prevStatus);
}

@Test
public void testStopAlreadyStop() {
// check that stop jobs does not trying to stop jobs that are
// not already stopped/stopping
List<JobStatus> doNothingStatuses =
Arrays.asList(
JobStatus.SUSPENDED, JobStatus.SUSPENDING,
JobStatus.ABORTED, JobStatus.ABORTING,
JobStatus.COMPLETED, JobStatus.ABORTED);

JobStatus prevStatus = this.job.getStatus();
for (JobStatus status : doNothingStatuses) {
this.job.setStatus(status);

StopIngestionJobRequest request =
StopIngestionJobRequest.newBuilder().setId(this.job.getId()).build();
this.tryStopJob(request, false);

verify(this.jobManager, never()).abortJob(this.job.getExtId());
}

this.job.setStatus(prevStatus);
}

@Test
public void testStopUnknownJobError() {
// check for UnsupportedOperationException when trying to stop jobs are
// in an in unknown state
JobStatus prevStatus = this.job.getStatus();
this.job.setStatus(JobStatus.UNKNOWN);

StopIngestionJobRequest request =
StopIngestionJobRequest.newBuilder().setId(this.job.getId()).build();
this.tryStopJob(request, true);

this.job.setStatus(prevStatus);
}
}