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
[2/6] [HELIX-4] Removing file based implementation
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/manager/file/StaticFileHelixManager.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/StaticFileHelixManager.java b/helix-core/src/main/java/org/apache/helix/manager/file/StaticFileHelixManager.java
deleted file mode 100644
index d1ba707..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/file/StaticFileHelixManager.java
+++ /dev/null
@@ -1,574 +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.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.helix.ClusterMessagingService;
-import org.apache.helix.ClusterView;
-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.HelixManager;
-import org.apache.helix.HelixProperty;
-import org.apache.helix.IdealStateChangeListener;
-import org.apache.helix.InstanceType;
-import org.apache.helix.LiveInstanceChangeListener;
-import org.apache.helix.MessageListener;
-import org.apache.helix.NotificationContext;
-import org.apache.helix.PreConnectCallback;
-import org.apache.helix.PropertyType;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.healthcheck.ParticipantHealthReportCollector;
-import org.apache.helix.model.IdealState;
-import org.apache.helix.model.Message;
-import org.apache.helix.model.InstanceConfig.InstanceConfigProperty;
-import org.apache.helix.participant.StateMachineEngine;
-import org.apache.helix.participant.statemachine.StateModel;
-import org.apache.helix.participant.statemachine.StateModelFactory;
-import org.apache.helix.store.PropertyStore;
-import org.apache.helix.store.zk.ZkHelixPropertyStore;
-import org.apache.helix.tools.ClusterViewSerializer;
-import org.apache.helix.tools.IdealStateCalculatorByShuffling;
-import org.apache.log4j.Logger;
-
-
-@Deprecated
-public class StaticFileHelixManager implements HelixManager
-{
- private static final Logger LOG = Logger.getLogger(StaticFileHelixManager.class.getName());
- // for backward compatibility
- // TODO remove it later
- private final ClusterView _clusterView;
- private final String _clusterName;
- private final InstanceType _instanceType;
- private final String _instanceName;
- private boolean _isConnected;
- public static final String _sessionId = "12345";
- public static final String configFile = "configFile";
-
- public StaticFileHelixManager(String clusterName, String instanceName, InstanceType instanceType,
- String clusterViewFile)
- {
- _clusterName = clusterName;
- _instanceName = instanceName;
- _instanceType = instanceType;
- _clusterView = ClusterViewSerializer.deserialize(new File(clusterViewFile));
- }
-
- // FIXIT
- // reorder the messages to reduce the possibility that a S->M message for a
- // given
- // db partition gets executed before a O->S message
- private static void addMessageInOrder(List<ZNRecord> msgList, Message newMsg)
- {
- String toState = newMsg.getToState();
- if (toState.equals("MASTER"))
- {
- msgList.add(newMsg.getRecord());
- }
- if (toState.equals("SLAVE"))
- {
- msgList.add(0, newMsg.getRecord());
- }
- }
-
- private static List<Message> computeMessagesForSimpleTransition(ZNRecord idealStateRecord)
- {
- List<Message> msgList = new ArrayList<Message>();
-
- IdealState idealState = new IdealState(idealStateRecord);
- for (String stateUnitKey : idealState.getPartitionSet())
- {
- Map<String, String> instanceStateMap;
- instanceStateMap = idealState.getInstanceStateMap(stateUnitKey);
- }
-
- return msgList;
- }
-
- public static class DBParam
- {
- public String name;
- public int partitions;
-
- public DBParam(String n, int p)
- {
- name = n;
- partitions = p;
- }
- }
-
- public static ClusterView generateStaticConfigClusterView(String[] nodesInfo,
- List<DBParam> dbParams, int replica)
- {
- // create mock cluster view
- ClusterView view = new ClusterView();
-
- // add nodes
- List<ZNRecord> nodeConfigList = new ArrayList<ZNRecord>();
- List<String> instanceNames = new ArrayList<String>();
-
- Arrays.sort(nodesInfo, new Comparator<String>() {
-
- @Override
- public int compare(String str1, String str2)
- {
- return str1.compareTo(str2);
- }
-
- });
-
- // set CONFIGS
- for (String nodeInfo : nodesInfo)
- {
- int lastPos = nodeInfo.lastIndexOf(":");
- if (lastPos == -1)
- {
- throw new IllegalArgumentException("nodeInfo should be in format of host:port, " + nodeInfo);
- }
-
- String host = nodeInfo.substring(0, lastPos);
- String port = nodeInfo.substring(lastPos + 1);
- String nodeId = host + "_" + port;
- ZNRecord nodeConfig = new ZNRecord(nodeId);
-
- nodeConfig.setSimpleField(InstanceConfigProperty.HELIX_ENABLED.toString(),
- Boolean.toString(true));
- nodeConfig.setSimpleField(InstanceConfigProperty.HELIX_HOST.toString(), host);
- nodeConfig.setSimpleField(InstanceConfigProperty.HELIX_PORT.toString(), port);
-
- instanceNames.add(nodeId);
-
- nodeConfigList.add(nodeConfig);
- }
- view.setClusterPropertyList(PropertyType.CONFIGS, nodeConfigList);
-
- // set IDEALSTATES
- // compute ideal states for each db
- List<ZNRecord> idealStates = new ArrayList<ZNRecord>();
- for (DBParam dbParam : dbParams)
- {
- ZNRecord result = IdealStateCalculatorByShuffling.calculateIdealState(instanceNames,
- dbParam.partitions, replica, dbParam.name);
-
- idealStates.add(result);
- }
- view.setClusterPropertyList(PropertyType.IDEALSTATES, idealStates);
-
- // calculate messages for transition using naive algorithm
- Map<String, List<ZNRecord>> msgListForInstance = new HashMap<String, List<ZNRecord>>();
- List<ZNRecord> idealStatesArray = view.getPropertyList(PropertyType.IDEALSTATES);
- for (ZNRecord idealStateRecord : idealStatesArray)
- {
- // IdealState idealState = new IdealState(idealStateRecord);
-
- List<Message> messages = computeMessagesForSimpleTransition(idealStateRecord);
-
- for (Message message : messages)
- {
- // logger.info("Sending message to " + message.getTgtName() +
- // " transition "
- // + message.getStateUnitKey() + " from:" +
- // message.getFromState() +
- // " to:"
- // + message.getToState());
- // client.addMessage(message, message.getTgtName());
- String instance = message.getTgtName();
- List<ZNRecord> msgList = msgListForInstance.get(instance);
- if (msgList == null)
- {
- msgList = new ArrayList<ZNRecord>();
- msgListForInstance.put(instance, msgList);
- }
- // msgList.add(message);
- addMessageInOrder(msgList, message);
- }
- }
-
- // set INSTANCES
- // put message lists into cluster view
- List<ClusterView.MemberInstance> insList = new ArrayList<ClusterView.MemberInstance>();
- for (Map.Entry<String, List<ZNRecord>> entry : msgListForInstance.entrySet())
- {
- String instance = entry.getKey();
- List<ZNRecord> msgList = entry.getValue();
-
- ClusterView.MemberInstance ins = view.getMemberInstance(instance, true);
- ins.setInstanceProperty(PropertyType.MESSAGES, msgList);
- // ins.setInstanceProperty(InstancePropertyType.CURRENTSTATES,
- // null);
- // ins.setInstanceProperty(InstancePropertyType.ERRORS, null);
- // ins.setInstanceProperty(InstancePropertyType.STATUSUPDATES,
- // null);
- insList.add(ins);
- }
-
- // sort it
- ClusterView.MemberInstance[] insArray = new ClusterView.MemberInstance[insList.size()];
- insArray = insList.toArray(insArray);
- Arrays.sort(insArray, new Comparator<ClusterView.MemberInstance>() {
-
- @Override
- public int compare(ClusterView.MemberInstance ins1, ClusterView.MemberInstance ins2)
- {
- return ins1.getInstanceName().compareTo(ins2.getInstanceName());
- }
-
- });
-
- insList = Arrays.asList(insArray);
- view.setInstances(insList);
-
- return view;
- }
-
- @Override
- public void disconnect()
- {
- _isConnected = false;
- }
-
- @Override
- public void addIdealStateChangeListener(IdealStateChangeListener listener)
- {
-
- NotificationContext context = new NotificationContext(this);
- context.setType(NotificationContext.Type.INIT);
- List<ZNRecord> idealStates = _clusterView.getPropertyList(PropertyType.IDEALSTATES);
- listener.onIdealStateChange(
- HelixProperty.convertToTypedList(IdealState.class, idealStates), context);
- }
-
- @Override
- public void addLiveInstanceChangeListener(LiveInstanceChangeListener listener)
- {
- throw new UnsupportedOperationException(
- "addLiveInstanceChangeListener is not supported by File Based cluster manager");
- }
-
- @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)
- {
- NotificationContext context = new NotificationContext(this);
- context.setType(NotificationContext.Type.INIT);
- List<ZNRecord> messages;
- messages = _clusterView.getMemberInstance(instanceName, true).getInstanceProperty(
- PropertyType.MESSAGES);
- listener.onMessage(instanceName, HelixProperty.convertToTypedList(Message.class, messages),
- context);
- }
-
- @Override
- public void addCurrentStateChangeListener(CurrentStateChangeListener listener,
- String instanceName, String sessionId)
- {
- throw new UnsupportedOperationException(
- "addCurrentStateChangeListener is not supported by File Based cluster manager");
- }
-
- @Override
- public void addExternalViewChangeListener(ExternalViewChangeListener listener)
- {
- throw new UnsupportedOperationException(
- "addExternalViewChangeListener() is NOT supported by File Based cluster manager");
- }
-
- @Override
- public DataAccessor getDataAccessor()
- {
- return null;
- }
-
- @Override
- public String getClusterName()
- {
- return _clusterName;
- }
-
- @Override
- public String getInstanceName()
- {
- return _instanceName;
- }
-
- @Override
- public void connect()
- {
- _isConnected = true;
- }
-
- @Override
- public String getSessionId()
- {
- return _sessionId;
- }
-
- public static ClusterView convertStateModelMapToClusterView(String outFile, String instanceName,
- StateModelFactory<StateModel> stateModelFactory)
- {
- Map<String, StateModel> currentStateMap = stateModelFactory.getStateModelMap();
- ClusterView curView = new ClusterView();
-
- ClusterView.MemberInstance memberInstance = curView.getMemberInstance(instanceName, true);
- List<ZNRecord> curStateList = new ArrayList<ZNRecord>();
-
- for (Map.Entry<String, StateModel> entry : currentStateMap.entrySet())
- {
- String stateUnitKey = entry.getKey();
- String curState = entry.getValue().getCurrentState();
- ZNRecord record = new ZNRecord(stateUnitKey);
- record.setSimpleField(stateUnitKey, curState);
- curStateList.add(record);
- }
-
- memberInstance.setInstanceProperty(PropertyType.CURRENTSTATES, curStateList);
-
- // serialize to file
- // String outFile = "/tmp/curClusterView_" + instanceName +".json";
- if (outFile != null)
- {
- // ClusterViewSerializer serializer = new
- // ClusterViewSerializer(outFile);
- // serializer.serialize(curView);
- ClusterViewSerializer.serialize(curView, new File(outFile));
- }
-
- return curView;
- }
-
- public static boolean verifyFileBasedClusterStates(String instanceName, String expectedFile,
- String curFile)
- {
- boolean ret = true;
- ClusterView expectedView = ClusterViewSerializer.deserialize(new File(expectedFile));
- ClusterView curView = ClusterViewSerializer.deserialize(new File(curFile));
-
- // ideal_state for instance with the given instanceName
- Map<String, String> idealStates = new HashMap<String, String>();
- for (ZNRecord idealStateItem : expectedView.getPropertyList(PropertyType.IDEALSTATES))
- {
- Map<String, Map<String, String>> allIdealStates = idealStateItem.getMapFields();
-
- for (Map.Entry<String, Map<String, String>> entry : allIdealStates.entrySet())
- {
- if (entry.getValue().containsKey(instanceName))
- {
- String state = entry.getValue().get(instanceName);
- idealStates.put(entry.getKey(), state);
- }
- }
- }
-
- ClusterView.MemberInstance memberInstance = curView.getMemberInstance(instanceName, false);
- List<ZNRecord> curStateList = memberInstance.getInstanceProperty(PropertyType.CURRENTSTATES);
-
- if (curStateList == null && idealStates.size() > 0)
- {
- LOG.info("current state is null");
- return false;
- } else if (curStateList == null && idealStates.size() == 0)
- {
- LOG.info("empty current state and ideal state");
- return true;
- } else if (curStateList.size() != idealStates.size())
- {
- LOG.info("Number of current states (" + curStateList.size() + ") mismatch "
- + "number of ideal states (" + idealStates.size() + ")");
- return false;
- }
-
- for (ZNRecord record : curStateList)
- {
- String stateUnitKey = record.getId();
- String curState = record.getSimpleField(stateUnitKey);
-
- // if (!curState.equalsIgnoreCase("offline"))
- // nonOfflineNr++;
-
- if (!idealStates.containsKey(stateUnitKey))
- {
- LOG.error("Current state does not contain " + stateUnitKey);
- ret = false;
- continue;
- }
-
- String idealState = idealStates.get(stateUnitKey);
- if (!curState.equalsIgnoreCase(idealState))
- {
- LOG.error("State mismatch--unit_key:" + stateUnitKey + " cur:" + curState + " ideal:"
- + idealState + " instance_name:" + instanceName);
- ret = false;
- continue;
- }
-
- }
-
- return ret;
- }
-
- @Override
- public boolean isConnected()
- {
- return _isConnected;
- }
-
- @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;
- }
-
- @Override
- public HelixAdmin getClusterManagmentTool()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public PropertyStore<ZNRecord> getPropertyStore()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ClusterMessagingService getMessagingService()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @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()
- {
- throw new UnsupportedOperationException("getVersion() not implemented in StaticFileClusterManager");
- }
-
- @Override
- public StateMachineEngine getStateMachineEngine()
- {
- throw new UnsupportedOperationException("getStateMachineEngine() not implemented in StaticFileClusterManager");
- }
-
- @Override
- public boolean isLeader()
- {
- throw new UnsupportedOperationException("isLeader() not implemented in StaticFileClusterManager");
- }
-
- @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()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @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/package-info.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/file/package-info.java b/helix-core/src/main/java/org/apache/helix/manager/file/package-info.java
deleted file mode 100644
index c98b9f5..0000000
--- a/helix-core/src/main/java/org/apache/helix/manager/file/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/**
- * A file-based implementation of Helix cluster manager (Deprecated)
- *
- */
-package org.apache.helix.manager.file;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/store/PropertyStoreFactory.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/store/PropertyStoreFactory.java b/helix-core/src/main/java/org/apache/helix/store/PropertyStoreFactory.java
index 4add6e6..8a4d187 100644
--- a/helix-core/src/main/java/org/apache/helix/store/PropertyStoreFactory.java
+++ b/helix-core/src/main/java/org/apache/helix/store/PropertyStoreFactory.java
@@ -21,7 +21,6 @@ package org.apache.helix.store;
import org.apache.helix.manager.zk.ByteArraySerializer;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.store.file.FilePropertyStore;
import org.apache.helix.store.zk.ZKPropertyStore;
import org.apache.log4j.Logger;
@@ -47,21 +46,4 @@ public class PropertyStoreFactory
new ByteArraySerializer());
return new ZKPropertyStore<T>(zkClient, serializer, rootNamespace);
}
-
- public static <T extends Object> PropertyStore<T> getFilePropertyStore(PropertySerializer<T> serializer,
- String rootNamespace,
- PropertyJsonComparator<T> comparator)
- {
- if (comparator == null || serializer == null || rootNamespace == null)
- {
- throw new IllegalArgumentException("arguments can't be null");
- }
-
- LOG.info("Get a file property store. root: " + rootNamespace);
- FilePropertyStore<T> store =
- new FilePropertyStore<T>(serializer, rootNamespace, comparator);
- return store;
-
- }
-
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/store/file/FileHelixPropertyStore.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/store/file/FileHelixPropertyStore.java b/helix-core/src/main/java/org/apache/helix/store/file/FileHelixPropertyStore.java
deleted file mode 100644
index 8d10d1f..0000000
--- a/helix-core/src/main/java/org/apache/helix/store/file/FileHelixPropertyStore.java
+++ /dev/null
@@ -1,312 +0,0 @@
-package org.apache.helix.store.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 org.I0Itec.zkclient.DataUpdater;
-import org.I0Itec.zkclient.IZkChildListener;
-import org.I0Itec.zkclient.IZkDataListener;
-import org.apache.helix.store.HelixPropertyListener;
-import org.apache.helix.store.HelixPropertyStore;
-import org.apache.helix.store.PropertyChangeListener;
-import org.apache.helix.store.PropertyJsonComparator;
-import org.apache.helix.store.PropertySerializer;
-import org.apache.helix.store.PropertyStat;
-import org.apache.helix.store.PropertyStoreException;
-import org.apache.zookeeper.data.Stat;
-
-
-public class FileHelixPropertyStore<T> implements HelixPropertyStore<T>
-{
- final FilePropertyStore<T> _store;
-
- public FileHelixPropertyStore(final PropertySerializer<T> serializer,
- String rootNamespace,
- final PropertyJsonComparator<T> comparator)
- {
- _store = new FilePropertyStore<T>(serializer, rootNamespace, comparator);
- }
-
- @Override
- public boolean create(String path, T record, int options)
- {
- return set(path, record, options);
- }
-
- @Override
- public boolean set(String path, T record, int options)
- {
- try
- {
- _store.setProperty(path, record);
- return true;
- }
- catch (PropertyStoreException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return false;
- }
-
- @Override
- public boolean update(String path, DataUpdater<T> updater, int options)
- {
- _store.updatePropertyUntilSucceed(path, updater);
- return true;
- }
-
- @Override
- public boolean remove(String path, int options)
- {
- try
- {
- _store.removeProperty(path);
- return true;
- }
- catch (PropertyStoreException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return false;
- }
-
- @Override
- public boolean[] createChildren(List<String> paths, List<T> records, int options)
- {
- return setChildren(paths, records, options);
- }
-
- @Override
- public boolean[] setChildren(List<String> paths, List<T> records, int options)
- {
- boolean[] success = new boolean[paths.size()];
- for (int i = 0; i < paths.size(); i++)
- {
- success[i] = create(paths.get(i), records.get(i), options);
- }
- return success;
- }
-
- @Override
- public boolean[] updateChildren(List<String> paths,
- List<DataUpdater<T>> updaters,
- int options)
- {
- boolean[] success = new boolean[paths.size()];
- for (int i = 0; i < paths.size(); i++)
- {
- success[i] = update(paths.get(i), updaters.get(i), options);
- }
- return success;
-
- }
-
- @Override
- public boolean[] remove(List<String> paths, int options)
- {
- boolean[] success = new boolean[paths.size()];
- for (int i = 0; i < paths.size(); i++)
- {
- success[i] = remove(paths.get(i), options);
- }
- return success;
- }
-
- @Override
- public T get(String path, Stat stat, int options)
- {
- PropertyStat propertyStat = new PropertyStat();
- try
- {
- T value = _store.getProperty(path, propertyStat);
- if (stat != null)
- {
- stat.setVersion(propertyStat.getVersion());
- stat.setMtime(propertyStat.getLastModifiedTime());
- }
- return value;
- }
- catch (PropertyStoreException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- @Override
- public List<T> get(List<String> paths, List<Stat> stats, int options)
- {
- List<T> values = new ArrayList<T>();
- for (int i = 0; i < paths.size(); i++)
- {
- values.add(get(paths.get(i), stats.get(i), options));
- }
- return values;
- }
-
- @Override
- public List<T> getChildren(String parentPath, List<Stat> stats, int options)
- {
- List<String> childNames = getChildNames(parentPath, options);
-
- if (childNames == null)
- {
- return null;
- }
-
- List<String> paths = new ArrayList<String>();
- for (String childName : childNames)
- {
- String path = parentPath + "/" + childName;
- paths.add(path);
- }
-
- return get(paths, stats, options);
- }
-
- @Override
- public List<String> getChildNames(String parentPath, int options)
- {
- try
- {
- return _store.getPropertyNames(parentPath);
- }
- catch (PropertyStoreException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return Collections.emptyList();
- }
-
- @Override
- public boolean exists(String path, int options)
- {
- return _store.exists(path);
- }
-
- @Override
- public boolean[] exists(List<String> paths, int options)
- {
- boolean[] exists = new boolean[paths.size()];
- for (int i = 0; i < paths.size(); i++)
- {
- exists[i] = exists(paths.get(i), options);
- }
- return exists;
- }
-
- @Override
- public Stat[] getStats(List<String> paths, int options)
- {
- Stat[] stats = new Stat[paths.size()];
- for (int i = 0; i < paths.size(); i++)
- {
- stats[i] = getStat(paths.get(i), options);
- }
- return stats;
- }
-
- @Override
- public Stat getStat(String path, int options)
- {
- Stat stat = new Stat();
- get(path, stat, options);
- return stat;
- }
-
- @Override
- public void subscribeDataChanges(String path, IZkDataListener listener)
- {
- throw new UnsupportedOperationException("subscribeDataChanges not supported");
- }
-
- @Override
- public void unsubscribeDataChanges(String path, IZkDataListener listener)
- {
- throw new UnsupportedOperationException("unsubscribeDataChanges not supported");
- }
-
- @Override
- public List<String> subscribeChildChanges(String path, IZkChildListener listener)
- {
- throw new UnsupportedOperationException("subscribeChildChanges not supported");
- }
-
- @Override
- public void unsubscribeChildChanges(String path, IZkChildListener listener)
- {
- throw new UnsupportedOperationException("unsubscribeChildChanges not supported");
- }
-
- @Override
- public void start()
- {
- _store.start();
- }
-
- @Override
- public void stop()
- {
- _store.stop();
- }
-
- @Override
- public void subscribe(String parentPath, final HelixPropertyListener listener)
- {
- try
- {
- _store.subscribeForPropertyChange(parentPath, new PropertyChangeListener<T>()
- {
-
- @Override
- public void onPropertyChange(String key)
- {
- listener.onDataChange(key);
- }
- });
- }
- catch (PropertyStoreException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public void unsubscribe(String parentPath, HelixPropertyListener listener)
- {
- throw new UnsupportedOperationException("unsubscribe not supported");
- }
-
- @Override
- public void reset()
- {
- // TODO Auto-generated method stub
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/store/file/FilePropertyStore.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/store/file/FilePropertyStore.java b/helix-core/src/main/java/org/apache/helix/store/file/FilePropertyStore.java
deleted file mode 100644
index a59d1d3..0000000
--- a/helix-core/src/main/java/org/apache/helix/store/file/FilePropertyStore.java
+++ /dev/null
@@ -1,946 +0,0 @@
-package org.apache.helix.store.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.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import org.I0Itec.zkclient.DataUpdater;
-import org.apache.commons.io.DirectoryWalker;
-import org.apache.commons.io.FileUtils;
-import org.apache.helix.manager.file.FileCallbackHandler;
-import org.apache.helix.store.PropertyChangeListener;
-import org.apache.helix.store.PropertyJsonComparator;
-import org.apache.helix.store.PropertySerializer;
-import org.apache.helix.store.PropertyStat;
-import org.apache.helix.store.PropertyStore;
-import org.apache.helix.store.PropertyStoreException;
-import org.apache.log4j.Logger;
-
-
-/**
- *
- * property store that built upon a file system
- * since file systems usually have sophisticated cache mechanisms
- * there is no need for another cache for file property store
- *
- * NOTES:
- * lastModified timestamp provided by java file io has only second level precision
- * so it is possible that files have been modified without changing its lastModified timestamp
- * the solution is to use a map that caches the files changed in last second
- * and in the next round of refresh, check against this map to figure out whether a file
- * has been changed/created in the last second
- * @link http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6939260
- *
- * @author zzhang
- * @param <T>
- */
-
-public class FilePropertyStore<T> implements PropertyStore<T>
-{
- private static Logger logger = Logger.getLogger(FilePropertyStore.class);
-
- private final String ROOT = "/";
- private final long TIMEOUT = 30L;
- private final long REFRESH_PERIOD = 1000; // ms
- private final int _id = new Random().nextInt();
- private final String _rootNamespace;
- private PropertySerializer<T> _serializer;
- private final PropertyJsonComparator<T> _comparator;
-
- private Thread _refreshThread;
- private final AtomicBoolean _stopRefreshThread;
- private final CountDownLatch _firstRefreshCounter;
- private final ReadWriteLock _readWriteLock;
-
- private Map<String, T> _lastModifiedFiles = new HashMap<String, T>();
- private Map<String, T> _curModifiedFiles = new HashMap<String, T>();
-
- private final Map< String, CopyOnWriteArraySet<PropertyChangeListener<T> > > _fileChangeListeners; // map key to listener
-
- private class FilePropertyStoreRefreshThread implements Runnable
- {
- private final PropertyStoreDirWalker _dirWalker;
-
- public class PropertyStoreDirWalker extends DirectoryWalker
- {
- private final File _propertyStoreRootDir;
- private long _lastNotifiedTime = 0;
- private long _currentHighWatermark;
-
- public PropertyStoreDirWalker(String rootNamespace, ReadWriteLock readWriteLock)
- {
- _propertyStoreRootDir = new File(rootNamespace);
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- protected void handleFile(File file, int depth, Collection results) throws IOException
- {
- if (file.lastModified() < _lastNotifiedTime)
- {
- return;
- }
-
- String path = getRelativePath(file.getAbsolutePath());
- T newValue = null;
- try
- {
- newValue = getProperty(path);
- } catch (PropertyStoreException e)
- {
- logger.error("fail to get property, path:" + path, e);
- }
-
- if (file.lastModified() == _lastNotifiedTime && _lastModifiedFiles.containsKey(path))
- {
- T value = _lastModifiedFiles.get(path);
-
- if (_comparator.compare(value, newValue) == 0)
- {
- if (file.lastModified() == _currentHighWatermark)
- {
- _curModifiedFiles.put(path, newValue);
- }
- return;
- }
- }
-
- if (file.lastModified() > _currentHighWatermark)
- {
- _currentHighWatermark = file.lastModified();
-
- _curModifiedFiles.clear();
- _curModifiedFiles.put(path, newValue);
- }
- else if (file.lastModified() == _currentHighWatermark)
- {
- _curModifiedFiles.put(path, newValue);
- }
-
- // debug
-// logger.error("file: " + file.getAbsolutePath() + " changed@" + file.lastModified() + " (" +
-// new Date(file.lastModified()) + ")");
- results.add(file);
- }
-
- @Override
- protected boolean handleDirectory(File dir, int depth, Collection results) throws IOException
- {
- if (dir.lastModified() < _lastNotifiedTime)
- {
- return true;
- }
-
- String path = getRelativePath(dir.getAbsolutePath());
- T newValue = null;
- try
- {
- newValue = getProperty(path);
- }
- catch (PropertyStoreException e)
- {
- logger.error("fail to get property, path:" + path, e);
- }
-
- if (dir.lastModified() == _lastNotifiedTime && _lastModifiedFiles.containsKey(path))
- {
- T value = _lastModifiedFiles.get(path);
- if (_comparator.compare(value, newValue) == 0)
- {
- if (dir.lastModified() == _currentHighWatermark)
- {
- _curModifiedFiles.put(path, newValue);
- }
- return true;
- }
- }
- _curModifiedFiles.put(path, newValue);
-
- if (dir.lastModified() > _currentHighWatermark)
- {
- _currentHighWatermark = dir.lastModified();
-
- _curModifiedFiles.clear();
- _curModifiedFiles.put(path, newValue);
- }
- else if (dir.lastModified() == _currentHighWatermark)
- {
- _curModifiedFiles.put(path, newValue);
- }
-
- logger.debug("dir: " + dir.getAbsolutePath() + " changed@" + dir.lastModified() +
- " (" + new Date(dir.lastModified()) + ")");
- results.add(dir);
-
- return true;
- }
-
- public void walk()
- {
- HashSet<File> files = new HashSet<File>();
-
- try
- {
- _currentHighWatermark = _lastNotifiedTime;
- _readWriteLock.readLock().lock();
- super.walk(_propertyStoreRootDir, files);
- }
- catch (IOException e)
- {
- logger.error("IO exception when walking through dir:" + _propertyStoreRootDir, e);
- }
- finally
- {
- _lastNotifiedTime = _currentHighWatermark;
- _lastModifiedFiles.clear();
-
- Map<String, T> temp = _lastModifiedFiles;
- _lastModifiedFiles = _curModifiedFiles;
- _curModifiedFiles = temp;
- _readWriteLock.readLock().unlock();
- }
-
- // TODO see if we can use DirectoryFileComparator.DIRECTORY_COMPARATOR.sort()
- File[] fileArray = new File[files.size()];
- fileArray = files.toArray(fileArray);
- Arrays.sort(fileArray, new Comparator<File>() {
-
- @Override
- public int compare(File file1, File file2)
- {
- return file1.getAbsoluteFile().compareTo(file2.getAbsoluteFile());
- }
-
- });
-
-
- // notify listeners
- for (int i = 0; i < fileArray.length; i++)
- {
- File file = fileArray[i];
-
- // debug
-// logger.error("Before send notification of " + file.getAbsolutePath() + " to listeners " + _fileChangeListeners);
-
- for (Map.Entry< String, CopyOnWriteArraySet<PropertyChangeListener<T> > > entry : _fileChangeListeners.entrySet())
- {
- String absPath = file.getAbsolutePath();
- if (absPath.startsWith(entry.getKey()))
- {
- for (PropertyChangeListener<T> listener : entry.getValue())
- {
- if (listener instanceof FileCallbackHandler)
- {
- FileCallbackHandler handler = (FileCallbackHandler) listener;
-
- // debug
-// logger.error("Send notification of " + file.getAbsolutePath() + " to listener:" + handler.getListener());
- }
- listener.onPropertyChange(getRelativePath(absPath));
- }
- }
- }
- }
- }
- }
-
- public FilePropertyStoreRefreshThread(ReadWriteLock readWriteLock)
- {
- _dirWalker = new PropertyStoreDirWalker(_rootNamespace, readWriteLock);
- }
-
- @Override
- public void run()
- {
- while (!_stopRefreshThread.get())
- {
- _dirWalker.walk();
- _firstRefreshCounter.countDown();
-
- try
- {
- Thread.sleep(REFRESH_PERIOD);
-// System.out.println("refresh thread is running");
- }
- catch (InterruptedException ie)
- {
- // do nothing
- }
- }
-
- logger.info("Quitting file property store refresh thread");
-
- }
-
- }
-
-// public FilePropertyStore(final PropertySerializer<T> serializer)
-// {
-// this(serializer, System.getProperty("java.io.tmpdir"));
-// }
-
- public FilePropertyStore(final PropertySerializer<T> serializer, String rootNamespace,
- final PropertyJsonComparator<T> comparator)
- {
- _serializer = serializer;
- _comparator = comparator;
- _stopRefreshThread = new AtomicBoolean(false);
- _firstRefreshCounter = new CountDownLatch(1);
- _readWriteLock = new ReentrantReadWriteLock();
-
- _fileChangeListeners = new ConcurrentHashMap< String, CopyOnWriteArraySet<PropertyChangeListener<T> > >();
-
- // Strip off leading slash
- while (rootNamespace.startsWith("/"))
- {
- // rootNamespace = rootNamespace.substring(1, rootNamespace.length());
- rootNamespace = rootNamespace.substring(1);
- }
- _rootNamespace = "/" + rootNamespace;
-
- this.createRootNamespace();
- }
-
-
- @Override
- public boolean start()
- {
- // check if start has already been invoked
- if (_firstRefreshCounter.getCount() == 0)
- return true;
-
- logger.debug("starting file property store polling thread, id=" + _id);
-
- _stopRefreshThread.set(false);
- _refreshThread = new Thread(new FilePropertyStoreRefreshThread(_readWriteLock),
- "FileRefreshThread_" + _id);
- // _refreshThread.setDaemon(true);
- _refreshThread.start();
-
- try
- {
- boolean timeout = !_firstRefreshCounter.await(TIMEOUT, TimeUnit.SECONDS);
- if (timeout)
- {
- throw new Exception("Timeout while waiting for the first refresh to complete");
- }
- }
- catch (InterruptedException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
-
- return true;
- }
-
- @Override
- public boolean stop()
- {
- if (_stopRefreshThread.compareAndSet(false, true))
- {
- // _stopRefreshThread.set(true);
- if (_refreshThread != null)
- {
- try
- {
- _refreshThread.join();
- }
- catch (InterruptedException e)
- {
- }
- }
- }
- return true;
- }
-
- private String getPath(String key)
- {
- // Strip off leading slash
- while (key.startsWith("/"))
- {
- // key = key.substring(1, key.length());
- key = key.substring(1);
- }
-
- // String path = key.equals(ROOT) ? _rootNamespace : (_rootNamespace + "/" + key);
- String path = key.equals("") ? _rootNamespace : (_rootNamespace + "/" + key);
- return path;
- }
-
- private String getRelativePath(String path)
- {
- // strip off rootPath from path
- if (!path.startsWith(_rootNamespace))
- {
- logger.warn("path does NOT start with: " + _rootNamespace);
- return path;
- }
-
- if (path.equals(_rootNamespace))
- return ROOT;
-
- // path = path.substring(_rootNamespace.length() + 1);
- path = path.substring(_rootNamespace.length());
-
- return path;
- }
-
- public void createRootNamespace()
- {
- createPropertyNamespace(ROOT);
- }
-
- @Override
- public void createPropertyNamespace(String prefix)
- {
- String path = getPath(prefix);
- File dir = new File(path);
- try
- {
- _readWriteLock.writeLock().lock();
- if (dir.exists())
- {
- logger.warn(path + " already exists");
- }
- else
- {
- if (!dir.mkdirs())
- {
- logger.warn("Failed to create: " + path);
- }
- }
- }
- catch (Exception e)
- {
- logger.error("Failed to create dir: " + path + "\nexception:" + e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
-
- }
-
- @Override
- public void setProperty(String key, T value) throws PropertyStoreException
- {
- String path = getPath(key);
- File file = new File(path); // null;
- // FileLock fLock = null;
- FileOutputStream fout = null;
-
- // TODO create non-exist dirs recursively
- try
- {
- _readWriteLock.writeLock().lock();
- // file = new File(path);
- if (!file.exists())
- {
- FileUtils.touch(file);
- }
-
- fout = new FileOutputStream(file);
- // FileChannel fChannel = fout.getChannel();
-
- // TODO need a timeout on lock operation
- // fLock = fChannel.lock();
-
- byte[] bytes = _serializer.serialize(value);
- fout.write(bytes);
- }
-// catch (FileNotFoundException e)
-// {
-// logger.error("fail to set property, key:" + key +
-// "\nfile not found exception:" + e);
-// }
- catch (IOException e)
- {
- logger.error("fail to set property. key:" + key +
- "value:" + value, e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- try
- {
- // if (fLock != null && fLock.isValid())
- // fLock.release();
-
- if (fout != null)
- {
- fout.close();
- }
- }
- catch (IOException e)
- {
- logger.error("fail to close file. key:" + key, e);
- }
-
- }
-
- }
-
- @Override
- public T getProperty(String key) throws PropertyStoreException
- {
- return this.getProperty(key, null);
- }
-
- @Override
- public T getProperty(String key, PropertyStat propertyStat) throws PropertyStoreException
- {
-
- String path = getPath(key);
- File file = null;
- // FileLock fLock = null;
- FileInputStream fin = null;
-
- try
- {
- // TODO need a timeout on lock operation
- _readWriteLock.readLock().lock();
-
- file = new File(path);
- if (!file.exists())
- {
- return null;
- }
-
- fin = new FileInputStream(file);
- // FileChannel fChannel = fin.getChannel();
- // fLock = fChannel.lock(0L, Long.MAX_VALUE, true);
-
- int availableBytes = fin.available();
- if (availableBytes == 0)
- {
- return null;
- }
-
- byte[] bytes = new byte[availableBytes];
- fin.read(bytes);
-
- if (propertyStat != null)
- {
- propertyStat.setLastModifiedTime(file.lastModified());
- }
-
- return _serializer.deserialize(bytes);
- }
- catch (FileNotFoundException e)
- {
- return null;
- }
- catch (IOException e)
- {
- logger.error("fail to get property. key:" + key, e);
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- try
- {
- // if (fLock != null && fLock.isValid())
- // fLock.release();
- if (fin != null)
- {
- fin.close();
- }
- }
- catch (IOException e)
- {
- logger.error("fail to close file. key:" + key, e);
- }
-
- }
-
- return null;
- }
-
- @Override
- public void removeProperty(String key) throws PropertyStoreException
- {
- String path = getPath(key);
- File file = new File(path);
-
- try
- {
- _readWriteLock.writeLock().lock();
- if (!file.exists())
- {
- return;
- }
-
- boolean success = file.delete();
- if (!success)
- {
- logger.error("fail to remove file. path:" + path);
- }
- }
- catch (Exception e)
- {
- logger.error("fail to remove file. path:" + path, e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
-
-
- }
-
- public void removeRootNamespace() throws PropertyStoreException
- {
- removeNamespace(ROOT);
- }
-
- @Override
- public void removeNamespace(String prefix) throws PropertyStoreException
- {
- String path = getPath(prefix);
-
- try
- {
- _readWriteLock.writeLock().lock();
- FileUtils.deleteDirectory(new File(path));
- }
- catch (IOException e)
- {
- logger.error("fail to remove namespace, path:" + path, e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- }
- }
-
- private void doGetPropertyNames(String path, List<String> leafNodes)
- throws PropertyStoreException
- {
- File file = new File(path);
- if (!file.exists())
- {
- return;
- }
-
- // List<String> childs = _zkClient.getChildren(path);
- if (file.isDirectory())
- {
- String[] childs = file.list();
- if (childs == null || childs.length == 0)
- {
- return;
- }
- for (String child : childs)
- {
- String pathToChild = path + "/" + child;
- doGetPropertyNames(pathToChild, leafNodes);
- }
- }
- else if (file.isFile())
- {
- // getProperty(getRelativePath(path));
- leafNodes.add(getRelativePath(path));
- return;
- }
- }
-
-
- @Override
- public List<String> getPropertyNames(String prefix) throws PropertyStoreException
- {
- String path = getPath(prefix);
- List<String> propertyNames = new ArrayList<String>();
-
- try
- {
- _readWriteLock.readLock().lock();
- doGetPropertyNames(path, propertyNames);
- }
- finally
- {
- _readWriteLock.readLock().unlock();
- }
-
- // sort it to get deterministic order
- Collections.sort(propertyNames);
-
- return propertyNames;
- }
-
- @Override
- public void setPropertyDelimiter(String delimiter) throws PropertyStoreException
- {
- throw new UnsupportedOperationException(
- "setPropertyDelimiter() is NOT supported by FilePropertyStore");
- }
-
- @Override
- public void subscribeForPropertyChange(String prefix, PropertyChangeListener<T> listener)
- throws PropertyStoreException
- {
- if (null != listener)
- {
- String path = getPath(prefix);
- synchronized (_fileChangeListeners)
- {
- CopyOnWriteArraySet<PropertyChangeListener <T> > listeners = _fileChangeListeners.get(path);
- if (listeners == null) {
- listeners = new CopyOnWriteArraySet<PropertyChangeListener <T> >();
- _fileChangeListeners.put(path, listeners);
- }
- listeners.add(listener);
- }
- }
-
- }
-
- @Override
- public void unsubscribeForPropertyChange(String prefix, PropertyChangeListener<T> listener)
- throws PropertyStoreException
- {
- if (null != listener)
- {
- String path = getPath(prefix);
- synchronized (_fileChangeListeners)
- {
- final Set<PropertyChangeListener<T> > listeners = _fileChangeListeners.get(path);
- if (listeners != null)
- {
- listeners.remove(listener);
- }
- if (listeners == null || listeners.isEmpty())
- {
- _fileChangeListeners.remove(path);
- }
- }
- }
-
- }
-
- @Override
- public boolean canParentStoreData()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public String getPropertyRootNamespace()
- {
- return _rootNamespace;
- }
-
- @Override
- public void updatePropertyUntilSucceed(String key, DataUpdater<T> updater)
- {
- updatePropertyUntilSucceed(key, updater, true);
- }
-
- @Override
- public void updatePropertyUntilSucceed(String key, DataUpdater<T> updater,
- boolean createIfAbsent)
- {
- String path = getPath(key);
- File file = new File(path);
- RandomAccessFile raFile = null;
- FileLock fLock = null;
-
- try
- {
- _readWriteLock.writeLock().lock();
- if (!file.exists())
- {
- FileUtils.touch(file);
- }
-
- raFile = new RandomAccessFile(file, "rw");
- FileChannel fChannel = raFile.getChannel();
- fLock = fChannel.lock();
-
- T current = getProperty(key);
- T update = updater.update(current);
- setProperty(key, update);
- }
- catch (Exception e)
- {
- logger.error("fail to updatePropertyUntilSucceed, path:" + path, e);
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- try
- {
- if (fLock != null && fLock.isValid())
- {
- fLock.release();
- }
-
- if (raFile != null)
- {
- raFile.close();
- }
- }
- catch (IOException e)
- {
- logger.error("fail to close file, path:" + path, e);
- }
- }
- }
-
-
- @Override
- public void setPropertySerializer(PropertySerializer<T> serializer)
- {
- _readWriteLock.writeLock().lock();
- _serializer = serializer;
- _readWriteLock.writeLock().unlock();
- }
-
- @Override
- public boolean compareAndSet(String key, T expected, T update, Comparator<T> comparator)
- {
- return compareAndSet(key, expected, update, comparator, false);
- }
-
- @Override
- public boolean compareAndSet(String key, T expected, T update, Comparator<T> comparator,
- boolean createIfAbsent)
- {
- String path = getPath(key);
- File file = new File(path);
-// FileInputStream fin = null;
-// FileOutputStream fout = null;
- RandomAccessFile raFile = null;
- FileLock fLock = null;
-
- try
- {
- _readWriteLock.writeLock().lock();
-
- if (createIfAbsent)
- {
- file.createNewFile();
- }
-
-// fin = new FileInputStream(file);
-// FileChannel fChannel = fin.getChannel();
- raFile = new RandomAccessFile(file, "rw");
- FileChannel fChannel = raFile.getChannel();
- fLock = fChannel.lock();
-
- T current = getProperty(key);
- if (comparator.compare(current, expected) == 0)
- {
-// fout = new FileOutputStream(file);
-//
-// byte[] bytes = _serializer.serialize(update);
-// fout.write(bytes);
- setProperty(key, update);
- return true;
- }
-
- return false;
- }
- catch (FileNotFoundException e)
- {
- logger.error("fail to compareAndSet. path:" + path, e);
- return false;
- }
- catch (Exception e)
- {
- logger.error("fail to compareAndSet. path:" + path, e);
- return false;
- }
- finally
- {
- _readWriteLock.writeLock().unlock();
- try
- {
- if (fLock != null && fLock.isValid())
- {
- fLock.release();
- }
-
- if (raFile != null)
- {
- raFile.close();
- }
-
-// if (fin != null)
-// {
-// fin.close();
-// }
-//
-// if (fout != null)
-// {
-// fout.close();
-// }
- }
- catch (IOException e)
- {
- logger.error("fail to close file. path:" + path, e);
- }
- }
-
- }
-
- @Override
- public boolean exists(String key)
- {
- String path = getPath(key);
- File file = new File(path);
- _readWriteLock.readLock().lock();
-
- boolean ret = file.exists();
- _readWriteLock.readLock().unlock();
- return ret;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/store/file/package-info.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/store/file/package-info.java b/helix-core/src/main/java/org/apache/helix/store/file/package-info.java
deleted file mode 100644
index d69a496..0000000
--- a/helix-core/src/main/java/org/apache/helix/store/file/package-info.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/**
- * Helix implementation of file-based property store (Deprecated)
- *
- */
-package org.apache.helix.store.file;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java b/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
index 323b9b2..4b39292 100644
--- a/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
+++ b/helix-core/src/main/java/org/apache/helix/tools/ClusterStateVerifier.java
@@ -39,7 +39,6 @@ import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
-import org.apache.helix.ClusterView;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.PropertyPathConfig;
import org.apache.helix.PropertyType;
@@ -54,7 +53,6 @@ import org.apache.helix.controller.stages.ClusterDataCache;
import org.apache.helix.controller.stages.ClusterEvent;
import org.apache.helix.controller.stages.CurrentStateComputationStage;
import org.apache.helix.controller.stages.ResourceComputationStage;
-import org.apache.helix.manager.file.FileHelixDataAccessor;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
@@ -65,7 +63,6 @@ import org.apache.helix.participant.statemachine.StateModel;
import org.apache.helix.participant.statemachine.StateModelFactory;
import org.apache.helix.store.PropertyJsonComparator;
import org.apache.helix.store.PropertyJsonSerializer;
-import org.apache.helix.store.file.FilePropertyStore;
import org.apache.helix.util.ZKClientPool;
import org.apache.log4j.Logger;
@@ -212,65 +209,6 @@ public class ClusterStateVerifier
}
}
- public static class BestPossAndExtViewFileVerifier implements Verifier
- {
- private final String rootPath;
- private final String clusterName;
- private final Map<String, Map<String, String>> errStates;
- private final FilePropertyStore<ZNRecord> fileStore;
-
- public BestPossAndExtViewFileVerifier(String rootPath, String clusterName)
- {
- this(rootPath, clusterName, null);
- }
-
- public BestPossAndExtViewFileVerifier(String rootPath,
- String clusterName,
- Map<String, Map<String, String>> errStates)
- {
- if (rootPath == null || clusterName == null)
- {
- throw new IllegalArgumentException("requires rootPath|clusterName");
- }
- this.rootPath = rootPath;
- this.clusterName = clusterName;
- this.errStates = errStates;
-
- this.fileStore =
- new FilePropertyStore<ZNRecord>(new PropertyJsonSerializer<ZNRecord>(ZNRecord.class),
- rootPath,
- new PropertyJsonComparator<ZNRecord>(ZNRecord.class));
- }
-
- @Override
- public boolean verify()
- {
- try
- {
- HelixDataAccessor accessor = new FileHelixDataAccessor(fileStore, clusterName);
-
- return ClusterStateVerifier.verifyBestPossAndExtView(accessor, errStates);
- }
- catch (Exception e)
- {
- LOG.error("exception in verification", e);
- return false;
- }
- finally
- {
- }
- }
-
- @Override
- public String toString()
- {
- String verifierName = getClass().getName();
- verifierName =
- verifierName.substring(verifierName.lastIndexOf('.') + 1, verifierName.length());
- return verifierName + "(" + rootPath + "@" + clusterName + ")";
- }
- }
-
public static class MasterNbInExtViewVerifier implements ZkVerifier
{
private final String zkAddr;
@@ -706,78 +644,6 @@ public class ClusterStateVerifier
return result;
}
- public static boolean verifyFileBasedClusterStates(String file,
- String instanceName,
- StateModelFactory<StateModel> stateModelFactory)
- {
- ClusterView clusterView = ClusterViewSerializer.deserialize(new File(file));
- boolean ret = true;
- int nonOfflineStateNr = 0;
-
- // ideal_state for instance with name $instanceName
- Map<String, String> instanceIdealStates = new HashMap<String, String>();
- for (ZNRecord idealStateItem : clusterView.getPropertyList(PropertyType.IDEALSTATES))
- {
- Map<String, Map<String, String>> idealStates = idealStateItem.getMapFields();
-
- for (Map.Entry<String, Map<String, String>> entry : idealStates.entrySet())
- {
- if (entry.getValue().containsKey(instanceName))
- {
- String state = entry.getValue().get(instanceName);
- instanceIdealStates.put(entry.getKey(), state);
- }
- }
- }
-
- Map<String, StateModel> currentStateMap = stateModelFactory.getStateModelMap();
-
- if (currentStateMap.size() != instanceIdealStates.size())
- {
- LOG.warn("Number of current states (" + currentStateMap.size() + ") mismatch "
- + "number of ideal states (" + instanceIdealStates.size() + ")");
- return false;
- }
-
- for (Map.Entry<String, String> entry : instanceIdealStates.entrySet())
- {
-
- String stateUnitKey = entry.getKey();
- String idealState = entry.getValue();
-
- if (!idealState.equalsIgnoreCase("offline"))
- {
- nonOfflineStateNr++;
- }
-
- if (!currentStateMap.containsKey(stateUnitKey))
- {
- LOG.warn("Current state does not contain " + stateUnitKey);
- // return false;
- ret = false;
- continue;
- }
-
- String curState = currentStateMap.get(stateUnitKey).getCurrentState();
- if (!idealState.equalsIgnoreCase(curState))
- {
- LOG.info("State mismatch--unit_key:" + stateUnitKey + " cur:" + curState
- + " ideal:" + idealState + " instance_name:" + instanceName);
- // return false;
- ret = false;
- continue;
- }
- }
-
- if (ret == true)
- {
- System.out.println(instanceName + ": verification succeed");
- LOG.info(instanceName + ": verification succeed (" + nonOfflineStateNr + " states)");
- }
-
- return ret;
- }
-
@SuppressWarnings("static-access")
private static Options constructCommandLineOptions()
{
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/java/org/apache/helix/tools/ClusterViewSerializer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/tools/ClusterViewSerializer.java b/helix-core/src/main/java/org/apache/helix/tools/ClusterViewSerializer.java
deleted file mode 100644
index 81e142f..0000000
--- a/helix-core/src/main/java/org/apache/helix/tools/ClusterViewSerializer.java
+++ /dev/null
@@ -1,181 +0,0 @@
-package org.apache.helix.tools;
-
-/*
- * 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.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.helix.ClusterView;
-import org.apache.helix.manager.file.StaticFileHelixManager;
-import org.apache.log4j.Logger;
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.map.DeserializationConfig;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.SerializationConfig;
-
-
-public class ClusterViewSerializer
-{
- private static Logger logger = Logger.getLogger(ClusterViewSerializer.class);
-
- public static void serialize(ClusterView view, File file)
- {
- ObjectMapper mapper = new ObjectMapper();
-
- SerializationConfig serializationConfig = mapper.getSerializationConfig();
- serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
- serializationConfig.set(SerializationConfig.Feature.AUTO_DETECT_GETTERS, true);
- serializationConfig.set(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
- serializationConfig.set(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
- // serializationConfig.set(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, true);
-
- try
- {
- mapper.writeValue(file, view);
- }
- catch (Exception e)
- {
- logger.error("Error during serialization of data:" + view, e);
- }
- }
-
- public static byte[] serialize(ClusterView view)
- {
- ObjectMapper mapper = new ObjectMapper();
-
- SerializationConfig serializationConfig = mapper.getSerializationConfig();
- serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
- serializationConfig.set(SerializationConfig.Feature.AUTO_DETECT_GETTERS, true);
- serializationConfig.set(SerializationConfig.Feature.AUTO_DETECT_FIELDS, true);
- serializationConfig.set(SerializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
- // serializationConfig.set(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, true);
-
- StringWriter sw = new StringWriter();
-
- try
- {
- mapper.writeValue(sw, view);
- return sw.toString().getBytes();
- }
- catch (Exception e)
- {
- logger.error("Error during serialization of data:" + view, e);
- }
-
- return new byte[0];
- }
-
- public static ClusterView deserialize(File file)
- {
- if (!file.exists())
- {
- logger.error(String.format("Static config file \"%s\" doesn't exist", file.getAbsolutePath()));
- return null;
- }
-
- ObjectMapper mapper = new ObjectMapper();
-
- DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
- deserializationConfig.set(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, true);
- deserializationConfig.set(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, true);
- // deserializationConfig.set(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
- deserializationConfig.set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true);
-
- try
- {
- ClusterView view = mapper.readValue(file, ClusterView.class);
- return view;
- }
- catch (Exception e)
- {
- logger.error("Error during deserialization of file:" + file.getAbsolutePath(), e);
- }
-
- return null;
- }
-
-
- public static ClusterView deserialize(byte[] bytes)
- {
- ObjectMapper mapper = new ObjectMapper();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-
- DeserializationConfig deserializationConfig = mapper.getDeserializationConfig();
- deserializationConfig.set(DeserializationConfig.Feature.AUTO_DETECT_FIELDS, true);
- deserializationConfig.set(DeserializationConfig.Feature.AUTO_DETECT_SETTERS, true);
- // deserializationConfig.set(DeserializationConfig.Feature.CAN_OVERRIDE_ACCESS_MODIFIERS, true);
- deserializationConfig.set(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, true);
-
- try
- {
- ClusterView view = mapper.readValue(bais, ClusterView.class);
- return view;
- }
- catch (Exception e)
- {
- logger.error("Error during deserialization of bytes:" + new String(bytes), e);
- }
-
- return null;
- }
-
- public static void main(String[] args) throws JsonGenerationException,
- JsonMappingException, IOException
- {
- // temporary test only
- // create fake db names and nodes
- List<StaticFileHelixManager.DBParam> dbParams = new ArrayList<StaticFileHelixManager.DBParam>();
- // dbParams.add(new FileBasedClusterManager.DBParam("BizFollow", 1));
- dbParams.add(new StaticFileHelixManager.DBParam("BizProfile_qatest218a", 128));
- // dbParams.add(new FileBasedClusterManager.DBParam("EspressoDB", 10));
- // dbParams.add(new FileBasedClusterManager.DBParam("MailboxDB", 128));
- // dbParams.add(new FileBasedClusterManager.DBParam("MyDB", 8));
- // dbParams.add(new FileBasedClusterManager.DBParam("schemata", 1));
- String[] nodesInfo = { "localhost:8900", "localhost:8901",
- "localhost:8902", "localhost:8903",
- "localhost:8904" };
- // String[] nodesInfo = { "esv4-app75.stg.linkedin.com:12918" };
- int replica = 0;
-
- ClusterView view = StaticFileHelixManager.generateStaticConfigClusterView(nodesInfo, dbParams, replica);
- String file = "/tmp/cluster-view-bizprofile.json";
- // ClusterViewSerializer serializer = new ClusterViewSerializer(file);
-
- byte[] bytes = ClusterViewSerializer.serialize(view);
- // logger.info("serialized bytes=" );
- // logger.info(new String(bytes));
- System.out.println("serialized bytes=");
- System.out.println(new String(bytes));
-
- ClusterView restoredView = ClusterViewSerializer.deserialize(bytes);
- // logger.info(restoredView);
-
- bytes = ClusterViewSerializer.serialize(restoredView);
- // logger.info(new String(bytes));
- System.out.println("restored cluster view=");
- System.out.println(new String(bytes));
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/main/scripts/integration-test/script/driver_cmd_dict.py
----------------------------------------------------------------------
diff --git a/helix-core/src/main/scripts/integration-test/script/driver_cmd_dict.py b/helix-core/src/main/scripts/integration-test/script/driver_cmd_dict.py
index 40d9d5c..41e7a0c 100644
--- a/helix-core/src/main/scripts/integration-test/script/driver_cmd_dict.py
+++ b/helix-core/src/main/scripts/integration-test/script/driver_cmd_dict.py
@@ -171,7 +171,7 @@ cmd_direct_call={
,"IVY_DIR/org/apache/commons/commons-math/2.1/commons-math-2.1.jar"
]+cm_jar_files
- ,"class_name":"org.apache.helix.mock.storage.DummyProcess"
+ ,"class_name":"org.apache.helix.mock.participant.DummyProcess"
,"before_cmd":"../../../mvn package -Dmaven.test.skip.exec=true" # build jar first
}
@@ -194,7 +194,7 @@ cmd_direct_call={
,"IVY_DIR/com/noelios/restlet/com.noelios.restlet/1.1.10/com.noelios.restlet-1.1.10.jar"
]+cm_jar_files
- ,"class_name":"org.apache.helix.mock.storage.MockHealthReportParticipant"
+ ,"class_name":"org.apache.helix.mock.participant.MockHealthReportParticipant"
,"before_cmd":"../../../mvn package -Dmaven.test.skip.exec=true" # build jar first
}
@@ -249,7 +249,7 @@ cmd_direct_call={
,"IVY_DIR/commons-cli/commons-cli/1.2/commons-cli-1.2.jar"
,"IVY_DIR/commons-math/commons-math/2.1/commons-math-2.1.jar"
]+cm_jar_files
- ,"class_name":"org.apache.helix.mock.storage.MockStorageProcess"
+ ,"class_name":"org.apache.helix.mock.participant.MockStorageProcess"
}
}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/DummyProcessThread.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/DummyProcessThread.java b/helix-core/src/test/java/org/apache/helix/DummyProcessThread.java
index 822de46..df22ff1 100644
--- a/helix-core/src/test/java/org/apache/helix/DummyProcessThread.java
+++ b/helix-core/src/test/java/org/apache/helix/DummyProcessThread.java
@@ -19,9 +19,9 @@ package org.apache.helix;
* under the License.
*/
-import org.apache.helix.mock.storage.DummyProcess.DummyLeaderStandbyStateModelFactory;
-import org.apache.helix.mock.storage.DummyProcess.DummyOnlineOfflineStateModelFactory;
-import org.apache.helix.mock.storage.DummyProcess.DummyStateModelFactory;
+import org.apache.helix.mock.participant.DummyProcess.DummyLeaderStandbyStateModelFactory;
+import org.apache.helix.mock.participant.DummyProcess.DummyOnlineOfflineStateModelFactory;
+import org.apache.helix.mock.participant.DummyProcess.DummyStateModelFactory;
import org.apache.helix.participant.StateMachineEngine;
import org.apache.log4j.Logger;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/TestClusterviewSerializer.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestClusterviewSerializer.java b/helix-core/src/test/java/org/apache/helix/TestClusterviewSerializer.java
deleted file mode 100644
index 28599f0..0000000
--- a/helix-core/src/test/java/org/apache/helix/TestClusterviewSerializer.java
+++ /dev/null
@@ -1,77 +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.io.File;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.apache.helix.ClusterView;
-import org.apache.helix.ZNRecord;
-import org.apache.helix.manager.file.StaticFileHelixManager;
-import org.apache.helix.tools.ClusterViewSerializer;
-import org.testng.AssertJUnit;
-import org.testng.annotations.Test;
-
-
-public class TestClusterviewSerializer
-{
- @Test ()
- public void testClusterviewSerializer() throws Exception
- {
- List<StaticFileHelixManager.DBParam> dbParams = new ArrayList<StaticFileHelixManager.DBParam>();
- // dbParams.add(new FileBasedClusterManager.DBParam("BizFollow", 1));
- dbParams.add(new StaticFileHelixManager.DBParam("BizProfile", 1));
- // dbParams.add(new FileBasedClusterManager.DBParam("EspressoDB", 10));
- // dbParams.add(new FileBasedClusterManager.DBParam("MailboxDB", 128));
- // dbParams.add(new FileBasedClusterManager.DBParam("MyDB", 8));
- // dbParams.add(new FileBasedClusterManager.DBParam("schemata", 1));
- // String[] nodesInfo = { "localhost:8900", "localhost:8901",
- // "localhost:8902", "localhost:8903",
- // "localhost:8904" };
- String[] nodesInfo = { "localhost:12918" };
- int replication = 0;
-
- ClusterView view = StaticFileHelixManager.generateStaticConfigClusterView(nodesInfo, dbParams, replication);
- view.setExternalView(new LinkedList<ZNRecord>());
- String file = "/tmp/clusterView.json";
- // ClusterViewSerializer serializer = new ClusterViewSerializer(file);
-
- // byte[] bytes;
- ClusterViewSerializer.serialize(view, new File(file));
- // String str1 = new String(bytes);
- ClusterView restoredView = ClusterViewSerializer.deserialize(new File(file));
- // logger.info(restoredView);
-
- // byte[] bytes2 = serializer.serialize(restoredView);
-
- VerifyClusterViews(view, restoredView);
- }
-
- public void VerifyClusterViews(ClusterView view1, ClusterView view2)
- {
- AssertJUnit.assertEquals(view1.getPropertyLists().size(), view2.getPropertyLists().size());
- AssertJUnit.assertEquals(view1.getExternalView().size(), view2.getExternalView().size());
- AssertJUnit.assertEquals(view1.getMemberInstanceMap().size(), view2.getMemberInstanceMap().size());
- AssertJUnit.assertEquals(view1.getInstances().size(), view2.getInstances().size());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/TestHelper.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestHelper.java b/helix-core/src/test/java/org/apache/helix/TestHelper.java
index 9e9d990..6ae7375 100644
--- a/helix-core/src/test/java/org/apache/helix/TestHelper.java
+++ b/helix-core/src/test/java/org/apache/helix/TestHelper.java
@@ -54,7 +54,6 @@ import org.apache.helix.PropertyType;
import org.apache.helix.ZNRecord;
import org.apache.helix.PropertyKey.Builder;
import org.apache.helix.controller.HelixControllerMain;
-import org.apache.helix.manager.file.FileDataAccessor;
import org.apache.helix.manager.zk.ZKHelixAdmin;
import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
@@ -67,7 +66,6 @@ import org.apache.helix.model.StateModelDefinition;
import org.apache.helix.model.IdealState.IdealStateModeProperty;
import org.apache.helix.model.Message.MessageType;
import org.apache.helix.model.StateModelDefinition.StateModelDefinitionProperty;
-import org.apache.helix.store.file.FilePropertyStore;
import org.apache.helix.store.zk.ZNode;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.util.ZKClientPool;
@@ -300,44 +298,6 @@ public class TestHelper
return null;
}
- // for file-based cluster manager
- public static boolean verifyEmptyCurStateFile(String clusterName,
- String resourceName,
- Set<String> instanceNames,
- FilePropertyStore<ZNRecord> filePropertyStore)
- {
- DataAccessor accessor = new FileDataAccessor(filePropertyStore, clusterName);
-
- for (String instanceName : instanceNames)
- {
- String path =
- PropertyPathConfig.getPath(PropertyType.CURRENTSTATES,
- clusterName,
- instanceName);
- List<String> subPaths =
- accessor.getChildNames(PropertyType.CURRENTSTATES, instanceName);
-
- for (String previousSessionId : subPaths)
- {
- if (filePropertyStore.exists(path + "/" + previousSessionId + "/" + resourceName))
- {
- CurrentState previousCurrentState =
- accessor.getProperty(CurrentState.class,
- PropertyType.CURRENTSTATES,
- instanceName,
- previousSessionId,
- resourceName);
-
- if (previousCurrentState.getRecord().getMapFields().size() != 0)
- {
- return false;
- }
- }
- }
- }
- return true;
- }
-
public static boolean verifyEmptyCurStateAndExtView(String clusterName,
String resourceName,
Set<String> instanceNames,
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
index 8e48d01..7c82c13 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestAddDropAlert.java
@@ -38,9 +38,9 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.storage.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockTransition;
+import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
index 2f85cbc..1ec68cc 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestDummyAlerts.java
@@ -32,8 +32,8 @@ import org.apache.helix.integration.ZkIntegrationTestBase;
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.MockTransition;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.HealthStat;
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-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
index ef537fa..5151898 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestExpandAlert.java
@@ -39,9 +39,9 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.storage.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockTransition;
+import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
index 332dae2..b681ecc 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleAlert.java
@@ -39,9 +39,9 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.storage.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockTransition;
+import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
index 2a69dcd..177948f 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestSimpleWildcardAlert.java
@@ -38,9 +38,9 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.storage.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockTransition;
+import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;
http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/99d394bf/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java b/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
index 6b0b9c5..1bdb038 100644
--- a/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
+++ b/helix-core/src/test/java/org/apache/helix/healthcheck/TestStalenessAlert.java
@@ -39,9 +39,9 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor;
import org.apache.helix.manager.zk.ZNRecordSerializer;
import org.apache.helix.manager.zk.ZkBaseDataAccessor;
import org.apache.helix.manager.zk.ZkClient;
-import org.apache.helix.mock.storage.MockEspressoHealthReportProvider;
-import org.apache.helix.mock.storage.MockParticipant;
-import org.apache.helix.mock.storage.MockTransition;
+import org.apache.helix.mock.participant.MockEspressoHealthReportProvider;
+import org.apache.helix.mock.participant.MockParticipant;
+import org.apache.helix.mock.participant.MockTransition;
import org.apache.helix.model.Message;
import org.apache.helix.tools.ClusterSetup;
import org.apache.helix.tools.ClusterStateVerifier;