-
Notifications
You must be signed in to change notification settings - Fork 358
[CDAP-21172]Added cdap-metadata-ext-spanner Module with ExtensionLoader #15959
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
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
46 changes: 46 additions & 0 deletions
46
cdap-data-fabric/src/main/java/io/cdap/cdap/spi/metadata/DefaultMetadataStorageContext.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,46 @@ | ||
| /* | ||
| * Copyright © 2025 Cask Data, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * 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 io.cdap.cdap.spi.metadata; | ||
|
|
||
| import io.cdap.cdap.common.conf.CConfiguration; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import javax.annotation.Nullable; | ||
|
|
||
|
|
||
| /** | ||
| * Default implementation of the {@link MetadataStorageContext}. | ||
| * TODO(CDAP-21174): Generalize the context for metadata storage | ||
| */ | ||
| public class DefaultMetadataStorageContext implements MetadataStorageContext { | ||
|
|
||
| private final Map<String, String> properties; | ||
|
|
||
| DefaultMetadataStorageContext(CConfiguration cConf, @Nullable String prefix) { | ||
| if (prefix != null) { | ||
| this.properties = Collections.unmodifiableMap(cConf.getPropsWithPrefix(prefix)); | ||
| } else { | ||
| this.properties = Collections.emptyMap(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> getProperties() { | ||
| return properties; | ||
| } | ||
| } | ||
|
|
96 changes: 96 additions & 0 deletions
96
cdap-data-fabric/src/main/java/io/cdap/cdap/spi/metadata/DelegatingMetadataStorage.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,96 @@ | ||
| /* | ||
| * Copyright © 2025 Cask Data, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * 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 io.cdap.cdap.spi.metadata; | ||
|
bhardwaj-priyanshu marked this conversation as resolved.
|
||
|
|
||
| import com.google.inject.Inject; | ||
| import io.cdap.cdap.common.conf.CConfiguration; | ||
| import io.cdap.cdap.common.conf.Constants; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Delegates {@link MetadataStorage} based on configured extension. | ||
| */ | ||
| public class DelegatingMetadataStorage implements MetadataStorage { | ||
|
sidhdirenge marked this conversation as resolved.
itsankit-google marked this conversation as resolved.
|
||
| private final CConfiguration cConf; | ||
| private final MetadataStorage delegate; | ||
| private static String prefix; | ||
| private static final String SPANNER_METADATA_STORAGE = "gcp-spanner"; | ||
|
|
||
| @Inject | ||
| DelegatingMetadataStorage(CConfiguration cConf, MetadataStorageExtensionLoader extensionLoader) throws Exception { | ||
| this.cConf = cConf; | ||
| this.delegate = extensionLoader.get(getName()); | ||
|
|
||
| if (this.delegate == null) { | ||
| throw new IllegalArgumentException("Unsupported MetadataProvider type: " + getName()); | ||
| } | ||
| // TODO(CDAP-21174): Generalize the context for metadata storage | ||
| if (getName().equals(SPANNER_METADATA_STORAGE)) { | ||
| this.prefix = String.format("%s%s.", Constants.Dataset.STORAGE_EXTENSION_PROPERTY_PREFIX, | ||
| SPANNER_METADATA_STORAGE); | ||
| } else { | ||
| this.prefix = null; | ||
| } | ||
|
itsankit-google marked this conversation as resolved.
|
||
|
|
||
| this.delegate.initialize(new DefaultMetadataStorageContext(cConf, prefix)); | ||
| } | ||
|
|
||
| @Override | ||
| public void createIndex() throws IOException { | ||
| delegate.createIndex(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| if (delegate != null) { | ||
| delegate.close(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return cConf.get(Constants.Metadata.STORAGE_PROVIDER_IMPLEMENTATION); | ||
| } | ||
|
|
||
| @Override | ||
| public void dropIndex() throws IOException { | ||
| delegate.dropIndex(); | ||
| } | ||
|
|
||
| @Override | ||
| public MetadataChange apply(MetadataMutation mutation, MutationOptions options) throws IOException { | ||
| return delegate.apply(mutation, options); | ||
| } | ||
|
|
||
| @Override | ||
| public List<MetadataChange> batch(List<? extends MetadataMutation> mutations, MutationOptions options) | ||
| throws IOException { | ||
| return delegate.batch(mutations, options); | ||
| } | ||
|
|
||
| @Override | ||
| public Metadata read(Read read) throws IOException { | ||
| return delegate.read(read); | ||
| } | ||
|
|
||
| @Override | ||
| public SearchResponse search(SearchRequest request) throws IOException { | ||
| return delegate.search(request); | ||
| } | ||
| } | ||
|
|
||
70 changes: 70 additions & 0 deletions
70
cdap-data-fabric/src/main/java/io/cdap/cdap/spi/metadata/MetadataStorageExtensionLoader.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,70 @@ | ||
| /* | ||
| * Copyright © 2025 Cask Data, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * 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 io.cdap.cdap.spi.metadata; | ||
|
|
||
| import com.google.inject.Inject; | ||
| import io.cdap.cdap.common.conf.CConfiguration; | ||
| import io.cdap.cdap.common.conf.Constants; | ||
| import io.cdap.cdap.common.lang.ClassPathResources; | ||
| import io.cdap.cdap.common.lang.FilterClassLoader; | ||
| import io.cdap.cdap.extension.AbstractExtensionLoader; | ||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Extension loader for {@link MetadataStorage} implementations. | ||
| */ | ||
| public class MetadataStorageExtensionLoader extends AbstractExtensionLoader<String, MetadataStorage> { | ||
|
|
||
| private static final Set<String> ALLOWED_RESOURCES = createAllowedResources(); | ||
| private static final Set<String> ALLOWED_PACKAGES = createPackageSets(ALLOWED_RESOURCES); | ||
|
|
||
| @Inject | ||
| public MetadataStorageExtensionLoader(CConfiguration cConf) { | ||
| super(cConf.get(Constants.Metadata.METADATA_STORAGE_EXT_DIR)); | ||
| } | ||
|
|
||
| private static Set<String> createAllowedResources() { | ||
| try { | ||
| return ClassPathResources.getResourcesWithDependencies(MetadataStorage.class.getClassLoader(), | ||
| MetadataStorage.class); | ||
| } catch (IOException e) { | ||
| throw new RuntimeException("Failed to trace dependencies for MetadataStorage extension.", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected Set<String> getSupportedTypesForProvider(MetadataStorage metadataStorage) { | ||
| return Collections.singleton(metadataStorage.getName()); | ||
| } | ||
|
|
||
| @Override | ||
| protected FilterClassLoader.Filter getExtensionParentClassLoaderFilter() { | ||
| return new FilterClassLoader.Filter() { | ||
| @Override | ||
| public boolean acceptResource(String resource) { | ||
| return ALLOWED_RESOURCES.contains(resource); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean acceptPackage(String packageName) { | ||
| return ALLOWED_PACKAGES.contains(packageName); | ||
| } | ||
| }; | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.