Repository navigation
Use JobManager's backend as persistent storage and source of truth #903
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
Merged
feast-ci-bot
merged 10 commits into
feast-dev:master
from
pyalex:jc-dataflow-as-database
Aug 11, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3532dcf
in memory job repository
pyalex b910f3b
handle empty response from dataflow
pyalex 176585f
test job with no labels
pyalex aff8969
some comments
pyalex 1e1f981
some apidocs
pyalex f20f769
fix comment
pyalex 78809bd
fix tests
pyalex e4bdfdb
refactor merging jobSelector & labels
pyalex 72d8bc3
default project name
pyalex 6cb4399
default project name
pyalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
core/src/main/java/feast/core/dao/FeatureSetJobStatusRepository.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
core/src/main/java/feast/core/job/InMemoryJobRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright 2018-2020 The Feast Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package feast.core.job; | ||
|
|
||
| import com.google.common.collect.Lists; | ||
| import feast.common.models.FeatureSetReference; | ||
| import feast.core.model.Job; | ||
| import feast.core.model.JobStatus; | ||
| import feast.proto.core.SourceProto; | ||
| import java.util.*; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Collectors; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| /** | ||
| * Keeps state of all jobs managed by current application in memory. On start loads persistent state | ||
| * through JobManager from JobManager backend. | ||
|
pyalex marked this conversation as resolved.
Resolved
|
||
| * | ||
| * <p>E.g., with Dataflow runner all jobs with their state stored on Google's side and accessible | ||
| * via API. So we don't need to persist this state ourselves. Instead we just fetch it once and then | ||
| * we apply same changes to dataflow (via JobManager) and to InMemoryRepository to keep them in | ||
| * sync. | ||
| * | ||
| * <p>Provides flexible access to objects via JPA-like filtering API. | ||
| */ | ||
| @Component | ||
| public class InMemoryJobRepository implements JobRepository { | ||
| private final JobManager jobManager; | ||
|
|
||
| /** Internal storage for all jobs mapped by their Id */ | ||
| private Map<String, Job> storage; | ||
|
pyalex marked this conversation as resolved.
Resolved
|
||
|
|
||
| @Autowired | ||
| public InMemoryJobRepository(JobManager jobManager) { | ||
| this.jobManager = jobManager; | ||
| this.storage = new HashMap<>(); | ||
|
|
||
| this.storage = | ||
| this.jobManager.listRunningJobs().stream().collect(Collectors.toMap(Job::getId, j -> j)); | ||
| } | ||
|
|
||
| /** | ||
| * Returns single job that has given source, store with given name ans its status is not in given | ||
| * statuses. We expect this parameters to specify only one RUNNING job (most of the time). But in | ||
| * case there're many - we return latest updated one. | ||
| * | ||
| * @return job that matches given parameters if it's present | ||
| */ | ||
| @Override | ||
| public Optional<Job> findFirstBySourceAndStoreNameAndStatusNotInOrderByLastUpdatedDesc( | ||
| SourceProto.Source source, String storeName, Collection<JobStatus> statuses) { | ||
| return this.storage.values().stream() | ||
| .filter( | ||
| j -> | ||
| j.getSource().equals(source) | ||
| && (storeName == null || j.getStores().containsKey(storeName)) | ||
| && (!statuses.contains(j.getStatus()))) | ||
| .max(Comparator.comparing(Job::getLastUpdated)); | ||
| } | ||
|
|
||
| private List<Job> findWithFilter(Predicate<Job> p) { | ||
| return this.storage.values().stream().filter(p).collect(Collectors.toList()); | ||
| } | ||
|
|
||
| /** Find Jobs that have given status */ | ||
| @Override | ||
| public List<Job> findByStatus(JobStatus status) { | ||
| return this.findWithFilter(j -> j.getStatus().equals(status)); | ||
| } | ||
|
|
||
| /** | ||
| * Find Jobs that have given FeatureSet (specified by {@link FeatureSetReference} allocated to it. | ||
| */ | ||
| @Override | ||
| public List<Job> findByFeatureSetReference(FeatureSetReference reference) { | ||
| return this.findWithFilter(j -> j.getFeatureSetDeliveryStatuses().containsKey(reference)); | ||
| } | ||
|
|
||
| /** Find Jobs that have one of the stores with given name */ | ||
| @Override | ||
| public List<Job> findByJobStoreName(String storeName) { | ||
| return this.findWithFilter(j -> j.getStores().containsKey(storeName)); | ||
| } | ||
|
|
||
| /** Find by Job's Id */ | ||
| @Override | ||
| public Optional<Job> findById(String jobId) { | ||
| return Optional.ofNullable(this.storage.get(jobId)); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Job> findAll() { | ||
| return Lists.newArrayList(this.storage.values()); | ||
| } | ||
|
|
||
| @Override | ||
| public void add(Job job) { | ||
| job.preSave(); | ||
|
|
||
| this.storage.put(job.getId(), job); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteAll() { | ||
| this.storage.clear(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.