abdullah alamoudi has uploaded a new change for review.

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

Change subject: [NO ISSUE][CLUS] Allow Extension of cc application context
......................................................................

[NO ISSUE][CLUS] Allow Extension of cc application context

- user model changes: no
- storage format changes: no
- interface changes: yes
  + ICcApplicationContext.setExtensionManager
  + ICcApplicationContext.getExtensionProperties

details:
- This change allows better extension of cc application context.
  While this was possible before this change, the cc can end up
  with multiple app context which can lead to bad situations.

Change-Id: I924716b037bf94b68dd9ffa2ec0043c75f4e81a6
---
D 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/extension/IAlgebraExtensionManager.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
M 
asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/ClusterLifecycleListener.java
M 
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java
M 
asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
6 files changed, 45 insertions(+), 47 deletions(-)


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

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/extension/IAlgebraExtensionManager.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/extension/IAlgebraExtensionManager.java
deleted file mode 100644
index d9641df..0000000
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/algebra/extension/IAlgebraExtensionManager.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * 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.algebra.extension;
-
-public interface IAlgebraExtensionManager {
-
-}
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
index 768416d..1ba418a 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
@@ -25,7 +25,6 @@
 
 import org.apache.asterix.algebra.base.ILangExtension;
 import org.apache.asterix.algebra.base.ILangExtension.Language;
-import org.apache.asterix.algebra.extension.IAlgebraExtensionManager;
 import org.apache.asterix.app.translator.DefaultStatementExecutorFactory;
 import org.apache.asterix.common.api.ExtensionId;
 import org.apache.asterix.common.api.IExtension;
@@ -48,7 +47,7 @@
  * AsterixDB's implementation of {@code IAlgebraExtensionManager} and {@code 
IFunctionExtensionManager}
  * which takes care of initializing extensions for App and Compilation purposes
  */
-public class CCExtensionManager implements IAlgebraExtensionManager, 
IFunctionExtensionManager {
+public class CCExtensionManager implements IFunctionExtensionManager {
 
     private final IStatementExecutorExtension statementExecutorExtension;
     private final ILangCompilationProvider aqlCompilationProvider;
@@ -110,18 +109,21 @@
 
     public IStatementExecutorFactory 
getStatementExecutorFactory(ExecutorService executorService) {
         if (statementExecutorFactory == null) {
-            statementExecutorFactory = statementExecutorExtension == null
-                    ? new DefaultStatementExecutorFactory(executorService)
-                    : 
statementExecutorExtension.getStatementExecutorFactory(executorService);
+            statementExecutorFactory =
+                    statementExecutorExtension == null ? new 
DefaultStatementExecutorFactory(executorService)
+                            : 
statementExecutorExtension.getStatementExecutorFactory(executorService);
         }
         return statementExecutorFactory;
     }
 
     public ILangCompilationProvider getCompilationProvider(Language lang) {
         switch (lang) {
-            case AQL: return aqlCompilationProvider;
-            case SQLPP: return sqlppCompilationProvider;
-            default: throw new IllegalArgumentException(String.valueOf(lang));
+            case AQL:
+                return aqlCompilationProvider;
+            case SQLPP:
+                return sqlppCompilationProvider;
+            default:
+                throw new IllegalArgumentException(String.valueOf(lang));
         }
     }
 
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
index 96cfe91..4e75bf7 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplication.java
@@ -25,6 +25,7 @@
 import static 
org.apache.asterix.api.http.server.ServletConstants.HYRACKS_CONNECTION_ATTR;
 import static 
org.apache.asterix.common.api.IClusterManagementWork.ClusterState.SHUTTING_DOWN;
 
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.ConcurrentMap;
@@ -80,6 +81,7 @@
 import org.apache.asterix.runtime.utils.CcApplicationContext;
 import org.apache.asterix.translator.IStatementExecutorContext;
 import org.apache.asterix.translator.IStatementExecutorFactory;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.application.ICCServiceContext;
 import org.apache.hyracks.api.application.IServiceContext;
 import org.apache.hyracks.api.client.HyracksConnection;
@@ -103,7 +105,7 @@
     protected IStorageComponentProvider componentProvider;
     protected StatementExecutorContext statementExecutorCtx;
     protected WebManager webManager;
-    protected CcApplicationContext appCtx;
+    protected ICcApplicationContext appCtx;
     private IJobCapacityController jobCapacityController;
     private IHyracksClientConnection hcc;
 
@@ -119,8 +121,8 @@
         if (args.length > 0) {
             throw new IllegalArgumentException("Unrecognized argument(s): " + 
Arrays.toString(args));
         }
-        final ClusterControllerService controllerService = 
(ClusterControllerService) ccServiceCtx
-                .getControllerService();
+        final ClusterControllerService controllerService =
+                (ClusterControllerService) ccServiceCtx.getControllerService();
         ccServiceCtx.setMessageBroker(new CCMessageBroker(controllerService));
 
         
configureLoggingLevel(ccServiceCtx.getAppConfig().getLoggingLevel(ExternalProperties.Option.LOG_LEVEL));
@@ -141,9 +143,7 @@
         componentProvider = new StorageComponentProvider();
         GlobalRecoveryManager globalRecoveryManager = 
createGlobalRecoveryManager();
         statementExecutorCtx = new StatementExecutorContext();
-        appCtx = new CcApplicationContext(ccServiceCtx, getHcc(), 
libraryManager, () -> MetadataManager.INSTANCE,
-                globalRecoveryManager, ftStrategy, new 
ActiveNotificationHandler(), componentProvider,
-                new MetadataLockManager());
+        appCtx = createApplicationContext(libraryManager, 
globalRecoveryManager, ftStrategy);
         ccExtensionManager = new CCExtensionManager(getExtensions());
         appCtx.setExtensionManager(ccExtensionManager);
         final CCConfig ccConfig = controllerService.getCCConfig();
@@ -165,6 +165,14 @@
         ccServiceCtx.addClusterLifecycleListener(new 
ClusterLifecycleListener(appCtx));
 
         jobCapacityController = new 
JobCapacityController(controllerService.getResourceManager());
+    }
+
+    protected ICcApplicationContext createApplicationContext(ILibraryManager 
libraryManager,
+            GlobalRecoveryManager globalRecoveryManager, 
IFaultToleranceStrategy ftStrategy)
+            throws AlgebricksException, IOException {
+        return new CcApplicationContext(ccServiceCtx, getHcc(), 
libraryManager, () -> MetadataManager.INSTANCE,
+                globalRecoveryManager, ftStrategy, new 
ActiveNotificationHandler(), componentProvider,
+                new MetadataLockManager());
     }
 
     protected GlobalRecoveryManager createGlobalRecoveryManager() throws 
Exception {
@@ -194,9 +202,7 @@
             LOGGER.info("Stopping Asterix cluster controller");
         }
         appCtx.getClusterStateManager().setState(SHUTTING_DOWN);
-        if (appCtx != null) {
-            ((ActiveNotificationHandler) 
appCtx.getActiveNotificationHandler()).stop();
-        }
+        ((ActiveNotificationHandler) 
appCtx.getActiveNotificationHandler()).stop();
         AsterixStateProxy.unregisterRemoteObject();
         webManager.stop();
     }
@@ -212,8 +218,8 @@
     }
 
     protected HttpServer setupJSONAPIServer(ExternalProperties 
externalProperties) throws Exception {
-        HttpServer jsonAPIServer = new HttpServer(webManager.getBosses(), 
webManager.getWorkers(),
-                externalProperties.getAPIServerPort());
+        HttpServer jsonAPIServer =
+                new HttpServer(webManager.getBosses(), 
webManager.getWorkers(), externalProperties.getAPIServerPort());
         jsonAPIServer.setAttribute(HYRACKS_CONNECTION_ATTR, hcc);
         jsonAPIServer.setAttribute(ASTERIX_APP_CONTEXT_INFO_ATTR, appCtx);
         jsonAPIServer.setAttribute(ServletConstants.EXECUTOR_SERVICE_ATTR,
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/ClusterLifecycleListener.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/ClusterLifecycleListener.java
index 50fe65e..8f479eb 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/ClusterLifecycleListener.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/ClusterLifecycleListener.java
@@ -34,7 +34,7 @@
 import org.apache.asterix.common.api.IClusterManagementWorkResponse.Status;
 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.common.config.ClusterProperties;
-import org.apache.asterix.common.exceptions.AsterixException;
+import org.apache.asterix.common.dataflow.ICcApplicationContext;
 import org.apache.asterix.event.schema.cluster.Node;
 import org.apache.asterix.metadata.MetadataManager;
 import org.apache.asterix.metadata.cluster.AddNodeWork;
@@ -42,7 +42,6 @@
 import org.apache.asterix.metadata.cluster.ClusterManagerProvider;
 import org.apache.asterix.metadata.cluster.RemoveNodeWork;
 import org.apache.asterix.metadata.cluster.RemoveNodeWorkResponse;
-import org.apache.asterix.runtime.utils.CcApplicationContext;
 import org.apache.hyracks.api.application.IClusterLifecycleListener;
 import org.apache.hyracks.api.config.IOption;
 import org.apache.hyracks.api.exceptions.HyracksException;
@@ -50,12 +49,12 @@
 public class ClusterLifecycleListener implements IClusterLifecycleListener {
 
     private static final Logger LOGGER = 
Logger.getLogger(ClusterLifecycleListener.class.getName());
-    private final CcApplicationContext appCtx;
+    private final ICcApplicationContext appCtx;
     private final LinkedBlockingQueue<Set<IClusterManagementWork>> 
workRequestQueue = new LinkedBlockingQueue<>();
     private final ClusterWorkExecutor eventHandler;
     private final List<IClusterManagementWorkResponse> pendingWorkResponses = 
new ArrayList<>();
 
-    public ClusterLifecycleListener(CcApplicationContext appCtx) {
+    public ClusterLifecycleListener(ICcApplicationContext appCtx) {
         this.appCtx = appCtx;
         eventHandler = new ClusterWorkExecutor(appCtx, workRequestQueue);
         Thread t = new Thread(eventHandler);
diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java
index 690d1fd..3f4d6a6 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/dataflow/ICcApplicationContext.java
@@ -22,6 +22,7 @@
 import org.apache.asterix.common.api.IMetadataLockManager;
 import org.apache.asterix.common.cluster.IClusterStateManager;
 import org.apache.asterix.common.cluster.IGlobalRecoveryManager;
+import org.apache.asterix.common.config.ExtensionProperties;
 import org.apache.asterix.common.context.IStorageComponentProvider;
 import org.apache.asterix.common.metadata.IMetadataBootstrap;
 import org.apache.asterix.common.replication.IFaultToleranceStrategy;
@@ -102,4 +103,16 @@
      * @return the cluster state manager
      */
     IClusterStateManager getClusterStateManager();
+
+    /**
+     * Set the extension manager
+     *
+     * @param extensionManager
+     */
+    void setExtensionManager(Object extensionManager);
+
+    /**
+     * @return the extension properties
+     */
+    ExtensionProperties getExtensionProperties();
 }
diff --git 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
index 0bd8b9e..63d3d6f 100644
--- 
a/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
+++ 
b/asterixdb/asterix-runtime/src/main/java/org/apache/asterix/runtime/utils/CcApplicationContext.java
@@ -38,7 +38,6 @@
 import org.apache.asterix.common.config.TransactionProperties;
 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.common.library.ILibraryManager;
 import org.apache.asterix.common.metadata.IMetadataBootstrap;
 import org.apache.asterix.common.replication.IFaultToleranceStrategy;
@@ -198,10 +197,12 @@
         return extensionManager;
     }
 
+    @Override
     public void setExtensionManager(Object extensionManager) {
         this.extensionManager = extensionManager;
     }
 
+    @Override
     public ExtensionProperties getExtensionProperties() {
         return extensionProperties;
     }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I924716b037bf94b68dd9ffa2ec0043c75f4e81a6
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: abdullah alamoudi <[email protected]>

Reply via email to