Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Create project if not exists on applyFeatureSet #596

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 4 additions & 9 deletions core/src/main/java/feast/core/service/SpecService.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,14 @@ public ApplyFeatureSetResponse applyFeatureSet(FeatureSetProto.FeatureSet newFea
// Validate incoming feature set
FeatureSetValidator.validateSpec(newFeatureSet);

// Ensure that the project already exists
// Find project or create new one if it does not exist
String project_name = newFeatureSet.getSpec().getProject();
Project project =
projectRepository
.findById(newFeatureSet.getSpec().getProject())
.orElseThrow(
() ->
new IllegalArgumentException(
String.format(
"Project name does not exist. Please create a project first: %s",
project_name)));

// Ensure that the project is not archived
.orElse(new Project(project_name));

// Ensure that the project retrieved from repository is not archived
if (project.isArchived()) {
throw new IllegalArgumentException(String.format("Project is archived: %s", project_name));
}
Expand Down
53 changes: 53 additions & 0 deletions core/src/test/java/feast/core/service/SpecServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ public void setUp() {
when(projectRepository.findAllByArchivedIsFalse())
.thenReturn(Collections.singletonList(new Project("project1")));
when(projectRepository.findById("project1")).thenReturn(Optional.of(new Project("project1")));
Project archivedProject = new Project("archivedproject");
archivedProject.setArchived(true);
when(projectRepository.findById(archivedProject.getName()))
.thenReturn(Optional.of(archivedProject));

Store store1 = newDummyStore("SERVING");
Store store2 = newDummyStore("WAREHOUSE");
Expand Down Expand Up @@ -706,6 +710,55 @@ public void applyFeatureSetShouldUpdateFeatureSetWhenConstraintsAreUpdated()
}
}

@Test
public void applyFeatureSetShouldCreateProjectWhenNotAlreadyExists()
throws InvalidProtocolBufferException {
Field f3f1 = new Field("f3f1", Enum.INT64);
Field f3f2 = new Field("f3f2", Enum.INT64);
Field f3e1 = new Field("f3e1", Enum.STRING);
FeatureSetProto.FeatureSet incomingFeatureSet =
(new FeatureSet(
"f3",
"newproject",
5,
100L,
Arrays.asList(f3e1),
Arrays.asList(f3f2, f3f1),
defaultSource,
FeatureSetStatus.STATUS_READY))
.toProto();

ApplyFeatureSetResponse applyFeatureSetResponse =
specService.applyFeatureSet(incomingFeatureSet);
assertThat(applyFeatureSetResponse.getStatus(), equalTo(Status.CREATED));
assertThat(
applyFeatureSetResponse.getFeatureSet().getSpec().getProject(),
equalTo(incomingFeatureSet.getSpec().getProject()));
}

@Test
public void applyFeatureSetShouldFailWhenProjectIsArchived()
throws InvalidProtocolBufferException {
Field f3f1 = new Field("f3f1", Enum.INT64);
Field f3f2 = new Field("f3f2", Enum.INT64);
Field f3e1 = new Field("f3e1", Enum.STRING);
FeatureSetProto.FeatureSet incomingFeatureSet =
(new FeatureSet(
"f3",
"archivedproject",
5,
100L,
Arrays.asList(f3e1),
Arrays.asList(f3f2, f3f1),
defaultSource,
FeatureSetStatus.STATUS_READY))
.toProto();

expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Project is archived");
specService.applyFeatureSet(incomingFeatureSet);
}

@Test
public void shouldUpdateStoreIfConfigChanges() throws InvalidProtocolBufferException {
when(storeRepository.findById("SERVING")).thenReturn(Optional.of(stores.get(0)));
Expand Down