use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.
the class WatchSomeThingJob method operation.
@Override
public void operation(JobExecutionContext context) throws Exception {
JobDataMap data = context.getJobDetail().getJobDataMap();
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
String zkHost = data.getString(JobDataMapConstract.ZOOKEEPER_ADDRESS);
// 获取client
CuratorClient curatorClient = null;
try {
curatorClient = mcf.getClient();
String basePath = mcf.getZkPath().getBaseRebalancePath();
String tasksPath = basePath + Constants.SEPARATOR + Constants.TASKS_NODE;
boolean isIt = isRecovery(curatorClient, tasksPath);
// 更新map的值
StateMap.put(RECOVERY_STATUSE, isIt);
// 发生副本迁移就删除数据
if (isIt) {
WatchDog.abandonFoods();
}
} catch (Exception e) {
LOG.error("{}", e);
EmailPool emailPool = EmailPool.getInstance();
MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
builder.setModel(this.getClass().getSimpleName() + "模块服务发生问题");
builder.setException(e);
builder.setMessage(mcf.getGroupName() + "(" + mcf.getServerId() + ")服务 看门狗发生错误");
builder.setVariable(data.getWrappedMap());
emailPool.sendEmail(builder);
}
}
use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.
the class CopyRecovery method recoveryDirs.
/**
* 概述:修复目录
* @param content
* @param zkHosts
* @param baseRoutesPath
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static TaskResultModel recoveryDirs(String content, String zkHosts, String baseRoutesPath, String dataPath) {
TaskResultModel result = new TaskResultModel();
BatchAtomModel batch = converStringToBatch(content);
if (batch == null) {
result.setSuccess(false);
LOG.debug("batch is empty");
return result;
}
List<AtomTaskModel> atoms = batch.getAtoms();
if (atoms == null || atoms.isEmpty()) {
result.setSuccess(true);
LOG.debug(" files is empty");
return result;
}
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
ServerIDManager sim = mcf.getSim();
ServiceManager sm = mcf.getSm();
StorageRegionManager snm = mcf.getSnm();
CuratorClient curatorClient = mcf.getClient();
StorageRegion sn;
SecondIDParser parser;
String snName;
int snId;
AtomTaskResultModel atomR;
List<String> errors;
for (AtomTaskModel atom : atoms) {
atomR = new AtomTaskResultModel();
atomR.setFiles(atom.getFiles());
atomR.setSn(atom.getStorageName());
snName = atom.getStorageName();
sn = snm.findStorageRegionByName(snName);
if (sn == null) {
atomR.setSuccess(false);
result.setSuccess(false);
result.add(atomR);
LOG.debug("sn == null snName :{}", snName);
continue;
}
snId = sn.getId();
parser = new SecondIDParser(curatorClient, snId, baseRoutesPath);
parser.updateRoute();
errors = recoveryFiles(sm, sim, parser, sn, atom, dataPath);
if (errors == null || errors.isEmpty()) {
result.add(atomR);
LOG.debug("result is empty snName:{}", snName);
continue;
}
atomR.addAll(errors);
atomR.setSuccess(false);
result.setSuccess(false);
}
return result;
}
use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.
the class CacheExample method main.
public static void main(String[] args) throws Exception {
CuratorClient client = CuratorClient.getClientInstance("192.168.101.86:2181");
final Set<String> set = new HashSet<String>();
PathChildrenCache cache = new PathChildrenCache(client.getInnerClient(), PATH, true);
cache.start();
PathChildrenCacheListener listener1 = new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
switch(event.getType()) {
case CHILD_ADDED:
{
System.out.println("1Node added: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
System.out.println("1Node added: " + event.getData().getPath());
break;
}
case CHILD_UPDATED:
{
System.out.println("1Node changed: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
System.out.println("1Node changed: " + new String(event.getData().getData()));
break;
}
case CHILD_REMOVED:
{
System.out.println("1Node removed: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
break;
}
default:
break;
}
}
};
// PathChildrenCacheListener listener2 = new PathChildrenCacheListener() {
//
// @Override
// public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
// switch (event.getType()) {
// case CHILD_ADDED: {
// System.out.println("2Node added: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
// System.out.println("2Node added: " + event.getData().getPath());
// break;
// }
// case CHILD_UPDATED: {
// System.out.println("2Node changed: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
// break;
// }
// case CHILD_REMOVED: {
// System.out.println("2Node removed: " + ZKPaths.getNodeFromPath(event.getData().getPath()));
// break;
// }
// default:
// break;
// }
// }
// };
ExecutorService services = Executors.newFixedThreadPool(5);
cache.getListenable().addListener(listener1, services);
// cache.getListenable().addListener(listener2,services);
// cache.getListenable().addListener(listener);
Thread.sleep(Long.MAX_VALUE);
cache.close();
client.close();
}
use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.
the class ZookeeperPaths method createZkPath.
public void createZkPath() {
CuratorClient client = null;
try {
client = CuratorClient.getClientInstance(zkHosts);
createPathIfNotExist(client, baseClusterName);
createPathIfNotExist(client, baseLocksPath);
createPathIfNotExist(client, baseSequencesPath);
createPathIfNotExist(client, baseServerIdSeqPath);
createPathIfNotExist(client, baseServerIdPath);
createPathIfNotExist(client, baseRebalancePath);
createPathIfNotExist(client, baseRoutePath);
createPathIfNotExist(client, baseUserPath);
createPathIfNotExist(client, baseTaskPath);
createPathIfNotExist(client, baseResourcesPath);
} finally {
client.close();
}
}
Aggregations