asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjaco...@apache.org
Subject [8/8] asterixdb git commit: Remove static cc application context instance
Date Fri, 21 Apr 2017 17:01:38 GMT
Remove static cc application context instance

Change-Id: Ia2e250405967ec880e7af6387aa981f39b3392c0
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1606
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/c67f33dd
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/c67f33dd
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/c67f33dd

Branch: refs/heads/master
Commit: c67f33ddf010f1a977bd19912e4c0f347b199d99
Parents: b1a07a0
Author: Abdullah Alamoudi <bamousaa@gmail.com>
Authored: Fri Apr 21 04:50:06 2017 +0300
Committer: Steven Jacobs <sjaco002@ucr.edu>
Committed: Fri Apr 21 10:00:58 2017 -0700

----------------------------------------------------------------------
 .../active/ActiveJobNotificationHandler.java    |   3 +-
 .../asterix/active/ActiveLifecycleListener.java |  19 +-
 .../ActiveSourceOperatorNodePushable.java       |   4 +-
 .../active/message/ActiveManagerMessage.java    |  12 +-
 .../active/message/ActivePartitionMessage.java  |  11 +-
 .../physical/InvertedIndexPOperator.java        |   4 +-
 .../provider/DefaultRuleSetFactory.java         |  29 ++-
 .../compiler/provider/IRuleSetFactory.java      |   7 +-
 .../jobgen/QueryLogicalExpressionJobGen.java    |   4 +-
 .../asterix/optimizer/base/RuleCollections.java |  14 +-
 .../optimizer/rules/ConstantFoldingRule.java    |  58 ++---
 .../translator/AbstractLangTranslator.java      |  11 +-
 .../translator/IStatementExecutorFactory.java   |   3 +-
 .../LangExpressionToPlanTranslator.java         |  27 +--
 .../apache/asterix/api/common/APIFramework.java |  35 ++-
 .../AppRuntimeContextProviderForRecovery.java   |   4 +-
 .../http/server/AbstractQueryApiServlet.java    |   9 +-
 .../asterix/api/http/server/ApiServlet.java     |  10 +-
 .../api/http/server/ClusterApiServlet.java      |   6 +-
 .../api/http/server/ConnectorApiServlet.java    |   7 +-
 .../asterix/api/http/server/DdlApiServlet.java  |   5 +-
 .../api/http/server/DiagnosticsApiServlet.java  |  11 +-
 .../asterix/api/http/server/FullApiServlet.java |   5 +-
 .../api/http/server/QueryApiServlet.java        |   5 +-
 .../api/http/server/QueryResultApiServlet.java  |   7 +-
 .../api/http/server/QueryServiceServlet.java    |  25 ++-
 .../api/http/server/QueryStatusApiServlet.java  |   5 +-
 .../http/server/QueryWebInterfaceServlet.java   |   8 +-
 .../asterix/api/http/server/RestApiServlet.java |  10 +-
 .../asterix/api/http/server/ResultUtil.java     |  18 +-
 .../api/http/server/UpdateApiServlet.java       |   5 +-
 .../api/http/server/VersionApiServlet.java      |  12 +-
 .../asterix/api/java/AsterixJavaClient.java     |  17 +-
 .../asterix/app/cc/ResourceIdManager.java       |   4 +-
 .../asterix/app/nc/NCAppRuntimeContext.java     |  41 ++--
 .../app/nc/task/BindMetadataNodeTask.java       |   4 +-
 .../asterix/app/nc/task/CheckpointTask.java     |   4 +-
 .../app/nc/task/ExternalLibrarySetupTask.java   |   4 +-
 .../asterix/app/nc/task/LocalRecoveryTask.java  |   4 +-
 .../app/nc/task/MetadataBootstrapTask.java      |   4 +-
 .../asterix/app/nc/task/RemoteRecoveryTask.java |   4 +-
 .../asterix/app/nc/task/StartFailbackTask.java  |   4 +-
 .../nc/task/StartLifecycleComponentsTask.java   |   4 +-
 .../nc/task/StartReplicationServiceTask.java    |   4 +-
 .../replication/AutoFaultToleranceStrategy.java |  22 +-
 .../FaultToleranceStrategyFactory.java          |  18 +-
 .../MetadataNodeFaultToleranceStrategy.java     |  17 +-
 .../replication/NoFaultToleranceStrategy.java   |   7 +-
 .../message/CompleteFailbackRequestMessage.java |  15 +-
 .../CompleteFailbackResponseMessage.java        |  15 +-
 .../message/NCLifecycleTaskReportMessage.java   |  11 +-
 ...PreparePartitionsFailbackRequestMessage.java |  12 +-
 ...reparePartitionsFailbackResponseMessage.java |  16 +-
 .../ReplayPartitionLogsRequestMessage.java      |  11 +-
 .../ReplayPartitionLogsResponseMessage.java     |  15 +-
 .../message/StartupTaskRequestMessage.java      |  11 +-
 .../message/StartupTaskResponseMessage.java     |   9 +-
 .../TakeoverMetadataNodeRequestMessage.java     |  11 +-
 .../TakeoverMetadataNodeResponseMessage.java    |  11 +-
 .../TakeoverPartitionsRequestMessage.java       |  11 +-
 .../TakeoverPartitionsResponseMessage.java      |  11 +-
 .../asterix/app/result/ResultPrinter.java       |   7 +-
 .../apache/asterix/app/result/ResultReader.java |   3 -
 .../DefaultStatementExecutorFactory.java        |   6 +-
 .../asterix/app/translator/QueryTranslator.java |  83 ++++---
 .../org/apache/asterix/drivers/AsterixCLI.java  |   5 +-
 .../asterix/drivers/AsterixClientDriver.java    |   2 +-
 .../hyracks/bootstrap/CCApplication.java        |  75 ++++---
 .../bootstrap/ClusterLifecycleListener.java     |  43 ++--
 .../hyracks/bootstrap/ClusterWorkExecutor.java  |  15 +-
 .../bootstrap/GlobalRecoveryManager.java        | 115 +++++-----
 .../hyracks/bootstrap/NCApplication.java        |  10 +-
 .../asterix/messaging/CCMessageBroker.java      |  13 +-
 .../MessagingChannelInterfaceFactory.java       |   6 +-
 .../asterix/messaging/NCMessageBroker.java      |  25 ++-
 .../org/apache/asterix/utils/DataverseUtil.java |   2 +-
 .../apache/asterix/utils/FeedOperations.java    |  55 ++---
 .../apache/asterix/utils/FlushDatasetUtil.java  |   3 +-
 .../http/servlet/ConnectorApiServletTest.java   |  13 +-
 .../api/http/servlet/VersionApiServletTest.java |   4 +-
 .../app/bootstrap/TestNodeController.java       |   5 +-
 .../aql/translator/QueryTranslatorTest.java     |   9 +-
 .../org/apache/asterix/test/dml/DmlTest.java    |   5 +-
 .../asterix/test/optimizer/OptimizerTest.java   |  26 ++-
 .../asterix/test/runtime/ExecutionTestUtil.java |   8 +-
 .../asterix/common/api/IAppRuntimeContext.java  | 119 ----------
 .../asterix/common/api/IApplicationContext.java |  63 ++++++
 .../common/api/INcApplicationContext.java       | 119 ++++++++++
 .../common/cluster/IGlobalRecoveryManager.java  |   3 +-
 .../common/config/IPropertiesProvider.java      |  41 ----
 .../AsterixVirtualBufferCacheProvider.java      |   4 +-
 .../CorrelatedPrefixMergePolicyFactory.java     |   4 +-
 .../context/TransactionSubsystemProvider.java   |   6 +-
 .../dataflow/IApplicationContextInfo.java       |  65 ------
 .../common/dataflow/ICcApplicationContext.java  |  76 +++++++
 .../LSMInsertDeleteOperatorNodePushable.java    |   6 +-
 .../messaging/api/IApplicationMessage.java      |  32 ---
 .../common/messaging/api/ICCMessageBroker.java  |   2 +-
 .../messaging/api/ICcAddressedMessage.java      |  33 +++
 .../common/messaging/api/INCMessageBroker.java  |   6 +-
 .../messaging/api/INcAddressedMessage.java      |  33 +++
 .../replication/IFaultToleranceStrategy.java    |   4 +-
 .../common/replication/INCLifecycleMessage.java |   4 +-
 .../IAppRuntimeContextProvider.java             |   4 +-
 .../adapter/factory/GenericAdapterFactory.java  |  26 ++-
 .../adapter/factory/LookupAdapterFactory.java   |  18 +-
 .../asterix/external/api/IAdapterFactory.java   |   6 +-
 .../api/IExternalDataSourceFactory.java         |  10 +-
 .../asterix/external/api/INodeResolver.java     |   4 +-
 .../feed/management/FeedEventsListener.java     |  14 +-
 .../external/input/HDFSDataSourceFactory.java   |  18 +-
 .../reader/hdfs/HDFSLookupReaderFactory.java    |   9 +-
 .../reader/rss/RSSRecordReaderFactory.java      |  11 +-
 .../stream/StreamRecordReaderFactory.java       |   6 +-
 .../twitter/TwitterRecordReaderFactory.java     |  10 +-
 .../factory/LocalFSInputStreamFactory.java      |  39 ++--
 .../factory/SocketClientInputStreamFactory.java |  13 +-
 .../factory/SocketServerInputStreamFactory.java |  19 +-
 .../factory/TwitterFirehoseStreamFactory.java   |   3 +-
 .../external/library/ExternalFunction.java      |  17 +-
 .../ExternalFunctionDescriptorProvider.java     |  19 +-
 .../library/ExternalFunctionProvider.java       |  23 +-
 .../ExternalScalarFunctionEvaluatorFactory.java |  12 +-
 .../library/RuntimeExternalFunctionUtil.java    |  31 +--
 .../FeedCollectOperatorNodePushable.java        |   4 +-
 .../operators/FeedIntakeOperatorDescriptor.java |  12 +-
 .../operators/FeedMetaComputeNodePushable.java  |   4 +-
 .../operators/FeedMetaStoreNodePushable.java    |   4 +-
 .../provider/AdapterFactoryProvider.java        |  14 +-
 .../provider/LookupReaderFactoryProvider.java   |   9 +-
 .../apache/asterix/external/util/HDFSUtils.java |  24 +-
 .../asterix/external/util/IdentityResolver.java |   3 +-
 .../asterix/external/util/NodeResolver.java     |  11 +-
 .../reader/RecordWithPKTestReaderFactory.java   |   9 +-
 .../record/reader/kv/KVTestReaderFactory.java   |   3 +-
 .../adapter/TestTypedAdapterFactory.java        |  19 +-
 .../apache/asterix/metadata/MetadataNode.java   |  10 +-
 .../asterix/metadata/api/IClusterManager.java   |   3 +-
 .../metadata/bootstrap/MetadataBootstrap.java   |   6 +-
 .../metadata/cluster/ClusterManager.java        |  16 +-
 .../cluster/ClusterManagerProvider.java         |   3 +-
 .../metadata/dataset/hints/DatasetHints.java    |  31 ++-
 .../asterix/metadata/dataset/hints/IHint.java   |   3 +-
 .../metadata/declared/MetadataProvider.java     |  48 ++--
 .../asterix/metadata/entities/Dataset.java      |  13 +-
 .../metadata/feeds/FeedMetadataUtil.java        |  24 +-
 .../asterix/metadata/utils/DatasetUtil.java     |  26 +--
 .../utils/ExternalIndexingOperations.java       |  62 +++---
 .../asterix/metadata/utils/IndexUtil.java       |  47 +++-
 .../utils/SecondaryBTreeOperationsHelper.java   |  26 +--
 .../utils/SecondaryIndexOperationsHelper.java   |  14 +-
 .../SecondaryInvertedIndexOperationsHelper.java |  45 ++--
 .../utils/SecondaryRTreeOperationsHelper.java   |   9 +-
 .../SecondaryTreeIndexOperationsHelper.java     |  25 +--
 .../management/ReplicationChannel.java          |  26 +--
 .../management/ReplicationManager.java          |  15 +-
 .../recovery/RemoteRecoveryManager.java         |  29 ++-
 .../job/listener/JobEventListenerFactory.java   |   6 +-
 ...tiTransactionJobletEventListenerFactory.java |   6 +-
 .../runtime/message/ReplicaEventMessage.java    |  10 +-
 .../message/ReportMaxResourceIdMessage.java     |  16 +-
 .../ReportMaxResourceIdRequestMessage.java      |  10 +-
 .../message/ResourceIdRequestMessage.java       |  18 +-
 .../ResourceIdRequestResponseMessage.java       |  10 +-
 .../LSMPrimaryUpsertOperatorNodePushable.java   |   6 +-
 .../std/FlushDatasetOperatorDescriptor.java     |   4 +-
 .../asterix/runtime/utils/AppContextInfo.java   | 221 -------------------
 .../runtime/utils/CcApplicationContext.java     | 216 ++++++++++++++++++
 .../runtime/utils/ClusterStateManager.java      |  40 ++--
 .../utils/RuntimeComponentsProvider.java        |  14 +-
 .../asterix/runtime/utils/RuntimeUtils.java     |  24 +-
 .../PrimaryIndexOperationTrackerFactory.java    |   4 +-
 .../SecondaryIndexOperationTrackerFactory.java  |   4 +-
 .../ExternalBTreeLocalResourceMetadata.java     |   4 +-
 ...rnalBTreeWithBuddyLocalResourceMetadata.java |   4 +-
 .../ExternalRTreeLocalResourceMetadata.java     |   4 +-
 .../resource/LSMBTreeLocalResourceMetadata.java |   4 +-
 .../LSMInvertedIndexLocalResourceMetadata.java  |   4 +-
 .../resource/LSMRTreeLocalResourceMetadata.java |   4 +-
 .../management/runtime/CommitRuntime.java       |   6 +-
 .../recovery/ReplicationCheckpointManager.java  |  26 +--
 .../locking/TestRuntimeContextProvider.java     |   4 +-
 182 files changed, 1837 insertions(+), 1613 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveJobNotificationHandler.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveJobNotificationHandler.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveJobNotificationHandler.java
index d7998f8..b4ed8e5 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveJobNotificationHandler.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveJobNotificationHandler.java
@@ -30,7 +30,6 @@ import org.apache.hyracks.api.job.JobId;
 import org.apache.hyracks.api.job.JobSpecification;
 
 public class ActiveJobNotificationHandler implements Runnable {
-    public static final ActiveJobNotificationHandler INSTANCE = new ActiveJobNotificationHandler();
     public static final String ACTIVE_ENTITY_PROPERTY_NAME = "ActiveJob";
     private static final Logger LOGGER = Logger.getLogger(ActiveJobNotificationHandler.class.getName());
     private static final boolean DEBUG = false;
@@ -38,7 +37,7 @@ public class ActiveJobNotificationHandler implements Runnable {
     private final Map<EntityId, IActiveEntityEventsListener> entityEventListeners;
     private final Map<JobId, EntityId> jobId2ActiveJobInfos;
 
-    private ActiveJobNotificationHandler() {
+    public ActiveJobNotificationHandler() {
         this.eventInbox = new LinkedBlockingQueue<>();
         this.jobId2ActiveJobInfos = new HashMap<>();
         this.entityEventListeners = new HashMap<>();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveLifecycleListener.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveLifecycleListener.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveLifecycleListener.java
index 6a10b0c..86c3e7d 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveLifecycleListener.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveLifecycleListener.java
@@ -34,20 +34,21 @@ import org.apache.hyracks.api.job.JobSpecification;
 public class ActiveLifecycleListener implements IJobLifecycleListener {
 
     private static final Logger LOGGER = Logger.getLogger(ActiveLifecycleListener.class.getName());
-    public static final ActiveLifecycleListener INSTANCE = new ActiveLifecycleListener();
 
+    private final ActiveJobNotificationHandler notificationHandler;
     private final LinkedBlockingQueue<ActiveEvent> jobEventInbox;
     private final ExecutorService executorService;
 
-    private ActiveLifecycleListener() {
-        jobEventInbox = ActiveJobNotificationHandler.INSTANCE.getEventInbox();
+    public ActiveLifecycleListener() {
+        notificationHandler = new ActiveJobNotificationHandler();
+        jobEventInbox = notificationHandler.getEventInbox();
         executorService = Executors.newSingleThreadExecutor();
-        executorService.execute(ActiveJobNotificationHandler.INSTANCE);
+        executorService.execute(notificationHandler);
     }
 
     @Override
     public synchronized void notifyJobStart(JobId jobId) throws HyracksException {
-        EntityId entityId = ActiveJobNotificationHandler.INSTANCE.getEntity(jobId);
+        EntityId entityId = notificationHandler.getEntity(jobId);
         if (entityId != null) {
             jobEventInbox.add(new ActiveEvent(jobId, Kind.JOB_STARTED, entityId));
         }
@@ -55,7 +56,7 @@ public class ActiveLifecycleListener implements IJobLifecycleListener {
 
     @Override
     public synchronized void notifyJobFinish(JobId jobId) throws HyracksException {
-        EntityId entityId = ActiveJobNotificationHandler.INSTANCE.getEntity(jobId);
+        EntityId entityId = notificationHandler.getEntity(jobId);
         if (entityId != null) {
             jobEventInbox.add(new ActiveEvent(jobId, Kind.JOB_FINISHED, entityId));
         } else {
@@ -67,7 +68,7 @@ public class ActiveLifecycleListener implements IJobLifecycleListener {
 
     @Override
     public void notifyJobCreation(JobId jobId, JobSpecification spec) throws HyracksException {
-        ActiveJobNotificationHandler.INSTANCE.notifyJobCreation(jobId, spec);
+        notificationHandler.notifyJobCreation(jobId, spec);
     }
 
     public void receive(ActivePartitionMessage message) {
@@ -78,4 +79,8 @@ public class ActiveLifecycleListener implements IJobLifecycleListener {
     public void stop() {
         executorService.shutdown();
     }
+
+    public ActiveJobNotificationHandler getNotificationHandler() {
+        return notificationHandler;
+    }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveSourceOperatorNodePushable.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveSourceOperatorNodePushable.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveSourceOperatorNodePushable.java
index ac3caf3..98a6979 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveSourceOperatorNodePushable.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/ActiveSourceOperatorNodePushable.java
@@ -22,7 +22,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.asterix.active.message.ActivePartitionMessage;
-import org.apache.asterix.common.api.IAppRuntimeContext;
+import org.apache.asterix.common.api.INcApplicationContext;
 import org.apache.hyracks.api.comm.IFrameWriter;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -40,7 +40,7 @@ public abstract class ActiveSourceOperatorNodePushable extends AbstractUnaryOutp
 
     public ActiveSourceOperatorNodePushable(IHyracksTaskContext ctx, ActiveRuntimeId runtimeId) {
         this.ctx = ctx;
-        activeManager = (ActiveManager) ((IAppRuntimeContext) ctx.getJobletContext().getServiceContext()
+        activeManager = (ActiveManager) ((INcApplicationContext) ctx.getJobletContext().getServiceContext()
                 .getApplicationContext()).getActiveManager();
         this.runtimeId = runtimeId;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActiveManagerMessage.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActiveManagerMessage.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActiveManagerMessage.java
index da3ac1c..231ec25 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActiveManagerMessage.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActiveManagerMessage.java
@@ -21,12 +21,11 @@ package org.apache.asterix.active.message;
 import java.io.Serializable;
 
 import org.apache.asterix.active.ActiveManager;
-import org.apache.asterix.common.api.IAppRuntimeContext;
-import org.apache.asterix.common.messaging.api.IApplicationMessage;
+import org.apache.asterix.common.api.INcApplicationContext;
+import org.apache.asterix.common.messaging.api.INcAddressedMessage;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
-import org.apache.hyracks.api.service.IControllerService;
 
-public class ActiveManagerMessage implements IApplicationMessage {
+public class ActiveManagerMessage implements INcAddressedMessage {
     public static final byte STOP_ACTIVITY = 0x00;
 
     private static final long serialVersionUID = 1L;
@@ -53,9 +52,8 @@ public class ActiveManagerMessage implements IApplicationMessage {
     }
 
     @Override
-    public void handle(IControllerService cs) throws HyracksDataException, InterruptedException {
-        IAppRuntimeContext appContext = (IAppRuntimeContext) cs.getApplicationContext();
-        ((ActiveManager) appContext.getActiveManager()).submit(this);
+    public void handle(INcApplicationContext appCtx) throws HyracksDataException, InterruptedException {
+        ((ActiveManager) appCtx.getActiveManager()).submit(this);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActivePartitionMessage.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActivePartitionMessage.java b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActivePartitionMessage.java
index 3c7aa06..335121a 100644
--- a/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActivePartitionMessage.java
+++ b/asterixdb/asterix-active/src/main/java/org/apache/asterix/active/message/ActivePartitionMessage.java
@@ -22,12 +22,12 @@ import java.io.Serializable;
 
 import org.apache.asterix.active.ActiveLifecycleListener;
 import org.apache.asterix.active.ActiveRuntimeId;
-import org.apache.asterix.common.messaging.api.IApplicationMessage;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
+import org.apache.asterix.common.messaging.api.ICcAddressedMessage;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
 import org.apache.hyracks.api.job.JobId;
-import org.apache.hyracks.api.service.IControllerService;
 
-public class ActivePartitionMessage implements IApplicationMessage {
+public class ActivePartitionMessage implements ICcAddressedMessage {
 
     public static final byte ACTIVE_RUNTIME_REGISTERED = 0x00;
     public static final byte ACTIVE_RUNTIME_DEREGISTERED = 0x01;
@@ -66,8 +66,9 @@ public class ActivePartitionMessage implements IApplicationMessage {
     }
 
     @Override
-    public void handle(IControllerService cs) throws HyracksDataException, InterruptedException {
-        ActiveLifecycleListener.INSTANCE.receive(this);
+    public void handle(ICcApplicationContext appCtx) throws HyracksDataException, InterruptedException {
+        ActiveLifecycleListener activeListener = (ActiveLifecycleListener) appCtx.getActiveLifecycleListener();
+        activeListener.receive(this);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/InvertedIndexPOperator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/InvertedIndexPOperator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/InvertedIndexPOperator.java
index 5eae36b..3d7ba34 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/InvertedIndexPOperator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/operators/physical/InvertedIndexPOperator.java
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.asterix.common.dataflow.IApplicationContextInfo;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.metadata.MetadataException;
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.declared.DataSourceId;
@@ -234,7 +234,7 @@ public class InvertedIndexPOperator extends IndexSearchPOperator {
                     invertedIndexFieldsForNonBulkLoadOps[k] = k;
                 }
             }
-            IApplicationContextInfo appContext = (IApplicationContextInfo) context.getAppContext();
+            ICcApplicationContext appContext = (ICcApplicationContext) context.getAppContext();
             Pair<IFileSplitProvider, AlgebricksPartitionConstraint> secondarySplitsAndConstraint =
                     metadataProvider.getSplitProviderAndConstraints(dataset, indexName);
             // TODO: Here we assume there is only one search key field.

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/DefaultRuleSetFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/DefaultRuleSetFactory.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/DefaultRuleSetFactory.java
index 32d766b..2db5d9a 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/DefaultRuleSetFactory.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/DefaultRuleSetFactory.java
@@ -21,6 +21,7 @@ package org.apache.asterix.compiler.provider;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.optimizer.base.RuleCollections;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.common.utils.Pair;
@@ -32,17 +33,19 @@ import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 public class DefaultRuleSetFactory implements IRuleSetFactory {
 
     @Override
-    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getLogicalRewrites()
-            throws AlgebricksException {
-        return buildLogical();
+    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getLogicalRewrites(
+            ICcApplicationContext appCtx) throws AlgebricksException {
+        return buildLogical(appCtx);
     }
 
     @Override
-    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getPhysicalRewrites() {
-        return buildPhysical();
+    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getPhysicalRewrites(
+            ICcApplicationContext appCtx) {
+        return buildPhysical(appCtx);
     }
 
-    public static List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> buildLogical() {
+    public static List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> buildLogical(
+            ICcApplicationContext appCtx) {
         List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> defaultLogicalRewrites = new ArrayList<>();
         SequentialFixpointRuleController seqCtrlNoDfs = new SequentialFixpointRuleController(false);
         SequentialFixpointRuleController seqCtrlFullDfs = new SequentialFixpointRuleController(true);
@@ -51,17 +54,18 @@ public class DefaultRuleSetFactory implements IRuleSetFactory {
         defaultLogicalRewrites.add(new Pair<>(seqOnceCtrl, RuleCollections.buildTypeInferenceRuleCollection()));
         defaultLogicalRewrites.add(new Pair<>(seqOnceCtrl, RuleCollections.buildAutogenerateIDRuleCollection()));
         defaultLogicalRewrites
-            .add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildNormalizationRuleCollection()));
+                .add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildNormalizationRuleCollection(appCtx)));
         defaultLogicalRewrites
                 .add(new Pair<>(seqCtrlNoDfs, RuleCollections.buildCondPushDownAndJoinInferenceRuleCollection()));
-        defaultLogicalRewrites.add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildLoadFieldsRuleCollection()));
+        defaultLogicalRewrites.add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildLoadFieldsRuleCollection(appCtx)));
         // fj
         defaultLogicalRewrites.add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildFuzzyJoinRuleCollection()));
         //
-        defaultLogicalRewrites.add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildNormalizationRuleCollection()));
+        defaultLogicalRewrites
+                .add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildNormalizationRuleCollection(appCtx)));
         defaultLogicalRewrites
                 .add(new Pair<>(seqCtrlNoDfs, RuleCollections.buildCondPushDownAndJoinInferenceRuleCollection()));
-        defaultLogicalRewrites.add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildLoadFieldsRuleCollection()));
+        defaultLogicalRewrites.add(new Pair<>(seqCtrlFullDfs, RuleCollections.buildLoadFieldsRuleCollection(appCtx)));
         defaultLogicalRewrites.add(new Pair<>(seqOnceCtrl, RuleCollections.buildDataExchangeRuleCollection()));
         defaultLogicalRewrites.add(new Pair<>(seqCtrlNoDfs, RuleCollections.buildConsolidationRuleCollection()));
         defaultLogicalRewrites.add(new Pair<>(seqOnceCtrl, RuleCollections.buildFulltextContainsRuleCollection()));
@@ -72,14 +76,15 @@ public class DefaultRuleSetFactory implements IRuleSetFactory {
         return defaultLogicalRewrites;
     }
 
-    public static List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> buildPhysical() {
+    public static List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> buildPhysical(
+            ICcApplicationContext appCtx) {
         List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> defaultPhysicalRewrites = new ArrayList<>();
         SequentialOnceRuleController seqOnceCtrl = new SequentialOnceRuleController(true);
         SequentialOnceRuleController seqOnceTopLevel = new SequentialOnceRuleController(false);
         defaultPhysicalRewrites
                 .add(new Pair<>(seqOnceCtrl, RuleCollections.buildPhysicalRewritesAllLevelsRuleCollection()));
         defaultPhysicalRewrites
-                .add(new Pair<>(seqOnceTopLevel, RuleCollections.buildPhysicalRewritesTopLevelRuleCollection()));
+                .add(new Pair<>(seqOnceTopLevel, RuleCollections.buildPhysicalRewritesTopLevelRuleCollection(appCtx)));
         defaultPhysicalRewrites.add(new Pair<>(seqOnceCtrl, RuleCollections.prepareForJobGenRuleCollection()));
         return defaultPhysicalRewrites;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/IRuleSetFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/IRuleSetFactory.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/IRuleSetFactory.java
index af07355..dabac3d 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/IRuleSetFactory.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/compiler/provider/IRuleSetFactory.java
@@ -20,6 +20,7 @@ package org.apache.asterix.compiler.provider;
 
 import java.util.List;
 
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.algebricks.core.rewriter.base.AbstractRuleController;
@@ -31,13 +32,15 @@ public interface IRuleSetFactory {
      * @return the logical rewrites
      * @throws AlgebricksException
      */
-    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getLogicalRewrites()
+    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getLogicalRewrites(
+            ICcApplicationContext appCtx)
             throws AlgebricksException;
 
     /**
      * @return the physical rewrites
      */
-    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getPhysicalRewrites()
+    public List<Pair<AbstractRuleController, List<IAlgebraicRewriteRule>>> getPhysicalRewrites(
+            ICcApplicationContext appCtx)
             throws AlgebricksException;
 
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/jobgen/QueryLogicalExpressionJobGen.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/jobgen/QueryLogicalExpressionJobGen.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/jobgen/QueryLogicalExpressionJobGen.java
index 54bb0bd..9f88bb6 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/jobgen/QueryLogicalExpressionJobGen.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/jobgen/QueryLogicalExpressionJobGen.java
@@ -20,6 +20,7 @@ package org.apache.asterix.jobgen;
 
 import java.util.List;
 
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.functions.FunctionDescriptorTag;
 import org.apache.asterix.external.library.ExternalFunctionDescriptorProvider;
 import org.apache.asterix.formats.base.IDataFormat;
@@ -136,8 +137,9 @@ public class QueryLogicalExpressionJobGen implements ILogicalExpressionJobGen {
             IDataFormat format = FormatUtils.getDefaultFormat();
             fd = format.resolveFunction(expr, env);
         } else {
+            ICcApplicationContext appCtx = (ICcApplicationContext) context.getAppContext();
             fd = ExternalFunctionDescriptorProvider
-                    .getExternalFunctionDescriptor((IExternalFunctionInfo) expr.getFunctionInfo());
+                    .getExternalFunctionDescriptor((IExternalFunctionInfo) expr.getFunctionInfo(), appCtx);
         }
         return fd.createEvaluatorFactory(args);
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
index ec73185..d94a045 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/base/RuleCollections.java
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.optimizer.rules.AddEquivalenceClassForRecordConstructorRule;
 import org.apache.asterix.optimizer.rules.AsterixExtractFunctionsFromJoinConditionRule;
 import org.apache.asterix.optimizer.rules.AsterixInlineVariablesRule;
@@ -161,7 +162,7 @@ public final class RuleCollections {
         return Collections.singletonList(new FullTextContainsParameterCheckRule());
     }
 
-    public static final List<IAlgebraicRewriteRule> buildNormalizationRuleCollection() {
+    public static final List<IAlgebraicRewriteRule> buildNormalizationRuleCollection(ICcApplicationContext appCtx) {
         List<IAlgebraicRewriteRule> normalization = new LinkedList<>();
         normalization.add(new ResolveVariableRule());
         normalization.add(new CheckInsertUpsertReturningRule());
@@ -186,7 +187,7 @@ public final class RuleCollections {
         // so that PushAggFunc can happen in fewer places.
         normalization.add(new PushAggFuncIntoStandaloneAggregateRule());
         normalization.add(new ListifyUnnestingFunctionRule());
-        normalization.add(new ConstantFoldingRule());
+        normalization.add(new ConstantFoldingRule(appCtx));
         normalization.add(new RemoveRedundantSelectRule());
         normalization.add(new UnnestToDataScanRule());
         normalization.add(new MetaFunctionToMetaVariableRule());
@@ -236,7 +237,7 @@ public final class RuleCollections {
         return condPushDownAndJoinInference;
     }
 
-    public static final List<IAlgebraicRewriteRule> buildLoadFieldsRuleCollection() {
+    public static final List<IAlgebraicRewriteRule> buildLoadFieldsRuleCollection(ICcApplicationContext appCtx) {
         List<IAlgebraicRewriteRule> fieldLoads = new LinkedList<>();
         fieldLoads.add(new LoadRecordFieldsRule());
         fieldLoads.add(new PushFieldAccessRule());
@@ -245,7 +246,7 @@ public final class RuleCollections {
         fieldLoads.add(new RemoveRedundantVariablesRule());
         fieldLoads.add(new AsterixInlineVariablesRule());
         fieldLoads.add(new RemoveUnusedAssignAndAggregateRule());
-        fieldLoads.add(new ConstantFoldingRule());
+        fieldLoads.add(new ConstantFoldingRule(appCtx));
         fieldLoads.add(new RemoveRedundantSelectRule());
         fieldLoads.add(new FeedScanCollectionToUnnest());
         fieldLoads.add(new NestedSubplanToJoinRule());
@@ -340,13 +341,14 @@ public final class RuleCollections {
         return physicalRewritesAllLevels;
     }
 
-    public static final List<IAlgebraicRewriteRule> buildPhysicalRewritesTopLevelRuleCollection() {
+    public static final List<IAlgebraicRewriteRule> buildPhysicalRewritesTopLevelRuleCollection(
+            ICcApplicationContext appCtx) {
         List<IAlgebraicRewriteRule> physicalRewritesTopLevel = new LinkedList<>();
         physicalRewritesTopLevel.add(new PushNestedOrderByUnderPreSortedGroupByRule());
         physicalRewritesTopLevel.add(new CopyLimitDownRule());
         // CopyLimitDownRule may generates non-topmost limits with numeric_adds functions.
         // We are going to apply a constant folding rule again for this case.
-        physicalRewritesTopLevel.add(new ConstantFoldingRule());
+        physicalRewritesTopLevel.add(new ConstantFoldingRule(appCtx));
         physicalRewritesTopLevel.add(new PushLimitIntoOrderByRule());
         physicalRewritesTopLevel.add(new IntroduceProjectsRule());
         physicalRewritesTopLevel.add(new SetAlgebricksPhysicalOperatorsRule());

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ConstantFoldingRule.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ConstantFoldingRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ConstantFoldingRule.java
index 98e9f9d..5ef41c4 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ConstantFoldingRule.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/ConstantFoldingRule.java
@@ -24,6 +24,7 @@ import java.nio.ByteBuffer;
 import java.util.List;
 
 import org.apache.asterix.common.config.GlobalConfig;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.dataflow.data.common.ExpressionTypeComputer;
 import org.apache.asterix.dataflow.data.nontagged.MissingWriterFactory;
 import org.apache.asterix.formats.nontagged.ADMPrinterFactoryProvider;
@@ -55,8 +56,8 @@ import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCa
 import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractLogicalExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
-import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
 import org.apache.hyracks.algebricks.core.algebra.expressions.ExpressionRuntimeProvider;
+import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
 import org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.StatefulFunctionCallExpression;
 import org.apache.hyracks.algebricks.core.algebra.expressions.UnnestingFunctionCallExpression;
@@ -80,16 +81,16 @@ import com.google.common.collect.ImmutableSet;
 public class ConstantFoldingRule implements IAlgebraicRewriteRule {
 
     private final ConstantFoldingVisitor cfv = new ConstantFoldingVisitor();
+    private final JobGenContext jobGenCtx;
 
     // Function Identifier sets that the ConstantFolding rule should skip to apply.
     // Most of them are record-related functions.
     private static final ImmutableSet<FunctionIdentifier> FUNC_ID_SET_THAT_SHOULD_NOT_BE_APPLIED =
-            ImmutableSet.of(BuiltinFunctions.RECORD_MERGE, BuiltinFunctions.ADD_FIELDS,
-                    BuiltinFunctions.REMOVE_FIELDS, BuiltinFunctions.GET_RECORD_FIELDS,
-                    BuiltinFunctions.GET_RECORD_FIELD_VALUE, BuiltinFunctions.FIELD_ACCESS_NESTED,
-                    BuiltinFunctions.GET_ITEM, BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR,
-                    BuiltinFunctions.FIELD_ACCESS_BY_INDEX, BuiltinFunctions.CAST_TYPE,
-                    BuiltinFunctions.META, BuiltinFunctions.META_KEY);
+            ImmutableSet.of(BuiltinFunctions.RECORD_MERGE, BuiltinFunctions.ADD_FIELDS, BuiltinFunctions.REMOVE_FIELDS,
+                    BuiltinFunctions.GET_RECORD_FIELDS, BuiltinFunctions.GET_RECORD_FIELD_VALUE,
+                    BuiltinFunctions.FIELD_ACCESS_NESTED, BuiltinFunctions.GET_ITEM,
+                    BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR, BuiltinFunctions.FIELD_ACCESS_BY_INDEX,
+                    BuiltinFunctions.CAST_TYPE, BuiltinFunctions.META, BuiltinFunctions.META_KEY);
 
     /** Throws exceptions in substituiteProducedVariable, setVarType, and one getVarType method. */
     private static final IVariableTypeEnvironment _emptyTypeEnv = new IVariableTypeEnvironment() {
@@ -121,16 +122,17 @@ public class ConstantFoldingRule implements IAlgebraicRewriteRule {
         }
     };
 
-    private static final JobGenContext _jobGenCtx = new JobGenContext(null, null, null,
-            SerializerDeserializerProvider.INSTANCE, BinaryHashFunctionFactoryProvider.INSTANCE,
-            BinaryHashFunctionFamilyProvider.INSTANCE, BinaryComparatorFactoryProvider.INSTANCE,
-            TypeTraitProvider.INSTANCE, BinaryBooleanInspector.FACTORY, BinaryIntegerInspector.FACTORY,
-            ADMPrinterFactoryProvider.INSTANCE, MissingWriterFactory.INSTANCE, null,
-            new ExpressionRuntimeProvider(QueryLogicalExpressionJobGen.INSTANCE),
-            ExpressionTypeComputer.INSTANCE, null, null, null, null, GlobalConfig.DEFAULT_FRAME_SIZE, null);
-
     private static final IOperatorSchema[] _emptySchemas = new IOperatorSchema[] {};
 
+    public ConstantFoldingRule(ICcApplicationContext appCtx) {
+        jobGenCtx = new JobGenContext(null, null, appCtx, SerializerDeserializerProvider.INSTANCE,
+                BinaryHashFunctionFactoryProvider.INSTANCE, BinaryHashFunctionFamilyProvider.INSTANCE,
+                BinaryComparatorFactoryProvider.INSTANCE, TypeTraitProvider.INSTANCE, BinaryBooleanInspector.FACTORY,
+                BinaryIntegerInspector.FACTORY, ADMPrinterFactoryProvider.INSTANCE, MissingWriterFactory.INSTANCE, null,
+                new ExpressionRuntimeProvider(QueryLogicalExpressionJobGen.INSTANCE), ExpressionTypeComputer.INSTANCE,
+                null, null, null, null, GlobalConfig.DEFAULT_FRAME_SIZE, null);
+    }
+
     @Override
     public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
             throws AlgebricksException {
@@ -168,13 +170,13 @@ public class ConstantFoldingRule implements IAlgebraicRewriteRule {
         @Override
         public Pair<Boolean, ILogicalExpression> visitConstantExpression(ConstantExpression expr, Void arg)
                 throws AlgebricksException {
-            return new Pair<Boolean, ILogicalExpression>(false, expr);
+            return new Pair<>(false, expr);
         }
 
         @Override
         public Pair<Boolean, ILogicalExpression> visitVariableReferenceExpression(VariableReferenceExpression expr,
                 Void arg) throws AlgebricksException {
-            return new Pair<Boolean, ILogicalExpression>(false, expr);
+            return new Pair<>(false, expr);
         }
 
         @Override
@@ -182,12 +184,12 @@ public class ConstantFoldingRule implements IAlgebraicRewriteRule {
                 Void arg) throws AlgebricksException {
             boolean changed = changeRec(expr, arg);
             if (!checkArgs(expr) || !expr.isFunctional()) {
-                return new Pair<Boolean, ILogicalExpression>(changed, expr);
+                return new Pair<>(changed, expr);
             }
 
             // Skip Constant Folding for the record-related functions.
             if (FUNC_ID_SET_THAT_SHOULD_NOT_BE_APPLIED.contains(expr.getFunctionIdentifier())) {
-                return new Pair<Boolean, ILogicalExpression>(false, null);
+                return new Pair<>(false, null);
             }
 
             //Current List SerDe assumes a strongly typed list, so we do not constant fold the list constructors if they are not strongly typed
@@ -199,7 +201,7 @@ public class ConstantFoldingRule implements IAlgebraicRewriteRule {
                     //case1: listType == null,  could be a nested list inside a list<ANY>
                     //case2: itemType = ANY
                     //case3: itemType = a nested list
-                    return new Pair<Boolean, ILogicalExpression>(false, null);
+                    return new Pair<>(false, null);
                 }
             }
             if (expr.getFunctionIdentifier().equals(BuiltinFunctions.FIELD_ACCESS_BY_NAME)) {
@@ -208,20 +210,20 @@ public class ConstantFoldingRule implements IAlgebraicRewriteRule {
                 int k = rt.getFieldIndex(str);
                 if (k >= 0) {
                     // wait for the ByNameToByIndex rule to apply
-                    return new Pair<Boolean, ILogicalExpression>(changed, expr);
+                    return new Pair<>(changed, expr);
                 }
             }
 
-            IScalarEvaluatorFactory fact = _jobGenCtx.getExpressionRuntimeProvider().createEvaluatorFactory(expr,
-                    _emptyTypeEnv, _emptySchemas, _jobGenCtx);
+            IScalarEvaluatorFactory fact = jobGenCtx.getExpressionRuntimeProvider().createEvaluatorFactory(expr,
+                    _emptyTypeEnv, _emptySchemas, jobGenCtx);
             try {
                 IScalarEvaluator eval = fact.createScalarEvaluator(null);
                 eval.evaluate(null, p);
                 Object t = _emptyTypeEnv.getType(expr);
 
                 @SuppressWarnings("rawtypes")
-                ISerializerDeserializer serde = _jobGenCtx.getSerializerDeserializerProvider()
-                        .getSerializerDeserializer(t);
+                ISerializerDeserializer serde =
+                        jobGenCtx.getSerializerDeserializerProvider().getSerializerDeserializer(t);
                 bbis.setByteBuffer(ByteBuffer.wrap(p.getByteArray(), p.getStartOffset(), p.getLength()), 0);
                 IAObject o = (IAObject) serde.deserialize(dis);
                 return new Pair<>(true, new ConstantExpression(new AsterixConstantValue(o)));
@@ -234,21 +236,21 @@ public class ConstantFoldingRule implements IAlgebraicRewriteRule {
         public Pair<Boolean, ILogicalExpression> visitAggregateFunctionCallExpression(
                 AggregateFunctionCallExpression expr, Void arg) throws AlgebricksException {
             boolean changed = changeRec(expr, arg);
-            return new Pair<Boolean, ILogicalExpression>(changed, expr);
+            return new Pair<>(changed, expr);
         }
 
         @Override
         public Pair<Boolean, ILogicalExpression> visitStatefulFunctionCallExpression(
                 StatefulFunctionCallExpression expr, Void arg) throws AlgebricksException {
             boolean changed = changeRec(expr, arg);
-            return new Pair<Boolean, ILogicalExpression>(changed, expr);
+            return new Pair<>(changed, expr);
         }
 
         @Override
         public Pair<Boolean, ILogicalExpression> visitUnnestingFunctionCallExpression(
                 UnnestingFunctionCallExpression expr, Void arg) throws AlgebricksException {
             boolean changed = changeRec(expr, arg);
-            return new Pair<Boolean, ILogicalExpression>(changed, expr);
+            return new Pair<>(changed, expr);
         }
 
         private boolean changeRec(AbstractFunctionCallExpression expr, Void arg) throws AlgebricksException {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AbstractLangTranslator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AbstractLangTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AbstractLangTranslator.java
index 3cdeb6f..e2589da 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AbstractLangTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/AbstractLangTranslator.java
@@ -25,6 +25,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.asterix.common.api.IClusterManagementWork.ClusterState;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.lang.common.statement.DatasetDecl;
@@ -36,7 +37,6 @@ import org.apache.asterix.lang.common.statement.NodeGroupDropStatement;
 import org.apache.asterix.metadata.dataset.hints.DatasetHints;
 import org.apache.asterix.metadata.entities.Dataverse;
 import org.apache.asterix.metadata.utils.MetadataConstants;
-import org.apache.asterix.runtime.utils.AppContextInfo;
 import org.apache.asterix.runtime.utils.ClusterStateManager;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -49,11 +49,12 @@ public abstract class AbstractLangTranslator {
 
     private static final Logger LOGGER = Logger.getLogger(AbstractLangTranslator.class.getName());
 
-    public void validateOperation(Dataverse defaultDataverse, Statement stmt) throws AsterixException {
+    public void validateOperation(ICcApplicationContext appCtx, Dataverse defaultDataverse, Statement stmt)
+            throws AsterixException {
 
         if (!(ClusterStateManager.INSTANCE.getState().equals(ClusterState.ACTIVE)
                 && ClusterStateManager.INSTANCE.isGlobalRecoveryCompleted())) {
-            int maxWaitCycles = AppContextInfo.INSTANCE.getExternalProperties().getMaxWaitClusterActive();
+            int maxWaitCycles = appCtx.getExternalProperties().getMaxWaitClusterActive();
             try {
                 ClusterStateManager.INSTANCE.waitForState(ClusterState.ACTIVE, maxWaitCycles, TimeUnit.SECONDS);
             } catch (HyracksDataException e) {
@@ -80,7 +81,7 @@ public abstract class AbstractLangTranslator {
         }
 
         if (!ClusterStateManager.INSTANCE.isGlobalRecoveryCompleted()) {
-            int maxWaitCycles = AppContextInfo.INSTANCE.getExternalProperties().getMaxWaitClusterActive();
+            int maxWaitCycles = appCtx.getExternalProperties().getMaxWaitClusterActive();
             int waitCycleCount = 0;
             try {
                 while (!ClusterStateManager.INSTANCE.isGlobalRecoveryCompleted() && waitCycleCount < maxWaitCycles) {
@@ -162,7 +163,7 @@ public abstract class AbstractLangTranslator {
                     Pair<Boolean, String> validationResult = null;
                     StringBuffer errorMsgBuffer = new StringBuffer();
                     for (Entry<String, String> hint : hints.entrySet()) {
-                        validationResult = DatasetHints.validate(hint.getKey(), hint.getValue());
+                        validationResult = DatasetHints.validate(appCtx, hint.getKey(), hint.getValue());
                         if (!validationResult.first) {
                             errorMsgBuffer.append("Dataset: " + datasetStmt.getName().getValue()
                                     + " error in processing hint: " + hint.getKey() + " " + validationResult.second);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IStatementExecutorFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IStatementExecutorFactory.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IStatementExecutorFactory.java
index cf54921..23365de 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IStatementExecutorFactory.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IStatementExecutorFactory.java
@@ -21,6 +21,7 @@ package org.apache.asterix.translator;
 import java.util.List;
 
 import org.apache.asterix.common.context.IStorageComponentProvider;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.lang.common.base.Statement;
 
@@ -44,6 +45,6 @@ public interface IStatementExecutorFactory {
      *            provides storage related components
      * @return an implementation of {@code IStatementExecutor} thaxt is used to execute the passed list of statements
      */
-    IStatementExecutor create(List<Statement> statements, SessionConfig conf,
+    IStatementExecutor create(ICcApplicationContext appCtx, List<Statement> statements, SessionConfig conf,
             ILangCompilationProvider compilationProvider, IStorageComponentProvider storageComponentProvider);
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index c4cc486..4b4ef8e 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -34,6 +34,7 @@ import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
 import org.apache.asterix.algebra.operators.CommitOperator;
 import org.apache.asterix.common.config.DatasetConfig.DatasetType;
 import org.apache.asterix.common.config.MetadataProperties;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.CompilationException;
 import org.apache.asterix.common.functions.FunctionConstants;
 import org.apache.asterix.common.functions.FunctionSignature;
@@ -94,7 +95,6 @@ import org.apache.asterix.om.functions.FunctionInfo;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.om.types.IAType;
 import org.apache.asterix.runtime.formats.FormatUtils;
-import org.apache.asterix.runtime.utils.AppContextInfo;
 import org.apache.asterix.translator.CompiledStatements.CompiledInsertStatement;
 import org.apache.asterix.translator.CompiledStatements.CompiledLoadFromFileStatement;
 import org.apache.asterix.translator.CompiledStatements.CompiledSubscribeFeedStatement;
@@ -316,7 +316,7 @@ class LangExpressionToPlanTranslator
         if (outputDatasetName == null) {
             FileSplit outputFileSplit = metadataProvider.getOutputFile();
             if (outputFileSplit == null) {
-                outputFileSplit = getDefaultOutputFileLocation();
+                outputFileSplit = getDefaultOutputFileLocation(metadataProvider.getApplicationContext());
             }
             metadataProvider.setOutputFile(outputFileSplit);
 
@@ -606,8 +606,8 @@ class LangExpressionToPlanTranslator
                 }
             }
             // A change feed, we don't need the assign to access PKs
-            upsertOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading,
-                    metaExpSingletonList, InsertDeleteUpsertOperator.Kind.UPSERT, false);
+            upsertOp = new InsertDeleteUpsertOperator(targetDatasource, varRef, varRefsForLoading, metaExpSingletonList,
+                    InsertDeleteUpsertOperator.Kind.UPSERT, false);
             // Create and add a new variable used for representing the original record
             upsertOp.setPrevRecordVar(context.newVar());
             upsertOp.setPrevRecordType(targetDatasource.getItemType());
@@ -730,11 +730,11 @@ class LangExpressionToPlanTranslator
                 dataset.getDatasetDetails(), domain);
     }
 
-    private FileSplit getDefaultOutputFileLocation() throws MetadataException {
+    private FileSplit getDefaultOutputFileLocation(ICcApplicationContext appCtx) throws MetadataException {
         String outputDir = System.getProperty("java.io.tmpDir");
         String filePath =
                 outputDir + System.getProperty("file.separator") + OUTPUT_FILE_PREFIX + outputFileID.incrementAndGet();
-        MetadataProperties metadataProperties = AppContextInfo.INSTANCE.getMetadataProperties();
+        MetadataProperties metadataProperties = appCtx.getMetadataProperties();
         return new ManagedFileSplit(metadataProperties.getMetadataNodeName(), filePath);
     }
 
@@ -1005,8 +1005,8 @@ class LangExpressionToPlanTranslator
         arguments.add(new MutableObject<>(ConstantExpression.TRUE));
         arguments.add(new MutableObject<>(new VariableReferenceExpression(opAndVarForThen.second)));
         arguments.add(new MutableObject<>(new VariableReferenceExpression(opAndVarForElse.second)));
-        AbstractFunctionCallExpression swithCaseExpr = new ScalarFunctionCallExpression(
-                FunctionUtil.getFunctionInfo(BuiltinFunctions.SWITCH_CASE), arguments);
+        AbstractFunctionCallExpression swithCaseExpr =
+                new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SWITCH_CASE), arguments);
         AssignOperator assignOp = new AssignOperator(selectVar, new MutableObject<>(swithCaseExpr));
         assignOp.getInputs().add(new MutableObject<>(opAndVarForElse.first));
 
@@ -1176,8 +1176,7 @@ class LangExpressionToPlanTranslator
         firstOp.getInputs().add(topOp);
         topOp = lastOp;
 
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 =
-                langExprToAlgExpression(qe.getSatisfiesExpr(), topOp);
+        Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = langExprToAlgExpression(qe.getSatisfiesExpr(), topOp);
 
         AggregateFunctionCallExpression fAgg;
         SelectOperator s;
@@ -1219,8 +1218,7 @@ class LangExpressionToPlanTranslator
             Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo1 = langExprToAlgExpression(fb.getLeftExpr(), topOp);
             f.getArguments().add(new MutableObject<>(eo1.first));
             topOp = eo1.second;
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 =
-                    langExprToAlgExpression(fb.getRightExpr(), topOp);
+            Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo2 = langExprToAlgExpression(fb.getRightExpr(), topOp);
             f.getArguments().add(new MutableObject<>(eo2.first));
             topOp = eo2.second;
         }
@@ -1699,9 +1697,8 @@ class LangExpressionToPlanTranslator
         Mutable<ILogicalExpression> expr = new MutableObject<>(
                 new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.IS_UNKOWN),
                         new ArrayList<>(Collections.singletonList(new MutableObject<>(logicalExpr)))));
-        arguments.add(new MutableObject<>(
-                new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.NOT),
-                        new ArrayList<>(Collections.singletonList(expr)))));
+        arguments.add(new MutableObject<>(new ScalarFunctionCallExpression(
+                FunctionUtil.getFunctionInfo(BuiltinFunctions.NOT), new ArrayList<>(Collections.singletonList(expr)))));
         return new MutableObject<>(
                 new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.AND), arguments));
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index f0e8588..b12935d 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -63,7 +63,6 @@ import org.apache.asterix.lang.common.util.FunctionUtil;
 import org.apache.asterix.metadata.declared.MetadataProvider;
 import org.apache.asterix.optimizer.base.FuzzyUtils;
 import org.apache.asterix.runtime.job.listener.JobEventListenerFactory;
-import org.apache.asterix.runtime.utils.AppContextInfo;
 import org.apache.asterix.transaction.management.service.transaction.JobIdFactory;
 import org.apache.asterix.translator.CompiledStatements.ICompiledDmlStatement;
 import org.apache.asterix.translator.IStatementExecutor.Stats;
@@ -113,13 +112,13 @@ public class APIFramework {
     private static final int MIN_FRAME_LIMIT_FOR_JOIN = 5;
 
     // A white list of supported configurable parameters.
-    private static final Set<String> CONFIGURABLE_PARAMETER_NAMES = ImmutableSet.of(
-            CompilerProperties.COMPILER_JOINMEMORY_KEY, CompilerProperties.COMPILER_GROUPMEMORY_KEY,
-            CompilerProperties.COMPILER_SORTMEMORY_KEY, CompilerProperties.COMPILER_PARALLELISM_KEY,
-            FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, FuzzyUtils.SIM_FUNCTION_PROP_NAME,
-            FuzzyUtils.SIM_THRESHOLD_PROP_NAME, SubscribeFeedStatement.WAIT_FOR_COMPLETION,
-            FeedActivityDetails.FEED_POLICY_NAME, FeedActivityDetails.COLLECT_LOCATIONS, "inline_with", "hash_merge",
-            "output-record-type");
+    private static final Set<String> CONFIGURABLE_PARAMETER_NAMES =
+            ImmutableSet.of(CompilerProperties.COMPILER_JOINMEMORY_KEY, CompilerProperties.COMPILER_GROUPMEMORY_KEY,
+                    CompilerProperties.COMPILER_SORTMEMORY_KEY, CompilerProperties.COMPILER_PARALLELISM_KEY,
+                    FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, FuzzyUtils.SIM_FUNCTION_PROP_NAME,
+                    FuzzyUtils.SIM_THRESHOLD_PROP_NAME, SubscribeFeedStatement.WAIT_FOR_COMPLETION,
+                    FeedActivityDetails.FEED_POLICY_NAME, FeedActivityDetails.COLLECT_LOCATIONS, "inline_with",
+                    "hash_merge", "output-record-type");
 
     private final IRewriterFactory rewriterFactory;
     private final IAstPrintVisitorFactory astPrintVisitorFactory;
@@ -145,8 +144,7 @@ public class APIFramework {
                 IExpressionEvalSizeComputer expressionEvalSizeComputer,
                 IMergeAggregationExpressionFactory mergeAggregationExpressionFactory,
                 IExpressionTypeComputer expressionTypeComputer, IMissableTypeComputer missableTypeComputer,
-                IConflictingTypeResolver conflictingTypeResolver,
-                PhysicalOptimizationConfig physicalOptimizationConfig,
+                IConflictingTypeResolver conflictingTypeResolver, PhysicalOptimizationConfig physicalOptimizationConfig,
                 AlgebricksPartitionConstraint clusterLocations) {
             return new AlgebricksOptimizationContext(varCounter, expressionEvalSizeComputer,
                     mergeAggregationExpressionFactory, expressionTypeComputer, missableTypeComputer,
@@ -222,7 +220,7 @@ public class APIFramework {
             }
             printPlanPostfix(conf);
         }
-        CompilerProperties compilerProperties = AppContextInfo.INSTANCE.getCompilerProperties();
+        CompilerProperties compilerProperties = metadataProvider.getApplicationContext().getCompilerProperties();
         int frameSize = compilerProperties.getFrameSize();
         Map<String, String> querySpecificConfig = metadataProvider.getConfig();
         validateConfig(querySpecificConfig); // Validates the user-overridden query parameters.
@@ -243,8 +241,8 @@ public class APIFramework {
         HeuristicCompilerFactoryBuilder builder =
                 new HeuristicCompilerFactoryBuilder(OptimizationContextFactory.INSTANCE);
         builder.setPhysicalOptimizationConfig(OptimizationConfUtil.getPhysicalOptimizationConfig());
-        builder.setLogicalRewrites(ruleSetFactory.getLogicalRewrites());
-        builder.setPhysicalRewrites(ruleSetFactory.getPhysicalRewrites());
+        builder.setLogicalRewrites(ruleSetFactory.getLogicalRewrites(metadataProvider.getApplicationContext()));
+        builder.setPhysicalRewrites(ruleSetFactory.getPhysicalRewrites(metadataProvider.getApplicationContext()));
         IDataFormat format = metadataProvider.getFormat();
         ICompilerFactory compilerFactory = builder.create();
         builder.setExpressionEvalSizeComputer(format.getExpressionEvalSizeComputer());
@@ -282,7 +280,8 @@ public class APIFramework {
             try {
                 LogicalOperatorPrettyPrintVisitor pvisitor = new LogicalOperatorPrettyPrintVisitor();
                 PlanPrettyPrinter.printPlan(plan, pvisitor, 0);
-                ResultUtil.printResults(pvisitor.get().toString(), conf, new Stats(), null);
+                ResultUtil.printResults(metadataProvider.getApplicationContext(), pvisitor.get().toString(), conf,
+                        new Stats(), null);
                 return null;
             } catch (IOException e) {
                 throw new AlgebricksException(e);
@@ -296,8 +295,7 @@ public class APIFramework {
         builder.setBinaryBooleanInspectorFactory(format.getBinaryBooleanInspectorFactory());
         builder.setBinaryIntegerInspectorFactory(format.getBinaryIntegerInspectorFactory());
         builder.setComparatorFactoryProvider(format.getBinaryComparatorFactoryProvider());
-        builder.setExpressionRuntimeProvider(
-                new ExpressionRuntimeProvider(QueryLogicalExpressionJobGen.INSTANCE));
+        builder.setExpressionRuntimeProvider(new ExpressionRuntimeProvider(QueryLogicalExpressionJobGen.INSTANCE));
         builder.setHashFunctionFactoryProvider(format.getBinaryHashFunctionFactoryProvider());
         builder.setHashFunctionFamilyProvider(format.getBinaryHashFunctionFamilyProvider());
         builder.setMissingWriterFactory(format.getMissingWriterFactory());
@@ -327,7 +325,7 @@ public class APIFramework {
 
         JobEventListenerFactory jobEventListenerFactory =
                 new JobEventListenerFactory(asterixJobId, metadataProvider.isWriteTransaction());
-        JobSpecification spec = compiler.createJob(AppContextInfo.INSTANCE, jobEventListenerFactory);
+        JobSpecification spec = compiler.createJob(metadataProvider.getApplicationContext(), jobEventListenerFactory);
 
         // When the top-level statement is a query, the statement parameter is null.
         if (statement == null) {
@@ -465,8 +463,7 @@ public class APIFramework {
             int minFrameLimit)
             throws AlgebricksException {
         IOptionType<Long> longBytePropertyInterpreter = OptionTypes.LONG_BYTE_UNIT;
-        long memBudget =
-                parameter == null ? memBudgetInConfiguration : longBytePropertyInterpreter.parse(parameter);
+        long memBudget = parameter == null ? memBudgetInConfiguration : longBytePropertyInterpreter.parse(parameter);
         int frameLimit = (int) (memBudget / frameSize);
         if (frameLimit < minFrameLimit) {
             throw AsterixException.create(ErrorCode.COMPILATION_BAD_QUERY_PARAMETER_VALUE, parameterName,

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AppRuntimeContextProviderForRecovery.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AppRuntimeContextProviderForRecovery.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AppRuntimeContextProviderForRecovery.java
index d8a2fab..6a3472d 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AppRuntimeContextProviderForRecovery.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AppRuntimeContextProviderForRecovery.java
@@ -20,7 +20,7 @@ package org.apache.asterix.api.common;
 
 import org.apache.asterix.app.nc.NCAppRuntimeContext;
 import org.apache.asterix.common.api.ThreadExecutor;
-import org.apache.asterix.common.api.IAppRuntimeContext;
+import org.apache.asterix.common.api.INcApplicationContext;
 import org.apache.asterix.common.api.IDatasetLifecycleManager;
 import org.apache.asterix.common.transactions.IAppRuntimeContextProvider;
 import org.apache.asterix.common.transactions.ITransactionSubsystem;
@@ -85,7 +85,7 @@ public class AppRuntimeContextProviderForRecovery implements IAppRuntimeContextP
     }
 
     @Override
-    public IAppRuntimeContext getAppContext() {
+    public INcApplicationContext getAppContext() {
         return asterixAppRuntimeContext;
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/AbstractQueryApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/AbstractQueryApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/AbstractQueryApiServlet.java
index f79a2da..a9c4b39 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/AbstractQueryApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/AbstractQueryApiServlet.java
@@ -26,6 +26,7 @@ import java.util.UUID;
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.asterix.app.result.ResultReader;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.common.exceptions.RuntimeDataException;
 import org.apache.hyracks.api.client.IHyracksClientConnection;
@@ -34,6 +35,7 @@ import org.apache.hyracks.client.dataset.HyracksDataset;
 import org.apache.hyracks.http.server.AbstractServlet;
 
 public class AbstractQueryApiServlet extends AbstractServlet {
+    protected final ICcApplicationContext appCtx;
 
     public enum ResultFields {
         REQUEST_ID("requestID"),
@@ -91,8 +93,9 @@ public class AbstractQueryApiServlet extends AbstractServlet {
         }
     }
 
-    AbstractQueryApiServlet(ConcurrentMap<String, Object> ctx, String[] paths) {
+    AbstractQueryApiServlet(ICcApplicationContext appCtx, ConcurrentMap<String, Object> ctx, String[] paths) {
         super(ctx, paths);
+        this.appCtx = appCtx;
     }
 
     protected IHyracksDataset getHyracksDataset() throws Exception { // NOSONAR
@@ -101,8 +104,8 @@ public class AbstractQueryApiServlet extends AbstractServlet {
             if (hds == null) {
                 hds = (IHyracksDataset) ctx.get(HYRACKS_DATASET_ATTR);
                 if (hds == null) {
-                    hds = new HyracksDataset(getHyracksClientConnection(), ResultReader.FRAME_SIZE,
-                            ResultReader.NUM_READERS);
+                    hds = new HyracksDataset(getHyracksClientConnection(),
+                            appCtx.getCompilerProperties().getFrameSize(), ResultReader.NUM_READERS);
                     ctx.put(HYRACKS_DATASET_ATTR, hds);
                 }
             }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
index e435da7..3384332 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ApiServlet.java
@@ -38,6 +38,7 @@ import javax.imageio.ImageIO;
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.context.IStorageComponentProvider;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.lang.aql.parser.TokenMgrError;
@@ -67,15 +68,17 @@ public class ApiServlet extends AbstractServlet {
     private static final Logger LOGGER = Logger.getLogger(ApiServlet.class.getName());
     public static final String HTML_STATEMENT_SEPARATOR = "<!-- BEGIN -->";
 
+    private final ICcApplicationContext appCtx;
     private final ILangCompilationProvider aqlCompilationProvider;
     private final ILangCompilationProvider sqlppCompilationProvider;
     private final IStatementExecutorFactory statementExectorFactory;
     private final IStorageComponentProvider componentProvider;
 
-    public ApiServlet(ConcurrentMap<String, Object> ctx, String[] paths,
+    public ApiServlet(ConcurrentMap<String, Object> ctx, String[] paths, ICcApplicationContext appCtx,
             ILangCompilationProvider aqlCompilationProvider, ILangCompilationProvider sqlppCompilationProvider,
             IStatementExecutorFactory statementExecutorFactory, IStorageComponentProvider componentProvider) {
         super(ctx, paths);
+        this.appCtx = appCtx;
         this.aqlCompilationProvider = aqlCompilationProvider;
         this.sqlppCompilationProvider = sqlppCompilationProvider;
         this.statementExectorFactory = statementExecutorFactory;
@@ -126,7 +129,8 @@ public class ApiServlet extends AbstractServlet {
                 synchronized (ctx) {
                     hds = (IHyracksDataset) ctx.get(HYRACKS_DATASET_ATTR);
                     if (hds == null) {
-                        hds = new HyracksDataset(hcc, ResultReader.FRAME_SIZE, ResultReader.NUM_READERS);
+                        hds = new HyracksDataset(hcc, appCtx.getCompilerProperties().getFrameSize(),
+                                ResultReader.NUM_READERS);
                         ctx.put(HYRACKS_DATASET_ATTR, hds);
                     }
                 }
@@ -140,7 +144,7 @@ public class ApiServlet extends AbstractServlet {
             sessionConfig.setOOBData(isSet(printExprParam), isSet(printRewrittenExprParam),
                     isSet(printLogicalPlanParam), isSet(printOptimizedLogicalPlanParam), isSet(printJob));
             MetadataManager.INSTANCE.init();
-            IStatementExecutor translator = statementExectorFactory.create(aqlStatements, sessionConfig,
+            IStatementExecutor translator = statementExectorFactory.create(appCtx, aqlStatements, sessionConfig,
                     compilationProvider, componentProvider);
             double duration;
             long startTime = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java
index 984eef2..82e8f7a 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterApiServlet.java
@@ -28,7 +28,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Pattern;
 
-import org.apache.asterix.runtime.utils.AppContextInfo;
+import org.apache.asterix.runtime.utils.CcApplicationContext;
 import org.apache.asterix.runtime.utils.ClusterStateManager;
 import org.apache.hyracks.api.config.IOption;
 import org.apache.hyracks.api.config.Section;
@@ -99,8 +99,8 @@ public class ClusterApiServlet extends AbstractServlet {
 
     protected ObjectNode getClusterStateJSON(IServletRequest request, String pathToNode) {
         ObjectNode json = ClusterStateManager.INSTANCE.getClusterStateDescription();
-        AppContextInfo appConfig = (AppContextInfo) ctx.get(ASTERIX_APP_CONTEXT_INFO_ATTR);
-        json.putPOJO("config", ConfigUtils.getSectionOptionsForJSON(appConfig.getCCServiceContext().getAppConfig(),
+        CcApplicationContext appConfig = (CcApplicationContext) ctx.get(ASTERIX_APP_CONTEXT_INFO_ATTR);
+        json.putPOJO("config", ConfigUtils.getSectionOptionsForJSON(appConfig.getServiceContext().getAppConfig(),
                 Section.COMMON, getConfigSelector()));
 
         ArrayNode ncs = (ArrayNode) json.get("ncs");

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java
index 869289a..cb3c063 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ConnectorApiServlet.java
@@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.file.StorageComponentProvider;
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.MetadataTransactionContext;
@@ -58,9 +59,11 @@ import io.netty.handler.codec.http.HttpResponseStatus;
  */
 public class ConnectorApiServlet extends AbstractServlet {
     private static final Logger LOGGER = Logger.getLogger(ConnectorApiServlet.class.getName());
+    private ICcApplicationContext appCtx;
 
-    public ConnectorApiServlet(ConcurrentMap<String, Object> ctx, String[] paths) {
+    public ConnectorApiServlet(ConcurrentMap<String, Object> ctx, String[] paths, ICcApplicationContext appCtx) {
         super(ctx, paths);
+        this.appCtx = appCtx;
     }
 
     @Override
@@ -91,7 +94,7 @@ public class ConnectorApiServlet extends AbstractServlet {
             MetadataManager.INSTANCE.init();
             MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
             // Retrieves file splits of the dataset.
-            MetadataProvider metadataProvider = new MetadataProvider(null, new StorageComponentProvider());
+            MetadataProvider metadataProvider = new MetadataProvider(appCtx, null, new StorageComponentProvider());
             try {
                 metadataProvider.setMetadataTxnContext(mdTxnCtx);
                 Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DdlApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DdlApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DdlApiServlet.java
index a994470..4c1dbf7 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DdlApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DdlApiServlet.java
@@ -21,6 +21,7 @@ package org.apache.asterix.api.http.server;
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.asterix.common.context.IStorageComponentProvider;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.translator.IStatementExecutorFactory;
@@ -30,10 +31,10 @@ public class DdlApiServlet extends RestApiServlet {
     private static final byte ALLOWED_CATEGORIES =
             Statement.Category.QUERY | Statement.Category.UPDATE | Statement.Category.DDL;
 
-    public DdlApiServlet(ConcurrentMap<String, Object> ctx, String[] paths,
+    public DdlApiServlet(ConcurrentMap<String, Object> ctx, String[] paths, ICcApplicationContext appCtx,
             ILangCompilationProvider compilationProvider, IStatementExecutorFactory statementExecutorFactory,
             IStorageComponentProvider componentProvider) {
-        super(ctx, paths, compilationProvider, statementExecutorFactory, componentProvider);
+        super(ctx, paths, appCtx, compilationProvider, statementExecutorFactory, componentProvider);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
index 788927f..dcd0e70 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/DiagnosticsApiServlet.java
@@ -35,7 +35,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.asterix.api.http.servlet.ServletConstants;
-import org.apache.asterix.runtime.utils.AppContextInfo;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.hyracks.api.client.IHyracksClientConnection;
 import org.apache.hyracks.http.api.IServletRequest;
 import org.apache.hyracks.http.api.IServletResponse;
@@ -49,9 +49,11 @@ import io.netty.handler.codec.http.HttpResponseStatus;
 
 public class DiagnosticsApiServlet extends NodeControllerDetailsApiServlet {
     private static final Logger LOGGER = Logger.getLogger(DiagnosticsApiServlet.class.getName());
+    private final ICcApplicationContext appCtx;
 
-    public DiagnosticsApiServlet(ConcurrentMap<String, Object> ctx, String... paths) {
+    public DiagnosticsApiServlet(ConcurrentMap<String, Object> ctx, String[] paths, ICcApplicationContext appCtx) {
         super(ctx, paths);
+        this.appCtx = appCtx;
     }
 
     @Override
@@ -93,10 +95,9 @@ public class DiagnosticsApiServlet extends NodeControllerDetailsApiServlet {
                 executor.submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getNodeDetailsJSON(null, true, false)))));
 
         Map<String, Map<String, Future<ObjectNode>>> ncDataMap = new HashMap<>();
-        for (String nc : AppContextInfo.INSTANCE.getMetadataProperties().getNodeNames()) {
+        for (String nc : appCtx.getMetadataProperties().getNodeNames()) {
             Map<String, Future<ObjectNode>> ncData = new HashMap<>();
-            ncData.put("threaddump",
-                    executor.submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getThreadDump(nc)))));
+            ncData.put("threaddump", executor.submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getThreadDump(nc)))));
             ncData.put("config", executor
                     .submit(() -> fixupKeys((ObjectNode) om.readTree(hcc.getNodeDetailsJSON(nc, false, true)))));
             ncData.put("stats", executor.submit(() -> fixupKeys(processNodeStats(hcc, nc))));

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FullApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FullApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FullApiServlet.java
index eafae35..0a461c7 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FullApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/FullApiServlet.java
@@ -21,6 +21,7 @@ package org.apache.asterix.api.http.server;
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.asterix.common.context.IStorageComponentProvider;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.translator.IStatementExecutorFactory;
@@ -32,10 +33,10 @@ public class FullApiServlet extends RestApiServlet {
     private static final byte ALLOWED_CATEGORIES = Statement.Category.QUERY | Statement.Category.UPDATE
             | Statement.Category.DDL | Statement.Category.PROCEDURE;
 
-    public FullApiServlet(ConcurrentMap<String, Object> ctx, String[] paths,
+    public FullApiServlet(ConcurrentMap<String, Object> ctx, String[] paths, ICcApplicationContext appCtx,
             ILangCompilationProvider compilationProvider, IStatementExecutorFactory statementExecutorFactory,
             IStorageComponentProvider componentProvider) {
-        super(ctx, paths, compilationProvider, statementExecutorFactory, componentProvider);
+        super(ctx, paths, appCtx, compilationProvider, statementExecutorFactory, componentProvider);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/c67f33dd/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryApiServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryApiServlet.java
index 5075795..3e692d3 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryApiServlet.java
@@ -21,6 +21,7 @@ package org.apache.asterix.api.http.server;
 import java.util.concurrent.ConcurrentMap;
 
 import org.apache.asterix.common.context.IStorageComponentProvider;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.translator.IStatementExecutorFactory;
@@ -29,10 +30,10 @@ import org.apache.hyracks.http.api.IServletRequest;
 public class QueryApiServlet extends RestApiServlet {
     private static final byte ALLOWED_CATEGORIES = Statement.Category.QUERY;
 
-    public QueryApiServlet(ConcurrentMap<String, Object> ctx, String[] paths,
+    public QueryApiServlet(ConcurrentMap<String, Object> ctx, String[] paths, ICcApplicationContext appCtx,
             ILangCompilationProvider compilationProvider, IStatementExecutorFactory statementExecutorFactory,
             IStorageComponentProvider componentProvider) {
-        super(ctx, paths, compilationProvider, statementExecutorFactory, componentProvider);
+        super(ctx, paths, appCtx, compilationProvider, statementExecutorFactory, componentProvider);
     }
 
     @Override


Mime
View raw message