-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support of GC and S3 storages for registry in Java Feature Server (#2043
) * gs and s3 storages for registry Signed-off-by: pyalex <moskalenko.alexey@gmail.com> * some cleanup Signed-off-by: pyalex <moskalenko.alexey@gmail.com>
- Loading branch information
Showing
23 changed files
with
788 additions
and
270 deletions.
There are no files selected for viewing
This file contains 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 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
73 changes: 73 additions & 0 deletions
73
java/serving/src/main/java/feast/serving/config/RegistryConfig.java
This file contains 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,73 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2021 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.serving.config; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import com.google.cloud.storage.Storage; | ||
import com.google.cloud.storage.StorageOptions; | ||
import feast.serving.registry.*; | ||
import java.net.URI; | ||
import java.nio.file.Paths; | ||
import java.util.Optional; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
|
||
@Configuration | ||
public class RegistryConfig { | ||
@Bean | ||
@Lazy | ||
Storage googleStorage(FeastProperties feastProperties) { | ||
return StorageOptions.newBuilder() | ||
.setProjectId(feastProperties.getGcpProject()) | ||
.build() | ||
.getService(); | ||
} | ||
|
||
@Bean | ||
@Lazy | ||
AmazonS3 awsStorage(FeastProperties feastProperties) { | ||
return AmazonS3ClientBuilder.standard().withRegion(feastProperties.getAwsRegion()).build(); | ||
} | ||
|
||
@Bean | ||
RegistryFile registryFile(FeastProperties feastProperties, ApplicationContext context) { | ||
|
||
String registryPath = feastProperties.getRegistry(); | ||
Optional<String> scheme = Optional.ofNullable(URI.create(registryPath).getScheme()); | ||
|
||
switch (scheme.orElseGet(() -> "")) { | ||
case "gs": | ||
return new GSRegistryFile(context.getBean(Storage.class), registryPath); | ||
case "s3": | ||
return new S3RegistryFile(context.getBean(AmazonS3.class), registryPath); | ||
case "": | ||
case "file": | ||
return new LocalRegistryFile(Paths.get(registryPath)); | ||
default: | ||
throw new RuntimeException("Registry storage %s is unsupported"); | ||
} | ||
} | ||
|
||
@Bean | ||
RegistryRepository registryRepository( | ||
RegistryFile registryFile, FeastProperties feastProperties) { | ||
return new RegistryRepository(registryFile, feastProperties.getRegistryRefreshInterval()); | ||
} | ||
} |
This file contains 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 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
62 changes: 62 additions & 0 deletions
62
java/serving/src/main/java/feast/serving/registry/GSRegistryFile.java
This file contains 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,62 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2021 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.serving.registry; | ||
|
||
import com.google.cloud.storage.*; | ||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import feast.proto.core.RegistryProto; | ||
import java.util.Optional; | ||
|
||
public class GSRegistryFile implements RegistryFile { | ||
private Blob blob; | ||
|
||
public GSRegistryFile(Storage storage, String url) { | ||
blob = storage.get(BlobId.fromGsUtilUri(url)); | ||
if (blob == null) { | ||
throw new RuntimeException(String.format("Registry file %s was not found", url)); | ||
} | ||
} | ||
|
||
public RegistryProto.Registry getContent() { | ||
try { | ||
return RegistryProto.Registry.parseFrom(blob.getContent()); | ||
} catch (InvalidProtocolBufferException e) { | ||
throw new RuntimeException( | ||
String.format( | ||
"Couldn't read remote registry: %s. Error: %s", | ||
blob.getBlobId().toGsUtilUri(), e.getMessage())); | ||
} | ||
} | ||
|
||
public Optional<RegistryProto.Registry> getContentIfModified() { | ||
try { | ||
this.blob = blob.reload(Blob.BlobSourceOption.generationNotMatch()); | ||
} catch (StorageException e) { | ||
if (e.getCode() == 304) { | ||
// Content not modified | ||
return Optional.empty(); | ||
} else { | ||
throw new RuntimeException( | ||
String.format( | ||
"Couldn't read remote registry: %s. Error: %s", | ||
blob.getBlobId().toGsUtilUri(), e.getMessage())); | ||
} | ||
} | ||
|
||
return Optional.of(this.getContent()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
java/serving/src/main/java/feast/serving/registry/LocalRegistryFile.java
This file contains 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,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2021 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.serving.registry; | ||
|
||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import feast.proto.core.RegistryProto; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Optional; | ||
|
||
public class LocalRegistryFile implements RegistryFile { | ||
private RegistryProto.Registry cachedRegistry; | ||
|
||
public LocalRegistryFile(String path) { | ||
try { | ||
cachedRegistry = RegistryProto.Registry.parseFrom(Files.readAllBytes(Paths.get(path))); | ||
} catch (InvalidProtocolBufferException e) { | ||
throw new RuntimeException( | ||
String.format( | ||
"Couldn't read local registry: %s. Protobuf is invalid: %s", path, e.getMessage())); | ||
} catch (IOException e) { | ||
throw new RuntimeException( | ||
String.format("Couldn't read local registry file: %s. Error: %s", path, e.getMessage())); | ||
} | ||
} | ||
|
||
@Override | ||
public RegistryProto.Registry getContent() { | ||
return this.cachedRegistry; | ||
} | ||
|
||
@Override | ||
public Optional<RegistryProto.Registry> getContentIfModified() { | ||
return Optional.empty(); | ||
} | ||
} |
Oops, something went wrong.