-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[core] Support data token in RESTCatalog #4944
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
74b509e
support data token
jerry-024 cb44d26
add fileIO cache in RESTCatalog and fix some error define
jerry-024 183ba88
fix get fileIO for object table
jerry-024 3eb1af8
add test for refresh file IO in RESTCatalog
jerry-024 a3b478f
add open api for table credentials
jerry-024 5bbe2ab
remove no need code
jerry-024 a513283
add test for GetTableCredentialsResponse
jerry-024 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
148 changes: 148 additions & 0 deletions
148
paimon-core/src/main/java/org/apache/paimon/rest/RefreshCredentialFileIO.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,148 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 | ||
| * | ||
| * http://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 org.apache.paimon.rest; | ||
|
|
||
| import org.apache.paimon.catalog.CatalogContext; | ||
| import org.apache.paimon.catalog.Identifier; | ||
| import org.apache.paimon.fs.FileIO; | ||
| import org.apache.paimon.fs.FileStatus; | ||
| import org.apache.paimon.fs.Path; | ||
| import org.apache.paimon.fs.PositionOutputStream; | ||
| import org.apache.paimon.fs.SeekableInputStream; | ||
| import org.apache.paimon.options.CatalogOptions; | ||
| import org.apache.paimon.options.Options; | ||
| import org.apache.paimon.rest.auth.AuthSession; | ||
| import org.apache.paimon.rest.responses.GetTableCredentialsResponse; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| /** A {@link FileIO} to support refresh credential. */ | ||
| public class RefreshCredentialFileIO implements FileIO { | ||
|
|
||
| private static final long serialVersionUID = 1L; | ||
|
|
||
| private final ResourcePaths resourcePaths; | ||
| private final AuthSession catalogAuth; | ||
| protected Options options; | ||
| private final Identifier identifier; | ||
| private Long expireAtMillis; | ||
| private Map<String, String> credential; | ||
| private final transient RESTClient client; | ||
| private transient volatile FileIO lazyFileIO; | ||
|
|
||
| public RefreshCredentialFileIO( | ||
| ResourcePaths resourcePaths, | ||
| AuthSession catalogAuth, | ||
| Options options, | ||
| RESTClient client, | ||
| Identifier identifier) { | ||
| this.resourcePaths = resourcePaths; | ||
| this.catalogAuth = catalogAuth; | ||
| this.options = options; | ||
| this.identifier = identifier; | ||
| this.client = client; | ||
| } | ||
|
|
||
| @Override | ||
| public void configure(CatalogContext context) { | ||
| this.options = context.options(); | ||
| } | ||
|
|
||
| @Override | ||
| public SeekableInputStream newInputStream(Path path) throws IOException { | ||
| return fileIO().newInputStream(path); | ||
| } | ||
|
|
||
| @Override | ||
| public PositionOutputStream newOutputStream(Path path, boolean overwrite) throws IOException { | ||
| return fileIO().newOutputStream(path, overwrite); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStatus getFileStatus(Path path) throws IOException { | ||
| return fileIO().getFileStatus(path); | ||
| } | ||
|
|
||
| @Override | ||
| public FileStatus[] listStatus(Path path) throws IOException { | ||
| return fileIO().listStatus(path); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean exists(Path path) throws IOException { | ||
| return fileIO().exists(path); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean delete(Path path, boolean recursive) throws IOException { | ||
| return fileIO().delete(path, recursive); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean mkdirs(Path path) throws IOException { | ||
| return fileIO().mkdirs(path); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean rename(Path src, Path dst) throws IOException { | ||
| return fileIO().rename(src, dst); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isObjectStore() { | ||
| try { | ||
| return fileIO().isObjectStore(); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| private FileIO fileIO() throws IOException { | ||
| if (lazyFileIO == null || shouldRefresh()) { | ||
| synchronized (this) { | ||
| if (lazyFileIO == null || shouldRefresh()) { | ||
| GetTableCredentialsResponse response = getCredential(); | ||
| expireAtMillis = response.getExpiresAtMillis(); | ||
| credential = response.getCredential(); | ||
| Map<String, String> conf = RESTUtil.merge(options.toMap(), credential); | ||
| Options updateCredentialOption = new Options(conf); | ||
| lazyFileIO = | ||
| FileIO.get( | ||
| new Path(updateCredentialOption.get(CatalogOptions.WAREHOUSE)), | ||
| CatalogContext.create(updateCredentialOption)); | ||
| } | ||
| } | ||
| } | ||
| return lazyFileIO; | ||
| } | ||
|
|
||
| // todo: handle exception | ||
| private GetTableCredentialsResponse getCredential() { | ||
| return client.get( | ||
| resourcePaths.tableCredentials( | ||
| identifier.getDatabaseName(), identifier.getObjectName()), | ||
| GetTableCredentialsResponse.class, | ||
| catalogAuth.getHeaders()); | ||
| } | ||
|
|
||
| private boolean shouldRefresh() { | ||
| return expireAtMillis != null && expireAtMillis > System.currentTimeMillis(); | ||
| } | ||
| } | ||
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
60 changes: 60 additions & 0 deletions
60
paimon-core/src/main/java/org/apache/paimon/rest/responses/GetTableCredentialsResponse.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,60 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 | ||
| * | ||
| * http://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 org.apache.paimon.rest.responses; | ||
|
|
||
| import org.apache.paimon.rest.RESTResponse; | ||
|
|
||
| import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonCreator; | ||
| import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonGetter; | ||
| import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
| import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.annotation.JsonProperty; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** Response for table credentials. */ | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public class GetTableCredentialsResponse implements RESTResponse { | ||
|
|
||
| private static final String FIELD_CREDENTIAL = "credential"; | ||
| private static final String FIELD_EXPIREAT_MILLIS = "expiresAtMillis"; | ||
|
|
||
| @JsonProperty(FIELD_CREDENTIAL) | ||
| private final Map<String, String> credential; | ||
|
|
||
| @JsonProperty(FIELD_EXPIREAT_MILLIS) | ||
| private long expiresAtMillis; | ||
|
|
||
| @JsonCreator | ||
| public GetTableCredentialsResponse( | ||
| @JsonProperty(FIELD_EXPIREAT_MILLIS) long expiresAtMillis, | ||
| @JsonProperty(FIELD_CREDENTIAL) Map<String, String> credential) { | ||
| this.expiresAtMillis = expiresAtMillis; | ||
| this.credential = credential; | ||
| } | ||
|
|
||
| @JsonGetter(FIELD_CREDENTIAL) | ||
| public Map<String, String> getCredential() { | ||
| return credential; | ||
| } | ||
|
|
||
| @JsonGetter(FIELD_EXPIREAT_MILLIS) | ||
| public long getExpiresAtMillis() { | ||
| return expiresAtMillis; | ||
| } | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ser id