Search in sources :

Example 16 with CuratorClient

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);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) EmailPool(com.bonree.brfs.email.EmailPool) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 17 with CuratorClient

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;
}
Also used : SecondIDParser(com.bonree.brfs.rebalance.route.SecondIDParser) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) ServiceManager(com.bonree.brfs.common.service.ServiceManager) BatchAtomModel(com.bonree.brfs.schedulers.task.model.BatchAtomModel) AtomTaskResultModel(com.bonree.brfs.schedulers.task.model.AtomTaskResultModel) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel)

Example 18 with CuratorClient

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();
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) ExecutorService(java.util.concurrent.ExecutorService) HashSet(java.util.HashSet)

Example 19 with CuratorClient

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();
    }
}
Also used : CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Aggregations

CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)19 UserModel (com.bonree.brfs.authentication.model.UserModel)4 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)4 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)3 ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)3 SimpleAuthentication (com.bonree.brfs.authentication.SimpleAuthentication)2 ZookeeperPaths (com.bonree.brfs.common.ZookeeperPaths)2 Service (com.bonree.brfs.common.service.Service)2 ServiceManager (com.bonree.brfs.common.service.ServiceManager)2 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)2 EmailPool (com.bonree.brfs.email.EmailPool)2 SecondIDParser (com.bonree.brfs.rebalance.route.SecondIDParser)2 IOException (java.io.IOException)2 ProcessFinalizer (com.bonree.brfs.common.process.ProcessFinalizer)1 NormalRoute (com.bonree.brfs.common.rebalance.route.NormalRoute)1 VirtualRoute (com.bonree.brfs.common.rebalance.route.VirtualRoute)1 DefaultServiceManager (com.bonree.brfs.common.service.impl.DefaultServiceManager)1 JsonUtils (com.bonree.brfs.common.utils.JsonUtils)1 JsonException (com.bonree.brfs.common.utils.JsonUtils.JsonException)1 CuratorLocksClient (com.bonree.brfs.common.zookeeper.curator.locking.CuratorLocksClient)1