Murtadha Hubail has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1494

Change subject: [Preview] Replace Java Serialization For Persisted Objects
......................................................................

[Preview] Replace Java Serialization For Persisted Objects

Design discussion code.
Change-Id: I9cc87ac2ac6404cda83abf54e4cd0e9149f6dc19
---
A 
asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/PersistedResourceRegistry.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
M 
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Resource.java
M 
asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
M 
asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadata.java
A 
asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataDeserializer.java
A 
asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataSerializer.java
M 
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/application/IApplicationContext.java
A 
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IJsonSerializable.java
A 
hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IPersistedResourceRegistry.java
M 
hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/application/NCApplicationContext.java
11 files changed, 402 insertions(+), 22 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/94/1494/1

diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/PersistedResourceRegistry.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/PersistedResourceRegistry.java
new file mode 100644
index 0000000..8037ee1
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/PersistedResourceRegistry.java
@@ -0,0 +1,87 @@
+/*
+ * 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.asterix.api.common;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import 
org.apache.asterix.transaction.management.resource.LSMBTreeLocalResourceMetadata;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+public class PersistedResourceRegistry implements IPersistedResourceRegistry {
+
+    private static final Map<Integer, Class<? extends IJsonSerializable>> 
registeredClasses = new HashMap<>();
+
+    static {
+        /* WARNING: Class IDs are immutable and should never be changed.*/
+        registeredClasses.put(1, LSMBTreeLocalResourceMetadata.class);
+    }
+
+    public Class<? extends IJsonSerializable> getClassForId(int id) {
+        registeredClasses.computeIfAbsent(id, key -> {
+            throw new IllegalStateException(String.format("No class with id %s 
was registered.", key));
+        });
+        return registeredClasses.get(id);
+    }
+
+    @Override
+    public int getClassId(Class<? extends IJsonSerializable> clazz) {
+        Optional<Integer> classId = registeredClasses.entrySet()
+                .stream()
+                .filter(entry -> Objects.equals(entry.getValue(), clazz))
+                .map(Map.Entry::getKey).findAny();
+        if (classId.isPresent()) {
+            return classId.get();
+        }
+        throw new IllegalStateException(String.format("Class %s was not 
registered.", clazz.getName()));
+    }
+
+    @Override
+    public IJsonSerializable getClassInstance(int id) throws 
HyracksDataException {
+        Class<? extends IJsonSerializable> clazz = getClassForId(id);
+        try {
+            Constructor<? extends IJsonSerializable> declaredConstructor = 
clazz.getDeclaredConstructor();
+            declaredConstructor.setAccessible(true);
+            return declaredConstructor.newInstance();
+        } catch (NoSuchMethodException | IllegalAccessException | 
InstantiationException | InvocationTargetException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+
+    @Override
+    public IJsonSerializable deserialize(String json) throws 
HyracksDataException {
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+            JsonNode jsonNode = mapper.readTree(json);
+            int classId = jsonNode.get(CLASS_ID_STRING).asInt();
+            return getClassInstance(classId).fromJson(this, json);
+        } catch (IOException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+}
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
index bc270df..f8a13dc 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
@@ -26,6 +26,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.asterix.api.common.PersistedResourceRegistry;
 import org.apache.asterix.app.external.ExternalLibraryUtils;
 import org.apache.asterix.app.nc.NCAppRuntimeContext;
 import org.apache.asterix.common.api.AsterixThreadFactory;
@@ -125,7 +126,7 @@
         MessagingChannelInterfaceFactory interfaceFactory = new 
MessagingChannelInterfaceFactory(
                 (NCMessageBroker) messageBroker, messagingProperties);
         
ncApplicationContext.setMessagingChannelInterfaceFactory(interfaceFactory);
-
+        ncApplicationContext.setPersistedResourceRegistry(new 
PersistedResourceRegistry());
         boolean replicationEnabled = 
ClusterProperties.INSTANCE.isReplicationEnabled();
         boolean autoFailover = 
ClusterProperties.INSTANCE.isAutoFailoverEnabled();
         if (initialRun) {
diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Resource.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Resource.java
index e53ca7f..fe54ef2 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Resource.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/transactions/Resource.java
@@ -41,14 +41,18 @@
 public abstract class Resource implements Serializable {
 
     private static final long serialVersionUID = 1L;
-    private final int datasetId;
-    private final int partition;
-    protected final ITypeTraits[] filterTypeTraits;
-    protected final IBinaryComparatorFactory[] filterCmpFactories;
-    protected final int[] filterFields;
-    protected final ILSMOperationTrackerFactory opTrackerProvider;
-    protected final ILSMIOOperationCallbackFactory ioOpCallbackFactory;
-    protected final IMetadataPageManagerFactory metadataPageManagerFactory;
+    private int datasetId;
+    private int partition;
+    protected ITypeTraits[] filterTypeTraits;
+    protected IBinaryComparatorFactory[] filterCmpFactories;
+    protected int[] filterFields;
+    protected ILSMOperationTrackerFactory opTrackerProvider;
+    protected ILSMIOOperationCallbackFactory ioOpCallbackFactory;
+    protected IMetadataPageManagerFactory metadataPageManagerFactory;
+
+    protected Resource(){
+
+    }
 
     public Resource(int datasetId, int partition, ITypeTraits[] 
filterTypeTraits,
             IBinaryComparatorFactory[] filterCmpFactories, int[] filterFields,
diff --git 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
index 6cd1f8b..89db93f 100644
--- 
a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
+++ 
b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/bootstrap/MetadataBootstrap.java
@@ -19,6 +19,7 @@
 package org.apache.asterix.metadata.bootstrap;
 
 import java.io.File;
+import java.io.IOException;
 import java.rmi.RemoteException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -77,6 +78,7 @@
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.api.io.FileReference;
 import org.apache.hyracks.api.io.IIOManager;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
 import org.apache.hyracks.storage.am.common.api.ITreeIndexFrame;
 import org.apache.hyracks.storage.am.lsm.btree.impls.LSMBTree;
 import org.apache.hyracks.storage.am.lsm.btree.utils.LSMBTreeUtil;
@@ -370,6 +372,18 @@
                     metadataPartition.getPartitionId(), 
runtimeContext.getMetadataMergePolicyFactory(),
                     GlobalConfig.DEFAULT_COMPACTION_POLICY_PROPERTIES, null, 
null, null, null, opTrackerProvider,
                     ioOpCallbackFactory, 
runtimeContext.getStorageComponentProvider().getMetadataPageManagerFactory());
+
+            try {
+                //POC Code
+                final IPersistedResourceRegistry persistedResourceRegistry = 
appCtx.getPersistedResourceRegistry();
+                String json = ((LSMBTreeLocalResourceMetadata) 
localResourceMetadata)
+                        .asJson(persistedResourceRegistry);
+                LOGGER.warning("Serialized Resource: " + json);
+                LSMBTreeLocalResourceMetadata resource =
+                        (LSMBTreeLocalResourceMetadata) 
persistedResourceRegistry.deserialize(json);
+            } catch (IOException e) {
+                throw new HyracksDataException(e);
+            }
             ILocalResourceFactoryProvider localResourceFactoryProvider = new 
PersistentLocalResourceFactoryProvider(
                     partition -> localResourceMetadata, 
LocalResource.LSMBTreeResource);
             ILocalResourceFactory localResourceFactory = 
localResourceFactoryProvider.getLocalResourceFactory();
diff --git 
a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadata.java
 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadata.java
index f38711c..f511a6d 100644
--- 
a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadata.java
+++ 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadata.java
@@ -18,8 +18,12 @@
  */
 package org.apache.asterix.transaction.management.resource;
 
-import java.util.Map;
-
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.apache.asterix.common.api.IAppRuntimeContext;
 import org.apache.asterix.common.api.IDatasetLifecycleManager;
 import org.apache.asterix.common.transactions.Resource;
@@ -29,6 +33,8 @@
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.api.io.FileReference;
 import org.apache.hyracks.api.io.IIOManager;
+import org.apache.hyracks.api.io.IJsonSerializable;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
 import org.apache.hyracks.storage.am.common.api.IMetadataPageManagerFactory;
 import org.apache.hyracks.storage.am.lsm.btree.utils.LSMBTreeUtil;
 import 
org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperationCallbackFactory;
@@ -37,17 +43,26 @@
 import 
org.apache.hyracks.storage.am.lsm.common.api.ILSMOperationTrackerFactory;
 import org.apache.hyracks.storage.common.file.LocalResource;
 
-public class LSMBTreeLocalResourceMetadata extends Resource {
+import java.io.IOException;
+import java.util.Map;
+
+public class LSMBTreeLocalResourceMetadata extends Resource implements 
IJsonSerializable {
 
     private static final long serialVersionUID = 1L;
+    public static final long JSON_SERIAL_VERSION = 1L;
+    private static final boolean USE_JACKSON_SER_DESER = true;
 
-    protected final ITypeTraits[] typeTraits;
-    protected final IBinaryComparatorFactory[] cmpFactories;
-    protected final int[] bloomFilterKeyFields;
-    protected final boolean isPrimary;
-    protected final ILSMMergePolicyFactory mergePolicyFactory;
-    protected final Map<String, String> mergePolicyProperties;
-    protected final int[] btreeFields;
+    protected ITypeTraits[] typeTraits;
+    protected IBinaryComparatorFactory[] cmpFactories;
+    protected int[] bloomFilterKeyFields;
+    protected boolean isPrimary;
+    protected ILSMMergePolicyFactory mergePolicyFactory;
+    protected Map<String, String> mergePolicyProperties;
+    protected int[] btreeFields;
+
+    private LSMBTreeLocalResourceMetadata() {
+
+    }
 
     public LSMBTreeLocalResourceMetadata(ITypeTraits[] typeTraits, 
IBinaryComparatorFactory[] cmpFactories,
             int[] bloomFilterKeyFields, boolean isPrimary, int datasetID, int 
partition,
@@ -91,4 +106,54 @@
                 ioOpCallbackFactory.createIoOpCallback(), isPrimary, 
filterTypeTraits, filterCmpFactories, btreeFields,
                 filterFields, true, metadataPageManagerFactory);
     }
+
+    @Override
+    public String asJson(IPersistedResourceRegistry registry) throws 
HyracksDataException {
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+            LSMBTreeLocalResourceMetadataSerializer serializer = new 
LSMBTreeLocalResourceMetadataSerializer(registry);
+            SimpleModule module = new SimpleModule();
+            module.addSerializer(LSMBTreeLocalResourceMetadata.class, 
serializer);
+            mapper.registerModule(module);
+            return mapper.writeValueAsString(this);
+        } catch (JsonProcessingException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+
+    @Override
+    public IJsonSerializable fromJson(IPersistedResourceRegistry registry, 
String json)
+            throws HyracksDataException {
+        try {
+            if(!USE_JACKSON_SER_DESER){
+                return deserialize(json);
+            }
+            ObjectMapper mapper = new ObjectMapper();
+            LSMBTreeLocalResourceMetadataDeserializer deserializer =
+                    new LSMBTreeLocalResourceMetadataDeserializer(registry);
+            SimpleModule module = new SimpleModule();
+            module.addDeserializer(LSMBTreeLocalResourceMetadata.class, 
deserializer);
+            mapper.registerModule(module);
+            return mapper.readValue(json.getBytes(), 
LSMBTreeLocalResourceMetadata.class);
+        } catch (JsonParseException | JsonMappingException e) {
+            throw new HyracksDataException(e);
+        } catch (IOException e) {
+            throw new HyracksDataException(e);
+        }
+    }
+
+    private LSMBTreeLocalResourceMetadata deserialize(String json) throws 
IOException {
+        final ObjectMapper mapper = new ObjectMapper();
+        final ObjectNode jsonObject = mapper.readValue(json, ObjectNode.class);
+        LSMBTreeLocalResourceMetadata resource = new 
LSMBTreeLocalResourceMetadata();
+        long jsonSerialVersion = 
jsonObject.get(IPersistedResourceRegistry.CLASS_ID_STRING).asLong();
+        if (jsonSerialVersion != JSON_SERIAL_VERSION) {
+            throw new HyracksDataException("Class version mismatch.");
+        }
+        resource.isPrimary = jsonObject.get("isPrimary").asBoolean();
+        resource.bloomFilterKeyFields = 
mapper.convertValue(jsonObject.get("bloomFilterKeyFields"), int[].class);
+        resource.btreeFields = 
mapper.convertValue(jsonObject.get("btreeFields"), int[].class);
+        resource.mergePolicyProperties = 
mapper.convertValue(jsonObject.get("mergePolicyProperties"), Map.class);
+        return resource;
+    }
 }
diff --git 
a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataDeserializer.java
 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataDeserializer.java
new file mode 100644
index 0000000..57660ab
--- /dev/null
+++ 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataDeserializer.java
@@ -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.asterix.transaction.management.resource;
+
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+
+import java.io.IOException;
+import java.util.Map;
+
+public class LSMBTreeLocalResourceMetadataDeserializer extends 
JsonDeserializer<LSMBTreeLocalResourceMetadata> {
+
+    private final IPersistedResourceRegistry registry;
+
+    public 
LSMBTreeLocalResourceMetadataDeserializer(IPersistedResourceRegistry registry) {
+        this.registry = registry;
+    }
+
+    @Override
+    public LSMBTreeLocalResourceMetadata deserialize(JsonParser p, 
DeserializationContext ctxt)
+            throws IOException, JsonProcessingException {
+        final ObjectMapper mapper = new ObjectMapper();
+        JsonNode node = p.readValueAsTree();
+        long jsonSerialVersion = 
node.get(IPersistedResourceRegistry.CLASS_VERSION_STRING).asLong();
+        if (jsonSerialVersion != 
LSMBTreeLocalResourceMetadata.JSON_SERIAL_VERSION) {
+            throw new HyracksDataException("Class version mismatch.");
+        }
+        int classId = 
node.get(IPersistedResourceRegistry.CLASS_VERSION_STRING).asInt();
+        LSMBTreeLocalResourceMetadata resource = 
(LSMBTreeLocalResourceMetadata) registry.getClassInstance(classId);
+        resource.isPrimary = node.get("isPrimary").asBoolean();
+        resource.bloomFilterKeyFields = 
mapper.convertValue(node.get("bloomFilterKeyFields"), int[].class);
+        resource.btreeFields = mapper.convertValue(node.get("btreeFields"), 
int[].class);
+        resource.mergePolicyProperties = 
mapper.convertValue(node.get("mergePolicyProperties"), Map.class);
+
+        //TODO deserialize ITypeTraits[], IBinaryComparatorFactory[], 
ILSMMergePolicyFactory
+        return resource;
+    }
+}
diff --git 
a/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataSerializer.java
 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataSerializer.java
new file mode 100644
index 0000000..a6b85fb
--- /dev/null
+++ 
b/asterixdb/asterix-transactions/src/main/java/org/apache/asterix/transaction/management/resource/LSMBTreeLocalResourceMetadataSerializer.java
@@ -0,0 +1,66 @@
+/*
+ * 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.asterix.transaction.management.resource;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
+
+import java.io.IOException;
+
+public class LSMBTreeLocalResourceMetadataSerializer extends 
JsonSerializer<LSMBTreeLocalResourceMetadata> {
+
+    private final IPersistedResourceRegistry registry;
+
+    public LSMBTreeLocalResourceMetadataSerializer(IPersistedResourceRegistry 
registry) {
+        this.registry = registry;
+    }
+
+    @Override
+    public void serialize(LSMBTreeLocalResourceMetadata value, JsonGenerator 
gen,
+            SerializerProvider serializers) throws IOException, 
JsonProcessingException {
+        gen.writeStartObject();
+
+        gen.writeFieldName(IPersistedResourceRegistry.CLASS_VERSION_STRING);
+        gen.writeNumber(LSMBTreeLocalResourceMetadata.JSON_SERIAL_VERSION);
+
+        gen.writeFieldName(IPersistedResourceRegistry.CLASS_NAME_STRING);
+        gen.writeString(LSMBTreeLocalResourceMetadata.class.getName());
+
+        gen.writeFieldName(IPersistedResourceRegistry.CLASS_ID_STRING);
+        
gen.writeNumber(registry.getClassId(LSMBTreeLocalResourceMetadata.class));
+
+        gen.writeFieldName("isPrimary");
+        gen.writeBoolean(value.isPrimary);
+
+        gen.writeFieldName("bloomFilterKeyFields");
+        gen.writeObject(value.bloomFilterKeyFields);
+
+        gen.writeFieldName("btreeFields");
+        gen.writeObject(value.btreeFields);
+
+        gen.writeFieldName("mergePolicyProperties");
+        gen.writeObject(value.mergePolicyProperties);
+
+        //TODO serialize ITypeTraits[], IBinaryComparatorFactory[], 
IBinaryComparatorFactory
+        gen.writeEndObject();
+    }
+}
diff --git 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/application/IApplicationContext.java
 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/application/IApplicationContext.java
index 7b07174..115f202 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/application/IApplicationContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/application/IApplicationContext.java
@@ -18,12 +18,13 @@
  */
 package org.apache.hyracks.api.application;
 
-import java.io.Serializable;
-import java.util.concurrent.ThreadFactory;
-
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
 import org.apache.hyracks.api.job.IJobSerializerDeserializerContainer;
 import org.apache.hyracks.api.messages.IMessageBroker;
 import org.apache.hyracks.api.service.IControllerService;
+
+import java.io.Serializable;
+import java.util.concurrent.ThreadFactory;
 
 /**
  * Base class of the {@link ICCApplicationContext} and the {@link 
INCApplicationContext}.
@@ -56,4 +57,11 @@
      */
     public IControllerService getControllerService();
 
+    default void setPersistedResourceRegistry(IPersistedResourceRegistry 
registry) {
+        throw new UnsupportedOperationException();
+    }
+
+    default IPersistedResourceRegistry getPersistedResourceRegistry() {
+        throw new UnsupportedOperationException();
+    }
 }
diff --git 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IJsonSerializable.java
 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IJsonSerializable.java
new file mode 100644
index 0000000..d2f27c8
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IJsonSerializable.java
@@ -0,0 +1,29 @@
+/*
+ * 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.hyracks.api.io;
+
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public interface IJsonSerializable {
+
+    String asJson(IPersistedResourceRegistry registry) throws 
HyracksDataException;
+
+    IJsonSerializable fromJson(IPersistedResourceRegistry registry, String 
json)
+            throws HyracksDataException;
+}
diff --git 
a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IPersistedResourceRegistry.java
 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IPersistedResourceRegistry.java
new file mode 100644
index 0000000..4c3e2b0
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/io/IPersistedResourceRegistry.java
@@ -0,0 +1,36 @@
+/*
+ * 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.hyracks.api.io;
+
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
+public interface IPersistedResourceRegistry {
+
+    String CLASS_ID_STRING = "classId";
+    String CLASS_VERSION_STRING = "version";
+    String CLASS_NAME_STRING = "className";
+
+    Class<? extends IJsonSerializable> getClassForId(int id);
+
+    int getClassId(Class<? extends IJsonSerializable> clazz);
+
+    IJsonSerializable getClassInstance(int id) throws HyracksDataException;
+
+    IJsonSerializable deserialize(String json) throws HyracksDataException;
+}
diff --git 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/application/NCApplicationContext.java
 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/application/NCApplicationContext.java
index f52099d..4ccb6ea 100644
--- 
a/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/application/NCApplicationContext.java
+++ 
b/hyracks-fullstack/hyracks/hyracks-control/hyracks-control-nc/src/main/java/org/apache/hyracks/control/nc/application/NCApplicationContext.java
@@ -26,6 +26,7 @@
 import org.apache.hyracks.api.application.INCApplicationContext;
 import org.apache.hyracks.api.application.IStateDumpHandler;
 import org.apache.hyracks.api.comm.IChannelInterfaceFactory;
+import org.apache.hyracks.api.io.IPersistedResourceRegistry;
 import org.apache.hyracks.api.lifecycle.ILifeCycleComponentManager;
 import org.apache.hyracks.api.resources.memory.IMemoryManager;
 import org.apache.hyracks.api.service.IControllerService;
@@ -45,6 +46,7 @@
     private IStateDumpHandler sdh;
     private final NodeControllerService ncs;
     private IChannelInterfaceFactory messagingChannelInterfaceFactory;
+    private IPersistedResourceRegistry registry;
 
     public NCApplicationContext(NodeControllerService ncs, ServerContext 
serverCtx, IOManager ioManager,
             String nodeId, MemoryManager memoryManager, 
ILifeCycleComponentManager lifeCyclecomponentManager,
@@ -121,4 +123,12 @@
     public void setMessagingChannelInterfaceFactory(IChannelInterfaceFactory 
interfaceFactory) {
         this.messagingChannelInterfaceFactory = interfaceFactory;
     }
+
+    @Override public void 
setPersistedResourceRegistry(IPersistedResourceRegistry registry) {
+        this.registry = registry;
+    }
+
+    @Override public IPersistedResourceRegistry getPersistedResourceRegistry() 
{
+        return registry;
+    }
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1494
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9cc87ac2ac6404cda83abf54e4cd0e9149f6dc19
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Murtadha Hubail <hubail...@gmail.com>

Reply via email to