You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ki...@apache.org on 2012/11/09 02:02:42 UTC
[1/6] git commit: [HELIX-4] Removing file based implementation
Updated Branches:
refs/heads/master 0c0198876 -> 99d394bfb
[HELIX-4] Removing file based implementation
Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/99d394bf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/99d394bf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/99d394bf
Branch: refs/heads/master
Commit: 99d394bfb4e2fcc561f39d59a94f9c64f48399fd
Parents: 0c01988
Author: Kishore Gopalakrishna <g....@gmail.com>
Authored: Thu Nov 8 17:02:17 2012 -0800
Committer: Kishore Gopalakrishna <g....@gmail.com>
Committed: Thu Nov 8 17:02:17 2012 -0800
----------------------------------------------------------------------
.../org/apache/helix/tools/TestResetInstance.java | 4 +-
.../helix/tools/TestResetPartitionState.java | 4 +-
.../org/apache/helix/tools/TestResetResource.java | 4 +-
.../main/java/org/apache/helix/ClusterView.java | 172 ---
.../java/org/apache/helix/HelixManagerFactory.java | 53 -
.../apache/helix/examples/BootstrapProcess.java | 34 +-
.../org/apache/helix/examples/ExampleProcess.java | 23 +-
.../manager/file/DynamicFileHelixManager.java | 465 -------
.../helix/manager/file/FileCallbackHandler.java | 298 -----
.../helix/manager/file/FileDataAccessor.java | 324 -----
.../apache/helix/manager/file/FileHelixAdmin.java | 489 --------
.../helix/manager/file/FileHelixDataAccessor.java | 371 ------
.../helix/manager/file/StaticFileHelixManager.java | 574 ---------
.../apache/helix/manager/file/package-info.java | 23 -
.../apache/helix/store/PropertyStoreFactory.java | 18 -
.../helix/store/file/FileHelixPropertyStore.java | 312 -----
.../apache/helix/store/file/FilePropertyStore.java | 946 ---------------
.../org/apache/helix/store/file/package-info.java | 23 -
.../apache/helix/tools/ClusterStateVerifier.java | 134 --
.../apache/helix/tools/ClusterViewSerializer.java | 181 ---
.../integration-test/script/driver_cmd_dict.py | 6 +-
.../java/org/apache/helix/DummyProcessThread.java | 6 +-
.../apache/helix/TestClusterviewSerializer.java | 77 --
.../src/test/java/org/apache/helix/TestHelper.java | 40 -
.../apache/helix/healthcheck/TestAddDropAlert.java | 6 +-
.../apache/helix/healthcheck/TestDummyAlerts.java | 4 +-
.../apache/helix/healthcheck/TestExpandAlert.java | 6 +-
.../apache/helix/healthcheck/TestSimpleAlert.java | 6 +-
.../helix/healthcheck/TestSimpleWildcardAlert.java | 6 +-
.../helix/healthcheck/TestStalenessAlert.java | 6 +-
.../helix/healthcheck/TestWildcardAlert.java | 6 +-
.../apache/helix/integration/FileCMTestBase.java | 212 ----
.../TestAddNodeAfterControllerStart.java | 2 +-
.../TestAddStateModelFactoryAfterConnect.java | 4 +-
.../helix/integration/TestAutoIsWithEmptyMap.java | 2 +-
.../helix/integration/TestBucketizedResource.java | 2 +-
.../integration/TestCarryOverBadCurState.java | 2 +-
.../org/apache/helix/integration/TestDisable.java | 2 +-
.../helix/integration/TestDistributedCMMain.java | 2 +-
.../TestDistributedClusterController.java | 2 +-
.../org/apache/helix/integration/TestDrop.java | 4 +-
.../integration/TestDynamicFileClusterManager.java | 64 -
.../TestEnablePartitionDuringDisable.java | 4 +-
.../helix/integration/TestErrorPartition.java | 4 +-
.../helix/integration/TestExternalViewUpdates.java | 2 +-
.../integration/TestFileBasedHelixManager.java | 71 --
.../apache/helix/integration/TestGroupMessage.java | 2 +-
.../integration/TestHelixCustomCodeRunner.java | 4 +-
.../helix/integration/TestMessageThrottle.java | 2 +-
.../helix/integration/TestNonOfflineInitState.java | 4 +-
.../apache/helix/integration/TestNullReplica.java | 2 +-
.../apache/helix/integration/TestPauseSignal.java | 2 +-
.../helix/integration/TestRenamePartition.java | 2 +-
.../helix/integration/TestResetInstance.java | 4 +-
.../helix/integration/TestResetPartitionState.java | 4 +-
.../helix/integration/TestResetResource.java | 4 +-
.../helix/integration/TestRestartParticipant.java | 4 +-
.../apache/helix/integration/TestSchemataSM.java | 2 +-
.../integration/TestSessionExpiryInTransition.java | 4 +-
.../integration/TestStandAloneCMSessionExpiry.java | 2 +-
.../integration/TestStateTransitionTimeout.java | 8 +-
.../helix/manager/file/MockFileHelixManager.java | 279 -----
.../manager/file/TestFileCallbackHandler.java | 108 --
.../helix/manager/file/TestFileDataAccessor.java | 98 --
.../helix/manager/file/TestStaticFileCM.java | 152 ---
.../manager/file/UnitTestDynFileClusterMgr.java | 286 -----
.../helix/mock/consumer/ConsumerAdapter.java | 138 ---
.../apache/helix/mock/consumer/RelayConfig.java | 85 --
.../apache/helix/mock/consumer/RelayConsumer.java | 112 --
.../helix/mock/participant/DummyProcess.java | 487 ++++++++
.../MockEspressoHealthReportProvider.java | 87 ++
.../participant/MockHealthReportParticipant.java | 278 +++++
.../apache/helix/mock/participant/MockJobIntf.java | 28 +
.../helix/mock/participant/MockParticipant.java | 619 ++++++++++
.../helix/mock/participant/MockTransition.java | 43 +
.../apache/helix/mock/relay/DummyRelayProcess.java | 252 ----
.../helix/mock/relay/RelayIdealStateGenerator.java | 52 -
.../helix/mock/router/MockRouterProcess.java | 162 ---
.../apache/helix/mock/router/RouterAdapter.java | 25 -
.../helix/mock/spectator/MockSpectatorProcess.java | 160 +++
.../apache/helix/mock/storage/DummyProcess.java | 550 ---------
.../helix/mock/storage/HealthCheckStateModel.java | 251 ----
.../mock/storage/HealthCheckStateModelFactory.java | 54 -
.../storage/MockEspressoHealthReportProvider.java | 87 --
.../mock/storage/MockHealthReportParticipant.java | 278 -----
.../org/apache/helix/mock/storage/MockJobIntf.java | 28 -
.../apache/helix/mock/storage/MockParticipant.java | 619 ----------
.../helix/mock/storage/MockStorageProcess.java | 175 ---
.../apache/helix/mock/storage/MockTransition.java | 43 -
.../apache/helix/mock/storage/StorageAdapter.java | 210 ----
.../helix/mock/storage/StorageStateModel.java | 161 ---
.../mock/storage/StorageStateModelFactory.java | 53 -
.../helix/store/TestPropertyStoreFactory.java | 97 --
.../helix/store/file/TestFilePropertyStore.java | 160 ---
94 files changed, 1781 insertions(+), 9486 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/build
----------------------------------------------------------------------
diff --git a/build b/build
old mode 100644
new mode 100755
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
index 1a2d1a6..66e3a98 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetInstance.java
@@ -26,8 +26,8 @@ import java.util.Set;
import org.apache.helix.TestHelper;
import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockParticipant.ErrTransition;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockParticipant.ErrTransition;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.webapp.resources.JsonParameters;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
index 58dfd32..6ffcc8b 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetPartitionState.java
@@ -31,8 +31,8 @@ import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockParticipant.ErrTransition;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockParticipant.ErrTransition;
import org.apache.helix.model.LiveInstance;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
----------------------------------------------------------------------
diff --git a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
index 41e3e06..0a930c0 100644
--- a/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
+++ b/helix-admin-webapp/src/test/java/org/apache/helix/tools/TestResetResource.java
@@ -26,8 +26,8 @@ import java.util.Set;
import org.apache.helix.TestHelper;
import org.apache.helix.mock.controller.ClusterController;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockParticipant.ErrTransition;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockParticipant.ErrTransition;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
import org.apache.helix.webapp.resources.JsonParameters;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/ClusterView.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/ClusterView.java b/helix-core/src/main/java/org/apache/helix/ClusterView.java
deleted file mode 100644
index 96580f0..0000000
--- a/helix-core/src/main/java/org/apache/helix/ClusterView.java
+++ /dev/null
@@ -1,172 +0,0 @@
-package org.apache.helix;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-@Deprecated
-public class ClusterView
-{
- private Map<PropertyType, List<ZNRecord>> clusterPropertyLists;
-
- // getter/setter's are needed for private fields for
- // serialization/de-serialization
- // ref:
- // http://jackson.codehaus.org/DataBindingDeepDive
- // @JsonProperty
- public void setClusterPropertyLists(Map<PropertyType, List<ZNRecord>> clusterPropertyLists)
- {
- this.clusterPropertyLists = clusterPropertyLists;
- }
-
- // @JsonProperty
- public Map<PropertyType, List<ZNRecord>> getPropertyLists()
- {
- return clusterPropertyLists;
- }
-
- public void setClusterPropertyList(PropertyType type, List<ZNRecord> propertyList)
- {
- clusterPropertyLists.put(type, propertyList);
- }
-
- public List<ZNRecord> getPropertyList(PropertyType type)
- {
- return clusterPropertyLists.get(type);
- }
-
- public void setMemberInstanceMap(Map<String, MemberInstance> memberInstanceMap)
- {
- this._memberInstanceMap = memberInstanceMap;
- }
-
- @JsonProperty
- public Map<String, MemberInstance> getMemberInstanceMap()
- {
- return _memberInstanceMap;
- }
-
- public void set_memberInstanceMap(Map<String, MemberInstance> _memberInstanceMap)
- {
- this._memberInstanceMap = _memberInstanceMap;
- }
-
- private Map<String, MemberInstance> _memberInstanceMap;
- private List<MemberInstance> _instances;
-
- public void setInstances(List<MemberInstance> instances)
- {
- this._instances = instances;
- }
-
- public List<MemberInstance> getInstances()
- {
- return _instances;
- }
-
- public static class MemberInstance
- {
- private Map<PropertyType, List<ZNRecord>> _instanceProperties = new TreeMap<PropertyType, List<ZNRecord>>();
-
- public void setClusterProperties(Map<PropertyType, List<ZNRecord>> instanceProperties)
- {
- this._instanceProperties = instanceProperties;
- }
-
- // @JsonProperty
- public Map<PropertyType, List<ZNRecord>> getInstanceProperties()
- {
- return _instanceProperties;
- }
-
- public void setInstanceProperty(PropertyType type, List<ZNRecord> values)
- {
- _instanceProperties.put(type, values);
- }
-
- public List<ZNRecord> getInstanceProperty(PropertyType type)
- {
- return _instanceProperties.get(type);
- }
-
- private String _instanceName;
-
- // for JSON de-serialization
- public MemberInstance()
- {
-
- }
-
- public MemberInstance(String instanceName)
- {
- this._instanceName = instanceName;
- }
-
- public String getInstanceName()
- {
- return _instanceName;
- }
-
- public void setInstanceName(String instanceName)
- {
- this._instanceName = instanceName;
- }
-
- }
-
- public MemberInstance getMemberInstance(String instanceName, boolean createNewIfAbsent)
- {
- if (!_memberInstanceMap.containsKey(instanceName))
- {
- _memberInstanceMap.put(instanceName, new MemberInstance(instanceName));
- }
- return _memberInstanceMap.get(instanceName);
- }
-
- private List<ZNRecord> _externalView;
-
- public ClusterView()
- {
- clusterPropertyLists = new TreeMap<PropertyType, List<ZNRecord>>();
- setClusterPropertyList(PropertyType.IDEALSTATES, new ArrayList<ZNRecord>());
- setClusterPropertyList(PropertyType.CONFIGS, new ArrayList<ZNRecord>());
- setClusterPropertyList(PropertyType.LIVEINSTANCES, new ArrayList<ZNRecord>());
- setClusterPropertyList(PropertyType.INSTANCES, new ArrayList<ZNRecord>());
-
- _memberInstanceMap = new HashMap<String, ClusterView.MemberInstance>();
- }
-
- public List<ZNRecord> getExternalView()
- {
- return _externalView;
- }
-
- public void setExternalView(List<ZNRecord> externalView)
- {
- this._externalView = externalView;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/HelixManagerFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixManagerFactory.java b/helix-core/src/main/java/org/apache/helix/HelixManagerFactory.java
index 9f04709..7c3c206 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixManagerFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixManagerFactory.java
@@ -25,10 +25,7 @@ package org.apache.helix;
* for zk-based cluster managers, the getZKXXX(..zkClient) that takes a zkClient parameter
* are intended for session expiry test purpose
*/
-import org.apache.helix.manager.file.DynamicFileHelixManager;
-import org.apache.helix.manager.file.StaticFileHelixManager;
import org.apache.helix.manager.zk.ZKHelixManager;
-import org.apache.helix.store.file.FilePropertyStore;
import org.apache.log4j.Logger;
@@ -55,54 +52,4 @@ public final class HelixManagerFactory
return new ZKHelixManager(clusterName, instanceName, type, zkAddr);
}
- /**
- * Construct a file-based cluster manager using a static cluster-view file the
- * cluster-view file contains pre-computed state transition messages from initial
- * OFFLINE states to ideal states
- *
- * @param clusterName
- * @param instanceName
- * @param type
- * @param clusterViewFile
- * @return
- * @throws Exception
- */
- @Deprecated
- public static HelixManager getStaticFileHelixManager(String clusterName,
- String instanceName,
- InstanceType type,
- String clusterViewFile) throws Exception
- {
- if (type != InstanceType.PARTICIPANT)
- {
- throw new IllegalArgumentException("Static file-based cluster manager doesn't support type other than participant");
- }
- return new StaticFileHelixManager(clusterName, instanceName, type, clusterViewFile);
- }
-
- /**
- * Construct a dynamic file-based cluster manager
- *
- * @param clusterName
- * @param instanceName
- * @param type
- * @param file
- * property store: all dynamic-file based participants/controller shall use the
- * same file property store to avoid race condition in updating files
- * @return
- * @throws Exception
- */
- @Deprecated
- public static HelixManager getDynamicFileHelixManager(String clusterName,
- String instanceName,
- InstanceType type,
- FilePropertyStore<ZNRecord> store) throws Exception
- {
- if (type != InstanceType.PARTICIPANT && type != InstanceType.CONTROLLER)
- {
- throw new IllegalArgumentException("Dynamic file-based cluster manager doesn't support types other than participant and controller");
- }
-
- return new DynamicFileHelixManager(clusterName, instanceName, type, store);
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/examples/BootstrapProcess.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/BootstrapProcess.java b/helix-core/src/main/java/org/apache/helix/examples/BootstrapProcess.java
index f6c7bac..8d5be5c 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/BootstrapProcess.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/BootstrapProcess.java
@@ -92,34 +92,23 @@ public class BootstrapProcess
private final int delay;
public BootstrapProcess(String zkConnectString, String clusterName,
- String instanceName, String file, String stateModel, int delay)
+ String instanceName, String stateModel, int delay)
{
this.zkConnectString = zkConnectString;
this.clusterName = clusterName;
this.instanceName = instanceName;
- this._file = file;
stateModelType = stateModel;
this.delay = delay;
}
public void start() throws Exception
{
- if (_file == null)
- {
manager = HelixManagerFactory.getZKHelixManager(clusterName,
instanceName,
InstanceType.PARTICIPANT,
zkConnectString);
- }
- else
- {
- manager = HelixManagerFactory.getStaticFileHelixManager(clusterName,
- instanceName,
- InstanceType.PARTICIPANT,
- _file);
-
- }
+
stateModelFactory = new BootstrapHandler();
// genericStateMachineHandler = new StateMachineEngine();
// genericStateMachineHandler.registerStateModelFactory("MasterSlave", stateModelFactory);
@@ -133,12 +122,6 @@ public class BootstrapProcess
MessageType.USER_DEFINE_MSG.toString(),
new CustomMessageHandlerFactory());
manager.connect();
- if (_file != null)
- {
- ClusterStateVerifier.verifyFileBasedClusterStates(_file, instanceName,
- stateModelFactory);
-
- }
}
public static class CustomMessageHandlerFactory implements
@@ -312,7 +295,6 @@ public class BootstrapProcess
String zkConnectString = "localhost:2181";
String clusterName = "storage-integration-cluster";
String instanceName = "localhost_8905";
- String file = null;
String stateModelValue = "MasterSlave";
int delay = 0;
boolean skipZeroArgs = true;// false is for dev testing
@@ -327,16 +309,6 @@ public class BootstrapProcess
int port = Integer.parseInt(portString);
instanceName = host + "_" + port;
- file = cmd.getOptionValue(configFile);
- if (file != null)
- {
- File f = new File(file);
- if (!f.exists())
- {
- System.err.println("static config file doesn't exist");
- System.exit(1);
- }
- }
stateModelValue = cmd.getOptionValue(stateModel);
if (cmd.hasOption(transDelay))
@@ -359,7 +331,7 @@ public class BootstrapProcess
System.out.println("Starting Process with ZK:" + zkConnectString);
BootstrapProcess process = new BootstrapProcess(zkConnectString,
- clusterName, instanceName, file, stateModelValue, delay);
+ clusterName, instanceName, stateModelValue, delay);
process.start();
Thread.currentThread().join();
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java b/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
index 58b861e..c94c25b 100644
--- a/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
+++ b/helix-core/src/main/java/org/apache/helix/examples/ExampleProcess.java
@@ -60,7 +60,6 @@ public class ExampleProcess
// private StateMachineEngine genericStateMachineHandler;
- private String _file = null;
private StateModelFactory<StateModel> stateModelFactory;
private final int delay;
@@ -70,25 +69,15 @@ public class ExampleProcess
this.zkConnectString = zkConnectString;
this.clusterName = clusterName;
this.instanceName = instanceName;
- this._file = file;
stateModelType = stateModel;
this.delay = delay;
}
public void start() throws Exception
{
- if (_file == null)
- {
- manager = HelixManagerFactory.getZKHelixManager(clusterName,
- instanceName, InstanceType.PARTICIPANT, zkConnectString);
-
- } else
- {
- manager = HelixManagerFactory.getStaticFileHelixManager(clusterName,
- instanceName, InstanceType.PARTICIPANT, _file);
-
- }
-
+ manager = HelixManagerFactory.getZKHelixManager(clusterName, instanceName,
+ InstanceType.PARTICIPANT, zkConnectString);
+
if ("MasterSlave".equalsIgnoreCase(stateModelType))
{
stateModelFactory = new MasterSlaveStateModelFactory(delay);
@@ -108,12 +97,6 @@ public class ExampleProcess
manager.connect();
manager.getMessagingService().registerMessageHandlerFactory(
MessageType.STATE_TRANSITION.toString(), stateMach);
- if (_file != null)
- {
- ClusterStateVerifier.verifyFileBasedClusterStates(_file, instanceName,
- stateModelFactory);
-
- }
}
public void stop()
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/manager/file/DynamicFileHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/DynamicFileHelixManager.java b/helix-core/src/main/java/org/apache/helix/manager/file/DynamicFileHelixManager.java
deleted file mode 100644
index 68024c3..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/file/DynamicFileHelixManager.java
+++ /dev/null
@@ -1,465 +0,0 @@
-package org.apache.helix.manager.file;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-import static org.apache.helix.HelixConstants.ChangeType.CURRENT_STATE;
-import static org.apache.helix.HelixConstants.ChangeType.IDEAL_STATE;
-import static org.apache.helix.HelixConstants.ChangeType.LIVE_INSTANCE;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.helix.ClusterMessagingService;
-import org.apache.helix.ConfigAccessor;
-import org.apache.helix.ConfigChangeListener;
-import org.apache.helix.ControllerChangeListener;
-import org.apache.helix.CurrentStateChangeListener;
-import org.apache.helix.DataAccessor;
-import org.apache.helix.ExternalViewChangeListener;
-import org.apache.helix.HealthStateChangeListener;
-import org.apache.helix.HelixAdmin;
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixException;
-import org.apache.helix.HelixManager;
-import org.apache.helix.IdealStateChangeListener;
-import org.apache.helix.InstanceType;
-import org.apache.helix.LiveInstanceChangeListener;
-import org.apache.helix.MessageListener;
-import org.apache.helix.PreConnectCallback;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.ConfigScope.ConfigScopeProperty;
-import org.apache.helix.HelixConstants.ChangeType;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
-import org.apache.helix.messaging.DefaultMessagingService;
-import org.apache.helix.model.LiveInstance;
-import org.apache.helix.model.Message.MessageType;
-import org.apache.helix.participant.HelixStateMachineEngine;
-import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.store.PropertyJsonComparator;
-import org.apache.helix.store.PropertyJsonSerializer;
-import org.apache.helix.store.PropertyStore;
-import org.apache.helix.store.file.FilePropertyStore;
-import org.apache.helix.store.zk.ZkHelixPropertyStore;
-import org.apache.helix.tools.PropertiesReader;
-import org.apache.helix.util.HelixUtil;
-import org.apache.log4j.Logger;
-import org.apache.zookeeper.Watcher.Event.EventType;
-
-
-@Deprecated
-public class DynamicFileHelixManager implements HelixManager
-{
- private static final Logger LOG = Logger.getLogger(StaticFileHelixManager.class.getName());
- private final FileDataAccessor _fileDataAccessor;
- private final FileHelixDataAccessor _accessor;
-
- private final String _clusterName;
- private final InstanceType _instanceType;
- private final String _instanceName;
- private boolean _isConnected;
- private final List<FileCallbackHandler> _handlers;
- private final FileHelixAdmin _mgmtTool;
-
- private final String _sessionId; // = "12345";
- public static final String configFile = "configFile";
- private final DefaultMessagingService _messagingService;
- private final FilePropertyStore<ZNRecord> _store;
- private final String _version;
- private final StateMachineEngine _stateMachEngine;
- private PropertyStore<ZNRecord> _propertyStore = null;
-
- public DynamicFileHelixManager(String clusterName, String instanceName,
- InstanceType instanceType, FilePropertyStore<ZNRecord> store)
- {
- _clusterName = clusterName;
- _instanceName = instanceName;
- _instanceType = instanceType;
-
- _handlers = new ArrayList<FileCallbackHandler>();
-
- _store = store;
- _fileDataAccessor = new FileDataAccessor(_store, clusterName);
- _accessor = new FileHelixDataAccessor(_store, clusterName);
-
- _mgmtTool = new FileHelixAdmin(_store);
- _messagingService = new DefaultMessagingService(this);
- _sessionId = UUID.randomUUID().toString();
- if (instanceType == InstanceType.PARTICIPANT)
- {
- addLiveInstance();
- addMessageListener(_messagingService.getExecutor(), _instanceName);
- }
-
- _version = new PropertiesReader("cluster-manager-version.properties")
- .getProperty("clustermanager.version");
-
- _stateMachEngine = new HelixStateMachineEngine(this);
-
- _messagingService.registerMessageHandlerFactory(MessageType.STATE_TRANSITION.toString(),
- _stateMachEngine);
- }
-
- @Override
- public void disconnect()
- {
- _store.stop();
- _messagingService.getExecutor().shutDown();
-
- _isConnected = false;
- }
-
- @Override
- public void addIdealStateChangeListener(IdealStateChangeListener listener)
- {
- final String path = HelixUtil.getIdealStatePath(_clusterName);
-
- FileCallbackHandler callbackHandler = createCallBackHandler(path, listener, new EventType[] {
- EventType.NodeDataChanged, EventType.NodeDeleted, EventType.NodeCreated }, IDEAL_STATE);
- _handlers.add(callbackHandler);
-
- }
-
- @Override
- public void addLiveInstanceChangeListener(LiveInstanceChangeListener listener)
- {
- final String path = HelixUtil.getLiveInstancesPath(_clusterName);
- FileCallbackHandler callbackHandler = createCallBackHandler(path, listener, new EventType[] {
- EventType.NodeDataChanged, EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated },
- LIVE_INSTANCE);
- _handlers.add(callbackHandler);
- }
-
- @Override
- public void addConfigChangeListener(ConfigChangeListener listener)
- {
- throw new UnsupportedOperationException(
- "addConfigChangeListener() is NOT supported by File Based cluster manager");
- }
-
- @Override
- public void addMessageListener(MessageListener listener, String instanceName)
- {
- final String path = HelixUtil.getMessagePath(_clusterName, instanceName);
-
- FileCallbackHandler callbackHandler = createCallBackHandler(path, listener, new EventType[] {
- EventType.NodeDataChanged, EventType.NodeDeleted, EventType.NodeCreated },
- ChangeType.MESSAGE);
- _handlers.add(callbackHandler);
-
- }
-
- @Override
- public void addCurrentStateChangeListener(CurrentStateChangeListener listener,
- String instanceName, String sessionId)
- {
- final String path = HelixUtil.getCurrentStateBasePath(_clusterName, instanceName) + "/"
- + sessionId;
-
- FileCallbackHandler callbackHandler = createCallBackHandler(path, listener, new EventType[] {
- EventType.NodeChildrenChanged, EventType.NodeDeleted, EventType.NodeCreated },
- CURRENT_STATE);
-
- _handlers.add(callbackHandler);
- }
-
- @Override
- public void addExternalViewChangeListener(ExternalViewChangeListener listener)
- {
- throw new UnsupportedOperationException(
- "addExternalViewChangeListener() is NOT supported by File Based cluster manager");
- }
-
- @Override
- public DataAccessor getDataAccessor()
- {
- return _fileDataAccessor;
- }
-
- @Override
- public String getClusterName()
- {
- return _clusterName;
- }
-
- @Override
- public String getInstanceName()
- {
- return _instanceName;
- }
-
- @Override
- public void connect()
- {
- if (!isClusterSetup(_clusterName))
- {
- throw new HelixException("Initial cluster structure is not set up for cluster:"
- + _clusterName);
- }
- _messagingService.onConnected();
- _store.start();
- _isConnected = true;
- }
-
- @Override
- public String getSessionId()
- {
- return _sessionId;
- }
-
- @Override
- public boolean isConnected()
- {
- return _isConnected;
- }
-
- private boolean isClusterSetup(String clusterName)
- {
- if (clusterName == null || _store == null)
- {
- return false;
- }
-
- boolean isValid = _store.exists(PropertyPathConfig.getPath(PropertyType.IDEALSTATES,
- clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName,
- ConfigScopeProperty.CLUSTER.toString()))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName,
- ConfigScopeProperty.PARTICIPANT.toString()))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName,
- ConfigScopeProperty.RESOURCE.toString()))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.LIVEINSTANCES, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.INSTANCES, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.EXTERNALVIEW, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.CONTROLLER, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.STATEMODELDEFS, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.MESSAGES_CONTROLLER, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.ERRORS_CONTROLLER, clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.STATUSUPDATES_CONTROLLER,
- clusterName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.HISTORY, clusterName));
-
- return isValid;
- }
-
- private boolean isInstanceSetup()
- {
- if (_instanceType == InstanceType.PARTICIPANT
- || _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
- {
- boolean isValid = _store.exists(PropertyPathConfig.getPath(PropertyType.CONFIGS,
- _clusterName, ConfigScopeProperty.PARTICIPANT.toString(), _instanceName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.MESSAGES, _clusterName,
- _instanceName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, _clusterName,
- _instanceName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.STATUSUPDATES, _clusterName,
- _instanceName))
- && _store.exists(PropertyPathConfig.getPath(PropertyType.ERRORS, _clusterName,
- _instanceName));
-
- return isValid;
- }
- return true;
- }
-
- private void addLiveInstance()
- {
- if (!isClusterSetup(_clusterName))
- {
- throw new HelixException("Initial cluster structure is not set up for cluster:"
- + _clusterName);
- }
-
- if (!isInstanceSetup())
- {
- throw new HelixException("Instance is not configured for instance:" + _instanceName
- + " instanceType:" + _instanceType);
- }
-
- LiveInstance liveInstance = new LiveInstance(_instanceName);
- liveInstance.setSessionId(_sessionId);
-// _fileDataAccessor.setProperty(PropertyType.LIVEINSTANCES, liveInstance.getRecord(),
-// _instanceName);
-
- Builder keyBuilder = _accessor.keyBuilder();
- _accessor.setProperty(keyBuilder.liveInstance(_instanceName), liveInstance);
-
- }
-
- @Override
- public long getLastNotificationTime()
- {
- return 0;
- }
-
- @Override
- public void addControllerListener(ControllerChangeListener listener)
- {
- throw new UnsupportedOperationException(
- "addControllerListener() is NOT supported by File Based cluster manager");
- }
-
- @Override
- public boolean removeListener(Object listener)
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- private FileCallbackHandler createCallBackHandler(String path, Object listener,
- EventType[] eventTypes, ChangeType changeType)
- {
- if (listener == null)
- {
- throw new HelixException("Listener cannot be null");
- }
- return new FileCallbackHandler(this, path, listener, eventTypes, changeType);
- }
-
- @Override
- public HelixAdmin getClusterManagmentTool()
- {
- return _mgmtTool;
- }
-
- private void checkConnected()
- {
- if (!isConnected())
- {
- throw new HelixException("ClusterManager not connected. Call clusterManager.connect()");
- }
- }
-
- @Override
- public PropertyStore<ZNRecord> getPropertyStore()
- {
- checkConnected();
-
- if (_propertyStore == null)
- {
- String path = PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, _clusterName);
-
- String propertyStoreRoot = _store.getPropertyRootNamespace() + path;
- _propertyStore =
- new FilePropertyStore<ZNRecord>(new PropertyJsonSerializer<ZNRecord>(ZNRecord.class),
- propertyStoreRoot,
- new PropertyJsonComparator<ZNRecord>(ZNRecord.class));
- }
- return _propertyStore;
- }
-
- @Override
- public ClusterMessagingService getMessagingService()
- {
- return _messagingService;
- }
-
- @Override
- public ParticipantHealthReportCollector getHealthReportCollector()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public InstanceType getInstanceType()
- {
- return _instanceType;
- }
-
- @Override
- public void addHealthStateChangeListener(HealthStateChangeListener listener, String instanceName)
- throws Exception
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public String getVersion()
- {
- return _version;
- }
-
- @Override
- public StateMachineEngine getStateMachineEngine()
- {
- return _stateMachEngine;
- }
-
- @Override
- public boolean isLeader()
- {
- if (_instanceType != InstanceType.CONTROLLER)
- {
- return false;
- }
-
- return true;
- }
-
- @Override
- public ConfigAccessor getConfigAccessor()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void startTimerTasks()
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void stopTimerTasks()
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public HelixDataAccessor getHelixDataAccessor()
- {
- return _accessor;
- }
-
- @Override
- public void addPreConnectCallback(PreConnectCallback callback)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/manager/file/FileCallbackHandler.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/FileCallbackHandler.java b/helix-core/src/main/java/org/apache/helix/manager/file/FileCallbackHandler.java
deleted file mode 100644
index 3ec6246..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/file/FileCallbackHandler.java
+++ /dev/null
@@ -1,298 +0,0 @@
-package org.apache.helix.manager.file;
-
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.apache.helix.HelixConstants.ChangeType.CONFIG;
-import static org.apache.helix.HelixConstants.ChangeType.CURRENT_STATE;
-import static org.apache.helix.HelixConstants.ChangeType.EXTERNAL_VIEW;
-import static org.apache.helix.HelixConstants.ChangeType.IDEAL_STATE;
-import static org.apache.helix.HelixConstants.ChangeType.LIVE_INSTANCE;
-import static org.apache.helix.HelixConstants.ChangeType.MESSAGE;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.helix.ConfigChangeListener;
-import org.apache.helix.ControllerChangeListener;
-import org.apache.helix.CurrentStateChangeListener;
-import org.apache.helix.ExternalViewChangeListener;
-import org.apache.helix.HelixManager;
-import org.apache.helix.IdealStateChangeListener;
-import org.apache.helix.LiveInstanceChangeListener;
-import org.apache.helix.MessageListener;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.HelixConstants.ChangeType;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.model.CurrentState;
-import org.apache.helix.model.ExternalView;
-import org.apache.helix.model.IdealState;
-import org.apache.helix.model.InstanceConfig;
-import org.apache.helix.model.LiveInstance;
-import org.apache.helix.model.Message;
-import org.apache.helix.store.PropertyChangeListener;
-import org.apache.helix.store.PropertyStoreException;
-import org.apache.helix.store.file.FilePropertyStore;
-import org.apache.helix.util.HelixUtil;
-import org.apache.log4j.Logger;
-import org.apache.zookeeper.Watcher.Event.EventType;
-
-
-// TODO remove code duplication: CallbackHandler and CallbackHandlerForFile
-@Deprecated
-public class FileCallbackHandler implements PropertyChangeListener<ZNRecord>
-{
-
- private static Logger LOG = Logger.getLogger(FileCallbackHandler.class);
-
- private final String _path;
- private final Object _listener;
- private final EventType[] _eventTypes;
- private final ChangeType _changeType;
-// private final FileDataAccessor _accessor;
- private final FileHelixDataAccessor _accessor;
- private final AtomicLong lastNotificationTimeStamp;
- private final HelixManager _manager;
- private final FilePropertyStore<ZNRecord> _store;
-
- public FileCallbackHandler(HelixManager manager, String path, Object listener,
- EventType[] eventTypes, ChangeType changeType)
- {
- this._manager = manager;
- this._accessor = (FileHelixDataAccessor) manager.getHelixDataAccessor();
- this._path = path;
- this._listener = listener;
- this._eventTypes = eventTypes;
- this._changeType = changeType;
- this._store = (FilePropertyStore<ZNRecord>) _accessor.getStore();
- lastNotificationTimeStamp = new AtomicLong(System.nanoTime());
-
- init();
- }
-
- public Object getListener()
- {
- return _listener;
- }
-
- public Object getPath()
- {
- return _path;
- }
-
- public void invoke(NotificationContext changeContext) throws Exception
- {
- // This allows the listener to work with one change at a time
- synchronized (_listener)
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug(Thread.currentThread().getId() + " START:INVOKE "
- + changeContext.getPathChanged() + " listener:"
- + _listener.getClass().getCanonicalName());
- }
-
- Builder keyBuilder = _accessor.keyBuilder();
-
- if (_changeType == IDEAL_STATE)
- {
- // System.err.println("ideal state change");
- IdealStateChangeListener idealStateChangeListener = (IdealStateChangeListener) _listener;
- subscribeForChanges(changeContext, true, true);
- List<IdealState> idealStates = _accessor.getChildValues(keyBuilder.idealStates());
- idealStateChangeListener.onIdealStateChange(idealStates, changeContext);
-
- } else if (_changeType == CONFIG)
- {
-
- ConfigChangeListener configChangeListener = (ConfigChangeListener) _listener;
- subscribeForChanges(changeContext, true, true);
- List<InstanceConfig> configs = _accessor.getChildValues(keyBuilder.instanceConfigs());
- configChangeListener.onConfigChange(configs, changeContext);
-
- } else if (_changeType == LIVE_INSTANCE)
- {
- LiveInstanceChangeListener liveInstanceChangeListener = (LiveInstanceChangeListener) _listener;
- subscribeForChanges(changeContext, true, false);
- List<LiveInstance> liveInstances = _accessor.getChildValues(keyBuilder.liveInstances());
- liveInstanceChangeListener.onLiveInstanceChange(liveInstances, changeContext);
-
- } else if (_changeType == CURRENT_STATE)
- {
- CurrentStateChangeListener currentStateChangeListener;
- currentStateChangeListener = (CurrentStateChangeListener) _listener;
- subscribeForChanges(changeContext, true, true);
- String instanceName = HelixUtil.getInstanceNameFromPath(_path);
- String[] pathParts = _path.split("/");
- List<CurrentState> currentStates = _accessor.getChildValues(keyBuilder.currentStates(instanceName, pathParts[pathParts.length - 1]));
- currentStateChangeListener.onStateChange(instanceName, currentStates, changeContext);
-
- } else if (_changeType == MESSAGE)
- {
- MessageListener messageListener = (MessageListener) _listener;
- subscribeForChanges(changeContext, true, false);
- String instanceName = _manager.getInstanceName();
- List<Message> messages = _accessor.getChildValues(keyBuilder.messages(instanceName));
- messageListener.onMessage(instanceName, messages, changeContext);
- } else if (_changeType == EXTERNAL_VIEW)
- {
- ExternalViewChangeListener externalViewListener = (ExternalViewChangeListener) _listener;
- subscribeForChanges(changeContext, true, true);
- List<ExternalView> externalViewList = _accessor.getChildValues(keyBuilder.externalViews());
- externalViewListener.onExternalViewChange(externalViewList, changeContext);
- } else if (_changeType == ChangeType.CONTROLLER)
- {
- ControllerChangeListener controllerChangelistener = (ControllerChangeListener) _listener;
- subscribeForChanges(changeContext, true, false);
- controllerChangelistener.onControllerChange(changeContext);
- }
-
- if (LOG.isDebugEnabled())
- {
- LOG.debug(Thread.currentThread().getId() + " END:INVOKE " + changeContext.getPathChanged()
- + " listener:" + _listener.getClass().getCanonicalName());
- }
- }
- }
-
- private void subscribeForChanges(NotificationContext changeContext, boolean watchParent,
- boolean watchChild)
- {
- if (changeContext.getType() == NotificationContext.Type.INIT)
- {
- try
- {
- // _accessor.subscribeForPropertyChange(_path, this);
- _store.subscribeForPropertyChange(_path, this);
- } catch (PropertyStoreException e)
- {
- LOG.error("fail to subscribe for changes" + "\nexception:" + e);
- }
- }
- }
-
- public EventType[] getEventTypes()
- {
- return _eventTypes;
- }
-
- // this will invoke the listener so that it sets up the initial values from
- // the file property store if any exists
- public void init()
- {
- updateNotificationTime(System.nanoTime());
- try
- {
- NotificationContext changeContext = new NotificationContext(_manager);
- changeContext.setType(NotificationContext.Type.INIT);
- invoke(changeContext);
- } catch (Exception e)
- {
- // TODO handle exception
- LOG.error("fail to init", e);
- }
- }
-
- public void reset()
- {
- try
- {
- NotificationContext changeContext = new NotificationContext(_manager);
- changeContext.setType(NotificationContext.Type.FINALIZE);
- invoke(changeContext);
- } catch (Exception e)
- {
- // TODO handle exception
- LOG.error("fail to reset" + "\nexception:" + e);
- // ZKExceptionHandler.getInstance().handle(e);
- }
- }
-
- private void updateNotificationTime(long nanoTime)
- {
- long l = lastNotificationTimeStamp.get();
- while (nanoTime > l)
- {
- boolean b = lastNotificationTimeStamp.compareAndSet(l, nanoTime);
- if (b)
- {
- break;
- } else
- {
- l = lastNotificationTimeStamp.get();
- }
- }
- }
-
- @Override
- public void onPropertyChange(String key)
- {
- // debug
- // LOG.error("on property change, key:" + key + ", path:" + _path);
-
- try
- {
- if (needToNotify(key))
- {
- // debug
- // System.err.println("notified on property change, key:" + key +
- // ", path:" +
- // path);
-
- updateNotificationTime(System.nanoTime());
- NotificationContext changeContext = new NotificationContext(_manager);
- changeContext.setType(NotificationContext.Type.CALLBACK);
- invoke(changeContext);
- }
- } catch (Exception e)
- {
- // TODO handle exception
- // ZKExceptionHandler.getInstance().handle(e);
- LOG.error("fail onPropertyChange", e);
- }
- }
-
- private boolean needToNotify(String key)
- {
- boolean ret = false;
- switch (_changeType)
- {
- // both child/data changes matter
- case IDEAL_STATE:
- case CURRENT_STATE:
- case CONFIG:
- ret = key.startsWith(_path);
- break;
- // only child changes matter
- case LIVE_INSTANCE:
- case MESSAGE:
- case EXTERNAL_VIEW:
- case CONTROLLER:
- // ret = key.equals(_path);
- ret = key.startsWith(_path);
- break;
- default:
- break;
- }
-
- return ret;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/manager/file/FileDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/FileDataAccessor.java b/helix-core/src/main/java/org/apache/helix/manager/file/FileDataAccessor.java
deleted file mode 100644
index 9517b19..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/file/FileDataAccessor.java
+++ /dev/null
@@ -1,324 +0,0 @@
-package org.apache.helix.manager.file;
-
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.I0Itec.zkclient.DataUpdater;
-import org.apache.helix.DataAccessor;
-import org.apache.helix.HelixProperty;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.store.PropertyStore;
-import org.apache.helix.store.PropertyStoreException;
-import org.apache.helix.store.file.FilePropertyStore;
-import org.apache.log4j.Logger;
-
-
-@Deprecated
-public class FileDataAccessor implements DataAccessor
-{
- private static Logger LOG = Logger.getLogger(FileDataAccessor.class);
- // store that is used by FileDataAccessor
- private final FilePropertyStore<ZNRecord> _store;
- private final String _clusterName;
- private final ReadWriteLock _readWriteLock = new ReentrantReadWriteLock();
-
- public FileDataAccessor(FilePropertyStore<ZNRecord> store, String clusterName)
- {
- _store = store;
- _clusterName = clusterName;
- }
-
- @Override
- public boolean setProperty(PropertyType type, HelixProperty value, String... keys)
- {
- return setProperty(type, value.getRecord(), keys);
- }
-
- @Override
- public boolean setProperty(PropertyType type, ZNRecord value, String... keys)
- {
- String path = PropertyPathConfig.getPath(type, _clusterName, keys);
-
- try
- {
- _readWriteLock.writeLock().lock();
- _store.setProperty(path, value);
- return true;
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to set cluster property clusterName: " + _clusterName +
- " type:" + type +
- " keys:" + keys + "\nexception: " + e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
- return false;
- }
-
- @Override
- public boolean updateProperty(PropertyType type, HelixProperty value, String... keys)
- {
- return updateProperty(type, value.getRecord(), keys);
- }
-
- @Override
- public boolean updateProperty(PropertyType type, ZNRecord value, String... keys)
- {
- try
- {
- _readWriteLock.writeLock().lock();
- String path = PropertyPathConfig.getPath(type, _clusterName, keys);
- if (type.isUpdateOnlyOnExists())
- {
- updateIfExists(path, value, type.isMergeOnUpdate());
- }
- else
- {
- createOrUpdate(path, value, type.isMergeOnUpdate());
- }
- return true;
- }
- catch (PropertyStoreException e)
- {
- LOG.error("fail to update instance property, " +
- " type:" + type + " keys:" + keys, e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
- return false;
-
- }
-
- @Override
- public <T extends HelixProperty>
- T getProperty(Class<T> clazz, PropertyType type, String... keys)
- {
- ZNRecord record = getProperty(type, keys);
- if (record == null)
- {
- return null;
- }
- return HelixProperty.convertToTypedInstance(clazz, record);
- }
-
- @Override
- public ZNRecord getProperty(PropertyType type, String... keys)
- {
- String path = PropertyPathConfig.getPath(type, _clusterName, keys);
-
- try
- {
- _readWriteLock.readLock().lock();
- return _store.getProperty(path);
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to get cluster property clusterName: " + _clusterName +
- " type:" + type +
- " keys:" + keys, e);
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- }
- return null;
- }
-
- @Override
- public boolean removeProperty(PropertyType type, String... keys)
- {
- String path = PropertyPathConfig.getPath(type, _clusterName, keys);
-
- try
- {
- _readWriteLock.writeLock().lock();
- _store.removeProperty(path);
- return true;
- }
- catch (PropertyStoreException e)
- {
- LOG.error("Fail to remove instance property, " +
- " type:" + type + " keys:" + keys, e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
-
- return false;
- }
-
- @Override
- public List<String> getChildNames(PropertyType type, String... keys)
- {
- String path = PropertyPathConfig.getPath(type, _clusterName, keys);
-
- try
- {
- _readWriteLock.readLock().lock();
-
- List<String> childs = _store.getPropertyNames(path);
- return childs;
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to get child names:" + _clusterName +
- " parentPath:" + path + "\nexception: " + e);
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- }
-
- return Collections.emptyList();
- }
-
- @Override
- public <T extends HelixProperty>
- List<T> getChildValues(Class<T> clazz, PropertyType type, String... keys)
- {
- List<ZNRecord> list = getChildValues(type, keys);
- return HelixProperty.convertToTypedList(clazz, list);
- }
-
- @Override
- public List<ZNRecord> getChildValues(PropertyType type, String... keys)
- {
- String path = PropertyPathConfig.getPath(type, _clusterName, keys);
- List<ZNRecord> records = new ArrayList<ZNRecord>();
- try
- {
- _readWriteLock.readLock().lock();
-
- List<String> childs = _store.getPropertyNames(path);
- if (childs == null || childs.size() == 0)
- {
- return Collections.emptyList();
- }
-
- for (String child : childs)
- {
- ZNRecord record = _store.getProperty(child);
- if (record != null)
- {
- records.add(record);
- }
- }
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to get child properties cluster:" + _clusterName +
- " parentPath:" + path + "\nexception: " + e);
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- }
- return records;
- }
-
- // HACK remove it later
- public PropertyStore<ZNRecord> getStore()
- {
- return _store;
- }
-
- private void updateIfExists(String path, final ZNRecord record, boolean mergeOnUpdate)
- throws PropertyStoreException
- {
- if (_store.exists(path))
- {
- _store.setProperty(path, record);
- }
- }
-
- private void createOrUpdate(String path, final ZNRecord record, final boolean mergeOnUpdate)
- throws PropertyStoreException
- {
- final int RETRYLIMIT = 3;
- int retryCount = 0;
- while (retryCount < RETRYLIMIT)
- {
- try
- {
- if (_store.exists(path))
- {
- DataUpdater<ZNRecord> updater = new DataUpdater<ZNRecord>()
- {
- @Override
- public ZNRecord update(ZNRecord currentData)
- {
- if(mergeOnUpdate)
- {
- currentData.merge(record);
- return currentData;
- }
- return record;
- }
- };
- _store.updatePropertyUntilSucceed(path, updater);
-
- }
- else
- {
- if(record.getDeltaList().size() > 0)
- {
- ZNRecord newRecord = new ZNRecord(record.getId());
- newRecord.merge(record);
- _store.setProperty(path, newRecord);
- }
- else
- {
- _store.setProperty(path, record);
- }
- }
- break;
- }
- catch (Exception e)
- {
- retryCount = retryCount + 1;
- LOG.warn("Exception trying to update " + path + " Exception:"
- + e.getMessage() + ". Will retry.");
- }
- }
- }
-
- @Override
- public <T extends HelixProperty> Map<String, T> getChildValuesMap(Class<T> clazz,
- PropertyType type, String... keys)
- {
- List<T> list = getChildValues(clazz, type, keys);
- return HelixProperty.convertListToMap(list);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java b/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java
deleted file mode 100644
index 0a0a593..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixAdmin.java
+++ /dev/null
@@ -1,489 +0,0 @@
-package org.apache.helix.manager.file;
-
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.helix.ConfigScope;
-import org.apache.helix.HelixAdmin;
-import org.apache.helix.PropertyPathConfig;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.ConfigScope.ConfigScopeProperty;
-import org.apache.helix.model.ExternalView;
-import org.apache.helix.model.IdealState;
-import org.apache.helix.model.InstanceConfig;
-import org.apache.helix.model.StateModelDefinition;
-import org.apache.helix.model.IdealState.IdealStateModeProperty;
-import org.apache.helix.store.PropertyStoreException;
-import org.apache.helix.store.file.FilePropertyStore;
-import org.apache.helix.tools.StateModelConfigGenerator;
-import org.apache.helix.util.HelixUtil;
-import org.apache.log4j.Logger;
-
-
-@Deprecated
-public class FileHelixAdmin implements HelixAdmin
-{
- private static Logger logger =
- Logger.getLogger(FileHelixAdmin.class);
- private final FilePropertyStore<ZNRecord> _store;
-
- public FileHelixAdmin(FilePropertyStore<ZNRecord> store)
- {
- _store = store;
- }
-
- @Override
- public List<String> getClusters()
- {
- throw new UnsupportedOperationException("getClusters() is NOT supported by FileClusterManagementTool");
-
- }
-
- @Override
- public List<String> getInstancesInCluster(String clusterName)
- {
- // String path = HelixUtil.getConfigPath(clusterName);
- String path =
- PropertyPathConfig.getPath(PropertyType.CONFIGS,
- clusterName,
- ConfigScopeProperty.PARTICIPANT.toString());
-
- List<String> childs = null;
- List<String> instanceNames = new ArrayList<String>();
- try
- {
- childs = _store.getPropertyNames(path);
- for (String child : childs)
- {
- // strip config path from instanceName
- String instanceName = child.substring(child.lastIndexOf('/') + 1);
- instanceNames.add(instanceName);
- }
- return instanceNames;
- }
- catch (PropertyStoreException e)
- {
- logger.error("Fail to getInstancesInCluster, cluster " + clusterName, e);
- }
-
- return null;
- }
-
- @Override
- public List<String> getResourcesInCluster(String clusterName)
- {
- // TODO Auto-generated method stub
- // return null;
- throw new UnsupportedOperationException("getResourcesInCluster() is NOT supported by FileClusterManagementTool");
-
- }
-
- @Override
- public void addCluster(String clusterName, boolean overwritePrevRecord)
- {
- String path;
- try
- {
- _store.removeNamespace(clusterName);
- _store.createPropertyNamespace(clusterName);
- _store.createPropertyNamespace(HelixUtil.getIdealStatePath(clusterName));
-
- // CONFIG's
- // _store.createPropertyNamespace(HelixUtil.getConfigPath(clusterName));
- path =
- PropertyPathConfig.getPath(PropertyType.CONFIGS,
- clusterName,
- ConfigScopeProperty.CLUSTER.toString(),
- clusterName);
- _store.setProperty(path, new ZNRecord(clusterName));
- path =
- PropertyPathConfig.getPath(PropertyType.CONFIGS,
- clusterName,
- ConfigScopeProperty.PARTICIPANT.toString());
- _store.createPropertyNamespace(path);
- path =
- PropertyPathConfig.getPath(PropertyType.CONFIGS,
- clusterName,
- ConfigScopeProperty.RESOURCE.toString());
- _store.createPropertyNamespace(path);
-
- // PROPERTY STORE
- path = PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, clusterName);
- _store.createPropertyNamespace(path);
-
- _store.createPropertyNamespace(HelixUtil.getLiveInstancesPath(clusterName));
- _store.createPropertyNamespace(HelixUtil.getMemberInstancesPath(clusterName));
- _store.createPropertyNamespace(HelixUtil.getExternalViewPath(clusterName));
- _store.createPropertyNamespace(HelixUtil.getStateModelDefinitionPath(clusterName));
-
- StateModelConfigGenerator generator = new StateModelConfigGenerator();
- addStateModelDef(clusterName,
- "MasterSlave",
- new StateModelDefinition(generator.generateConfigForMasterSlave()));
-
- // controller
- _store.createPropertyNamespace(HelixUtil.getControllerPath(clusterName));
- path = PropertyPathConfig.getPath(PropertyType.HISTORY, clusterName);
- final ZNRecord emptyHistory = new ZNRecord(PropertyType.HISTORY.toString());
- final List<String> emptyList = new ArrayList<String>();
- emptyHistory.setListField(clusterName, emptyList);
- _store.setProperty(path, emptyHistory);
-
- path = PropertyPathConfig.getPath(PropertyType.MESSAGES_CONTROLLER, clusterName);
- _store.createPropertyNamespace(path);
-
- path =
- PropertyPathConfig.getPath(PropertyType.STATUSUPDATES_CONTROLLER, clusterName);
- _store.createPropertyNamespace(path);
-
- path = PropertyPathConfig.getPath(PropertyType.ERRORS_CONTROLLER, clusterName);
- _store.createPropertyNamespace(path);
-
- }
- catch (PropertyStoreException e)
- {
- logger.error("Fail to add cluster " + clusterName, e);
- }
-
- }
-
- @Override
- public void addResource(String clusterName,
- String resource,
- int numResources,
- String stateModelRef)
- {
- String idealStatePath = HelixUtil.getIdealStatePath(clusterName);
- String resourceIdealStatePath = idealStatePath + "/" + resource;
-
- // if (_zkClient.exists(dbIdealStatePath))
- // {
- // logger.warn("Skip the operation. DB ideal state directory exists:"
- // + dbIdealStatePath);
- // return;
- // }
-
- IdealState idealState = new IdealState(resource);
- idealState.setNumPartitions(numResources);
- idealState.setStateModelDefRef(stateModelRef);
- idealState.setReplicas(Integer.toString(0));
- idealState.setIdealStateMode(IdealStateModeProperty.AUTO.toString());
- try
- {
- _store.setProperty(resourceIdealStatePath, idealState.getRecord());
- }
- catch (PropertyStoreException e)
- {
- logger.error("Fail to add resource, cluster:" + clusterName + " resourceName:"
- + resource, e);
- }
-
- }
-
- @Override
- public void addResource(String clusterName,
- String resource,
- int numResources,
- String stateModelRef,
- String idealStateMode)
- {
- throw new UnsupportedOperationException("ideal state mode not supported in file-based cluster manager");
- }
-
- @Override
- public void addResource(String clusterName,
- String resource,
- int numResources,
- String stateModelRef,
- String idealStateMode,
- int bucketSize)
- {
- throw new UnsupportedOperationException("bucketize not supported in file-based cluster manager");
- }
-
- @Override
- public void addInstance(String clusterName, InstanceConfig config)
- {
- String configsPath =
- PropertyPathConfig.getPath(PropertyType.CONFIGS,
- clusterName,
- ConfigScopeProperty.PARTICIPANT.toString());
- String nodeId = config.getId();
- String nodeConfigPath = configsPath + "/" + nodeId;
-
- try
- {
- _store.setProperty(nodeConfigPath, config.getRecord());
- _store.createPropertyNamespace(HelixUtil.getMessagePath(clusterName, nodeId));
- _store.createPropertyNamespace(HelixUtil.getCurrentStateBasePath(clusterName,
- nodeId));
- _store.createPropertyNamespace(HelixUtil.getErrorsPath(clusterName, nodeId));
- _store.createPropertyNamespace(HelixUtil.getStatusUpdatesPath(clusterName, nodeId));
- }
- catch (Exception e)
- {
- logger.error("Fail to add node, cluster:" + clusterName + "\nexception: " + e);
- }
-
- }
-
- @Override
- public void dropInstance(String clusterName, InstanceConfig config)
- {
- String configsPath =
- PropertyPathConfig.getPath(PropertyType.CONFIGS,
- clusterName,
- ConfigScopeProperty.PARTICIPANT.toString());
- String nodeId = config.getId();
- String nodeConfigPath = configsPath + "/" + nodeId;
-
- try
- {
- _store.setProperty(nodeConfigPath, config.getRecord());
- }
- catch (Exception e)
- {
- logger.error("Fail to drop node, cluster:" + clusterName, e);
- }
- }
-
- @Override
- public IdealState getResourceIdealState(String clusterName, String resourceName)
- {
- return new FileDataAccessor(_store, clusterName).getProperty(IdealState.class,
- PropertyType.IDEALSTATES,
- resourceName);
- }
-
- @Override
- public void setResourceIdealState(String clusterName,
- String resourceName,
- IdealState idealState)
- {
- new FileDataAccessor(_store, clusterName).setProperty(PropertyType.IDEALSTATES,
- idealState,
- resourceName);
- }
-
- @Override
- public void enableInstance(String clusterName, String instanceName, boolean enabled)
- {
- throw new UnsupportedOperationException("enableInstance() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void enableCluster(String clusterName, boolean enabled)
- {
- throw new UnsupportedOperationException("enableCluster() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void addStateModelDef(String clusterName,
- String stateModelDef,
- StateModelDefinition stateModel)
- {
-
- String stateModelDefPath = HelixUtil.getStateModelDefinitionPath(clusterName);
- String stateModelPath = stateModelDefPath + "/" + stateModelDef;
-
- try
- {
- _store.setProperty(stateModelPath, stateModel.getRecord());
- }
- catch (PropertyStoreException e)
- {
- logger.error("Fail to addStateModelDef, cluster:" + clusterName + " stateModelDef:"
- + stateModelDef, e);
- }
-
- }
-
- @Override
- public void dropResource(String clusterName, String resourceName)
- {
- new FileDataAccessor(_store, clusterName).removeProperty(PropertyType.IDEALSTATES,
- resourceName);
-
- }
-
- @Override
- public List<String> getStateModelDefs(String clusterName)
- {
- throw new UnsupportedOperationException("getStateModelDefs() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public InstanceConfig getInstanceConfig(String clusterName, String instanceName)
- {
- throw new UnsupportedOperationException("getInstanceConfig() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public StateModelDefinition getStateModelDef(String clusterName, String stateModelName)
- {
- throw new UnsupportedOperationException("getStateModelDef() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public ExternalView getResourceExternalView(String clusterName, String resource)
- {
- throw new UnsupportedOperationException("getResourceExternalView() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void enablePartition(boolean enabled,
- String clusterName,
- String instanceName,
- String resourceName,
- List<String> partitionNames)
- {
- throw new UnsupportedOperationException("enablePartition() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void resetPartition(String clusterName,
- String instanceName,
- String resourceName,
- List<String> partitionNames)
- {
- throw new UnsupportedOperationException("resetPartition() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void resetInstance(String clusterName, List<String> instanceNames)
- {
- throw new UnsupportedOperationException("resetInstance() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void resetResource(String clusterName, List<String> resourceNames)
- {
- throw new UnsupportedOperationException("resetResource() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void addStat(String clusterName, String statName)
- {
- throw new UnsupportedOperationException("addStat() is NOT supported by FileClusterManagementTool");
-
- }
-
- @Override
- public void addAlert(String clusterName, String alertName)
- {
- throw new UnsupportedOperationException("addAlert() is NOT supported by FileClusterManagementTool");
-
- }
-
- @Override
- public void dropStat(String clusterName, String statName)
- {
- throw new UnsupportedOperationException("dropStat() is NOT supported by FileClusterManagementTool");
-
- }
-
- @Override
- public void dropAlert(String clusterName, String alertName)
- {
- throw new UnsupportedOperationException("dropAlert() is NOT supported by FileClusterManagementTool");
-
- }
-
- @Override
- public void dropCluster(String clusterName)
- {
- throw new UnsupportedOperationException("dropCluster() is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void addClusterToGrandCluster(String clusterName, String grandCluster)
- {
- throw new UnsupportedOperationException("addCluster(clusterName, overwritePrevRecord, grandCluster) is NOT supported by FileClusterManagementTool");
- }
-
- @Override
- public void setConfig(ConfigScope scope, Map<String, String> properties)
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-
- @Override
- public Map<String, String> getConfig(ConfigScope scope, Set<String> keys)
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-
- @Override
- public List<String> getConfigKeys(ConfigScopeProperty scope,
- String clusterName,
- String... keys)
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-
- @Override
- public void removeConfig(ConfigScope scope, Set<String> keys)
- {
- throw new UnsupportedOperationException("unsupported operation");
-
- }
-
- @Override
- public void rebalance(String clusterName, String resourceName, int replica)
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-
- @Override
- public void addIdealState(String clusterName, String resourceName, String idealStateFile) throws IOException
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-
- @Override
- public void addStateModelDef(String clusterName,
- String stateModelDefName,
- String stateModelDefFile) throws IOException
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-
- @Override
- public void addMessageConstraint(String clusterName,
- String constraintId,
- Map<String, String> constraints)
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-
- @Override
- public void addResource(String clusterName, String resourceName,
- IdealState idealstate)
- {
- throw new UnsupportedOperationException("unsupported operation");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixDataAccessor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixDataAccessor.java b/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixDataAccessor.java
deleted file mode 100644
index af43981..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/file/FileHelixDataAccessor.java
+++ /dev/null
@@ -1,371 +0,0 @@
-package org.apache.helix.manager.file;
-
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.I0Itec.zkclient.DataUpdater;
-import org.apache.helix.BaseDataAccessor;
-import org.apache.helix.HelixDataAccessor;
-import org.apache.helix.HelixProperty;
-import org.apache.helix.PropertyKey;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.PropertyKey.Builder;
-import org.apache.helix.store.PropertyStore;
-import org.apache.helix.store.PropertyStoreException;
-import org.apache.helix.store.file.FilePropertyStore;
-import org.apache.log4j.Logger;
-
-
-@Deprecated
-public class FileHelixDataAccessor implements HelixDataAccessor
-{
- private static Logger LOG = Logger.getLogger(FileHelixDataAccessor.class);
-
- private final FilePropertyStore<ZNRecord> _store;
- private final String _clusterName;
- private final ReadWriteLock _readWriteLock = new ReentrantReadWriteLock();
- private final Builder _propertyKeyBuilder;
-
-
- public FileHelixDataAccessor(FilePropertyStore<ZNRecord> store,
- String clusterName)
- {
- _store = store;
- _clusterName = clusterName;
- _propertyKeyBuilder = new PropertyKey.Builder(_clusterName);
- }
-
- @Override
- public boolean createProperty(PropertyKey key, HelixProperty value)
- {
- return updateProperty(key, value);
- }
-
- @Override
- public <T extends HelixProperty> boolean setProperty(PropertyKey key, T value)
- {
- String path = key.getPath();
- try
- {
- _readWriteLock.writeLock().lock();
- _store.setProperty(path, value.getRecord());
- return true;
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to set cluster property clusterName: " + _clusterName +
- " type:" + key.getType() +
- " keys:" + Arrays.toString(key.getParams()), e);
- return false;
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
- }
-
- @Override
- public <T extends HelixProperty> boolean updateProperty(PropertyKey key,
- T value)
- {
- PropertyType type = key.getType();
- String path = key.getPath();
-
- try
- {
- _readWriteLock.writeLock().lock();
-
- if (type.isUpdateOnlyOnExists())
- {
- updateIfExists(path, value.getRecord(), type.isMergeOnUpdate());
- }
- else
- {
- createOrUpdate(path, value.getRecord(), type.isMergeOnUpdate());
- }
- return true;
- }
- catch (PropertyStoreException e)
- {
- LOG.error("fail to update property. type:" +
- type + ", keys:" + Arrays.toString(key.getParams()), e);
- return false;
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
-
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends HelixProperty> T getProperty(PropertyKey key)
- {
- String path = key.getPath();
- try
- {
- _readWriteLock.readLock().lock();
- ZNRecord record = _store.getProperty(path);
- if (record == null)
- {
- return null;
- }
- return (T) HelixProperty.convertToTypedInstance(key.getTypeClass(), record);
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to get property. clusterName: " + _clusterName +
- " type:" + key.getType() +
- " keys:" + Arrays.toString(key.getParams()), e);
- return null;
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- }
- }
-
- @Override
- public boolean removeProperty(PropertyKey key)
- {
- String path = key.getPath();;
-
- try
- {
- _readWriteLock.writeLock().lock();
- _store.removeProperty(path);
- return true;
- }
- catch (PropertyStoreException e)
- {
- LOG.error("Fail to remove property. type:" +
- key.getType() + ", keys:" + Arrays.toString(key.getParams()), e);
- return false;
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
- }
-
- @Override
- public List<String> getChildNames(PropertyKey key)
- {
- String path = key.getPath();;
-
- try
- {
- _readWriteLock.readLock().lock();
-
- List<String> childs = _store.getPropertyNames(path);
- return childs;
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to get child names. clusterName: " + _clusterName +
- ", parentPath:" + path, e);
-
- return Collections.emptyList();
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends HelixProperty> List<T> getChildValues(PropertyKey key)
- {
- String path = key.getPath();
- List<T> records = new ArrayList<T>();
- try
- {
- _readWriteLock.readLock().lock();
-
- List<String> childs = _store.getPropertyNames(path);
- if (childs == null || childs.size() == 0)
- {
- return Collections.emptyList();
- }
-
- for (String child : childs)
- {
- ZNRecord record = _store.getProperty(child);
- if (record != null)
- {
- records.add((T) HelixProperty.convertToTypedInstance(key.getTypeClass(), record));
- }
- }
- }
- catch(PropertyStoreException e)
- {
- LOG.error("Fail to get child properties. clusterName:" + _clusterName +
- ", parentPath:" + path, e);
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- }
-
- return records;
- }
-
- @Override
- public <T extends HelixProperty> Map<String, T> getChildValuesMap(
- PropertyKey key)
- {
- List<T> list = getChildValues(key);
- return HelixProperty.convertListToMap(list);
- }
-
- @Override
- public Builder keyBuilder()
- {
- return _propertyKeyBuilder;
- }
-
- @Override
- public <T extends HelixProperty> boolean[] createChildren(
- List<PropertyKey> keys, List<T> children)
- {
- boolean[] success = new boolean[keys.size()];
- for (int i = 0; i < keys.size(); i++)
- {
- success[i] = createProperty(keys.get(i), children.get(i));
- }
- return success;
- }
-
- @Override
- public <T extends HelixProperty> boolean[] setChildren(
- List<PropertyKey> keys, List<T> children)
- {
- boolean[] success = new boolean[keys.size()];
- for (int i = 0; i < keys.size(); i++)
- {
- success[i] = setProperty(keys.get(i), children.get(i));
- }
- return success;
- }
-
- @Override
- public BaseDataAccessor getBaseDataAccessor()
- {
- throw new UnsupportedOperationException("No BaseDataAccessor for FileHelixDataAccessor");
- }
-
- // HACK remove it later
- public PropertyStore<ZNRecord> getStore()
- {
- return _store;
- }
-
- private void createOrUpdate(String path, final ZNRecord record, final boolean mergeOnUpdate)
- throws PropertyStoreException
- {
- final int RETRYLIMIT = 3;
- int retryCount = 0;
- while (retryCount < RETRYLIMIT)
- {
- try
- {
- if (_store.exists(path))
- {
- DataUpdater<ZNRecord> updater = new DataUpdater<ZNRecord>()
- {
- @Override
- public ZNRecord update(ZNRecord currentData)
- {
- if(mergeOnUpdate)
- {
- currentData.merge(record);
- return currentData;
- }
- return record;
- }
- };
- _store.updatePropertyUntilSucceed(path, updater);
-
- }
- else
- {
- if(record.getDeltaList().size() > 0)
- {
- ZNRecord newRecord = new ZNRecord(record.getId());
- newRecord.merge(record);
- _store.setProperty(path, newRecord);
- }
- else
- {
- _store.setProperty(path, record);
- }
- }
- break;
- }
- catch (Exception e)
- {
- retryCount = retryCount + 1;
- LOG.warn("Exception trying to update " + path + " Exception:"
- + e.getMessage() + ". Will retry.");
- }
- }
- }
-
- private void updateIfExists(String path, final ZNRecord record, boolean mergeOnUpdate)
- throws PropertyStoreException
- {
- if (_store.exists(path))
- {
- _store.setProperty(path, record);
- }
- }
-
- @Override
- public <T extends HelixProperty> boolean[] updateChildren(List<String> paths,
- List<DataUpdater<ZNRecord>> updaters, int options)
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends HelixProperty> List<T> getProperty(List<PropertyKey> keys)
- {
- List<T> list = new ArrayList<T>();
- for (PropertyKey key : keys)
- {
- list.add((T)getProperty(key));
- }
- return list;
- }
-
-}