Return-Path: X-Original-To: apmail-helix-commits-archive@minotaur.apache.org Delivered-To: apmail-helix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 87BC0102EE for ; Wed, 21 Aug 2013 20:44:11 +0000 (UTC) Received: (qmail 71816 invoked by uid 500); 21 Aug 2013 20:44:11 -0000 Delivered-To: apmail-helix-commits-archive@helix.apache.org Received: (qmail 71791 invoked by uid 500); 21 Aug 2013 20:44:11 -0000 Mailing-List: contact commits-help@helix.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@helix.incubator.apache.org Delivered-To: mailing list commits@helix.incubator.apache.org Received: (qmail 71715 invoked by uid 99); 21 Aug 2013 20:44:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Aug 2013 20:44:11 +0000 X-ASF-Spam-Status: No, hits=-2002.8 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 21 Aug 2013 20:43:41 +0000 Received: (qmail 66176 invoked by uid 99); 21 Aug 2013 20:43:16 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Aug 2013 20:43:16 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4B5628C1FD3; Wed, 21 Aug 2013 20:43:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zzhang@apache.org To: commits@helix.incubator.apache.org Date: Wed, 21 Aug 2013 20:44:04 -0000 Message-Id: <2dd5d00e9eb844b6a3f267678cfd2617@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [51/51] [partial] git commit: [HELIX-198] Unify helix code style, rb=13710 X-Virus-Checked: Checked by ClamAV on apache.org [HELIX-198] Unify helix code style, rb=13710 Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/f414aad4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/f414aad4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/f414aad4 Branch: refs/heads/master Commit: f414aad4c9b26fc767eaf373f7691f8e0487a598 Parents: 18f603a Author: zzhang Authored: Wed Aug 21 13:42:57 2013 -0700 Committer: zzhang Committed: Wed Aug 21 13:42:57 2013 -0700 ---------------------------------------------------------------------- .../apache/helix/webapp/HelixAdminWebApp.java | 53 +- .../helix/webapp/RestAdminApplication.java | 116 +- .../resources/ClusterRepresentationUtil.java | 165 +-- .../helix/webapp/resources/ClusterResource.java | 102 +- .../webapp/resources/ClustersResource.java | 71 +- .../helix/webapp/resources/ConfigResource.java | 150 +- .../webapp/resources/ConstraintResource.java | 68 +- .../webapp/resources/ControllerResource.java | 71 +- .../ControllerStatusUpdateResource.java | 69 +- .../webapp/resources/CurrentStateResource.java | 59 +- .../webapp/resources/CurrentStatesResource.java | 51 +- .../helix/webapp/resources/ErrorResource.java | 59 +- .../helix/webapp/resources/ErrorsResource.java | 55 +- .../webapp/resources/ExternalViewResource.java | 48 +- .../webapp/resources/IdealStateResource.java | 106 +- .../webapp/resources/InstanceResource.java | 146 +- .../webapp/resources/InstancesResource.java | 126 +- .../helix/webapp/resources/JsonParameters.java | 213 +-- .../webapp/resources/ResourceGroupResource.java | 86 +- .../resources/ResourceGroupsResource.java | 117 +- .../resources/SchedulerTasksResource.java | 157 +- .../webapp/resources/StateModelResource.java | 71 +- .../webapp/resources/StateModelsResource.java | 109 +- .../webapp/resources/StatusUpdateResource.java | 67 +- .../webapp/resources/StatusUpdatesResource.java | 52 +- .../helix/webapp/resources/ZkChildResource.java | 80 +- .../helix/webapp/resources/ZkPathResource.java | 100 +- .../org/apache/helix/tools/AdminTestBase.java | 34 +- .../org/apache/helix/tools/AdminTestHelper.java | 46 +- .../tools/TestHelixAdminScenariosRest.java | 255 ++-- .../apache/helix/tools/TestResetInstance.java | 84 +- .../helix/tools/TestResetPartitionState.java | 295 ++-- .../apache/helix/tools/TestResetResource.java | 83 +- .../webapp/TestClusterManagementWebapp.java | 220 ++- .../org/apache/helix/agent/AgentStateModel.java | 83 +- .../helix/agent/AgentStateModelFactory.java | 7 +- .../apache/helix/agent/CommandAttribute.java | 16 +- .../org/apache/helix/agent/CommandConfig.java | 34 +- .../org/apache/helix/agent/HelixAgentMain.java | 81 +- .../helix/agent/ProcessMonitorThread.java | 16 +- .../java/org/apache/helix/agent/SystemUtil.java | 35 +- .../org/apache/helix/agent/TestHelixAgent.java | 152 +- .../java/org/apache/helix/AccessOption.java | 26 +- .../java/org/apache/helix/BaseDataAccessor.java | 33 +- .../apache/helix/ClusterMessagingService.java | 42 +- .../java/org/apache/helix/ConfigAccessor.java | 209 +-- .../org/apache/helix/ConfigChangeListener.java | 9 +- .../apache/helix/ControllerChangeListener.java | 4 +- .../main/java/org/apache/helix/Criteria.java | 63 +- .../helix/CurrentStateChangeListener.java | 9 +- .../java/org/apache/helix/ExternalCommand.java | 313 ++-- .../helix/ExternalViewChangeListener.java | 6 +- .../main/java/org/apache/helix/GroupCommit.java | 128 +- .../apache/helix/HealthStateChangeListener.java | 9 +- .../main/java/org/apache/helix/HelixAdmin.java | 161 +- .../java/org/apache/helix/HelixConstants.java | 14 +- .../org/apache/helix/HelixDataAccessor.java | 29 +- .../org/apache/helix/HelixDefinedState.java | 32 +- .../java/org/apache/helix/HelixException.java | 9 +- .../java/org/apache/helix/HelixManager.java | 88 +- .../org/apache/helix/HelixManagerFactory.java | 11 +- .../apache/helix/HelixManagerProperties.java | 68 +- .../java/org/apache/helix/HelixProperty.java | 129 +- .../java/org/apache/helix/HelixTimerTask.java | 5 +- .../apache/helix/IdealStateChangeListener.java | 4 +- .../helix/InstanceConfigChangeListener.java | 9 +- .../java/org/apache/helix/InstanceType.java | 14 +- .../helix/LiveInstanceChangeListener.java | 6 +- .../apache/helix/LiveInstanceInfoProvider.java | 7 +- .../java/org/apache/helix/MessageListener.java | 4 +- .../org/apache/helix/NotificationContext.java | 67 +- .../org/apache/helix/PreConnectCallback.java | 4 +- .../main/java/org/apache/helix/PropertyKey.java | 451 ++---- .../org/apache/helix/PropertyPathConfig.java | 55 +- .../java/org/apache/helix/PropertyType.java | 100 +- .../helix/ScopedConfigChangeListener.java | 18 +- .../main/java/org/apache/helix/ZNRecord.java | 307 ++-- .../org/apache/helix/ZNRecordAssembler.java | 18 +- .../org/apache/helix/ZNRecordBucketizer.java | 71 +- .../java/org/apache/helix/ZNRecordDelta.java | 25 +- .../java/org/apache/helix/ZNRecordUpdater.java | 12 +- .../helix/alerts/AccumulateAggregator.java | 86 +- .../org/apache/helix/alerts/Aggregator.java | 34 +- .../java/org/apache/helix/alerts/Alert.java | 63 +- .../apache/helix/alerts/AlertComparator.java | 13 +- .../org/apache/helix/alerts/AlertParser.java | 205 ++- .../org/apache/helix/alerts/AlertProcessor.java | 166 +-- .../helix/alerts/AlertValueAndStatus.java | 35 +- .../org/apache/helix/alerts/AlertsHolder.java | 386 +++-- .../apache/helix/alerts/DecayAggregator.java | 103 +- .../org/apache/helix/alerts/DivideOperator.java | 22 +- .../org/apache/helix/alerts/ExpandOperator.java | 20 +- .../helix/alerts/ExpressionOperatorType.java | 44 +- .../apache/helix/alerts/ExpressionParser.java | 361 ++--- .../helix/alerts/GreaterAlertComparator.java | 36 +- .../apache/helix/alerts/MultiplyOperator.java | 63 +- .../java/org/apache/helix/alerts/Operator.java | 174 ++- .../main/java/org/apache/helix/alerts/Stat.java | 46 +- .../org/apache/helix/alerts/StatsHolder.java | 210 +-- .../apache/helix/alerts/SumEachOperator.java | 42 +- .../org/apache/helix/alerts/SumOperator.java | 61 +- .../java/org/apache/helix/alerts/Tuple.java | 124 +- .../apache/helix/alerts/WindowAggregator.java | 126 +- .../helix/controller/ExternalViewGenerator.java | 71 +- .../controller/GenericHelixController.java | 370 ++--- .../helix/controller/HelixControllerMain.java | 147 +- .../controller/HierarchicalDataHolder.java | 85 +- .../controller/pipeline/AbstractBaseStage.java | 34 +- .../helix/controller/pipeline/Pipeline.java | 25 +- .../controller/pipeline/PipelineRegistry.java | 21 +- .../apache/helix/controller/pipeline/Stage.java | 6 +- .../helix/controller/pipeline/StageContext.java | 3 +- .../controller/pipeline/StageException.java | 12 +- .../controller/rebalancer/AutoRebalancer.java | 86 +- .../controller/rebalancer/CustomRebalancer.java | 19 +- .../helix/controller/rebalancer/Rebalancer.java | 18 +- .../rebalancer/SemiAutoRebalancer.java | 12 +- .../util/ConstraintBasedAssignment.java | 75 +- .../restlet/ZKPropertyTransferServer.java | 220 ++- .../controller/restlet/ZNRecordUpdate.java | 53 +- .../restlet/ZNRecordUpdateResource.java | 45 +- .../restlet/ZkPropertyTransferApplication.java | 18 +- .../restlet/ZkPropertyTransferClient.java | 129 +- .../helix/controller/stages/AttributeName.java | 3 +- .../stages/BestPossibleStateCalcStage.java | 84 +- .../stages/BestPossibleStateOutput.java | 34 +- .../controller/stages/ClusterDataCache.java | 157 +- .../helix/controller/stages/ClusterEvent.java | 35 +- .../stages/CompatibilityCheckStage.java | 32 +- .../stages/CurrentStateComputationStage.java | 101 +- .../controller/stages/CurrentStateOutput.java | 110 +- .../stages/ExternalViewComputeStage.java | 189 ++- .../controller/stages/HealthDataCache.java | 38 +- .../stages/MessageGenerationOutput.java | 35 +- .../stages/MessageGenerationPhase.java | 138 +- .../stages/MessageSelectionStage.java | 163 +-- .../stages/MessageSelectionStageOutput.java | 27 +- .../controller/stages/MessageThrottleStage.java | 121 +- .../stages/MessageThrottleStageOutput.java | 21 +- .../controller/stages/ReadClusterDataStage.java | 40 +- .../controller/stages/ReadHealthDataStage.java | 14 +- .../stages/RebalanceIdealStateStage.java | 41 +- .../stages/ResourceComputationStage.java | 66 +- .../stages/StatsAggregationStage.java | 222 +-- .../controller/stages/TaskAssignmentStage.java | 78 +- .../strategy/AutoRebalanceStrategy.java | 25 +- .../apache/helix/examples/BootstrapHandler.java | 67 +- .../apache/helix/examples/BootstrapProcess.java | 194 +-- .../apache/helix/examples/DummyParticipant.java | 60 +- .../apache/helix/examples/ExampleHelper.java | 30 +- .../apache/helix/examples/ExampleProcess.java | 116 +- .../examples/IdealStateBuilderExample.java | 70 +- .../helix/examples/IdealStateExample.java | 76 +- .../LeaderStandbyStateModelFactory.java | 71 +- .../examples/MasterSlaveStateModelFactory.java | 82 +- .../OnlineOfflineStateModelFactory.java | 74 +- .../org/apache/helix/examples/Quickstart.java | 129 +- .../healthcheck/AccumulateAggregationType.java | 12 +- .../helix/healthcheck/AggregationType.java | 6 +- .../healthcheck/AggregationTypeFactory.java | 48 +- .../helix/healthcheck/DecayAggregationType.java | 18 +- .../DefaultHealthReportProvider.java | 33 +- .../helix/healthcheck/DefaultPerfCounters.java | 54 +- .../helix/healthcheck/HealthReportProvider.java | 9 +- .../healthcheck/HealthStatsAggregationTask.java | 50 +- .../healthcheck/HealthStatsAggregator.java | 82 +- .../ParticipantHealthReportCollector.java | 5 +- .../ParticipantHealthReportCollectorImpl.java | 10 +- .../ParticipantHealthReportTask.java | 3 +- .../PerformanceHealthReportProvider.java | 75 +- .../java/org/apache/helix/healthcheck/Stat.java | 64 +- .../healthcheck/StatHealthReportProvider.java | 62 +- .../healthcheck/WindowAggregationType.java | 31 +- .../helix/josql/ClusterJosqlQueryProcessor.java | 182 +-- .../josql/ZNRecordJosqlFunctionHandler.java | 62 +- .../org/apache/helix/josql/ZNRecordRow.java | 133 +- .../helix/manager/zk/AbstractManager.java | 260 ++-- .../helix/manager/zk/BasicZkSerializer.java | 15 +- .../helix/manager/zk/ByteArraySerializer.java | 14 +- .../java/org/apache/helix/manager/zk/Cache.java | 95 +- .../helix/manager/zk/CallbackHandler.java | 455 +++--- .../manager/zk/ChainedPathZkSerializer.java | 67 +- .../helix/manager/zk/ControllerManager.java | 44 +- .../manager/zk/ControllerManagerHelper.java | 50 +- .../manager/zk/CurStateCarryOverUpdater.java | 21 +- .../DefaultControllerMessageHandlerFactory.java | 53 +- ...ltParticipantErrorMessageHandlerFactory.java | 95 +- .../DefaultSchedulerMessageHandlerFactory.java | 308 ++-- .../zk/DistributedControllerManager.java | 37 +- .../manager/zk/DistributedLeaderElection.java | 9 +- .../helix/manager/zk/HelixGroupCommit.java | 104 +- .../helix/manager/zk/ParticipantManager.java | 21 +- .../manager/zk/ParticipantManagerHelper.java | 67 +- .../helix/manager/zk/PathBasedZkSerializer.java | 5 +- .../helix/manager/zk/WriteThroughCache.java | 58 +- .../helix/manager/zk/ZKExceptionHandler.java | 22 +- .../apache/helix/manager/zk/ZKHelixAdmin.java | 970 +++++------- .../helix/manager/zk/ZKHelixDataAccessor.java | 281 ++-- .../apache/helix/manager/zk/ZKHelixManager.java | 825 +++++------ .../org/apache/helix/manager/zk/ZKUtil.java | 312 ++-- .../helix/manager/zk/ZNRecordSerializer.java | 62 +- .../manager/zk/ZNRecordStreamingSerializer.java | 147 +- .../helix/manager/zk/ZkAsyncCallbacks.java | 101 +- .../helix/manager/zk/ZkBaseDataAccessor.java | 652 +++------ .../manager/zk/ZkCacheBaseDataAccessor.java | 593 +++----- .../helix/manager/zk/ZkCacheEventThread.java | 56 +- .../helix/manager/zk/ZkCallbackCache.java | 179 +-- .../org/apache/helix/manager/zk/ZkClient.java | 287 ++-- .../helix/manager/zk/ZkStateChangeListener.java | 71 +- .../zk/serializer/JacksonPayloadSerializer.java | 20 +- .../apache/helix/messaging/AsyncCallback.java | 97 +- .../helix/messaging/CriteriaEvaluator.java | 93 +- .../messaging/DefaultMessagingService.java | 253 ++-- .../handling/AsyncCallbackService.java | 88 +- .../messaging/handling/BatchMessageHandler.java | 379 ++--- .../messaging/handling/BatchMessageWrapper.java | 11 +- .../messaging/handling/CurrentStateUpdate.java | 24 +- .../messaging/handling/GroupMessageHandler.java | 69 +- .../handling/HelixBatchMessageTask.java | 180 ++- .../handling/HelixStateTransitionHandler.java | 273 ++-- .../helix/messaging/handling/HelixTask.java | 263 ++-- .../messaging/handling/HelixTaskExecutor.java | 538 +++---- .../messaging/handling/HelixTaskResult.java | 46 +- .../messaging/handling/MessageHandler.java | 63 +- .../handling/MessageHandlerFactory.java | 7 +- .../helix/messaging/handling/MessageTask.java | 14 +- .../messaging/handling/MessageTaskInfo.java | 27 +- .../messaging/handling/MessageTimeoutTask.java | 45 +- .../helix/messaging/handling/TaskExecutor.java | 111 +- .../org/apache/helix/model/AlertHistory.java | 9 +- .../org/apache/helix/model/AlertStatus.java | 34 +- .../java/org/apache/helix/model/Alerts.java | 34 +- .../apache/helix/model/ClusterConstraints.java | 87 +- .../org/apache/helix/model/ConfigScope.java | 89 +- .../org/apache/helix/model/ConstraintItem.java | 36 +- .../org/apache/helix/model/CurrentState.java | 137 +- .../main/java/org/apache/helix/model/Error.java | 9 +- .../org/apache/helix/model/ExternalView.java | 34 +- .../java/org/apache/helix/model/HealthStat.java | 61 +- .../apache/helix/model/HelixConfigScope.java | 105 +- .../java/org/apache/helix/model/IdealState.java | 298 ++-- .../org/apache/helix/model/InstanceConfig.java | 124 +- .../org/apache/helix/model/LeaderHistory.java | 22 +- .../org/apache/helix/model/LiveInstance.java | 57 +- .../java/org/apache/helix/model/Message.java | 306 ++-- .../java/org/apache/helix/model/Partition.java | 22 +- .../org/apache/helix/model/PauseSignal.java | 12 +- .../org/apache/helix/model/PersistentStats.java | 86 +- .../java/org/apache/helix/model/Resource.java | 58 +- .../apache/helix/model/ResourceAssignment.java | 3 +- .../helix/model/StateModelDefinition.java | 194 +-- .../org/apache/helix/model/StatusUpdate.java | 10 +- .../java/org/apache/helix/model/Transition.java | 26 +- .../helix/model/builder/AutoModeISBuilder.java | 31 +- .../builder/AutoRebalanceModeISBuilder.java | 34 +- .../builder/ClusterConstraintsBuilder.java | 31 +- .../helix/model/builder/ConfigScopeBuilder.java | 63 +- .../model/builder/ConstraintItemBuilder.java | 45 +- .../model/builder/CustomModeISBuilder.java | 63 +- .../model/builder/HelixConfigScopeBuilder.java | 34 +- .../helix/model/builder/IdealStateBuilder.java | 240 ++- .../builder/StateTransitionTableBuilder.java | 91 +- .../helix/monitoring/ParticipantMonitor.java | 88 +- .../helix/monitoring/SensorNameProvider.java | 3 +- .../apache/helix/monitoring/StatCollector.java | 41 +- .../monitoring/StateTransitionContext.java | 78 +- .../monitoring/StateTransitionDataPoint.java | 23 +- .../helix/monitoring/ZKPathDataDumpTask.java | 64 +- .../monitoring/mbeans/ClusterAlertItem.java | 62 +- .../mbeans/ClusterAlertItemMBean.java | 7 +- .../mbeans/ClusterAlertMBeanCollection.java | 234 ++- .../monitoring/mbeans/ClusterMBeanObserver.java | 54 +- .../monitoring/mbeans/ClusterStatusMonitor.java | 210 +-- .../mbeans/ClusterStatusMonitorMBean.java | 15 +- .../mbeans/HelixStageLatencyMonitor.java | 55 +- .../mbeans/HelixStageLatencyMonitorMBean.java | 3 +- .../monitoring/mbeans/MessageQueueMonitor.java | 30 +- .../mbeans/MessageQueueMonitorMBean.java | 5 +- .../monitoring/mbeans/ResourceMonitor.java | 68 +- .../monitoring/mbeans/ResourceMonitorMBean.java | 9 +- .../mbeans/StateTransitionStatMonitor.java | 96 +- .../mbeans/StateTransitionStatMonitorMBean.java | 22 +- .../java/org/apache/helix/package-info.java | 1 + .../participant/CustomCodeCallbackHandler.java | 3 +- .../helix/participant/CustomCodeInvoker.java | 47 +- .../DistClusterControllerElection.java | 235 ++- .../DistClusterControllerStateModel.java | 84 +- .../DistClusterControllerStateModelFactory.java | 9 +- .../participant/GenericLeaderStandbyModel.java | 78 +- .../GenericLeaderStandbyStateModelFactory.java | 16 +- .../participant/HelixCustomCodeRunner.java | 47 +- .../participant/HelixStateMachineEngine.java | 195 +-- .../helix/participant/StateMachineEngine.java | 5 +- .../statemachine/ScheduledTaskStateModel.java | 78 +- .../ScheduledTaskStateModelFactory.java | 16 +- .../participant/statemachine/StateModel.java | 97 +- .../statemachine/StateModelFactory.java | 42 +- .../statemachine/StateModelInfo.java | 3 +- .../statemachine/StateModelParser.java | 200 ++- .../statemachine/StateTransitionError.java | 12 +- .../participant/statemachine/Transition.java | 3 +- .../helix/spectator/RoutingTableProvider.java | 144 +- .../helix/store/HelixPropertyListener.java | 6 +- .../apache/helix/store/HelixPropertyStore.java | 11 +- .../helix/store/PropertyChangeListener.java | 4 +- .../helix/store/PropertyJsonComparator.java | 33 +- .../helix/store/PropertyJsonSerializer.java | 36 +- .../apache/helix/store/PropertySerializer.java | 7 +- .../org/apache/helix/store/PropertyStat.java | 21 +- .../helix/store/PropertyStoreException.java | 11 +- .../helix/store/ZNRecordJsonSerializer.java | 12 +- .../org/apache/helix/store/zk/PropertyItem.java | 23 +- .../java/org/apache/helix/store/zk/ZNode.java | 83 +- .../helix/store/zk/ZkHelixPropertyStore.java | 20 +- .../org/apache/helix/store/zk/ZkListener.java | 7 +- .../apache/helix/tools/CLMLogFileAppender.java | 39 +- .../org/apache/helix/tools/ClusterSetup.java | 1045 +++++-------- .../helix/tools/ClusterStateVerifier.java | 463 +++--- .../tools/DefaultIdealStateCalculator.java | 658 ++++----- .../IdealCalculatorByConsistentHashing.java | 275 ++-- .../helix/tools/IdealStateCalculatorByRush.java | 170 +-- .../tools/IdealStateCalculatorByShuffling.java | 55 +- .../IdealStateCalculatorForEspressoRelay.java | 76 +- .../java/org/apache/helix/tools/JmxDumper.java | 349 ++--- .../org/apache/helix/tools/LocalZKServer.java | 36 +- .../org/apache/helix/tools/MessagePoster.java | 58 +- .../java/org/apache/helix/tools/RUSHrHash.java | 108 +- .../helix/tools/StateModelConfigGenerator.java | 192 +-- .../org/apache/helix/tools/TestCommand.java | 42 +- .../org/apache/helix/tools/TestExecutor.java | 649 +++------ .../org/apache/helix/tools/TestTrigger.java | 81 +- .../org/apache/helix/tools/YAISCalculator.java | 108 +- .../java/org/apache/helix/tools/ZKDumper.java | 26 +- .../org/apache/helix/tools/ZKLogFormatter.java | 220 ++- .../org/apache/helix/tools/ZkLogAnalyzer.java | 231 +-- .../apache/helix/tools/ZkLogCSVFormatter.java | 319 ++-- .../java/org/apache/helix/tools/ZnodeOpArg.java | 122 +- .../java/org/apache/helix/tools/ZnodeValue.java | 51 +- .../java/org/apache/helix/util/HelixUtil.java | 115 +- .../java/org/apache/helix/util/PathUtils.java | 141 +- .../org/apache/helix/util/RebalanceUtil.java | 76 +- .../org/apache/helix/util/StatusUpdateUtil.java | 394 ++--- .../org/apache/helix/util/StringTemplate.java | 35 +- .../org/apache/helix/util/ZKClientPool.java | 133 +- .../org/apache/helix/util/ZNRecordUtil.java | 71 +- .../org/apache/helix/DummyProcessThread.java | 40 +- .../src/test/java/org/apache/helix/Mocks.java | 1379 +++++++++--------- .../java/org/apache/helix/ScriptTestHelper.java | 42 +- .../org/apache/helix/TestConfigAccessor.java | 134 +- .../TestEspressoStorageClusterIdealState.java | 222 ++- .../java/org/apache/helix/TestGetProperty.java | 18 +- .../java/org/apache/helix/TestGroupCommit.java | 23 +- .../apache/helix/TestHelixConfigAccessor.java | 213 ++- .../org/apache/helix/TestHelixTaskExecutor.java | 24 +- .../org/apache/helix/TestHelixTaskHandler.java | 38 +- .../test/java/org/apache/helix/TestHelper.java | 659 +++------ .../apache/helix/TestHierarchicalDataStore.java | 25 +- .../org/apache/helix/TestListenerCallback.java | 208 +-- ...estParticipantHealthReportCollectorImpl.java | 89 +- .../java/org/apache/helix/TestPerfCounters.java | 74 +- .../TestPerformanceHealthReportProvider.java | 256 ++-- .../apache/helix/TestPropertyPathConfig.java | 26 +- .../helix/TestRelayIdealStateCalculator.java | 58 +- .../java/org/apache/helix/TestRoutingTable.java | 76 +- .../apache/helix/TestShuffledIdealState.java | 173 +-- .../java/org/apache/helix/TestZKCallback.java | 53 +- .../apache/helix/TestZKRoutingInfoProvider.java | 111 +- .../java/org/apache/helix/TestZNRecord.java | 10 +- .../apache/helix/TestZNRecordBucketizer.java | 41 +- .../test/java/org/apache/helix/TestZkBasis.java | 282 ++-- .../org/apache/helix/TestZkClientWrapper.java | 142 +- .../org/apache/helix/TestZkConnectionCount.java | 34 +- .../java/org/apache/helix/TestZnodeModify.java | 91 +- .../org/apache/helix/ZkHelixTestManager.java | 22 +- .../java/org/apache/helix/ZkTestHelper.java | 363 ++--- .../java/org/apache/helix/ZkUnitTestBase.java | 189 +-- .../org/apache/helix/alerts/TestAddAlerts.java | 47 +- .../helix/alerts/TestAddPersistentStats.java | 124 +- .../helix/alerts/TestAlertValidation.java | 258 ++-- .../alerts/TestArrivingParticipantStats.java | 133 +- .../helix/alerts/TestBaseStatsValidation.java | 294 ++-- .../apache/helix/alerts/TestEvaluateAlerts.java | 480 +++--- .../org/apache/helix/alerts/TestOperators.java | 548 +++---- .../org/apache/helix/alerts/TestStatsMatch.java | 152 +- .../helix/controller/stages/BaseStageTest.java | 88 +- .../controller/stages/DummyClusterManager.java | 115 +- .../TestBestPossibleCalcStageCompatibility.java | 44 +- .../stages/TestBestPossibleStateCalcStage.java | 38 +- .../controller/stages/TestClusterEvent.java | 5 +- .../stages/TestCompatibilityCheckStage.java | 87 +- .../TestCurrentStateComputationStage.java | 59 +- .../stages/TestMessageThrottleStage.java | 146 +- .../stages/TestMsgSelectionStage.java | 53 +- .../stages/TestParseInfoFromAlert.java | 31 +- .../stages/TestRebalancePipeline.java | 224 ++- .../stages/TestResourceComputationStage.java | 175 +-- .../strategy/TestAutoRebalanceStrategy.java | 95 +- .../helix/healthcheck/TestAddDropAlert.java | 70 +- .../healthcheck/TestAlertActionTriggering.java | 146 +- .../helix/healthcheck/TestAlertFireHistory.java | 442 +++--- .../helix/healthcheck/TestDummyAlerts.java | 97 +- .../helix/healthcheck/TestExpandAlert.java | 163 +-- .../helix/healthcheck/TestSimpleAlert.java | 187 ++- .../healthcheck/TestSimpleWildcardAlert.java | 210 ++- .../helix/healthcheck/TestStalenessAlert.java | 158 +- .../helix/healthcheck/TestWildcardAlert.java | 194 ++- .../helix/integration/IntegrationTest.java | 9 +- .../helix/integration/TestAddClusterV2.java | 115 +- .../TestAddNodeAfterControllerStart.java | 164 +-- .../TestAddStateModelFactoryAfterConnect.java | 85 +- .../integration/TestAutoIsWithEmptyMap.java | 26 +- .../helix/integration/TestAutoRebalance.java | 249 ++-- .../TestAutoRebalancePartitionLimit.java | 177 +-- .../helix/integration/TestBasicSpectator.java | 45 +- .../helix/integration/TestBatchMessage.java | 330 ++--- .../integration/TestBatchMessageWrapper.java | 76 +- .../integration/TestBucketizedResource.java | 60 +- .../integration/TestCMWithFailParticipant.java | 14 +- .../integration/TestCarryOverBadCurState.java | 53 +- .../integration/TestCleanupExternalView.java | 164 +-- .../helix/integration/TestClusterStartsup.java | 109 +- .../helix/integration/TestCustomIdealState.java | 52 +- .../TestCustomizedIdealStateRebalancer.java | 133 +- .../apache/helix/integration/TestDisable.java | 250 ++-- .../helix/integration/TestDisableNode.java | 24 +- .../helix/integration/TestDisablePartition.java | 22 +- .../integration/TestDistributedCMMain.java | 127 +- .../TestDistributedClusterController.java | 96 +- .../apache/helix/integration/TestDriver.java | 226 ++- .../org/apache/helix/integration/TestDrop.java | 303 ++-- .../helix/integration/TestDropResource.java | 64 +- .../TestEnablePartitionDuringDisable.java | 85 +- .../helix/integration/TestErrorPartition.java | 88 +- .../helix/integration/TestExpandCluster.java | 68 +- .../helix/integration/TestExternalCmd.java | 17 +- .../integration/TestExternalViewUpdates.java | 59 +- .../helix/integration/TestFailOverPerf1kp.java | 31 +- .../integration/TestHelixCustomCodeRunner.java | 90 +- .../helix/integration/TestHelixInstanceTag.java | 54 +- .../TestHelixUsingDifferentParams.java | 44 +- .../helix/integration/TestInstanceAutoJoin.java | 55 +- .../integration/TestInvalidAutoIdealState.java | 150 +- .../TestMessagePartitionStateMismatch.java | 35 +- .../helix/integration/TestMessageThrottle.java | 97 +- .../helix/integration/TestMessageThrottle2.java | 62 +- .../helix/integration/TestMessagingService.java | 245 ++-- .../integration/TestNonOfflineInitState.java | 73 +- .../helix/integration/TestNullReplica.java | 45 +- .../TestParticipantErrorMessage.java | 65 +- .../TestParticipantNameCollision.java | 18 +- .../helix/integration/TestPauseSignal.java | 60 +- .../helix/integration/TestRenamePartition.java | 97 +- .../helix/integration/TestResetInstance.java | 75 +- .../integration/TestResetPartitionState.java | 111 +- .../helix/integration/TestResetResource.java | 75 +- .../integration/TestRestartParticipant.java | 82 +- .../helix/integration/TestSchedulerMessage.java | 764 +++++----- .../helix/integration/TestSchemataSM.java | 54 +- .../TestSessionExpiryInTransition.java | 72 +- .../helix/integration/TestStandAloneCMMain.java | 21 +- .../TestStandAloneCMSessionExpiry.java | 66 +- ...estStartMultipleControllersWithSameName.java | 71 +- .../integration/TestStateTransitionTimeout.java | 152 +- .../helix/integration/TestStatusUpdate.java | 59 +- .../helix/integration/TestSwapInstance.java | 110 +- .../integration/TestZkCallbackHandlerLeak.java | 904 ++++++------ .../helix/integration/TestZkReconnect.java | 67 +- .../integration/ZkIntegrationTestBase.java | 62 +- .../integration/ZkStandAloneCMTestBase.java | 96 +- ...dAloneCMTestBaseWithPropertyServerCheck.java | 52 +- .../manager/ClusterControllerManager.java | 40 +- .../manager/ClusterDistributedController.java | 42 +- .../manager/MockParticipantManager.java | 56 +- .../manager/TestConsecutiveZkSessionExpiry.java | 118 +- .../manager/TestControllerManager.java | 77 +- .../TestDistributedControllerManager.java | 103 +- .../manager/TestParticipantManager.java | 126 +- .../integration/manager/TestStateModelLeak.java | 102 +- .../manager/TestZkCallbackHandlerLeak.java | 389 +++-- .../integration/manager/ZkTestManager.java | 3 +- .../josql/TestClusterJosqlQueryProcessor.java | 70 +- .../apache/helix/josql/TestJosqlProcessor.java | 190 ++- .../org/apache/helix/manager/MockListener.java | 32 +- .../TestDefaultControllerMsgHandlerFactory.java | 48 +- .../helix/manager/zk/TestHandleNewSession.java | 50 +- .../manager/zk/TestLiveInstanceBounce.java | 30 +- .../zk/TestWtCacheAsyncOpMultiThread.java | 159 +- .../zk/TestWtCacheAsyncOpSingleThread.java | 134 +- .../zk/TestWtCacheSyncOpSingleThread.java | 122 +- .../manager/zk/TestZKLiveInstanceData.java | 77 +- .../zk/TestZKPropertyTransferServer.java | 45 +- .../org/apache/helix/manager/zk/TestZKUtil.java | 64 +- .../helix/manager/zk/TestZNRecordSizeLimit.java | 111 +- .../manager/zk/TestZkBaseDataAccessor.java | 236 ++- .../zk/TestZkCacheAsyncOpSingleThread.java | 196 +-- .../zk/TestZkCacheSyncOpSingleThread.java | 100 +- .../helix/manager/zk/TestZkClusterManager.java | 153 +- .../helix/manager/zk/TestZkHelixAdmin.java | 313 ++-- .../zk/TestZkManagerFlappingDetection.java | 240 ++- .../manager/zk/TestZkStateChangeListener.java | 43 +- .../TestJacksonPayloadSerializer.java | 87 +- .../helix/messaging/TestAsyncCallback.java | 47 +- .../helix/messaging/TestAsyncCallbackSvc.java | 74 +- .../messaging/TestDefaultMessagingService.java | 91 +- .../handling/TestConfigThreadpoolSize.java | 110 +- .../handling/TestHelixTaskExecutor.java | 343 ++--- .../handling/TestResourceThreadpoolSize.java | 35 +- .../mock/controller/ClusterController.java | 112 +- .../helix/mock/controller/MockController.java | 55 +- .../mock/controller/MockControllerProcess.java | 32 +- .../helix/mock/participant/DummyProcess.java | 290 ++-- .../helix/mock/participant/ErrTransition.java | 28 +- .../participant/MockBootstrapModelFactory.java | 7 +- .../participant/MockBootstrapStateModel.java | 25 +- .../MockEspressoHealthReportProvider.java | 104 +- .../MockHealthReportParticipant.java | 132 +- .../helix/mock/participant/MockJobIntf.java | 4 +- .../mock/participant/MockMSModelFactory.java | 20 +- .../mock/participant/MockMSStateModel.java | 73 +- .../helix/mock/participant/MockParticipant.java | 119 +- .../participant/MockSchemataModelFactory.java | 6 +- .../participant/MockSchemataStateModel.java | 21 +- .../helix/mock/participant/MockTransition.java | 11 +- .../helix/mock/participant/SleepTransition.java | 12 +- .../StoreAccessDiffNodeTransition.java | 36 +- .../StoreAccessOneNodeTransition.java | 31 +- .../mock/spectator/MockSpectatorProcess.java | 82 +- .../org/apache/helix/model/TestConstraint.java | 66 +- .../org/apache/helix/model/TestIdealState.java | 27 +- .../apache/helix/model/TestInstanceConfig.java | 11 +- .../model/builder/TestIdealStateBuilder.java | 104 +- .../monitoring/TestParticipantMonitor.java | 87 +- .../helix/monitoring/TestStatCollector.java | 44 +- .../TestClusterAlertItemMBeanCollection.java | 243 +-- .../mbeans/TestClusterStatusMonitor.java | 72 +- .../monitoring/mbeans/TestResourceMonitor.java | 69 +- .../helix/participant/MockZKHelixManager.java | 128 +- .../participant/TestDistControllerElection.java | 78 +- .../TestDistControllerStateModel.java | 55 +- .../TestDistControllerStateModelFactory.java | 16 +- .../statemachine/TestStateModelParser.java | 51 +- .../apache/helix/store/TestJsonComparator.java | 14 +- .../apache/helix/store/TestPropertyStat.java | 11 +- .../helix/store/TestPropertyStoreException.java | 13 +- .../store/zk/TestZkHelixPropertyStore.java | 203 +-- .../apache/helix/tools/TestClusterSetup.java | 324 ++-- .../apache/helix/tools/TestHelixAdminCli.java | 548 +++---- .../org/apache/helix/util/TestZKClientPool.java | 28 +- helix-style.xml | 283 ++++ .../java/org/apache/helix/lockmanager/Lock.java | 20 +- .../apache/helix/lockmanager/LockFactory.java | 6 +- .../helix/lockmanager/LockManagerDemo.java | 94 +- .../apache/helix/lockmanager/LockProcess.java | 68 +- .../apache/helix/recipes/rabbitmq/Consumer.java | 70 +- .../recipes/rabbitmq/ConsumerStateModel.java | 46 +- .../rabbitmq/ConsumerStateModelFactory.java | 14 +- .../helix/recipes/rabbitmq/ConsumerThread.java | 42 +- .../apache/helix/recipes/rabbitmq/Emitter.java | 30 +- .../recipes/rabbitmq/SetupConsumerCluster.java | 25 +- .../recipes/rabbitmq/StartClusterManager.java | 35 +- .../org/apache/helix/filestore/ChangeLog.java | 12 +- .../helix/filestore/ChangeLogGenerator.java | 70 +- .../helix/filestore/ChangeLogProcessor.java | 49 +- .../apache/helix/filestore/ChangeLogReader.java | 84 +- .../apache/helix/filestore/ChangeRecord.java | 19 +- .../apache/helix/filestore/CheckpointFile.java | 45 +- .../apache/helix/filestore/ExternalCommand.java | 317 ++-- .../helix/filestore/FileChangeWatcher.java | 3 +- .../org/apache/helix/filestore/FileStore.java | 69 +- .../helix/filestore/FileStoreStateModel.java | 140 +- .../filestore/FileStoreStateModelFactory.java | 16 +- .../helix/filestore/FileSystemWatchService.java | 97 +- .../apache/helix/filestore/IntegrationTest.java | 114 +- .../org/apache/helix/filestore/Replicator.java | 106 +- .../org/apache/helix/filestore/RsyncDaemon.java | 20 +- .../apache/helix/filestore/RsyncInvoker.java | 100 +- .../apache/helix/filestore/SetupCluster.java | 34 +- .../helix/filestore/StartClusterManager.java | 35 +- .../java/org/apache/helix/filestore/Test.java | 108 +- .../helix/servicediscovery/MyService.java | 23 +- .../servicediscovery/ServiceDiscovery.java | 104 +- .../servicediscovery/ServiceDiscoveryDemo.java | 48 +- .../helix/servicediscovery/ServiceMetadata.java | 25 +- .../taskexecution/AnalyticsTaskFactory.java | 60 +- .../apache/helix/taskexecution/CountTask.java | 88 +- .../org/apache/helix/taskexecution/Dag.java | 190 +-- .../apache/helix/taskexecution/FilterTask.java | 68 +- .../apache/helix/taskexecution/JoinTask.java | 79 +- .../taskexecution/RedisTaskResultStore.java | 136 +- .../apache/helix/taskexecution/ReportTask.java | 54 +- .../org/apache/helix/taskexecution/Task.java | 185 +-- .../apache/helix/taskexecution/TaskCluster.java | 88 +- .../helix/taskexecution/TaskExecutionDemo.java | 290 ++-- .../apache/helix/taskexecution/TaskFactory.java | 5 +- .../helix/taskexecution/TaskResultStore.java | 26 +- .../helix/taskexecution/TaskStateModel.java | 130 +- .../taskexecution/TaskStateModelFactory.java | 27 +- .../org/apache/helix/taskexecution/Worker.java | 201 +-- 598 files changed, 25936 insertions(+), 37736 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-admin-webapp/src/main/java/org/apache/helix/webapp/HelixAdminWebApp.java ---------------------------------------------------------------------- diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/HelixAdminWebApp.java b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/HelixAdminWebApp.java index 0a71ed1..1988636 100644 --- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/HelixAdminWebApp.java +++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/HelixAdminWebApp.java @@ -26,57 +26,48 @@ import org.restlet.Component; import org.restlet.Context; import org.restlet.data.Protocol; - -public class HelixAdminWebApp -{ +public class HelixAdminWebApp { public final Logger LOG = Logger.getLogger(HelixAdminWebApp.class); RestAdminApplication _adminApp = null; - Component _component = null; - + Component _component = null; + int _helixAdminPort; String _zkServerAddress; ZkClient _zkClient; - - public HelixAdminWebApp(String zkServerAddress, int adminPort) - { + + public HelixAdminWebApp(String zkServerAddress, int adminPort) { _zkServerAddress = zkServerAddress; _helixAdminPort = adminPort; } - - public synchronized void start() throws Exception - { + + public synchronized void start() throws Exception { LOG.info("helixAdminWebApp starting"); - if(_component == null) - { - _zkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); - _component = new Component(); + if (_component == null) { + _zkClient = + new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, + ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer()); + _component = new Component(); _component.getServers().add(Protocol.HTTP, _helixAdminPort); Context applicationContext = _component.getContext().createChildContext(); - applicationContext.getAttributes().put(RestAdminApplication.ZKSERVERADDRESS, _zkServerAddress); - applicationContext.getAttributes().put(RestAdminApplication.PORT, ""+_helixAdminPort); + applicationContext.getAttributes() + .put(RestAdminApplication.ZKSERVERADDRESS, _zkServerAddress); + applicationContext.getAttributes().put(RestAdminApplication.PORT, "" + _helixAdminPort); applicationContext.getAttributes().put(RestAdminApplication.ZKCLIENT, _zkClient); - _adminApp = new RestAdminApplication(applicationContext); + _adminApp = new RestAdminApplication(applicationContext); // Attach the application to the component and start it _component.getDefaultHost().attach(_adminApp); _component.start(); } LOG.info("helixAdminWebApp started on port " + _helixAdminPort); } - - public synchronized void stop() - { - try - { + + public synchronized void stop() { + try { _component.stop(); - } - catch(Exception e) - { + } catch (Exception e) { LOG.error("", e); - } - finally - { - if(_zkClient != null) - { + } finally { + if (_zkClient != null) { _zkClient.close(); } } http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-admin-webapp/src/main/java/org/apache/helix/webapp/RestAdminApplication.java ---------------------------------------------------------------------- diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/RestAdminApplication.java b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/RestAdminApplication.java index f753efa..ce951cd 100644 --- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/RestAdminApplication.java +++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/RestAdminApplication.java @@ -60,68 +60,70 @@ import org.restlet.data.Response; import org.restlet.resource.StringRepresentation; import org.restlet.util.Template; - -public class RestAdminApplication extends Application -{ +public class RestAdminApplication extends Application { public static final String HELP = "help"; public static final String ZKSERVERADDRESS = "zkSvr"; public static final String PORT = "port"; public static final String ZKCLIENT = "zkClient"; public static final int DEFAULT_PORT = 8100; - - public RestAdminApplication() - { + public RestAdminApplication() { super(); } - public RestAdminApplication(Context context) - { + public RestAdminApplication(Context context) { super(context); } - + @Override - public Restlet createRoot() - { + public Restlet createRoot() { Router router = new Router(getContext()); router.setDefaultMatchingMode(Template.MODE_EQUALS); router.attach("/clusters", ClustersResource.class); router.attach("/clusters/{clusterName}", ClusterResource.class); router.attach("/clusters/{clusterName}/resourceGroups", ResourceGroupsResource.class); - router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}", ResourceGroupResource.class); + router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}", + ResourceGroupResource.class); router.attach("/clusters/{clusterName}/instances", InstancesResource.class); router.attach("/clusters/{clusterName}/instances/{instanceName}", InstanceResource.class); - router.attach("/clusters/{clusterName}/instances/{instanceName}/currentState/{resourceName}", CurrentStateResource.class); - router.attach("/clusters/{clusterName}/instances/{instanceName}/statusUpdate/{resourceName}", StatusUpdateResource.class); - router.attach("/clusters/{clusterName}/instances/{instanceName}/errors/{resourceName}", ErrorResource.class); - router.attach("/clusters/{clusterName}/instances/{instanceName}/currentState", CurrentStatesResource.class); - router.attach("/clusters/{clusterName}/instances/{instanceName}/statusUpdate", StatusUpdatesResource.class); + router.attach("/clusters/{clusterName}/instances/{instanceName}/currentState/{resourceName}", + CurrentStateResource.class); + router.attach("/clusters/{clusterName}/instances/{instanceName}/statusUpdate/{resourceName}", + StatusUpdateResource.class); + router.attach("/clusters/{clusterName}/instances/{instanceName}/errors/{resourceName}", + ErrorResource.class); + router.attach("/clusters/{clusterName}/instances/{instanceName}/currentState", + CurrentStatesResource.class); + router.attach("/clusters/{clusterName}/instances/{instanceName}/statusUpdate", + StatusUpdatesResource.class); router.attach("/clusters/{clusterName}/instances/{instanceName}/errors", ErrorsResource.class); - router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}/idealState", IdealStateResource.class); - router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}/externalView", ExternalViewResource.class); + router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}/idealState", + IdealStateResource.class); + router.attach("/clusters/{clusterName}/resourceGroups/{resourceName}/externalView", + ExternalViewResource.class); router.attach("/clusters/{clusterName}/StateModelDefs/{modelName}", StateModelResource.class); router.attach("/clusters/{clusterName}/StateModelDefs", StateModelsResource.class); router.attach("/clusters/{clusterName}/SchedulerTasks", SchedulerTasksResource.class); router.attach("/clusters/{clusterName}/Controller", ControllerResource.class); - router.attach("/clusters/{clusterName}/Controller/statusUpdates/{MessageType}/{MessageId}", ControllerStatusUpdateResource.class); + router.attach("/clusters/{clusterName}/Controller/statusUpdates/{MessageType}/{MessageId}", + ControllerStatusUpdateResource.class); router.attach("/clusters/{clusterName}/configs", ConfigResource.class); router.attach("/clusters/{clusterName}/configs/{scope}", ConfigResource.class); router.attach("/clusters/{clusterName}/configs/{scope}/{scopeKey1}", ConfigResource.class); - router.attach("/clusters/{clusterName}/configs/{scope}/{scopeKey1}/{scopeKey2}", ConfigResource.class); + router.attach("/clusters/{clusterName}/configs/{scope}/{scopeKey1}/{scopeKey2}", + ConfigResource.class); router.attach("/clusters/{clusterName}/constraints/{constraintType}", ConstraintResource.class); - router.attach("/clusters/{clusterName}/constraints/{constraintType}/{constraintId}", ConstraintResource.class); + router.attach("/clusters/{clusterName}/constraints/{constraintType}/{constraintId}", + ConstraintResource.class); router.attach("/zkPath", ZkPathResource.class).setMatchingMode(Template.MODE_STARTS_WITH); router.attach("/zkChild", ZkChildResource.class).setMatchingMode(Template.MODE_STARTS_WITH); - Restlet mainpage = new Restlet() - { + Restlet mainpage = new Restlet() { @Override - public void handle(Request request, Response response) - { + public void handle(Request request, Response response) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(""); - stringBuilder - .append("Restlet Cluster Management page"); + stringBuilder.append("Restlet Cluster Management page"); stringBuilder.append(""); stringBuilder.append(""); stringBuilder.append(""); @@ -132,40 +134,39 @@ public class RestAdminApplication extends Application stringBuilder.append("
"); stringBuilder.append(""); stringBuilder.append(""); - response.setEntity(new StringRepresentation(stringBuilder.toString(), - MediaType.TEXT_HTML)); + response.setEntity(new StringRepresentation(stringBuilder.toString(), MediaType.TEXT_HTML)); } }; router.attach("", mainpage); return router; } - public static void printUsage(Options cliOptions) - { + public static void printUsage(Options cliOptions) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java " + RestAdminApplication.class.getName(), cliOptions); } @SuppressWarnings("static-access") - private static Options constructCommandLineOptions() - { - Option helpOption = OptionBuilder.withLongOpt(HELP) - .withDescription("Prints command-line options info").create(); + private static Options constructCommandLineOptions() { + Option helpOption = + OptionBuilder.withLongOpt(HELP).withDescription("Prints command-line options info") + .create(); helpOption.setArgs(0); helpOption.setRequired(false); helpOption.setArgName("print help message"); - Option zkServerOption = OptionBuilder.withLongOpt(ZKSERVERADDRESS) - .withDescription("Provide zookeeper address").create(); + Option zkServerOption = + OptionBuilder.withLongOpt(ZKSERVERADDRESS).withDescription("Provide zookeeper address") + .create(); zkServerOption.setArgs(1); zkServerOption.setRequired(true); zkServerOption.setArgName("ZookeeperServerAddress(Required)"); - Option portOption = OptionBuilder.withLongOpt(PORT) - .withDescription("Provide web service port").create(); + Option portOption = + OptionBuilder.withLongOpt(PORT).withDescription("Provide web service port").create(); portOption.setArgs(1); portOption.setRequired(false); - portOption.setArgName("web service port, default: "+ DEFAULT_PORT); + portOption.setArgName("web service port, default: " + DEFAULT_PORT); Options options = new Options(); options.addOption(helpOption); @@ -175,54 +176,43 @@ public class RestAdminApplication extends Application return options; } - public static void processCommandLineArgs(String[] cliArgs) throws Exception - { + public static void processCommandLineArgs(String[] cliArgs) throws Exception { CommandLineParser cliParser = new GnuParser(); Options cliOptions = constructCommandLineOptions(); CommandLine cmd = null; - try - { + try { cmd = cliParser.parse(cliOptions, cliArgs); - } - catch (ParseException pe) - { + } catch (ParseException pe) { System.err.println("RestAdminApplication: failed to parse command-line options: " + pe.toString()); printUsage(cliOptions); System.exit(1); } int port = DEFAULT_PORT; - if(cmd.hasOption(HELP)) - { + if (cmd.hasOption(HELP)) { printUsage(cliOptions); return; - } - else if(cmd.hasOption(PORT)) - { + } else if (cmd.hasOption(PORT)) { port = Integer.parseInt(cmd.getOptionValue(PORT)); } - + HelixAdminWebApp app = new HelixAdminWebApp(cmd.getOptionValue(ZKSERVERADDRESS), port); app.start(); - try - { + try { Thread.currentThread().join(); - } - finally - { + } finally { app.stop(); } } - + /** * @param args * @throws Exception */ - public static void main(String[] args) throws Exception - { + public static void main(String[] args) throws Exception { processCommandLineArgs(args); - + } } http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterRepresentationUtil.java ---------------------------------------------------------------------- diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterRepresentationUtil.java b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterRepresentationUtil.java index c823b48..ccac49a 100644 --- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterRepresentationUtil.java +++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterRepresentationUtil.java @@ -49,31 +49,21 @@ import org.codehaus.jackson.type.TypeReference; import org.restlet.data.Form; import org.restlet.data.MediaType; - -public class ClusterRepresentationUtil -{ +public class ClusterRepresentationUtil { private static final ZNRecord EMPTY_ZNRECORD = new ZNRecord("EMPTY_ZNRECORD"); - public static String getClusterPropertyAsString(ZkClient zkClient, - String clusterName, - PropertyKey propertyKey, - // String key, - MediaType mediaType) + public static String getClusterPropertyAsString(ZkClient zkClient, String clusterName, + PropertyKey propertyKey, + // String key, + MediaType mediaType) - throws JsonGenerationException, - JsonMappingException, - IOException - { + throws JsonGenerationException, JsonMappingException, IOException { return getClusterPropertyAsString(zkClient, clusterName, mediaType, propertyKey); } - public static String getClusterPropertyAsString(ZkClient zkClient, - String clusterName, - MediaType mediaType, - PropertyKey propertyKey) throws JsonGenerationException, - JsonMappingException, - IOException - { + public static String getClusterPropertyAsString(ZkClient zkClient, String clusterName, + MediaType mediaType, PropertyKey propertyKey) throws JsonGenerationException, + JsonMappingException, IOException { ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); @@ -83,20 +73,12 @@ public class ClusterRepresentationUtil return ZNRecordToJson(record); } - public static String getInstancePropertyNameListAsString(ZkClient zkClient, - String clusterName, - String instanceName, - PropertyType instanceProperty, - String key, - MediaType mediaType) throws JsonGenerationException, - JsonMappingException, - IOException - { + public static String getInstancePropertyNameListAsString(ZkClient zkClient, String clusterName, + String instanceName, PropertyType instanceProperty, String key, MediaType mediaType) + throws JsonGenerationException, JsonMappingException, IOException { String path = - HelixUtil.getInstancePropertyPath(clusterName, instanceName, instanceProperty) - + "/" + key; - if (zkClient.exists(path)) - { + HelixUtil.getInstancePropertyPath(clusterName, instanceName, instanceProperty) + "/" + key; + if (zkClient.exists(path)) { List recordNames = zkClient.getChildren(path); return ObjectToJson(recordNames); } @@ -104,13 +86,9 @@ public class ClusterRepresentationUtil return ObjectToJson(new ArrayList()); } - public static String getInstancePropertyAsString(ZkClient zkClient, - String clusterName, - PropertyKey propertyKey, - MediaType mediaType) throws JsonGenerationException, - JsonMappingException, - IOException - { + public static String getInstancePropertyAsString(ZkClient zkClient, String clusterName, + PropertyKey propertyKey, MediaType mediaType) throws JsonGenerationException, + JsonMappingException, IOException { ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); @@ -118,52 +96,38 @@ public class ClusterRepresentationUtil return ZNRecordToJson(records); } - public static String getInstancePropertiesAsString(ZkClient zkClient, - String clusterName, - PropertyKey propertyKey, - MediaType mediaType) throws JsonGenerationException, - JsonMappingException, - IOException - { + public static String getInstancePropertiesAsString(ZkClient zkClient, String clusterName, + PropertyKey propertyKey, MediaType mediaType) throws JsonGenerationException, + JsonMappingException, IOException { zkClient.setZkSerializer(new ZNRecordSerializer()); ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); - List records = - HelixProperty.convertToList(accessor.getChildValues(propertyKey)); + List records = HelixProperty.convertToList(accessor.getChildValues(propertyKey)); return ObjectToJson(records); } - public static String getPropertyAsString(ZkClient zkClient, - String clusterName, - PropertyKey propertyKey, - MediaType mediaType) throws JsonGenerationException, - JsonMappingException, - IOException - { + public static String getPropertyAsString(ZkClient zkClient, String clusterName, + PropertyKey propertyKey, MediaType mediaType) throws JsonGenerationException, + JsonMappingException, IOException { ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); ZNRecord record = EMPTY_ZNRECORD; HelixProperty property = accessor.getProperty(propertyKey); - if (property != null) - { + if (property != null) { record = property.getRecord(); } return ObjectToJson(record); } public static String ZNRecordToJson(ZNRecord record) throws JsonGenerationException, - JsonMappingException, - IOException - { + JsonMappingException, IOException { return ObjectToJson(record); } public static String ObjectToJson(Object object) throws JsonGenerationException, - JsonMappingException, - IOException - { + JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); SerializationConfig serializationConfig = mapper.getSerializationConfig(); serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true); @@ -174,17 +138,12 @@ public class ClusterRepresentationUtil return sw.toString(); } - public static HelixDataAccessor getClusterDataAccessor(ZkClient zkClient, - String clusterName) - { - return new ZKHelixDataAccessor(clusterName, - new ZkBaseDataAccessor(zkClient)); + public static HelixDataAccessor getClusterDataAccessor(ZkClient zkClient, String clusterName) { + return new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); } - public static T JsonToObject(Class clazz, String jsonString) throws JsonParseException, - JsonMappingException, - IOException - { + public static T JsonToObject(Class clazz, String jsonString) + throws JsonParseException, JsonMappingException, IOException { StringReader sr = new StringReader(jsonString); ObjectMapper mapper = new ObjectMapper(); return mapper.readValue(sr, clazz); @@ -192,54 +151,39 @@ public class ClusterRepresentationUtil } public static Map JsonToMap(String jsonString) throws JsonParseException, - JsonMappingException, - IOException - { + JsonMappingException, IOException { StringReader sr = new StringReader(jsonString); ObjectMapper mapper = new ObjectMapper(); - TypeReference> typeRef = - new TypeReference>() - { - }; + TypeReference> typeRef = new TypeReference>() { + }; return mapper.readValue(sr, typeRef); } public static Map getFormJsonParameters(Form form) throws JsonParseException, - JsonMappingException, - IOException - { + JsonMappingException, IOException { String jsonPayload = form.getFirstValue(JsonParameters.JSON_PARAMETERS, true); return ClusterRepresentationUtil.JsonToMap(jsonPayload); } - public static Map getFormJsonParameters(Form form, String key) throws JsonParseException, - JsonMappingException, - IOException - { + public static Map getFormJsonParameters(Form form, String key) + throws JsonParseException, JsonMappingException, IOException { String jsonPayload = form.getFirstValue(key, true); return ClusterRepresentationUtil.JsonToMap(jsonPayload); } public static String getFormJsonParameterString(Form form, String key) throws JsonParseException, - JsonMappingException, - IOException - { + JsonMappingException, IOException { return form.getFirstValue(key, true); } - public static T getFormJsonParameters(Class clazz, - Form form, - String key) throws JsonParseException, - JsonMappingException, - IOException - { + public static T getFormJsonParameters(Class clazz, Form form, String key) + throws JsonParseException, JsonMappingException, IOException { return JsonToObject(clazz, form.getFirstValue(key, true)); } - public static String getErrorAsJsonStringFromException(Exception e) - { + public static String getErrorAsJsonStringFromException(Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); @@ -247,12 +191,9 @@ public class ClusterRepresentationUtil String error = e.getMessage() + '\n' + sw.toString(); Map result = new TreeMap(); result.put("ERROR", error); - try - { + try { return ObjectToJson(result); - } - catch (Exception e1) - { + } catch (Exception e1) { StringWriter sw1 = new StringWriter(); PrintWriter pw1 = new PrintWriter(sw1); e.printStackTrace(pw1); @@ -260,29 +201,21 @@ public class ClusterRepresentationUtil } } - public static String getInstanceSessionId(ZkClient zkClient, - String clusterName, - String instanceName) - { + public static String getInstanceSessionId(ZkClient zkClient, String clusterName, + String instanceName) { ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(zkClient)); Builder keyBuilder = accessor.keyBuilder(); - ZNRecord liveInstance = - accessor.getProperty(keyBuilder.liveInstance(instanceName)).getRecord(); + ZNRecord liveInstance = accessor.getProperty(keyBuilder.liveInstance(instanceName)).getRecord(); return liveInstance.getSimpleField(LiveInstanceProperty.SESSION_ID.toString()); } - public static List getInstancePropertyList(ZkClient zkClient, - String clusterName, - String instanceName, - PropertyType property, - String key) - { + public static List getInstancePropertyList(ZkClient zkClient, String clusterName, + String instanceName, PropertyType property, String key) { String propertyPath = - HelixUtil.getInstancePropertyPath(clusterName, instanceName, property) + "/" - + key; + HelixUtil.getInstancePropertyPath(clusterName, instanceName, property) + "/" + key; return zkClient.getChildren(propertyPath); http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterResource.java ---------------------------------------------------------------------- diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterResource.java b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterResource.java index 7b93152..91b991d 100644 --- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterResource.java +++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClusterResource.java @@ -42,52 +42,42 @@ import org.restlet.resource.Resource; import org.restlet.resource.StringRepresentation; import org.restlet.resource.Variant; - -public class ClusterResource extends Resource -{ - public ClusterResource(Context context, Request request, Response response) - { +public class ClusterResource extends Resource { + public ClusterResource(Context context, Request request, Response response) { super(context, request, response); getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); } @Override - public boolean allowGet() - { + public boolean allowGet() { return true; } @Override - public boolean allowPost() - { + public boolean allowPost() { return true; } @Override - public boolean allowPut() - { + public boolean allowPut() { return false; } @Override - public boolean allowDelete() - { + public boolean allowDelete() { return true; } @Override - public Representation represent(Variant variant) - { + public Representation represent(Variant variant) { StringRepresentation presentation = null; - try - { + try { String clusterName = (String) getRequest().getAttributes().get("clusterName"); presentation = getClusterRepresentation(clusterName); } - catch (Exception e) - { + catch (Exception e) { String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e); presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON); @@ -97,11 +87,8 @@ public class ClusterResource extends Resource } StringRepresentation getClusterRepresentation(String clusterName) throws JsonGenerationException, - JsonMappingException, - IOException - { - ZkClient zkClient = - (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); + JsonMappingException, IOException { + ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); List instances = setupTool.getClusterManagementTool().getInstancesInCluster(clusterName); @@ -113,8 +100,7 @@ public class ClusterResource extends Resource setupTool.getClusterManagementTool().getResourcesInCluster(clusterName); clusterSummayRecord.setListField("resources", resources); - List models = - setupTool.getClusterManagementTool().getStateModelDefs(clusterName); + List models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName); clusterSummayRecord.setListField("stateModelDefs", models); HelixDataAccessor accessor = @@ -122,26 +108,21 @@ public class ClusterResource extends Resource Builder keyBuilder = accessor.keyBuilder(); LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader()); - if (leader != null) - { + if (leader != null) { clusterSummayRecord.setSimpleField("LEADER", leader.getInstanceName()); - } - else - { + } else { clusterSummayRecord.setSimpleField("LEADER", ""); } StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clusterSummayRecord), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); return representation; } @Override - public void acceptRepresentation(Representation entity) - { - try - { + public void acceptRepresentation(Representation entity) { + try { String clusterName = (String) getRequest().getAttributes().get("clusterName"); ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); @@ -150,64 +131,49 @@ public class ClusterResource extends Resource JsonParameters jsonParameters = new JsonParameters(entity); String command = jsonParameters.getCommand(); - if (command == null) - { - throw new HelixException("Could NOT find 'command' in parameterMap: " + jsonParameters._parameterMap); - } - else if (command.equalsIgnoreCase(ClusterSetup.activateCluster) + if (command == null) { + throw new HelixException("Could NOT find 'command' in parameterMap: " + + jsonParameters._parameterMap); + } else if (command.equalsIgnoreCase(ClusterSetup.activateCluster) || JsonParameters.CLUSTERSETUP_COMMAND_ALIASES.get(ClusterSetup.activateCluster) - .contains(command)) - { + .contains(command)) { jsonParameters.verifyCommand(ClusterSetup.activateCluster); boolean enabled = true; - if (jsonParameters.getParameter(JsonParameters.ENABLED) != null) - { - enabled = - Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED)); + if (jsonParameters.getParameter(JsonParameters.ENABLED) != null) { + enabled = Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED)); } String grandCluster = jsonParameters.getParameter(JsonParameters.GRAND_CLUSTER); setupTool.activateCluster(clusterName, grandCluster, enabled); - } - else if (command.equalsIgnoreCase(ClusterSetup.expandCluster)) - { + } else if (command.equalsIgnoreCase(ClusterSetup.expandCluster)) { setupTool.expandCluster(clusterName); - } - else - { - throw new HelixException("Unsupported command: " + command - + ". Should be one of [" + ClusterSetup.activateCluster + ", " - + ClusterSetup.expandCluster + "]"); + } else { + throw new HelixException("Unsupported command: " + command + ". Should be one of [" + + ClusterSetup.activateCluster + ", " + ClusterSetup.expandCluster + "]"); } getResponse().setEntity(getClusterRepresentation(clusterName)); getResponse().setStatus(Status.SUCCESS_OK); - } - catch (Exception e) - { + } catch (Exception e) { getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); } } @Override - public void removeRepresentations() - { - try - { + public void removeRepresentations() { + try { String clusterName = (String) getRequest().getAttributes().get("clusterName"); ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); setupTool.deleteCluster(clusterName); getResponse().setStatus(Status.SUCCESS_OK); - } - catch (Exception e) - { + } catch (Exception e) { getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); } } http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClustersResource.java ---------------------------------------------------------------------- diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClustersResource.java b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClustersResource.java index 9097504..84678ab 100644 --- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClustersResource.java +++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ClustersResource.java @@ -40,13 +40,10 @@ import org.restlet.resource.Resource; import org.restlet.resource.StringRepresentation; import org.restlet.resource.Variant; - -public class ClustersResource extends Resource -{ +public class ClustersResource extends Resource { private final static Logger LOG = Logger.getLogger(ClustersResource.class); - public ClustersResource(Context context, Request request, Response response) - { + public ClustersResource(Context context, Request request, Response response) { super(context, request, response); getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); @@ -54,33 +51,26 @@ public class ClustersResource extends Resource } @Override - public boolean allowPost() - { + public boolean allowPost() { return true; } @Override - public boolean allowPut() - { + public boolean allowPut() { return false; } @Override - public boolean allowDelete() - { + public boolean allowDelete() { return true; } @Override - public Representation represent(Variant variant) - { + public Representation represent(Variant variant) { StringRepresentation presentation = null; - try - { + try { presentation = getClustersRepresentation(); - } - catch (Exception e) - { + } catch (Exception e) { LOG.error("", e); String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e); presentation = new StringRepresentation(error, MediaType.APPLICATION_JSON); @@ -91,11 +81,8 @@ public class ClustersResource extends Resource } StringRepresentation getClustersRepresentation() throws JsonGenerationException, - JsonMappingException, - IOException - { - ZkClient zkClient = - (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); + JsonMappingException, IOException { + ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); List clusters = setupTool.getClusterManagementTool().getClusters(); @@ -103,54 +90,44 @@ public class ClustersResource extends Resource clustersRecord.setListField("clusters", clusters); StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clustersRecord), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); return representation; } @Override - public void acceptRepresentation(Representation entity) - { - try - { + public void acceptRepresentation(Representation entity) { + try { JsonParameters jsonParameters = new JsonParameters(entity); String command = jsonParameters.getCommand(); - if (command == null) - { - throw new HelixException("Could NOT find 'command' in parameterMap: " + jsonParameters._parameterMap); - } - else if (command.equalsIgnoreCase(ClusterSetup.addCluster)) - { + if (command == null) { + throw new HelixException("Could NOT find 'command' in parameterMap: " + + jsonParameters._parameterMap); + } else if (command.equalsIgnoreCase(ClusterSetup.addCluster)) { jsonParameters.verifyCommand(ClusterSetup.addCluster); ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); - setupTool.addCluster(jsonParameters.getParameter(JsonParameters.CLUSTER_NAME), - false); - } - else - { - throw new HelixException("Unsupported command: " + command - + ". Should be one of [" + ClusterSetup.addCluster + "]"); + setupTool.addCluster(jsonParameters.getParameter(JsonParameters.CLUSTER_NAME), false); + } else { + throw new HelixException("Unsupported command: " + command + ". Should be one of [" + + ClusterSetup.addCluster + "]"); } getResponse().setEntity(getClustersRepresentation()); getResponse().setStatus(Status.SUCCESS_OK); - } - catch (Exception e) - { + } catch (Exception e) { getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); LOG.error("Error in posting " + entity, e); } } @Override - public void removeRepresentations() - { + public void removeRepresentations() { } } http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/f414aad4/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ConfigResource.java ---------------------------------------------------------------------- diff --git a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ConfigResource.java b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ConfigResource.java index ce52926..c19ae9d 100644 --- a/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ConfigResource.java +++ b/helix-admin-webapp/src/main/java/org/apache/helix/webapp/resources/ConfigResource.java @@ -46,50 +46,43 @@ import org.restlet.resource.Resource; import org.restlet.resource.StringRepresentation; import org.restlet.resource.Variant; - -public class ConfigResource extends Resource -{ +public class ConfigResource extends Resource { private final static Logger LOG = Logger.getLogger(ConfigResource.class); - public ConfigResource(Context context, Request request, Response response) - { + public ConfigResource(Context context, Request request, Response response) { super(context, request, response); getVariants().add(new Variant(MediaType.TEXT_PLAIN)); getVariants().add(new Variant(MediaType.APPLICATION_JSON)); setModifiable(true); } - String getValue(String key) - { + String getValue(String key) { return (String) getRequest().getAttributes().get(key); } - static StringRepresentation getConfigScopes() throws Exception - { + static StringRepresentation getConfigScopes() throws Exception { StringRepresentation representation = null; ZNRecord record = new ZNRecord("Config"); List scopeList = Arrays.asList(ConfigScopeProperty.CLUSTER.toString(), - ConfigScopeProperty.RESOURCE.toString(), - ConfigScopeProperty.PARTICIPANT.toString(), - ConfigScopeProperty.PARTITION.toString()); + ConfigScopeProperty.RESOURCE.toString(), ConfigScopeProperty.PARTICIPANT.toString(), + ConfigScopeProperty.PARTITION.toString()); record.setListField("scopes", scopeList); representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); return representation; } - StringRepresentation getConfigKeys(ConfigScopeProperty scopeProperty, String... keys) throws Exception - { + StringRepresentation getConfigKeys(ConfigScopeProperty scopeProperty, String... keys) + throws Exception { StringRepresentation representation = null; // String clusterName = getValue("clusterName"); - ZkClient zkClient = - (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); + ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); HelixAdmin admin = setupTool.getClusterManagementTool(); ZNRecord record = new ZNRecord(scopeProperty + " Config"); @@ -101,20 +94,17 @@ public class ConfigResource extends Resource representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); return representation; } StringRepresentation getConfigs(// ConfigScope scope, - ConfigScopeProperty scopeProperty, - String... keys) throws Exception - { + ConfigScopeProperty scopeProperty, String... keys) throws Exception { StringRepresentation representation = null; -// String clusterName = getValue("clusterName"); + // String clusterName = getValue("clusterName"); - ZkClient zkClient = - (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); + ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); HelixAdmin admin = setupTool.getClusterManagementTool(); ZNRecord record = new ZNRecord(scopeProperty + " Config"); @@ -126,22 +116,19 @@ public class ConfigResource extends Resource representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); return representation; } @Override - public Representation represent(Variant variant) - { + public Representation represent(Variant variant) { StringRepresentation representation = null; String clusterName = getValue("clusterName"); String scopeStr = getValue("scope"); - try - { - if (scopeStr == null) - { + try { + if (scopeStr == null) { // path is "/clusters/{clusterName}/configs" return getConfigScopes(); } @@ -149,64 +136,53 @@ public class ConfigResource extends Resource scopeStr = scopeStr.toUpperCase(); ConfigScopeProperty scopeProperty = ConfigScopeProperty.valueOf(scopeStr); - switch (scopeProperty) - { + switch (scopeProperty) { case CLUSTER: case PARTICIPANT: case RESOURCE: String scopeKey1 = getValue("scopeKey1"); - if (scopeKey1 == null) - { + if (scopeKey1 == null) { // path is "/clusters/{clusterName}/configs/cluster|participant|resource" representation = getConfigKeys(scopeProperty, clusterName); - } - else - { + } else { // path is "/clusters/{clusterName}/configs/cluster|participant|resource/ // {clusterName}|{participantName}|{resourceName}" -// ConfigScope scope; -// if (scopeProperty == ConfigScopeProperty.CLUSTER) -// { -// scope = new ConfigScopeBuilder().build(scopeProperty, clusterName); -// } -// else -// { -// scope = new ConfigScopeBuilder().build(scopeProperty, clusterName, scopeKey1); -// } + // ConfigScope scope; + // if (scopeProperty == ConfigScopeProperty.CLUSTER) + // { + // scope = new ConfigScopeBuilder().build(scopeProperty, clusterName); + // } + // else + // { + // scope = new ConfigScopeBuilder().build(scopeProperty, clusterName, scopeKey1); + // } representation = getConfigs(scopeProperty, clusterName, scopeKey1); } break; case PARTITION: scopeKey1 = getValue("scopeKey1"); String scopeKey2 = getValue("scopeKey2"); - if (scopeKey1 == null) - { + if (scopeKey1 == null) { // path is "/clusters/{clusterName}/configs/partition" throw new HelixException("Missing resourceName"); - } - else if (scopeKey2 == null) - { + } else if (scopeKey2 == null) { // path is "/clusters/{clusterName}/configs/partition/resourceName" representation = getConfigKeys(scopeProperty, clusterName, scopeKey1); - } - else - { + } else { // path is // "/clusters/{clusterName}/configs/partition/resourceName/partitionName" -// ConfigScope scope = -// new ConfigScopeBuilder().build(scopeProperty, -// clusterName, -// scopeKey1, -// scopeKey2); + // ConfigScope scope = + // new ConfigScopeBuilder().build(scopeProperty, + // clusterName, + // scopeKey1, + // scopeKey2); representation = getConfigs(scopeProperty, clusterName, scopeKey1, scopeKey2); } break; default: break; } - } - catch (Exception e) - { + } catch (Exception e) { String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e); representation = new StringRepresentation(error, MediaType.APPLICATION_JSON); LOG.error("", e); @@ -217,36 +193,29 @@ public class ConfigResource extends Resource /** * set or remove configs depends on "command" field of jsonParameters in POST body - * * @param entity * @param scopeStr * @throws Exception */ - void setConfigs(Representation entity, ConfigScopeProperty type, String scopeArgs) throws Exception - { + void setConfigs(Representation entity, ConfigScopeProperty type, String scopeArgs) + throws Exception { JsonParameters jsonParameters = new JsonParameters(entity); String command = jsonParameters.getCommand(); - ZkClient zkClient = - (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); + ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT); ClusterSetup setupTool = new ClusterSetup(zkClient); - if (command.equalsIgnoreCase(ClusterSetup.setConfig)) - { + if (command.equalsIgnoreCase(ClusterSetup.setConfig)) { jsonParameters.verifyCommand(ClusterSetup.setConfig); String propertiesStr = jsonParameters.getParameter(JsonParameters.CONFIGS); // setupTool.setConfig(scopeStr, propertiesStr); setupTool.setConfig(type, scopeArgs, propertiesStr); - } - else if (command.equalsIgnoreCase(ClusterSetup.removeConfig)) - { + } else if (command.equalsIgnoreCase(ClusterSetup.removeConfig)) { jsonParameters.verifyCommand(ClusterSetup.removeConfig); String propertiesStr = jsonParameters.getParameter(JsonParameters.CONFIGS); setupTool.removeConfig(type, scopeArgs, propertiesStr); - } - else - { + } else { throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.setConfig + ", " + ClusterSetup.removeConfig + "]"); @@ -257,17 +226,14 @@ public class ConfigResource extends Resource } @Override - public void acceptRepresentation(Representation entity) - { + public void acceptRepresentation(Representation entity) { String clusterName = getValue("clusterName"); String scopeStr = getValue("scope").toUpperCase(); - try - { + try { ConfigScopeProperty scopeProperty = ConfigScopeProperty.valueOf(scopeStr); - switch (scopeProperty) - { + switch (scopeProperty) { case CLUSTER: String scopeArgs = clusterName; setConfigs(entity, scopeProperty, scopeArgs); @@ -276,12 +242,9 @@ public class ConfigResource extends Resource case RESOURCE: String scopeKey1 = getValue("scopeKey1"); - if (scopeKey1 == null) - { + if (scopeKey1 == null) { throw new HelixException("Missing resourceName|participantName"); - } - else - { + } else { scopeArgs = clusterName + "," + scopeKey1; setConfigs(entity, scopeProperty, scopeArgs); } @@ -289,12 +252,9 @@ public class ConfigResource extends Resource case PARTITION: scopeKey1 = getValue("scopeKey1"); String scopeKey2 = getValue("scopeKey2"); - if (scopeKey1 == null || scopeKey2 == null) - { + if (scopeKey1 == null || scopeKey2 == null) { throw new HelixException("Missing resourceName|partitionName"); - } - else - { + } else { scopeArgs = clusterName + "," + scopeKey1 + "," + scopeKey2; setConfigs(entity, scopeProperty, scopeArgs); } @@ -302,12 +262,10 @@ public class ConfigResource extends Resource default: break; } - } - catch (Exception e) - { + } catch (Exception e) { LOG.error("Error in posting " + entity, e); getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), - MediaType.APPLICATION_JSON); + MediaType.APPLICATION_JSON); getResponse().setStatus(Status.SUCCESS_OK); } }