Configuration Revamp - Ini section of node / cc details now returns ini param names instead of managix option names - Normalized command line -vs- ini file configuration parameter names - Eliminated unused parameters - Ini validation - Migrate *DB parameters out of [app] and into nc / cc sections as appropriate - Eliminate [app] section. Cluster-wide configuration lives in [common] - Sort properties alphabetically when returned by HTTP api
Change-Id: I95b7e0bd4538ef42817c8826e76412150074b754 Reviewed-on: https://asterix-gerrit.ics.uci.edu/1487 Reviewed-by: Michael Blow <[email protected]> Integration-Tests: Michael Blow <[email protected]> Tested-by: Michael Blow <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/4c7b5bfa Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/4c7b5bfa Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/4c7b5bfa Branch: refs/heads/master Commit: 4c7b5bfa29a5dd0d323f1d5f795e24ed8859206d Parents: a5bfa8b Author: Michael Blow <[email protected]> Authored: Mon Mar 6 21:55:58 2017 -0500 Committer: Michael Blow <[email protected]> Committed: Mon Mar 6 19:02:38 2017 -0800 ---------------------------------------------------------------------- asterixdb/asterix-app/pom.xml | 4 +- .../asterix-app/scripts/asterix/startnc.sh | 4 +- .../asterix-app/scripts/idefix/startnc1.sh | 2 +- .../asterix-app/scripts/idefix/startnc2.sh | 2 +- .../asterix-app/scripts/rainbow/startnc.sh | 4 +- .../apache/asterix/api/common/APIFramework.java | 13 +- .../common/AsterixHyracksIntegrationUtil.java | 143 ++-- .../api/http/server/ClusterApiServlet.java | 68 +- .../ClusterControllerDetailsApiServlet.java | 2 +- .../api/http/server/DiagnosticsApiServlet.java | 2 +- .../server/NodeControllerDetailsApiServlet.java | 2 +- .../api/http/server/VersionApiServlet.java | 15 +- .../api/http/servlet/ServletConstants.java | 2 +- .../asterix/app/nc/NCAppRuntimeContext.java | 16 +- .../replication/AutoFaultToleranceStrategy.java | 30 +- .../bootstrap/CCApplicationEntryPoint.java | 99 ++- .../bootstrap/ClusterLifecycleListener.java | 3 +- .../bootstrap/NCApplicationEntryPoint.java | 104 +-- .../apache/asterix/util/FaultToleranceUtil.java | 7 +- .../resources/asterix-build-configuration.xml | 5 + .../api/http/servlet/VersionApiServletTest.java | 4 +- .../app/bootstrap/TestNodeController.java | 5 +- .../asterix/common/config/ConfigUsageTest.java | 146 ++++ .../asterix/test/common/TestExecutor.java | 4 +- .../apache/asterix/test/common/TestHelper.java | 8 +- .../asterix/test/logging/CheckpointingTest.java | 2 +- .../ClusterStateDefaultParameterTest.java | 2 +- .../asterix/test/sqlpp/OptimizerParserTest.java | 10 +- .../asterix/test/sqlpp/ParserTestUtil.java | 7 +- .../asterix/test/sqlpp/SmokeParserTest.java | 10 +- .../src/test/resources/runtimets/api.xml | 5 - .../runtimets/queries/api/APIQueries.xml | 0 .../api/replication/replication.1.get.http | 25 - .../api/cluster_state_1/cluster_state_1.1.adm | 104 +-- .../cluster_state_1_full.1.adm | 102 +-- .../cluster_state_1_less.1.adm | 102 +-- .../results/api/replication/replication.1.adm | 9 - asterixdb/asterix-client-helper/pom.xml | 2 +- asterixdb/asterix-common/pom.xml | 8 + .../common/cluster/IClusterStateManager.java | 3 +- .../common/config/AbstractProperties.java | 52 -- .../common/config/AsterixProperties.java | 51 +- .../asterix/common/config/BuildProperties.java | 83 --- .../common/config/CompilerProperties.java | 83 ++- .../common/config/ExternalProperties.java | 142 ++-- .../asterix/common/config/FeedProperties.java | 93 ++- .../common/config/IPropertiesProvider.java | 18 +- .../common/config/IPropertyInterpreter.java | 23 - .../common/config/MessagingProperties.java | 50 +- .../common/config/MetadataProperties.java | 103 ++- .../asterix/common/config/NodeProperties.java | 87 +++ .../common/config/PropertiesAccessor.java | 352 +++++----- .../common/config/PropertyInterpreters.java | 67 -- .../common/config/ReplicationProperties.java | 124 ++-- .../common/config/StorageProperties.java | 192 ++++-- .../common/config/TransactionProperties.java | 133 ++-- .../src/main/resources/schema/cluster.xsd | 2 - .../asterix-doc/src/site/markdown/ncservice.md | 53 +- .../asterix-docker/docker/supervisord.conf | 6 +- .../event/service/AsterixEventServiceUtil.java | 13 +- .../main/resources/events/cc_start/cc_start.sh | 30 +- .../main/resources/events/node_join/nc_join.sh | 7 +- .../resources/events/node_restart/nc_restart.sh | 12 +- asterixdb/asterix-installer/pom.xml | 7 +- .../src/main/resources/clusters/local/local.xml | 2 - .../local/local_chained_declustering_rep.xml | 2 - .../installer/test/AbstractExecutionIT.java | 11 +- .../test/AsterixExternalLibraryIT.java | 4 +- .../installer/test/AsterixRestartIT.java | 5 +- .../installer/test/ClusterExecutionIT.java | 3 +- .../asterix/installer/test/ReplicationIT.java | 16 +- .../installer/transaction/RecoveryIT.java | 2 +- .../pom.xml | 2 +- .../management/ReplicationChannel.java | 2 +- .../management/ReplicationManager.java | 2 +- asterixdb/asterix-runtime/pom.xml | 5 +- .../asterix/runtime/utils/AppContextInfo.java | 29 +- .../runtime/utils/ClusterStateManager.java | 13 +- asterixdb/asterix-server/pom.xml | 16 +- .../src/main/opt/ansible/conf/cc.conf | 2 +- .../src/main/opt/ansible/yaml/gen_conf.yml | 2 +- .../src/main/opt/aws/yaml/aws_start.yml | 4 +- .../src/main/opt/local/conf/cc.conf | 16 +- .../server/test/SampleLocalClusterIT.java | 19 +- .../test/resources/NCServiceExecutionIT/cc.conf | 21 +- .../asterix/aoya/AsterixApplicationMaster.java | 27 +- .../apache/asterix/aoya/AsterixYARNClient.java | 6 +- .../algebricks/algebricks-tests/pom.xml | 7 +- .../util/AlgebricksHyracksIntegrationUtil.java | 54 +- hyracks-fullstack/hyracks/hyracks-api/pom.xml | 4 + .../api/application/IApplicationConfig.java | 48 -- .../api/application/IApplicationContext.java | 1 + .../application/ICCApplicationEntryPoint.java | 8 + .../application/IClusterLifecycleListener.java | 5 +- .../application/INCApplicationEntryPoint.java | 8 + .../hyracks/api/config/IApplicationConfig.java | 87 +++ .../hyracks/api/config/IConfigManager.java | 52 ++ .../hyracks/api/config/IConfigurator.java | 27 + .../org/apache/hyracks/api/config/IOption.java | 70 ++ .../apache/hyracks/api/config/IOptionType.java | 40 ++ .../org/apache/hyracks/api/config/Section.java | 41 ++ .../apache/hyracks/api/context/ICCContext.java | 6 +- .../apache/hyracks/api/io/IODeviceHandle.java | 8 +- .../hyracks/client/stats/HyracksUtils.java | 41 +- .../hyracks-control/hyracks-control-cc/pom.xml | 3 +- .../control/cc/CCApplicationEntryPoint.java | 68 ++ .../org/apache/hyracks/control/cc/CCDriver.java | 48 +- .../control/cc/ClusterControllerService.java | 143 ++-- .../hyracks/control/cc/NodeControllerState.java | 4 +- .../cc/application/CCApplicationContext.java | 5 +- .../hyracks/control/cc/cluster/NodeManager.java | 7 +- .../hyracks/control/cc/job/JobManager.java | 8 +- .../control/cc/work/GetNodeDetailsJSONWork.java | 59 +- .../control/cc/work/RegisterNodeWork.java | 13 +- .../hyracks/control/cc/work/TriggerNCWork.java | 14 +- .../control/cc/cluster/NodeManagerTest.java | 14 +- .../hyracks/control/cc/job/JobManagerTest.java | 23 +- .../hyracks-control-common/pom.xml | 10 +- .../common/application/ApplicationContext.java | 2 +- .../ConfigManagerApplicationConfig.java | 115 ++++ .../application/IniApplicationConfig.java | 105 --- .../control/common/config/Args4jArgument.java | 68 ++ .../control/common/config/Args4jOption.java | 102 +++ .../control/common/config/Args4jSetter.java | 74 ++ .../control/common/config/ConfigManager.java | 549 +++++++++++++++ .../control/common/config/ConfigUtils.java | 180 +++++ .../control/common/config/IConfigSetter.java | 30 + .../control/common/config/OptionTypes.java | 176 +++++ .../control/common/context/ServerContext.java | 2 +- .../control/common/controllers/CCConfig.java | 435 ++++++++---- .../common/controllers/ControllerConfig.java | 92 +++ .../control/common/controllers/IniUtils.java | 103 --- .../control/common/controllers/NCConfig.java | 676 ++++++++++++------- .../hyracks-control/hyracks-control-nc/pom.xml | 1 - .../control/nc/NCApplicationEntryPoint.java | 69 ++ .../org/apache/hyracks/control/nc/NCDriver.java | 43 +- .../control/nc/NodeControllerService.java | 92 +-- .../nc/application/NCApplicationContext.java | 2 +- .../hyracks-control/hyracks-nc-service/pom.xml | 8 +- .../hyracks/control/nc/service/NCService.java | 21 +- .../control/nc/service/NCServiceConfig.java | 10 +- .../hyracks/hyracks-dataflow-std/pom.xml | 2 +- hyracks-fullstack/hyracks/hyracks-dist/pom.xml | 2 +- .../src/main/resources/bin/startDebugNc.sh | 2 +- .../src/main/resources/bin/startcc.sh | 4 +- .../src/main/resources/bin/startnc.sh | 2 +- .../btree-example/btreeclient/pom.xml | 1 - .../btree/helper/NCApplicationEntryPoint.java | 7 + .../hyracks-integration-tests/pom.xml | 7 +- .../integration/AbstractIntegrationTest.java | 50 +- .../AbstractMultiNCIntegrationTest.java | 56 +- .../integration/NodesAPIIntegrationTest.java | 2 +- .../integration/PredistributedJobsTest.java | 51 +- .../hyracks-shutdown-test/pom.xml | 7 +- .../text-example/textclient/pom.xml | 1 - .../text-example/textserver/pom.xml | 11 +- .../tpch-example/tpchclient/pom.xml | 1 - .../hyracks-hdfs/hyracks-hdfs-core/pom.xml | 8 +- .../hyracks/hdfs/dataflow/DataflowTest.java | 25 +- .../apache/hyracks/hdfs/utils/HyracksUtils.java | 39 +- .../hyracks/http/server/AbstractServlet.java | 2 +- .../hyracks/ipc/impl/IPCConnectionManager.java | 8 +- .../maven/plugin/HyracksCCStartMojo.java | 4 +- .../maven/plugin/HyracksNCStartMojo.java | 10 +- .../hyracks/hyracks-server/docs/README | 10 +- .../hyracks/hyracks-server/pom.xml | 6 +- .../server/process/HyracksCCProcess.java | 5 +- .../apache/hyracks/server/test/NCServiceIT.java | 2 - .../src/test/resources/NCServiceIT/cc.conf | 12 +- .../hyracks/hyracks-test-support/pom.xml | 4 - .../test/support/TestNCApplicationContext.java | 3 +- .../apache/hyracks/test/support/TestUtils.java | 5 - .../org/apache/hyracks/util/StorageUtil.java | 7 +- .../org/apache/hyracks/util/file/FileUtil.java | 32 + hyracks-fullstack/pom.xml | 31 +- 175 files changed, 4726 insertions(+), 2653 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/pom.xml ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/pom.xml b/asterixdb/asterix-app/pom.xml index 74102a1..ede8cb1 100644 --- a/asterixdb/asterix-app/pom.xml +++ b/asterixdb/asterix-app/pom.xml @@ -149,11 +149,11 @@ <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <configuration> - <ignoredUsedUndeclaredDependencies> + <ignoredUsedUndeclaredDependencies combine.children="append"> <ignoredUsedUndeclaredDependency>commons-logging:commons-logging-api:*</ignoredUsedUndeclaredDependency> <ignoredUsedUndeclaredDependency>org.apache.hive:hive-exec:*</ignoredUsedUndeclaredDependency> </ignoredUsedUndeclaredDependencies> - <usedDependencies> + <usedDependencies combine.children="append"> <usedDependency>org.apache.hadoop:hadoop-common</usedDependency> <usedDependency>org.apache.asterix:asterix-external-data</usedDependency> </usedDependencies> http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/scripts/asterix/startnc.sh ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/scripts/asterix/startnc.sh b/asterixdb/asterix-app/scripts/asterix/startnc.sh index b4b9c3c..43f9e2a 100644 --- a/asterixdb/asterix-app/scripts/asterix/startnc.sh +++ b/asterixdb/asterix-app/scripts/asterix/startnc.sh @@ -27,5 +27,5 @@ NODEID=`ypcat hosts | grep asterix | grep -w $IPADDR | awk '{print $2}'` export JAVA_OPTS="-Xmx10g -Djava.net.preferIPv4Stack=true -Djava.io.tmpdir=/mnt/data/sdd/space/onose/tmp" -echo $HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cc-host 10.1.0.1 -cc-port 2222 -data-ip-address $IPADDR -node-id $NODEID -$HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cc-host 10.1.0.1 -cc-port 2222 -data-ip-address $IPADDR -node-id $NODEID &> $LOGSDIR/$NODEID.log & +echo $HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cluster-address 10.1.0.1 -cluster-port 2222 -data-listen-address $IPADDR -node-id $NODEID +$HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cluster-address 10.1.0.1 -cluster-port 2222 -data-listen-address $IPADDR -node-id $NODEID &> $LOGSDIR/$NODEID.log & http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/scripts/idefix/startnc1.sh ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/scripts/idefix/startnc1.sh b/asterixdb/asterix-app/scripts/idefix/startnc1.sh index e17253a..ae15596 100644 --- a/asterixdb/asterix-app/scripts/idefix/startnc1.sh +++ b/asterixdb/asterix-app/scripts/idefix/startnc1.sh @@ -22,4 +22,4 @@ export JAVA_OPTS="-DAsterixConfigFileName=test.properties -Djava.util.logging.config.file=/home/nicnic/Work/Asterix/hyracks/logging.properties" export HYRACKS_HOME="/home/nicnic/workspace/hyracks/tags/hyracks-0.1.5" -bash ${HYRACKS_HOME}/hyracks-server/target/appassembler/bin/hyracksnc -cc-host 127.0.0.1 -data-ip-address 127.0.0.1 -node-id "nc1" $* +bash ${HYRACKS_HOME}/hyracks-server/target/appassembler/bin/hyracksnc -cluster-address 127.0.0.1 -data-listen-address 127.0.0.1 -node-id "nc1" $* http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/scripts/idefix/startnc2.sh ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/scripts/idefix/startnc2.sh b/asterixdb/asterix-app/scripts/idefix/startnc2.sh index 2074cd7..4a3e370 100644 --- a/asterixdb/asterix-app/scripts/idefix/startnc2.sh +++ b/asterixdb/asterix-app/scripts/idefix/startnc2.sh @@ -20,5 +20,5 @@ export JAVA_OPTS="-DAsterixConfigFileName=test.properties -Djava.util.logging.config.file=/home/nicnic/Work/Asterix/hyracks/logging.properties" export HYRACKS_HOME="/home/nicnic/workspace/hyracks/tags/hyracks-0.1.5" -bash ${HYRACKS_HOME}/hyracks-server/target/appassembler/bin/hyracksnc -cc-host 127.0.0.1 -data-ip-address 127.0.0.1 -node-id "nc2" $* +bash ${HYRACKS_HOME}/hyracks-server/target/appassembler/bin/hyracksnc -cluster-address 127.0.0.1 -data-listen-address 127.0.0.1 -node-id "nc2" $* http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/scripts/rainbow/startnc.sh ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/scripts/rainbow/startnc.sh b/asterixdb/asterix-app/scripts/rainbow/startnc.sh index 5f1dadf..3d7b75e 100644 --- a/asterixdb/asterix-app/scripts/rainbow/startnc.sh +++ b/asterixdb/asterix-app/scripts/rainbow/startnc.sh @@ -27,5 +27,5 @@ NODEID=`ypcat hosts | grep rainbow | grep -w $IPADDR | awk '{print $2}'` export JAVA_OPTS="-DNodeControllerDataPath=/tmp/ncX/" -echo $HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cc-host 128.195.52.177 -cc-port 2222 -data-ip-address $IPADDR -node-id $NODEID -$HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cc-host 128.195.52.177 -cc-port 2222 -data-ip-address $IPADDR -node-id $NODEID &> $LOGSDIR/$NODEID.log & +echo $HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cluster-address 128.195.52.177 -cluster-port 2222 -data-listen-address $IPADDR -node-id $NODEID +$HYRACKS_HOME/hyracks-server/target/hyracks-server-0.1.3.1-binary-assembly/bin/hyracksnc -cluster-address 128.195.52.177 -cluster-port 2222 -data-listen-address $IPADDR -node-id $NODEID &> $LOGSDIR/$NODEID.log & http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/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 0f16179..0759599 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 @@ -34,9 +34,8 @@ import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory; import org.apache.asterix.app.result.ResultUtil; import org.apache.asterix.common.config.CompilerProperties; import org.apache.asterix.common.config.ExternalProperties; -import org.apache.asterix.common.config.IPropertyInterpreter; import org.apache.asterix.common.config.OptimizationConfUtil; -import org.apache.asterix.common.config.PropertyInterpreters; +import org.apache.hyracks.control.common.config.OptionTypes; import org.apache.asterix.common.exceptions.ACIDException; import org.apache.asterix.common.exceptions.CompilationException; import org.apache.asterix.common.utils.Job; @@ -96,6 +95,7 @@ import org.apache.hyracks.api.job.JobId; import org.apache.hyracks.api.job.JobSpecification; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.hyracks.api.config.IOptionType; /** * Provides helper methods for compilation of a query into a JobSpec and submission @@ -451,16 +451,15 @@ public class APIFramework { // Gets the frame limit. private int getFrameLimit(String parameter, long memBudgetInConfiguration, int frameSize) { - IPropertyInterpreter<Long> longBytePropertyInterpreter = PropertyInterpreters.getLongBytePropertyInterpreter(); + IOptionType<Long> longBytePropertyInterpreter = OptionTypes.LONG_BYTE_UNIT; long memBudget = - parameter == null ? memBudgetInConfiguration : longBytePropertyInterpreter.interpret(parameter); + parameter == null ? memBudgetInConfiguration : longBytePropertyInterpreter.parse(parameter); return (int) (memBudget / frameSize); } // Gets the parallelism parameter. private int getParallelism(String parameter, int parallelismInConfiguration) { - IPropertyInterpreter<Integer> integerIPropertyInterpreter = - PropertyInterpreters.getIntegerPropertyInterpreter(); - return parameter == null ? parallelismInConfiguration : integerIPropertyInterpreter.interpret(parameter); + IOptionType<Integer> integerIPropertyInterpreter = OptionTypes.INTEGER; + return parameter == null ? parallelismInConfiguration : integerIPropertyInterpreter.parse(parameter); } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java index 54804a1..fbb2208 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java @@ -18,6 +18,17 @@ */ package org.apache.asterix.api.common; +import static org.apache.asterix.api.common.AsterixHyracksIntegrationUtil.LoggerHolder.LOGGER; + +import java.io.File; +import java.io.IOException; +import java.net.Inet4Address; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apache.asterix.common.api.IClusterManagementWork.ClusterState; import org.apache.asterix.common.config.GlobalConfig; import org.apache.asterix.common.config.PropertiesAccessor; @@ -26,28 +37,19 @@ import org.apache.asterix.hyracks.bootstrap.CCApplicationEntryPoint; import org.apache.asterix.hyracks.bootstrap.NCApplicationEntryPoint; import org.apache.asterix.runtime.utils.ClusterStateManager; import org.apache.commons.io.FileUtils; +import org.apache.hyracks.api.application.ICCApplicationEntryPoint; +import org.apache.hyracks.api.application.INCApplicationEntryPoint; import org.apache.hyracks.api.client.HyracksConnection; import org.apache.hyracks.api.client.IHyracksClientConnection; import org.apache.hyracks.api.job.JobFlag; import org.apache.hyracks.api.job.JobId; import org.apache.hyracks.api.job.JobSpecification; import org.apache.hyracks.control.cc.ClusterControllerService; +import org.apache.hyracks.control.common.config.ConfigManager; import org.apache.hyracks.control.common.controllers.CCConfig; import org.apache.hyracks.control.common.controllers.NCConfig; import org.apache.hyracks.control.nc.NodeControllerService; -import java.io.File; -import java.io.IOException; -import java.net.Inet4Address; -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumSet; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import static org.apache.asterix.api.common.AsterixHyracksIntegrationUtil.LoggerHolder.LOGGER; - public class AsterixHyracksIntegrationUtil { static class LoggerHolder { static final Logger LOGGER = Logger.getLogger(AsterixHyracksIntegrationUtil.class.getName()); @@ -63,29 +65,38 @@ public class AsterixHyracksIntegrationUtil { public NodeControllerService[] ncs; public IHyracksClientConnection hcc; - private PropertiesAccessor propertiesAccessor; + private ConfigManager configManager; + private List<String> nodeNames; public void init(boolean deleteOldInstanceData) throws Exception { ncs = new NodeControllerService[0]; // ensure that ncs is not null - final CCConfig ccConfig = createCCConfig(); - propertiesAccessor = PropertiesAccessor.getInstance(ccConfig.getAppConfig()); + final ICCApplicationEntryPoint ccAppEntryPoint = createCCAppEntryPoint(); + configManager = new ConfigManager(); + ccAppEntryPoint.registerConfig(configManager); + final CCConfig ccConfig = createCCConfig(configManager); + cc = new ClusterControllerService(ccConfig, ccAppEntryPoint); + + nodeNames = ccConfig.getConfigManager().getNodeNames(); if (deleteOldInstanceData) { deleteTransactionLogs(); removeTestStorageFiles(); } + final List<NCConfig> ncConfigs = new ArrayList<>(); + nodeNames.forEach(nodeId -> ncConfigs.add(createNCConfig(nodeId, configManager))); + final PropertiesAccessor accessor = PropertiesAccessor.getInstance(configManager.getAppConfig()); + ncConfigs.forEach((ncConfig1) -> fixupIODevices(ncConfig1, accessor)); - cc = new ClusterControllerService(ccConfig); cc.start(); // Starts ncs. - List<String> nodes = propertiesAccessor.getNodeNames(); + nodeNames = ccConfig.getConfigManager().getNodeNames(); List<NodeControllerService> nodeControllers = new ArrayList<>(); List<Thread> startupThreads = new ArrayList<>(); - for (String ncName : nodes) { - NodeControllerService nodeControllerService = new NodeControllerService( - fixupIODevices(createNCConfig(ncName))); + for (NCConfig ncConfig : ncConfigs) { + final INCApplicationEntryPoint ncAppEntryPoint = createNCAppEntryPoint(); + NodeControllerService nodeControllerService = new NodeControllerService(ncConfig, ncAppEntryPoint); nodeControllers.add(nodeControllerService); - Thread ncStartThread = new Thread("IntegrationUtil-" + ncName) { + Thread ncStartThread = new Thread("IntegrationUtil-" + ncConfig.getNodeId()) { @Override public void run() { try { @@ -102,78 +113,83 @@ public class AsterixHyracksIntegrationUtil { for (Thread thread : startupThreads) { thread.join(); } + for (NCConfig ncConfig : ncConfigs) { + for (String ioDevice : ncConfig.getIODevices()) { + if (!new File(ioDevice).isAbsolute()) { + throw new IllegalStateException("iodevice not absolute: " + ioDevice); + } + } + } // Wait until cluster becomes active synchronized (ClusterStateManager.INSTANCE) { while (ClusterStateManager.INSTANCE.getState() != ClusterState.ACTIVE) { ClusterStateManager.INSTANCE.wait(); } } - hcc = new HyracksConnection(cc.getConfig().clientNetIpAddress, cc.getConfig().clientNetPort); + hcc = new HyracksConnection(cc.getConfig().getClientListenAddress(), cc.getConfig().getClientListenPort()); ncs = nodeControllers.toArray(new NodeControllerService[nodeControllers.size()]); } - protected CCConfig createCCConfig() throws IOException { - CCConfig ccConfig = new CCConfig(); - ccConfig.clusterNetIpAddress = Inet4Address.getLoopbackAddress().getHostAddress(); - ccConfig.clientNetIpAddress = Inet4Address.getLoopbackAddress().getHostAddress(); - ccConfig.clientNetPort = DEFAULT_HYRACKS_CC_CLIENT_PORT; - ccConfig.clusterNetPort = DEFAULT_HYRACKS_CC_CLUSTER_PORT; - ccConfig.defaultMaxJobAttempts = 0; - ccConfig.resultTTL = 120000; - ccConfig.resultSweepThreshold = 1000; - ccConfig.appCCMainClass = CCApplicationEntryPoint.class.getName(); + protected CCConfig createCCConfig(ConfigManager configManager) throws IOException { + CCConfig ccConfig = new CCConfig(configManager); + ccConfig.setClusterListenAddress(Inet4Address.getLoopbackAddress().getHostAddress()); + ccConfig.setClientListenAddress(Inet4Address.getLoopbackAddress().getHostAddress()); + ccConfig.setClientListenPort(DEFAULT_HYRACKS_CC_CLIENT_PORT); + ccConfig.setClusterListenPort(DEFAULT_HYRACKS_CC_CLUSTER_PORT); + ccConfig.setResultTTL(120000L); + ccConfig.setResultSweepThreshold(1000L); return ccConfig; } - protected NCConfig createNCConfig(String ncName) throws AsterixException, IOException { - NCConfig ncConfig = new NCConfig(); - ncConfig.ccHost = "localhost"; - ncConfig.ccPort = DEFAULT_HYRACKS_CC_CLUSTER_PORT; - ncConfig.clusterNetIPAddress = Inet4Address.getLoopbackAddress().getHostAddress(); - ncConfig.dataIPAddress = Inet4Address.getLoopbackAddress().getHostAddress(); - ncConfig.resultIPAddress = Inet4Address.getLoopbackAddress().getHostAddress(); - ncConfig.messagingIPAddress = Inet4Address.getLoopbackAddress().getHostAddress(); - ncConfig.nodeId = ncName; - ncConfig.resultTTL = 120000; - ncConfig.resultSweepThreshold = 1000; - ncConfig.appArgs = Collections.singletonList("-virtual-NC"); - ncConfig.appNCMainClass = NCApplicationEntryPoint.class.getName(); + protected ICCApplicationEntryPoint createCCAppEntryPoint() { + return new CCApplicationEntryPoint(); + } + + protected NCConfig createNCConfig(String ncName, ConfigManager configManager) { + NCConfig ncConfig = new NCConfig(ncName, configManager); + ncConfig.setClusterAddress("localhost"); + ncConfig.setClusterPort(DEFAULT_HYRACKS_CC_CLUSTER_PORT); + ncConfig.setClusterListenAddress(Inet4Address.getLoopbackAddress().getHostAddress()); + ncConfig.setDataListenAddress(Inet4Address.getLoopbackAddress().getHostAddress()); + ncConfig.setResultListenAddress(Inet4Address.getLoopbackAddress().getHostAddress()); + ncConfig.setMessagingListenAddress(Inet4Address.getLoopbackAddress().getHostAddress()); + ncConfig.setResultTTL(120000L); + ncConfig.setResultSweepThreshold(1000L); + ncConfig.setVirtualNC(true); return ncConfig; } - private NCConfig fixupIODevices(NCConfig ncConfig) throws AsterixException { + protected INCApplicationEntryPoint createNCAppEntryPoint() { + return new NCApplicationEntryPoint(); + } + + private NCConfig fixupIODevices(NCConfig ncConfig, PropertiesAccessor accessor) { String tempPath = System.getProperty(IO_DIR_KEY); if (tempPath.endsWith(File.separator)) { tempPath = tempPath.substring(0, tempPath.length() - 1); } LOGGER.info("Using the temp path: " + tempPath); // get initial partitions from properties - String[] nodeStores = propertiesAccessor.getStores().get(ncConfig.nodeId); + String[] nodeStores = accessor.getStores().get(ncConfig.getNodeId()); if (nodeStores == null) { - throw new AsterixException("Couldn't find stores for NC: " + ncConfig.nodeId); + throw new IllegalStateException("Couldn't find stores for NC: " + ncConfig.getNodeId()); } String tempDirPath = System.getProperty(IO_DIR_KEY); if (!tempDirPath.endsWith(File.separator)) { tempDirPath += File.separator; } - for (int p = 0; p < nodeStores.length; p++) { + List<String> ioDevices = new ArrayList<>(); + for (String nodeStore : nodeStores) { // create IO devices based on stores - String iodevicePath = tempDirPath + ncConfig.nodeId + File.separator + nodeStores[p]; + String iodevicePath = tempDirPath + ncConfig.getNodeId() + File.separator + nodeStore; File ioDeviceDir = new File(iodevicePath); ioDeviceDir.mkdirs(); - if (p == 0) { - ncConfig.ioDevices = iodevicePath; - } else { - ncConfig.ioDevices += "," + iodevicePath; - } + ioDevices.add(iodevicePath); } + configManager.set(ncConfig.getNodeId(), NCConfig.Option.IODEVICES, ioDevices.toArray(new String[0])); return ncConfig; } - public String[] getNcNames() { - return propertiesAccessor.getNodeNames().toArray(new String[propertiesAccessor.getNodeNames().size()]); - } - public IHyracksClientConnection getHyracksClientConnection() { return hcc; } @@ -222,15 +238,16 @@ public class AsterixHyracksIntegrationUtil { public void removeTestStorageFiles() { File dir = new File(System.getProperty(IO_DIR_KEY)); - for (String ncName : propertiesAccessor.getNodeNames()) { + for (String ncName : nodeNames) { File ncDir = new File(dir, ncName); FileUtils.deleteQuietly(ncDir); } } - private void deleteTransactionLogs() throws IOException { - for (String ncId : propertiesAccessor.getNodeNames()) { - File log = new File(propertiesAccessor.getTransactionLogDirs().get(ncId)); + private void deleteTransactionLogs() throws IOException, AsterixException { + for (String ncId : nodeNames) { + File log = new File( + PropertiesAccessor.getInstance(configManager.getAppConfig()).getTransactionLogDirs().get(ncId)); if (log.exists()) { FileUtils.deleteDirectory(log); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/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 34086e7..eafe312 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 @@ -18,37 +18,37 @@ */ package org.apache.asterix.api.http.server; +import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_APP_CONTEXT_INFO_ATTR; + import java.io.IOException; import java.io.PrintWriter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentMap; +import java.util.function.Predicate; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; -import org.apache.asterix.common.config.AbstractProperties; -import org.apache.asterix.common.config.ReplicationProperties; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpResponseStatus; import org.apache.asterix.common.utils.JSONUtil; +import org.apache.asterix.runtime.utils.AppContextInfo; import org.apache.asterix.runtime.utils.ClusterStateManager; +import org.apache.hyracks.api.config.IOption; +import org.apache.hyracks.api.config.Section; +import org.apache.hyracks.control.common.config.ConfigUtils; +import org.apache.hyracks.control.common.controllers.ControllerConfig; import org.apache.hyracks.http.api.IServletRequest; import org.apache.hyracks.http.api.IServletResponse; import org.apache.hyracks.http.server.AbstractServlet; import org.apache.hyracks.http.server.utils.HttpUtil; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpResponseStatus; - public class ClusterApiServlet extends AbstractServlet { private static final Logger LOGGER = Logger.getLogger(ClusterApiServlet.class.getName()); private static final Pattern PARENT_DIR = Pattern.compile("/[^./]+/\\.\\./"); - private static final Pattern REPLICATION_PROPERTY = Pattern.compile("^replication\\."); protected static final String NODE_ID_KEY = "node_id"; protected static final String CONFIG_URI_KEY = "configUri"; protected static final String STATS_URI_KEY = "statsUri"; @@ -57,10 +57,9 @@ public class ClusterApiServlet extends AbstractServlet { protected static final String FULL_SHUTDOWN_URI_KEY = "fullShutdownUri"; protected static final String VERSION_URI_KEY = "versionUri"; protected static final String DIAGNOSTICS_URI_KEY = "diagnosticsUri"; - protected static final String REPLICATION_URI_KEY = "replicationUri"; private final ObjectMapper om = new ObjectMapper(); - public ClusterApiServlet(ConcurrentMap<String, Object> ctx, String[] paths) { + public ClusterApiServlet(ConcurrentMap<String, Object> ctx, String... paths) { super(ctx, paths); } @@ -75,9 +74,6 @@ public class ClusterApiServlet extends AbstractServlet { case "": json = getClusterStateJSON(request, ""); break; - case "/replication": - json = getReplicationJSON(); - break; case "/summary": json = getClusterStateSummaryJSON(); break; @@ -99,35 +95,11 @@ public class ClusterApiServlet extends AbstractServlet { return ClusterStateManager.INSTANCE.getClusterStateSummary(); } - protected ObjectNode getReplicationJSON() { - for (AbstractProperties props : getPropertiesInstances()) { - if (props instanceof ReplicationProperties) { - ObjectNode json = om.createObjectNode(); - json.putPOJO("config", props.getProperties(key -> REPLICATION_PROPERTY.matcher(key).replaceFirst(""))); - return json; - } - } - throw new IllegalStateException("ERROR: replication properties not found"); - } - - protected Map<String, Object> getAllClusterProperties() { - Map<String, Object> allProperties = new HashMap<>(); - for (AbstractProperties properties : getPropertiesInstances()) { - if (!(properties instanceof ReplicationProperties)) { - allProperties.putAll(properties.getProperties()); - } - } - return allProperties; - } - - protected List<AbstractProperties> getPropertiesInstances() { - return AbstractProperties.getImplementations(); - } - protected ObjectNode getClusterStateJSON(IServletRequest request, String pathToNode) { ObjectNode json = ClusterStateManager.INSTANCE.getClusterStateDescription(); - Map<String, Object> allProperties = getAllClusterProperties(); - json.putPOJO("config", allProperties); + AppContextInfo appConfig = (AppContextInfo) ctx.get(ASTERIX_APP_CONTEXT_INFO_ATTR); + json.putPOJO("config", ConfigUtils.getSectionOptionsForJSON(appConfig.getCCApplicationContext().getAppConfig(), + Section.COMMON, getConfigSelector())); ArrayNode ncs = (ArrayNode) json.get("ncs"); final StringBuilder requestURL = new StringBuilder("http://"); @@ -156,7 +128,6 @@ public class ClusterApiServlet extends AbstractServlet { cc.put(CONFIG_URI_KEY, clusterURL + "cc/config"); cc.put(STATS_URI_KEY, clusterURL + "cc/stats"); cc.put(THREAD_DUMP_URI_KEY, clusterURL + "cc/threaddump"); - json.put(REPLICATION_URI_KEY, clusterURL + "replication"); json.put(SHUTDOWN_URI_KEY, adminURL + "shutdown"); json.put(FULL_SHUTDOWN_URI_KEY, adminURL + "shutdown?all=true"); json.put(VERSION_URI_KEY, adminURL + "version"); @@ -164,6 +135,11 @@ public class ClusterApiServlet extends AbstractServlet { return json; } + protected Predicate<IOption> getConfigSelector() { + return option -> option != ControllerConfig.Option.CONFIG_FILE + && option != ControllerConfig.Option.CONFIG_FILE_URL; + } + private String canonicalize(CharSequence requestURL) { String clusterURL = ""; String newClusterURL = requestURL.toString(); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java index d680e6e..52d4d67 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ClusterControllerDetailsApiServlet.java @@ -41,7 +41,7 @@ public class ClusterControllerDetailsApiServlet extends ClusterApiServlet { private static final Logger LOGGER = Logger.getLogger(ClusterControllerDetailsApiServlet.class.getName()); private final ObjectMapper om = new ObjectMapper(); - public ClusterControllerDetailsApiServlet(ConcurrentMap<String, Object> ctx, String[] paths) { + public ClusterControllerDetailsApiServlet(ConcurrentMap<String, Object> ctx, String... paths) { super(ctx, paths); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/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 ffe62b4..de227eb 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 @@ -50,7 +50,7 @@ import io.netty.handler.codec.http.HttpResponseStatus; public class DiagnosticsApiServlet extends NodeControllerDetailsApiServlet { private static final Logger LOGGER = Logger.getLogger(DiagnosticsApiServlet.class.getName()); - public DiagnosticsApiServlet(ConcurrentMap<String, Object> ctx, String[] paths) { + public DiagnosticsApiServlet(ConcurrentMap<String, Object> ctx, String... paths) { super(ctx, paths); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java index 07e70ab..d9757c7 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NodeControllerDetailsApiServlet.java @@ -48,7 +48,7 @@ public class NodeControllerDetailsApiServlet extends ClusterApiServlet { private static final Logger LOGGER = Logger.getLogger(NodeControllerDetailsApiServlet.class.getName()); private final ObjectMapper om = new ObjectMapper(); - public NodeControllerDetailsApiServlet(ConcurrentMap<String, Object> ctx, String[] paths) { + public NodeControllerDetailsApiServlet(ConcurrentMap<String, Object> ctx, String... paths) { super(ctx, paths); om.enable(SerializationFeature.INDENT_OUTPUT); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java index 91bebfe..a4cea39 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/VersionApiServlet.java @@ -18,7 +18,7 @@ */ package org.apache.asterix.api.http.server; -import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_BUILD_PROP_ATTR; +import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_APP_CONTEXT_INFO_ATTR; import java.io.IOException; import java.io.PrintWriter; @@ -27,18 +27,15 @@ import java.util.concurrent.ConcurrentMap; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.asterix.runtime.utils.AppContextInfo; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.netty.handler.codec.http.HttpResponseStatus; +import org.apache.asterix.common.config.IPropertiesProvider; import org.apache.hyracks.http.api.IServletRequest; import org.apache.hyracks.http.api.IServletResponse; import org.apache.hyracks.http.server.AbstractServlet; import org.apache.hyracks.http.server.utils.HttpUtil; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; - -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpResponseStatus; - public class VersionApiServlet extends AbstractServlet { private static final Logger LOGGER = Logger.getLogger(VersionApiServlet.class.getName()); @@ -49,7 +46,7 @@ public class VersionApiServlet extends AbstractServlet { @Override protected void get(IServletRequest request, IServletResponse response) { response.setStatus(HttpResponseStatus.OK); - AppContextInfo props = (AppContextInfo) ctx.get(ASTERIX_BUILD_PROP_ATTR); + IPropertiesProvider props = (IPropertiesProvider) ctx.get(ASTERIX_APP_CONTEXT_INFO_ATTR); Map<String, String> buildProperties = props.getBuildProperties().getAllProps(); ObjectMapper om = new ObjectMapper(); ObjectNode responseObject = om.createObjectNode(); http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ServletConstants.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ServletConstants.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ServletConstants.java index d5f31ff..5b96cab 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ServletConstants.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/servlet/ServletConstants.java @@ -21,7 +21,7 @@ package org.apache.asterix.api.http.servlet; public class ServletConstants { public static final String HYRACKS_CONNECTION_ATTR = "org.apache.asterix.HYRACKS_CONNECTION"; public static final String HYRACKS_DATASET_ATTR = "org.apache.asterix.HYRACKS_DATASET"; - public static final String ASTERIX_BUILD_PROP_ATTR = "org.apache.asterix.PROPS"; + public static final String ASTERIX_APP_CONTEXT_INFO_ATTR = "org.apache.asterix.APP_CONTEXT_INFO"; public static final String EXECUTOR_SERVICE = "org.apache.asterix.EXECUTOR_SERVICE"; private ServletConstants() { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java index 625f18f..5eba31d 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/nc/NCAppRuntimeContext.java @@ -41,6 +41,7 @@ import org.apache.asterix.common.config.ExternalProperties; import org.apache.asterix.common.config.FeedProperties; import org.apache.asterix.common.config.MessagingProperties; import org.apache.asterix.common.config.MetadataProperties; +import org.apache.asterix.common.config.NodeProperties; import org.apache.asterix.common.config.PropertiesAccessor; import org.apache.asterix.common.config.ReplicationProperties; import org.apache.asterix.common.config.StorageProperties; @@ -113,6 +114,7 @@ public class NCAppRuntimeContext implements IAppRuntimeContext { private BuildProperties buildProperties; private ReplicationProperties replicationProperties; private MessagingProperties messagingProperties; + private final NodeProperties nodeProperties; private ThreadExecutor threadExecutor; private IDatasetLifecycleManager datasetLifecycleManager; private IFileMapManager fileMapManager; @@ -150,6 +152,7 @@ public class NCAppRuntimeContext implements IAppRuntimeContext { buildProperties = new BuildProperties(propertiesAccessor); replicationProperties = new ReplicationProperties(propertiesAccessor); messagingProperties = new MessagingProperties(propertiesAccessor); + nodeProperties = new NodeProperties(propertiesAccessor); libraryManager = new ExternalLibraryManager(); if (extensions != null) { allExtensions.addAll(extensions); @@ -220,7 +223,7 @@ public class NCAppRuntimeContext implements IAppRuntimeContext { //PersistentLocalResourceRepository to replicate metadata files and delete backups on drop index localResourceRepository.setReplicationManager(replicationManager); - /** + /* * add the partitions that will be replicated in this node as inactive partitions */ //get nodes which replicate to this node @@ -254,12 +257,12 @@ public class NCAppRuntimeContext implements IAppRuntimeContext { */ ILifeCycleComponentManager lccm = ncApplicationContext.getLifeCycleComponentManager(); lccm.register((ILifeCycleComponent) bufferCache); - /** + /* * LogManager must be stopped after RecoveryManager, DatasetLifeCycleManager, and ReplicationManager * to process any logs that might be generated during stopping these components */ lccm.register((ILifeCycleComponent) txnSubsystem.getLogManager()); - /** + /* * ReplicationManager must be stopped after indexLifecycleManager and recovery manager * so that any logs/files generated during closing datasets or checkpoints are sent to remote replicas */ @@ -267,7 +270,7 @@ public class NCAppRuntimeContext implements IAppRuntimeContext { lccm.register(replicationManager); } lccm.register((ILifeCycleComponent) txnSubsystem.getRecoveryManager()); - /** + /* * Stopping indexLifecycleManager will flush and close all datasets. */ lccm.register((ILifeCycleComponent) datasetLifecycleManager); @@ -376,6 +379,11 @@ public class NCAppRuntimeContext implements IAppRuntimeContext { } @Override + public NodeProperties getNodeProperties() { + return nodeProperties; + } + + @Override public ILSMOperationTracker getLSMBTreeOperationTracker(int datasetID) { return datasetLifecycleManager.getOperationTracker(datasetID); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java index 5104610..8d8a0f2 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/replication/AutoFaultToleranceStrategy.java @@ -67,6 +67,7 @@ import org.apache.asterix.metadata.MetadataManager; import org.apache.asterix.runtime.utils.AppContextInfo; import org.apache.asterix.util.FaultToleranceUtil; import org.apache.hyracks.api.application.IClusterLifecycleListener.ClusterEventType; +import org.apache.hyracks.api.config.IOption; import org.apache.hyracks.api.exceptions.HyracksDataException; public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { @@ -113,9 +114,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { } private synchronized void notifyFailbackPlansNodeFailure(String nodeId) { - Iterator<NodeFailbackPlan> iterator = planId2FailbackPlanMap.values().iterator(); - while (iterator.hasNext()) { - NodeFailbackPlan plan = iterator.next(); + for (NodeFailbackPlan plan : planId2FailbackPlanMap.values()) { plan.notifyNodeFailure(nodeId); } } @@ -173,7 +172,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { try { messageBroker.sendApplicationMessageToNC(takeoverRequest, replica); } catch (Exception e) { - /** + /* * if we fail to send the request, it means the NC we tried to send the request to * has failed. When the failure notification arrives, we will send any pending request * that belongs to the failed NC to a different active replica. @@ -186,7 +185,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { private boolean addActiveReplica(String replica, ClusterPartition partition, Map<String, List<Integer>> partitionRecoveryPlan) { - Map<String, Map<String, String>> activeNcConfiguration = clusterManager.getActiveNcConfiguration(); + Map<String, Map<IOption, Object>> activeNcConfiguration = clusterManager.getActiveNcConfiguration(); if (activeNcConfiguration.containsKey(replica) && !failedNodes.contains(replica)) { if (!partitionRecoveryPlan.containsKey(replica)) { List<Integer> replicaPartitions = new ArrayList<>(); @@ -213,7 +212,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { ClusterPartition[] nodePartitions = clusterManager.getNodePartitions(replicaId); for (ClusterPartition partition : nodePartitions) { plan.addParticipant(partition.getActiveNodeId()); - /** + /* * if the partition original node is the returning node, * add it to the list of the partitions which will be failed back */ @@ -232,7 +231,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { private synchronized void processPendingFailbackPlans() { ClusterState state = clusterManager.getState(); - /** + /* * if the cluster state is not ACTIVE, then failbacks should not be processed * since some partitions are not active */ @@ -240,7 +239,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { while (!pendingProcessingFailbackPlans.isEmpty()) { //take the first pending failback plan NodeFailbackPlan plan = pendingProcessingFailbackPlans.pop(); - /** + /* * A plan at this stage will be in one of two states: * 1. PREPARING -> the participants were selected but we haven't sent any request. * 2. PENDING_ROLLBACK -> a participant failed before we send any requests @@ -253,7 +252,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { clusterManager.updateClusterPartition(partitionId, failbackNode, false); } - /** + /* * if the returning node is the original metadata node, * then metadata node will change after the failback completes */ @@ -268,7 +267,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { //force new jobs to wait clusterManager.setState(ClusterState.REBALANCING); handleFailbackRequests(plan, messageBroker); - /** + /* * wait until the current plan is completed before processing the next plan. * when the current one completes or is reverted, the cluster state will be * ACTIVE again, and the next failback plan (if any) will be processed. @@ -305,11 +304,11 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { clusterPartitionsMap.put(partition.getPartitionId(), partition); } for (ClusterPartition partition : clusterPartitons) { - if (partition.getActiveNodeId().equals(nodeId)) { + if (nodeId.equals(partition.getActiveNodeId())) { nodePartitions.add(partition); } } - /** + /* * if there is any pending takeover request this node was supposed to handle, * it needs to be sent to a different replica */ @@ -359,7 +358,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { public synchronized void process(PreparePartitionsFailbackResponseMessage msg) { NodeFailbackPlan plan = planId2FailbackPlanMap.get(msg.getPlanId()); plan.markRequestCompleted(msg.getRequestId()); - /** + /* * A plan at this stage will be in one of three states: * 1. PENDING_PARTICIPANT_REPONSE -> one or more responses are still expected (wait). * 2. PENDING_COMPLETION -> all responses received (time to send completion request). @@ -382,7 +381,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { } public synchronized void process(CompleteFailbackResponseMessage response) throws HyracksDataException { - /** + /* * the failback plan completed successfully: * Remove all references to it. * Remove the the failing back node from the failed nodes list. @@ -409,8 +408,7 @@ public class AutoFaultToleranceStrategy implements IFaultToleranceStrategy { // Since the metadata node will be changed, we need to rebind the proxy object MetadataManager.INSTANCE.rebindMetadataNode(); } catch (Exception e) { - - /** + /* * if we fail to send the request, it means the NC we tried to send the request to * has failed. When the failure notification arrives, a new NC will be assigned to * the metadata partition and a new metadata node takeover request will be sent to it. http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java index f3182cf..54f2c06 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java @@ -18,8 +18,33 @@ */ package org.apache.asterix.hyracks.bootstrap; +import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_APP_CONTEXT_INFO_ATTR; +import static org.apache.asterix.api.http.servlet.ServletConstants.HYRACKS_CONNECTION_ATTR; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ConcurrentMap; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apache.asterix.active.ActiveLifecycleListener; -import org.apache.asterix.api.http.server.*; +import org.apache.asterix.api.http.server.ApiServlet; +import org.apache.asterix.api.http.server.ClusterApiServlet; +import org.apache.asterix.api.http.server.ClusterControllerDetailsApiServlet; +import org.apache.asterix.api.http.server.ConnectorApiServlet; +import org.apache.asterix.api.http.server.DdlApiServlet; +import org.apache.asterix.api.http.server.DiagnosticsApiServlet; +import org.apache.asterix.api.http.server.FeedServlet; +import org.apache.asterix.api.http.server.FullApiServlet; +import org.apache.asterix.api.http.server.NodeControllerDetailsApiServlet; +import org.apache.asterix.api.http.server.QueryApiServlet; +import org.apache.asterix.api.http.server.QueryResultApiServlet; +import org.apache.asterix.api.http.server.QueryServiceServlet; +import org.apache.asterix.api.http.server.QueryStatusApiServlet; +import org.apache.asterix.api.http.server.QueryWebInterfaceServlet; +import org.apache.asterix.api.http.server.ShutdownApiServlet; +import org.apache.asterix.api.http.server.UpdateApiServlet; +import org.apache.asterix.api.http.server.VersionApiServlet; import org.apache.asterix.api.http.servlet.ServletConstants; import org.apache.asterix.app.cc.CCExtensionManager; import org.apache.asterix.app.cc.ResourceIdManager; @@ -27,6 +52,7 @@ import org.apache.asterix.app.external.ExternalLibraryUtils; import org.apache.asterix.app.replication.FaultToleranceStrategyFactory; import org.apache.asterix.common.api.AsterixThreadFactory; import org.apache.asterix.common.config.AsterixExtension; +import org.apache.asterix.common.config.AsterixProperties; import org.apache.asterix.common.config.ClusterProperties; import org.apache.asterix.common.config.ExternalProperties; import org.apache.asterix.common.config.MetadataProperties; @@ -47,9 +73,9 @@ import org.apache.asterix.runtime.job.resource.JobCapacityController; import org.apache.asterix.runtime.utils.AppContextInfo; import org.apache.asterix.translator.IStatementExecutorFactory; import org.apache.hyracks.api.application.ICCApplicationContext; -import org.apache.hyracks.api.application.ICCApplicationEntryPoint; import org.apache.hyracks.api.client.HyracksConnection; import org.apache.hyracks.api.client.IHyracksClientConnection; +import org.apache.hyracks.api.config.IConfigManager; import org.apache.hyracks.api.job.resource.IJobCapacityController; import org.apache.hyracks.api.lifecycle.LifeCycleComponentManager; import org.apache.hyracks.control.cc.ClusterControllerService; @@ -57,15 +83,9 @@ import org.apache.hyracks.control.common.controllers.CCConfig; import org.apache.hyracks.http.api.IServlet; import org.apache.hyracks.http.server.HttpServer; import org.apache.hyracks.http.server.WebManager; +import org.apache.hyracks.util.file.FileUtil; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_BUILD_PROP_ATTR; -import static org.apache.asterix.api.http.servlet.ServletConstants.HYRACKS_CONNECTION_ATTR; - -public class CCApplicationEntryPoint implements ICCApplicationEntryPoint { +public class CCApplicationEntryPoint extends org.apache.hyracks.control.cc.CCApplicationEntryPoint { private static final Logger LOGGER = Logger.getLogger(CCApplicationEntryPoint.class.getName()); private static IAsterixStateProxy proxy; @@ -75,8 +95,15 @@ public class CCApplicationEntryPoint implements ICCApplicationEntryPoint { private IJobCapacityController jobCapacityController; protected WebManager webManager; + public CCApplicationEntryPoint() { + CCConfig.defaultDir = FileUtil.joinPath(System.getProperty("java.io.tmpdir"), "asterixdb"); + } + @Override public void start(ICCApplicationContext ccAppCtx, String[] args) throws Exception { + if (args.length > 0) { + throw new IllegalArgumentException("Unrecognized argument(s): " + Arrays.toString(args)); + } final ClusterControllerService controllerService = (ClusterControllerService) ccAppCtx.getControllerService(); ICCMessageBroker messageBroker = new CCMessageBroker(controllerService); this.appCtx = ccAppCtx; @@ -100,7 +127,7 @@ public class CCApplicationEntryPoint implements ICCApplicationEntryPoint { AppContextInfo.INSTANCE.setExtensionManager(ccExtensionManager); final CCConfig ccConfig = controllerService.getCCConfig(); if (System.getProperty("java.rmi.server.hostname") == null) { - System.setProperty("java.rmi.server.hostname", ccConfig.clusterNetIpAddress); + System.setProperty("java.rmi.server.hostname", ccConfig.getClusterListenAddress()); } MetadataProperties metadataProperties = AppContextInfo.INSTANCE.getMetadataProperties(); @@ -165,7 +192,7 @@ public class CCApplicationEntryPoint implements ICCApplicationEntryPoint { new HttpServer(webManager.getBosses(), webManager.getWorkers(), externalProperties.getAPIServerPort()); IHyracksClientConnection hcc = getNewHyracksClientConnection(); jsonAPIServer.setAttribute(HYRACKS_CONNECTION_ATTR, hcc); - jsonAPIServer.setAttribute(ASTERIX_BUILD_PROP_ATTR, AppContextInfo.INSTANCE); + jsonAPIServer.setAttribute(ASTERIX_APP_CONTEXT_INFO_ATTR, AppContextInfo.INSTANCE); jsonAPIServer.setAttribute(ServletConstants.EXECUTOR_SERVICE, ((ClusterControllerService) appCtx.getControllerService()).getExecutor()); @@ -196,7 +223,7 @@ public class CCApplicationEntryPoint implements ICCApplicationEntryPoint { } protected void addServlet(HttpServer server, String path) { - server.addServlet(createServlet(server, path, path)); + server.addServlet(createServlet(server.ctx(), path, path)); } protected HttpServer setupQueryWebServer(ExternalProperties externalProperties) throws Exception { @@ -216,53 +243,53 @@ public class CCApplicationEntryPoint implements ICCApplicationEntryPoint { return feedServer; } - protected IServlet createServlet(HttpServer server, String key, String... paths) { + protected IServlet createServlet(ConcurrentMap<String, Object> ctx, String key, String... paths) { switch (key) { case Servlets.AQL: - return new FullApiServlet(server.ctx(), paths, ccExtensionManager.getAqlCompilationProvider(), + return new FullApiServlet(ctx, paths, ccExtensionManager.getAqlCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.AQL_QUERY: - return new QueryApiServlet(server.ctx(), paths, ccExtensionManager.getAqlCompilationProvider(), + return new QueryApiServlet(ctx, paths, ccExtensionManager.getAqlCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.AQL_UPDATE: - return new UpdateApiServlet(server.ctx(), paths, ccExtensionManager.getAqlCompilationProvider(), + return new UpdateApiServlet(ctx, paths, ccExtensionManager.getAqlCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.AQL_DDL: - return new DdlApiServlet(server.ctx(), paths, ccExtensionManager.getAqlCompilationProvider(), + return new DdlApiServlet(ctx, paths, ccExtensionManager.getAqlCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.SQLPP: - return new FullApiServlet(server.ctx(), paths, ccExtensionManager.getSqlppCompilationProvider(), + return new FullApiServlet(ctx, paths, ccExtensionManager.getSqlppCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.SQLPP_QUERY: - return new QueryApiServlet(server.ctx(), paths, ccExtensionManager.getSqlppCompilationProvider(), + return new QueryApiServlet(ctx, paths, ccExtensionManager.getSqlppCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.SQLPP_UPDATE: - return new UpdateApiServlet(server.ctx(), paths, ccExtensionManager.getSqlppCompilationProvider(), + return new UpdateApiServlet(ctx, paths, ccExtensionManager.getSqlppCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.SQLPP_DDL: - return new DdlApiServlet(server.ctx(), paths, ccExtensionManager.getSqlppCompilationProvider(), + return new DdlApiServlet(ctx, paths, ccExtensionManager.getSqlppCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.QUERY_STATUS: - return new QueryStatusApiServlet(server.ctx(), paths); + return new QueryStatusApiServlet(ctx, paths); case Servlets.QUERY_RESULT: - return new QueryResultApiServlet(server.ctx(), paths); + return new QueryResultApiServlet(ctx, paths); case Servlets.QUERY_SERVICE: - return new QueryServiceServlet(server.ctx(), paths, ccExtensionManager.getSqlppCompilationProvider(), + return new QueryServiceServlet(ctx, paths, ccExtensionManager.getSqlppCompilationProvider(), getStatementExecutorFactory(), componentProvider); case Servlets.CONNECTOR: - return new ConnectorApiServlet(server.ctx(), paths); + return new ConnectorApiServlet(ctx, paths); case Servlets.SHUTDOWN: - return new ShutdownApiServlet(server.ctx(), paths); + return new ShutdownApiServlet(ctx, paths); case Servlets.VERSION: - return new VersionApiServlet(server.ctx(), paths); + return new VersionApiServlet(ctx, paths); case Servlets.CLUSTER_STATE: - return new ClusterApiServlet(server.ctx(), paths); + return new ClusterApiServlet(ctx, paths); case Servlets.CLUSTER_STATE_NODE_DETAIL: - return new NodeControllerDetailsApiServlet(server.ctx(), paths); + return new NodeControllerDetailsApiServlet(ctx, paths); case Servlets.CLUSTER_STATE_CC_DETAIL: - return new ClusterControllerDetailsApiServlet(server.ctx(), paths); + return new ClusterControllerDetailsApiServlet(ctx, paths); case Servlets.DIAGNOSTICS: - return new DiagnosticsApiServlet(server.ctx(), paths); + return new DiagnosticsApiServlet(ctx, paths); default: throw new IllegalStateException(String.valueOf(key)); } @@ -283,7 +310,13 @@ public class CCApplicationEntryPoint implements ICCApplicationEntryPoint { return jobCapacityController; } + @Override + public void registerConfig(IConfigManager configManager) { + super.registerConfig(configManager); + AsterixProperties.registerConfigOptions(configManager); + } + public static synchronized void setAsterixStateProxy(IAsterixStateProxy proxy) { - CCApplicationEntryPoint.proxy = proxy; + org.apache.asterix.hyracks.bootstrap.CCApplicationEntryPoint.proxy = proxy; } } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/ClusterLifecycleListener.java ---------------------------------------------------------------------- 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 53b577a..8883504 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 @@ -43,6 +43,7 @@ import org.apache.asterix.metadata.cluster.RemoveNodeWork; import org.apache.asterix.metadata.cluster.RemoveNodeWorkResponse; import org.apache.asterix.runtime.utils.ClusterStateManager; import org.apache.hyracks.api.application.IClusterLifecycleListener; +import org.apache.hyracks.api.config.IOption; import org.apache.hyracks.api.exceptions.HyracksException; public class ClusterLifecycleListener implements IClusterLifecycleListener { @@ -66,7 +67,7 @@ public class ClusterLifecycleListener implements IClusterLifecycleListener { } @Override - public void notifyNodeJoin(String nodeId, Map<String, String> ncConfiguration) throws HyracksException { + public void notifyNodeJoin(String nodeId, Map<IOption, Object> ncConfiguration) throws HyracksException { if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("NC: " + nodeId + " joined"); } http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java index 7f649bc..238e93c 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java @@ -18,15 +18,24 @@ */ package org.apache.asterix.hyracks.bootstrap; +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.apache.asterix.app.nc.NCAppRuntimeContext; import org.apache.asterix.app.replication.message.StartupTaskRequestMessage; import org.apache.asterix.common.api.AsterixThreadFactory; import org.apache.asterix.common.api.IAppRuntimeContext; import org.apache.asterix.common.config.AsterixExtension; +import org.apache.asterix.common.config.AsterixProperties; import org.apache.asterix.common.config.ClusterProperties; import org.apache.asterix.common.config.IPropertiesProvider; import org.apache.asterix.common.config.MessagingProperties; import org.apache.asterix.common.config.MetadataProperties; +import org.apache.asterix.common.config.NodeProperties; import org.apache.asterix.common.config.StorageProperties; import org.apache.asterix.common.config.TransactionProperties; import org.apache.asterix.common.transactions.IRecoveryManager; @@ -40,53 +49,42 @@ import org.apache.asterix.messaging.NCMessageBroker; import org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository; import org.apache.commons.io.FileUtils; import org.apache.hyracks.api.application.INCApplicationContext; -import org.apache.hyracks.api.application.INCApplicationEntryPoint; +import org.apache.hyracks.api.config.IConfigManager; import org.apache.hyracks.api.job.resource.NodeCapacity; import org.apache.hyracks.api.messages.IMessageBroker; +import org.apache.hyracks.control.common.controllers.NCConfig; import org.apache.hyracks.control.nc.NodeControllerService; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; -import org.kohsuke.args4j.Option; +import org.apache.hyracks.util.file.FileUtil; -import java.io.File; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class NCApplicationEntryPoint implements INCApplicationEntryPoint { +public class NCApplicationEntryPoint extends org.apache.hyracks.control.nc.NCApplicationEntryPoint { private static final Logger LOGGER = Logger.getLogger(NCApplicationEntryPoint.class.getName()); - @Option(name = "-initial-run", usage = "A flag indicating if it's the first time the NC is started " - + "(default: false)", required = false) - public boolean initialRun = false; - - @Option(name = "-virtual-NC", usage = "A flag indicating if this NC is running on virtual cluster " - + "(default: false)", required = false) - public boolean virtualNC = false; - - private INCApplicationContext ncApplicationContext = null; + private INCApplicationContext ncAppCtx; private IAppRuntimeContext runtimeContext; private String nodeId; private boolean stopInitiated = false; private SystemState systemState; - private IMessageBroker messageBroker; + + public NCApplicationEntryPoint() { + NCConfig.defaultDir = FileUtil.joinPath(System.getProperty("java.io.tmpdir"), "asterixdb"); + NCConfig.defaultAppClass = "org.apache.asterix.hyracks.bootstrap.NCApplicationEntryPoint"; + } + + @Override + public void registerConfigOptions(IConfigManager configManager) { + super.registerConfigOptions(configManager); + AsterixProperties.registerConfigOptions(configManager); + } @Override public void start(INCApplicationContext ncAppCtx, String[] args) throws Exception { - CmdLineParser parser = new CmdLineParser(this); - try { - parser.parseArgument(args); - } catch (CmdLineException e) { - LOGGER.severe(e.getMessage()); - LOGGER.severe("Usage:"); - parser.printUsage(System.err); - throw e; + if (args.length > 0) { + throw new IllegalArgumentException("Unrecognized argument(s): " + Arrays.toString(args)); } - ncAppCtx.setThreadFactory( - new AsterixThreadFactory(ncAppCtx.getThreadFactory(), ncAppCtx.getLifeCycleComponentManager())); - ncApplicationContext = ncAppCtx; - nodeId = ncApplicationContext.getNodeId(); + ncAppCtx.setThreadFactory(new AsterixThreadFactory(ncAppCtx.getThreadFactory(), + ncAppCtx.getLifeCycleComponentManager())); + this.ncAppCtx = ncAppCtx; + nodeId = this.ncAppCtx.getNodeId(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Starting Asterix node controller: " + nodeId); } @@ -94,25 +92,25 @@ public class NCApplicationEntryPoint implements INCApplicationEntryPoint { final NodeControllerService controllerService = (NodeControllerService) ncAppCtx.getControllerService(); if (System.getProperty("java.rmi.server.hostname") == null) { - System.setProperty("java.rmi.server.hostname", - (controllerService).getConfiguration().clusterNetPublicIPAddress); + System.setProperty("java.rmi.server.hostname", (controllerService) + .getConfiguration().getClusterPublicAddress()); } - runtimeContext = new NCAppRuntimeContext(ncApplicationContext, getExtensions()); - MetadataProperties metadataProperties = ((IPropertiesProvider) runtimeContext).getMetadataProperties(); - if (!metadataProperties.getNodeNames().contains(ncApplicationContext.getNodeId())) { + runtimeContext = new NCAppRuntimeContext(this.ncAppCtx, getExtensions()); + MetadataProperties metadataProperties = runtimeContext.getMetadataProperties(); + if (!metadataProperties.getNodeNames().contains(this.ncAppCtx.getNodeId())) { if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info("Substitute node joining : " + ncApplicationContext.getNodeId()); + LOGGER.info("Substitute node joining : " + this.ncAppCtx.getNodeId()); } updateOnNodeJoin(); } - runtimeContext.initialize(initialRun); - ncApplicationContext.setApplicationObject(runtimeContext); - MessagingProperties messagingProperties = ((IPropertiesProvider) runtimeContext).getMessagingProperties(); - messageBroker = new NCMessageBroker(controllerService, messagingProperties); - ncApplicationContext.setMessageBroker(messageBroker); + runtimeContext.initialize(runtimeContext.getNodeProperties().isInitialRun()); + this.ncAppCtx.setApplicationObject(runtimeContext); + MessagingProperties messagingProperties = runtimeContext.getMessagingProperties(); + IMessageBroker messageBroker = new NCMessageBroker(controllerService, messagingProperties); + this.ncAppCtx.setMessageBroker(messageBroker); MessagingChannelInterfaceFactory interfaceFactory = new MessagingChannelInterfaceFactory( (NCMessageBroker) messageBroker, messagingProperties); - ncApplicationContext.setMessagingChannelInterfaceFactory(interfaceFactory); + this.ncAppCtx.setMessagingChannelInterfaceFactory(interfaceFactory); IRecoveryManager recoveryMgr = runtimeContext.getTransactionSubsystem().getRecoveryManager(); systemState = recoveryMgr.getSystemState(); @@ -148,7 +146,7 @@ public class NCApplicationEntryPoint implements INCApplicationEntryPoint { performLocalCleanUp(); //Note: stopping recovery manager will make a sharp checkpoint - ncApplicationContext.getLifeCycleComponentManager().stopAll(false); + ncAppCtx.getLifeCycleComponentManager().stopAll(false); runtimeContext.deinitialize(); } else { if (LOGGER.isLoggable(Level.INFO)) { @@ -160,17 +158,18 @@ public class NCApplicationEntryPoint implements INCApplicationEntryPoint { @Override public void notifyStartupComplete() throws Exception { // Since we don't pass initial run flag in AsterixHyracksIntegrationUtil, we use the virtualNC flag - if (systemState == SystemState.PERMANENT_DATA_LOSS && (initialRun || virtualNC)) { + final NodeProperties nodeProperties = runtimeContext.getNodeProperties(); + if (systemState == SystemState.PERMANENT_DATA_LOSS && (nodeProperties.isInitialRun() || nodeProperties.isVirtualNc())) { systemState = SystemState.BOOTSTRAPPING; } // Request startup tasks from CC - StartupTaskRequestMessage.send((NodeControllerService) ncApplicationContext.getControllerService(), + StartupTaskRequestMessage.send((NodeControllerService) ncAppCtx.getControllerService(), systemState); } @Override public NodeCapacity getCapacity() { - IPropertiesProvider propertiesProvider = (IPropertiesProvider) runtimeContext; + IPropertiesProvider propertiesProvider = runtimeContext; StorageProperties storageProperties = propertiesProvider.getStorageProperties(); // Deducts the reserved buffer cache size and memory component size from the maxium heap size, // and deducts one core for processing heartbeats. @@ -201,15 +200,16 @@ public class NCApplicationEntryPoint implements INCApplicationEntryPoint { } private void updateOnNodeJoin() { - MetadataProperties metadataProperties = ((IPropertiesProvider) runtimeContext).getMetadataProperties(); + MetadataProperties metadataProperties = runtimeContext.getMetadataProperties(); if (!metadataProperties.getNodeNames().contains(nodeId)) { - metadataProperties.getNodeNames().add(nodeId); Cluster cluster = ClusterProperties.INSTANCE.getCluster(); if (cluster == null) { throw new IllegalStateException("No cluster configuration found for this instance"); } + NCConfig ncConfig = ((NodeControllerService) ncAppCtx.getControllerService()).getConfiguration(); + ncConfig.getConfigManager().registerVirtualNode(nodeId); String asterixInstanceName = metadataProperties.getInstanceName(); - TransactionProperties txnProperties = ((IPropertiesProvider) runtimeContext).getTransactionProperties(); + TransactionProperties txnProperties = runtimeContext.getTransactionProperties(); Node self = null; List<Node> nodes; if (cluster.getSubstituteNodes() != null) { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java index 0ab4e54..241cd65 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/util/FaultToleranceUtil.java @@ -31,11 +31,12 @@ import org.apache.asterix.common.replication.Replica; import org.apache.asterix.runtime.message.ReplicaEventMessage; import org.apache.commons.lang3.StringUtils; import org.apache.hyracks.api.application.IClusterLifecycleListener.ClusterEventType; +import org.apache.hyracks.api.config.IOption; +import org.apache.hyracks.control.common.controllers.NCConfig; public class FaultToleranceUtil { private static final Logger LOGGER = Logger.getLogger(FaultToleranceUtil.class.getName()); - private static final String CLUSTER_NET_IP_ADDRESS_KEY = "cluster-net-ip-address"; private FaultToleranceUtil() { throw new AssertionError(); @@ -47,10 +48,10 @@ public class FaultToleranceUtil { List<String> primaryRemoteReplicas = replicationStrategy.getRemotePrimaryReplicas(nodeId).stream() .map(Replica::getId).collect(Collectors.toList()); String nodeIdAddress = StringUtils.EMPTY; - Map<String, Map<String, String>> activeNcConfiguration = clusterManager.getActiveNcConfiguration(); + Map<String, Map<IOption, Object>> activeNcConfiguration = clusterManager.getActiveNcConfiguration(); // In case the node joined with a new IP address, we need to send it to the other replicas if (event == ClusterEventType.NODE_JOIN) { - nodeIdAddress = activeNcConfiguration.get(nodeId).get(CLUSTER_NET_IP_ADDRESS_KEY); + nodeIdAddress = (String)activeNcConfiguration.get(nodeId).get(NCConfig.Option.CLUSTER_PUBLIC_ADDRESS); } ReplicaEventMessage msg = new ReplicaEventMessage(nodeId, nodeIdAddress, event); for (String replica : primaryRemoteReplicas) { http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/main/resources/asterix-build-configuration.xml ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/main/resources/asterix-build-configuration.xml b/asterixdb/asterix-app/src/main/resources/asterix-build-configuration.xml index 7390d57..42cc42c 100644 --- a/asterixdb/asterix-app/src/main/resources/asterix-build-configuration.xml +++ b/asterixdb/asterix-app/src/main/resources/asterix-build-configuration.xml @@ -110,4 +110,9 @@ <description>Number of reusable frames for NC to NC messaging. (Default = 512) </description> </property> + <property> + <name>log.level</name> + <value>INFO</value> + <description>foo</description> + </property> </asterixConfiguration> http://git-wip-us.apache.org/repos/asf/asterixdb/blob/4c7b5bfa/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionApiServletTest.java ---------------------------------------------------------------------- diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionApiServletTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionApiServletTest.java index 7fed010..52ac855 100644 --- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionApiServletTest.java +++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/api/http/servlet/VersionApiServletTest.java @@ -19,7 +19,7 @@ package org.apache.asterix.api.http.servlet; -import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_BUILD_PROP_ATTR; +import static org.apache.asterix.api.http.servlet.ServletConstants.ASTERIX_APP_CONTEXT_INFO_ATTR; import static org.apache.asterix.api.http.servlet.ServletConstants.HYRACKS_CONNECTION_ATTR; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -69,7 +69,7 @@ public class VersionApiServletTest { // Put stuff in let map servlet.ctx().put(HYRACKS_CONNECTION_ATTR, mockHcc); - servlet.ctx().put(ASTERIX_BUILD_PROP_ATTR, mockCtx); + servlet.ctx().put(ASTERIX_APP_CONTEXT_INFO_ATTR, mockCtx); // Sets up mock returns. when(mockResponse.writer()).thenReturn(outputWriter); when(mockRequest.getHttpRequest()).thenReturn(mockHttpRequest);
