Skip to content

Commit 26dddf3

Browse files
author
Komal Yadav
committed
Added SpannerMetadata Submodule and Extension Loader
Added SpannerMetadata Submodule and ExtensionLoader Added SpannerMetadata Submodule and ExtensionLoader changes
1 parent 2655ad1 commit 26dddf3

File tree

8 files changed

+60
-109
lines changed

8 files changed

+60
-109
lines changed

cdap-SpannerMetadata/src/main/java/io/cdap/cdap/metadata/spanner/SpannerMetadataStorage.java

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -106,43 +106,9 @@
106106
*/
107107
public class SpannerMetadataStorage implements MetadataStorage {
108108

109-
110-
private static final Logger LOG = LoggerFactory.getLogger(SpannerMetadataStorage.class);
111-
112-
private String instanceId = "instance";
113-
private String databaseId = "database";
114-
private String projectId = "project";
115-
private volatile SpannerOptions options;
116-
private volatile Spanner spanner;
117-
private volatile DatabaseClient dbClient;
118-
private volatile DatabaseAdminClient adminClient;
119-
120-
private static final Gson gson = new GsonBuilder()
121-
.registerTypeAdapter(ScopedName.class, new ScopedNameTypeAdapter())
122-
.registerTypeAdapter(ScopedNameOfKind.class, new ScopedNameOfKindTypeAdapter())
123-
.create();
124-
125-
126109
@Override
127110
public void initialize(MetadataStorageContext context) throws Exception {
128-
LOG.info("Initializing SpannerMetadataStorage...");
129-
Map<String, String> conf = context.getConfiguration();
130-
LOG.info(conf.toString());
131-
projectId=getProjectId(conf);
132-
databaseId=getDatabaseId(conf);
133-
instanceId=getInstanceId(conf);
134-
LOG.info(projectId,databaseId,instanceId);
135-
try {
136-
options = SpannerOptions.newBuilder().setProjectId(projectId).build();
137-
spanner = options.getService();
138-
dbClient = spanner.getDatabaseClient(DatabaseId.of(projectId, instanceId, databaseId));
139-
adminClient = spanner.getDatabaseAdminClient();
140-
LOG.info("Successfully initialized Spanner client for instance: {}, database: {}", instanceId, databaseId);
141-
} catch (SpannerException e) {
142-
LOG.error("Error initializing Spanner client: {}", e.getMessage(), e);
143-
throw new RuntimeException("Failed to initialize Spanner client", e);
144-
}
145-
LOG.info("SpannerMetadataStorage initialized.");
111+
146112
}
147113

148114
@Override
@@ -215,14 +181,4 @@ public Object getDatasetMetadata(String datasetName) {
215181
return Collections.emptyMap();
216182
}
217183

218-
public String getProjectId(Map<String, String> conf){
219-
return conf.get(projectId);
220-
}
221-
public String getDatabaseId(Map<String, String> conf){
222-
return conf.get(databaseId);
223-
}
224-
public String getInstanceId(Map<String, String> conf){
225-
return conf.get(instanceId);
226-
}
227-
228184
}

cdap-app-fabric/src/main/java/io/cdap/cdap/metadata/MetadataHttpHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ public void searchMetadata(HttpRequest request, HttpResponder responder,
361361
@Nullable @QueryParam("entityScope") String entityScope,
362362
@Nullable @QueryParam("responseFormat") @DefaultValue("v5") String responseFormat)
363363
throws Exception {
364-
365364
SearchRequest searchRequest = getValidatedSearchRequest(scope, namespaces, searchQuery, targets,
366365
sort,
367366
offset, limit, numCursors, cursorRequested, cursor,

cdap-common/src/main/java/io/cdap/cdap/extension/AbstractExtensionLoader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ private Map<EXTENSION_TYPE, EXTENSION> getAllExtensions(ServiceLoader<EXTENSION>
274274
Map<EXTENSION_TYPE, EXTENSION> extensions = new HashMap<>();
275275
Iterator<EXTENSION> iterator = serviceLoader.iterator();
276276
// Cannot use for each loop here, because we want to catch exceptions during iterator.next().
277-
LOG.info(iterator.toString());
278277
while (iterator.hasNext()) {
279278
try {
280279
EXTENSION extension = iterator.next();
@@ -284,6 +283,7 @@ private Map<EXTENSION_TYPE, EXTENSION> getAllExtensions(ServiceLoader<EXTENSION>
284283

285284
for (EXTENSION_TYPE type : getSupportedTypesForProvider(extension)) {
286285
if (extensions.containsKey(type)) {
286+
LOG.info("Ignoring extension {} for type {}", extension, type);
287287
} else {
288288
extensions.put(type, extension);
289289
}
@@ -335,6 +335,7 @@ private ServiceLoader<EXTENSION> createServiceLoader(File dir) {
335335
*/
336336
private ClassLoader getExtensionParentClassLoader() {
337337
FilterClassLoader.Filter filter = getExtensionParentClassLoaderFilter();
338+
338339
// SLF4j resources are always coming from parent.
339340
return new FilterClassLoader(getClass().getClassLoader(), new FilterClassLoader.Filter() {
340341
@Override

cdap-data-fabric/src/main/java/io/cdap/cdap/data/runtime/MetadataStorageExtensionLoader.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import java.util.Collections;
1515
import java.util.Set;
1616

17-
import static io.cdap.cdap.common.conf.Constants.Metadata.Metadata_Storage_EXT_DIR;
18-
1917
/**
2018
* Extension loader for {@link MetadataStorage} implementations.
2119
*/
@@ -26,7 +24,7 @@ public class MetadataStorageExtensionLoader extends AbstractExtensionLoader<Stri
2624
private static final Set<String> ALLOWED_RESOURCES = createAllowedResources();
2725
private static final Set<String> ALLOWED_PACKAGES = createPackageSets(ALLOWED_RESOURCES);
2826

29-
private final CConfiguration cConf;
27+
private final boolean ismetadatastorageEnabled;
3028

3129
/**
3230
* Constructs a {@link MetadataStorageExtensionLoader} to manage the loading of SpannerMetadata
@@ -37,9 +35,10 @@ public class MetadataStorageExtensionLoader extends AbstractExtensionLoader<Stri
3735
*/
3836
@Inject
3937
public MetadataStorageExtensionLoader(CConfiguration cConf) {
40-
super(Metadata_Storage_EXT_DIR);
41-
this.cConf=cConf;
42-
LOG.debug("Metadata Storage extensions directory: {}", Metadata_Storage_EXT_DIR);
38+
super(cConf.get(Constants.Metadata.Metadata_Storage_EXT_DIR));
39+
this.ismetadatastorageEnabled = cConf.getBoolean(Constants.Metadata.Metadata_Storage_Enabled);
40+
LOG.debug("Metadata Storage extensions directory: {}",
41+
cConf.get(Constants.Metadata.Metadata_Storage_EXT_DIR));
4342
}
4443

4544
private static Set<String> createAllowedResources() {
@@ -53,7 +52,7 @@ private static Set<String> createAllowedResources() {
5352

5453
@Override
5554
protected Set<String> getSupportedTypesForProvider(MetadataStorage metadataStorage) {
56-
if (!cConf.getBoolean(Constants.Metadata.Metadata_Storage_Enabled)) {
55+
if (ismetadatastorageEnabled) {
5756
LOG.info("metadataStorage is not Empty",Collections.singleton(metadataStorage.getName()));
5857
return Collections.singleton(metadataStorage.getName());
5958
}

cdap-data-fabric/src/main/java/io/cdap/cdap/data2/metadata/AuditMetadataStorage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public MetadataChange apply(MetadataMutation mutation, MutationOptions options)
133133

134134
@Override
135135
public List<MetadataChange> batch(List<? extends MetadataMutation> mutations,
136-
MutationOptions options) throws IOException {
136+
MutationOptions options) throws IOException {
137137
List<MetadataChange> changes;
138138
try {
139139
changes = storage.batch(mutations, options);

cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/common/DefaultStorageProvider.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class DefaultStorageProvider implements StorageProvider {
5454
this.extensionLoader = extensionLoader;
5555
this.metricsCollector = metricsCollectionService.getContext(
5656
Constants.Metrics.STORAGE_METRICS_TAGS);
57-
this.extensionLoader.getAll();
5857
}
5958

6059
@Override

cdap-data-fabric/src/main/java/io/cdap/cdap/spi/data/common/StorageProviderExtensionLoader.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
/**
3131
* A extension loader for {@link StorageProvider}.
3232
*/
33-
3433
final class StorageProviderExtensionLoader extends
3534
AbstractExtensionLoader<String, StorageProvider> {
3635

cdap-metadata-spi/src/main/java/io/cdap/cdap/spi/metadata/MetadataStorage.java

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package io.cdap.cdap.spi.metadata;
1818

1919
import io.cdap.cdap.api.annotation.Beta;
20-
2120
import java.io.Closeable;
2221
import java.io.IOException;
2322
import java.util.List;
@@ -28,63 +27,62 @@
2827
@Beta
2928
public interface MetadataStorage extends Closeable {
3029

31-
String getName();
32-
33-
default void initialize(MetadataStorageContext context) throws Exception {
34-
// no-op
35-
}
30+
/**
31+
* Create all tables or indexes required for operations.
32+
*/
33+
void createIndex() throws IOException;
3634

37-
Object getDatasetMetadata(String datasetName);
35+
/**
36+
* Drop all tables or indexes required for operations.
37+
*/
38+
void dropIndex() throws IOException;
3839

39-
/**
40-
* Create all tables or indexes required for operations.
41-
*/
42-
void createIndex() throws IOException;
40+
/**
41+
* Apply the given mutation to the metadata state.
42+
*
43+
* @param mutation the mutation to perform
44+
* @return the change effected by this mutation
45+
*/
46+
MetadataChange apply(MetadataMutation mutation, MutationOptions options) throws IOException;
4347

44-
/**
45-
* Drop all tables or indexes required for operations.
46-
*/
47-
void dropIndex() throws IOException;
48+
/**
49+
* Apply a batch of mutations to the metadata state.
50+
*
51+
* @param mutations the mutations to perform. They are applied in the order given by the
52+
* list.
53+
* @return the changes effected by each of the mutations, in the same order as the batch of
54+
* mutations.
55+
*/
56+
List<MetadataChange> batch(List<? extends MetadataMutation> mutations, MutationOptions options)
57+
throws IOException;
4858

49-
/**
50-
* Apply the given mutation to the metadata state.
51-
*
52-
* @param mutation the mutation to perform
53-
* @return the change effected by this mutation
54-
*/
55-
MetadataChange apply(MetadataMutation mutation, MutationOptions options) throws IOException;
59+
/**
60+
* Retrieve the metadata for an entity.
61+
*
62+
* @param read the read operation to perform
63+
* @return the metadata for the entity, never null.
64+
*/
65+
Metadata read(Read read) throws IOException;
5666

57-
/**
58-
* Apply a batch of mutations to the metadata state.
59-
*
60-
* @param mutations the mutations to perform. They are applied in the order given by the
61-
* list.
62-
* @return the changes effected by each of the mutations, in the same order as the batch of
63-
* mutations.
64-
*/
65-
List<MetadataChange> batch(List<? extends MetadataMutation> mutations, MutationOptions options)
66-
throws IOException;
67+
/**
68+
* Search the metadata and return matching entities.
69+
*
70+
* @param request the search request
71+
* @return the result of the search, never null.
72+
*/
73+
SearchResponse search(SearchRequest request) throws IOException;
6774

68-
/**
69-
* Retrieve the metadata for an entity.
70-
*
71-
* @param read the read operation to perform
72-
* @return the metadata for the entity, never null.
73-
*/
74-
Metadata read(Read read) throws IOException;
75+
/**
76+
* Close the storage provider. Do not throw exceptions - this will be called when the Metadata
77+
* service shuts down.
78+
*/
79+
@Override
80+
void close();
7581

76-
/**
77-
* Search the metadata and return matching entities.
78-
*
79-
* @param request the search request
80-
* @return the result of the search, never null.
81-
*/
82-
SearchResponse search(SearchRequest request) throws IOException;
82+
String getName();
83+
Object getDatasetMetadata(String datasetName);
8384

84-
/**
85-
* Close the storage provider. Do not throw exceptions - this will be called when the Metadata
86-
* service shuts down.
87-
*/
88-
@Override
89-
void close();
85+
default void initialize(MetadataStorageContext context) throws Exception {
86+
// no-op
87+
}
9088
}

0 commit comments

Comments
 (0)