Search in sources :

Example 1 with ServerIDManager

use of com.bonree.brfs.server.identification.ServerIDManager in project BRFS by zhangnianli.

the class ServerMain method main.

public static void main(String[] args) {
    ProcessFinalizer finalizer = new ProcessFinalizer();
    try {
        ResourceTaskConfig resourceConfig = ResourceTaskConfig.parse();
        // 初始化email发送配置
        EmailPool.getInstance();
        String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
        CuratorClient leaderClient = CuratorClient.getClientInstance(zkAddresses, 1000, 1000);
        CuratorClient client = CuratorClient.getClientInstance(zkAddresses);
        CuratorCacheFactory.init(zkAddresses);
        ZookeeperPaths zookeeperPaths = ZookeeperPaths.create(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_CLUSTER_NAME), zkAddresses);
        SimpleAuthentication authentication = SimpleAuthentication.getAuthInstance(zookeeperPaths.getBaseUserPath(), zookeeperPaths.getBaseLocksPath(), client.getInnerClient());
        UserModel model = authentication.getUser("root");
        if (model == null) {
            LOG.error("please init server!!!");
            System.exit(1);
        }
        ServerIDManager idManager = new ServerIDManager(client.getInnerClient(), zookeeperPaths);
        idManager.getFirstServerID();
        StorageRegionManager snManager = new DefaultStorageRegionManager(client.getInnerClient().usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), null);
        snManager.addStorageRegionStateListener(new StorageRegionStateListener() {

            @Override
            public void storageRegionAdded(StorageRegion node) {
                LOG.info("-----------StorageNameAdded--[{}]", node);
                idManager.getSecondServerID(node.getId());
            }

            @Override
            public void storageRegionUpdated(StorageRegion node) {
            }

            @Override
            public void storageRegionRemoved(StorageRegion node) {
                LOG.info("-----------StorageNameRemove--[{}]", node);
                idManager.deleteSecondServerID(node.getId());
            }
        });
        snManager.start();
        finalizer.add(snManager);
        ServiceManager sm = new DefaultServiceManager(client.getInnerClient().usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)));
        sm.start();
        finalizer.add(sm);
        // 磁盘管理模块
        // EmptyMain diskMain = new EmptyMain(sm);
        // diskMain.start();
        // 
        // finalizer.add(diskMain);
        DataNodeBootStrap dataNodeBootStrap = new DataNodeBootStrap(sm);
        dataNodeBootStrap.start();
        finalizer.add(dataNodeBootStrap);
        // 副本平衡模块
        sm.addServiceStateListener(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), new ServerChangeTaskGenetor(leaderClient, client, sm, idManager, zookeeperPaths.getBaseRebalancePath(), 3000, snManager));
        @SuppressWarnings("resource") RebalanceManager rebalanceServer = new RebalanceManager(zookeeperPaths, idManager, snManager, sm);
        rebalanceServer.start();
        String host = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_HOST);
        int port = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_PORT);
        int readPort = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_PORT);
        Service selfService = new Service();
        selfService.setHost(host);
        selfService.setPort(port);
        selfService.setExtraPort(readPort);
        selfService.setServiceGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
        String serviceId = idManager.getFirstServerID();
        selfService.setServiceId(serviceId);
        Service checkService = sm.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), serviceId);
        if (checkService == null) {
            sm.registerService(selfService);
            System.out.println(selfService);
        } else {
            LOG.error("serviceId : {} is exists, system will exit!!!", serviceId);
            System.exit(1);
        }
        finalizer.add(new Closeable() {

            @Override
            public void close() throws IOException {
                try {
                    sm.unregisterService(selfService);
                } catch (Exception e) {
                    LOG.error("unregister service[{}] error", selfService, e);
                }
            }
        });
        // 资源管理模块
        InitTaskManager.initManager(resourceConfig, zookeeperPaths, sm, snManager, idManager, client);
    } catch (Exception e) {
        LOG.error("launch server error!!!", e);
        System.exit(1);
    } finally {
        Runtime.getRuntime().addShutdownHook(finalizer);
    }
}
Also used : Closeable(java.io.Closeable) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) Service(com.bonree.brfs.common.service.Service) RebalanceManager(com.bonree.brfs.rebalance.RebalanceManager) IOException(java.io.IOException) ResourceTaskConfig(com.bonree.brfs.configuration.ResourceTaskConfig) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) IOException(java.io.IOException) UserModel(com.bonree.brfs.authentication.model.UserModel) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) DataNodeBootStrap(com.bonree.brfs.disknode.boot.DataNodeBootStrap) ZookeeperPaths(com.bonree.brfs.common.ZookeeperPaths) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) ServiceManager(com.bonree.brfs.common.service.ServiceManager) ServerChangeTaskGenetor(com.bonree.brfs.rebalance.task.ServerChangeTaskGenetor) SimpleAuthentication(com.bonree.brfs.authentication.SimpleAuthentication) ProcessFinalizer(com.bonree.brfs.common.process.ProcessFinalizer) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) StorageRegionStateListener(com.bonree.brfs.duplication.storageregion.StorageRegionStateListener)

Example 2 with ServerIDManager

use of com.bonree.brfs.server.identification.ServerIDManager in project BRFS by zhangnianli.

the class CopyCountCheck method collectionSnFiles.

/**
 * 概述:获取集群对应目录的文件
 * @param services
 * @param snList
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static Map<StorageRegion, List<String>> collectionSnFiles(List<Service> services, List<StorageRegion> snList, final Map<String, Long> snTimes) throws Exception {
    Map<StorageRegion, List<String>> snMap = new HashMap<>();
    DiskNodeClient client = null;
    int reCount;
    String snName = null;
    String path;
    List<String> strs;
    long time;
    String dirName;
    String sid;
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    ServerIDManager sim = mcf.getSim();
    CuratorClient zkClient = mcf.getClient();
    SecondIDParser parser;
    String basePath = mcf.getZkPath().getBaseRoutePath();
    int timeout = 10000;
    for (Service service : services) {
        try {
            client = TcpClientUtils.getClient(service.getHost(), service.getPort(), service.getExtraPort(), timeout);
            long granule;
            for (StorageRegion sn : snList) {
                parser = new SecondIDParser(zkClient, sn.getId(), basePath);
                parser.updateRoute();
                sid = sim.getOtherSecondID(service.getServiceId(), sn.getId());
                granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
                reCount = sn.getReplicateNum();
                snName = sn.getName();
                if (!snTimes.containsKey(snName)) {
                    LOG.debug("sntime don't contain {}", snName);
                    continue;
                }
                time = snTimes.get(snName);
                dirName = TimeUtils.timeInterval(time, granule);
                for (int i = 1; i <= reCount; i++) {
                    path = "/" + snName + "/" + i + "/" + dirName;
                    LOG.debug("path :{}", path);
                    strs = getFileList(parser, client, path, sid);
                    if (strs == null || strs.isEmpty()) {
                        LOG.debug("files is empty {}", path);
                        continue;
                    }
                    LOG.debug("Collection dirName :{},{} size :{}", dirName, path, strs.size());
                    if (!snMap.containsKey(sn)) {
                        snMap.put(sn, new ArrayList<>());
                    }
                    snMap.get(sn).addAll(strs);
                }
            }
        } catch (Exception e) {
            EmailPool emailPool = EmailPool.getInstance();
            MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
            builder.setModel("collect file execute 模块服务发生问题");
            builder.setException(e);
            builder.setMessage(mcf.getGroupName() + "(" + mcf.getServerId() + ")服务 执行任务时发生问题");
            Map<String, String> map = new HashedMap();
            map.put("remote ", service.getHost());
            map.put("connectTimeout", String.valueOf(timeout));
            map.put("sn", StringUtils.isEmpty(snName) ? "" : snName);
            if (snTimes != null && !snTimes.isEmpty()) {
                map.put("sntime", JSON.toJSONString(snTimes));
            }
            builder.setVariable(map);
            emailPool.sendEmail(builder);
            throw e;
        } finally {
            if (client != null) {
                try {
                    client.close();
                } catch (IOException e) {
                    LOG.error("{}", e);
                }
            }
        }
    }
    return clearUnLawFiles(snMap);
}
Also used : SecondIDParser(com.bonree.brfs.rebalance.route.SecondIDParser) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) Service(com.bonree.brfs.common.service.Service) EmailPool(com.bonree.brfs.email.EmailPool) IOException(java.io.IOException) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) IOException(java.io.IOException) DiskNodeClient(com.bonree.brfs.disknode.client.DiskNodeClient) HashedMap(org.apache.commons.collections.map.HashedMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashedMap(org.apache.commons.collections.map.HashedMap)

Example 3 with ServerIDManager

use of com.bonree.brfs.server.identification.ServerIDManager 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 4 with ServerIDManager

use of com.bonree.brfs.server.identification.ServerIDManager in project BRFS by zhangnianli.

the class BootStrap method main.

public static void main(String[] args) {
    ProcessFinalizer finalizer = new ProcessFinalizer();
    try {
        // 初始化email发送配置
        EmailPool.getInstance();
        String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
        String host = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_HOST);
        int port = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_PORT);
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient(zkAddresses, 3000, 15000, retryPolicy);
        client.start();
        client.blockUntilConnected();
        finalizer.add(client);
        CuratorCacheFactory.init(zkAddresses);
        String clusterName = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_CLUSTER_NAME);
        ZookeeperPaths zookeeperPaths = ZookeeperPaths.create(clusterName, zkAddresses);
        ServerIDManager idManager = new ServerIDManager(client, zookeeperPaths);
        SimpleAuthentication simpleAuthentication = SimpleAuthentication.getAuthInstance(zookeeperPaths.getBaseUserPath(), zookeeperPaths.getBaseLocksPath(), client);
        UserModel model = simpleAuthentication.getUser("root");
        if (model == null) {
            LOG.error("please init server!!!");
            System.exit(1);
        }
        Service service = new Service(UUID.randomUUID().toString(), Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_REGION_SERVICE_GROUP_NAME), host, port);
        ServiceManager serviceManager = new DefaultServiceManager(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)));
        serviceManager.start();
        finalizer.add(serviceManager);
        TimeExchangeEventEmitter timeEventEmitter = new TimeExchangeEventEmitter(2);
        finalizer.add(timeEventEmitter);
        StorageRegionIdBuilder storageIdBuilder = new ZkStorageRegionIdBuilder(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)));
        StorageRegionManager storageNameManager = new DefaultStorageRegionManager(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), storageIdBuilder);
        storageNameManager.start();
        finalizer.add(storageNameManager);
        // HttpDiskNodeConnectionPool connectionPool = new HttpDiskNodeConnectionPool(serviceManager);
        // finalizer.add(connectionPool);
        AsyncTcpClientGroup tcpClientGroup = new AsyncTcpClientGroup(Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_WRITER_WORKER_NUM));
        TcpDiskNodeConnectionPool connectionPool = new TcpDiskNodeConnectionPool(serviceManager, tcpClientGroup);
        finalizer.add(tcpClientGroup);
        FilePathMaker pathMaker = new IDFilePathMaker(idManager);
        int workerThreadNum = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_SERVER_IO_THREAD_NUM);
        HttpConfig httpConfig = HttpConfig.newBuilder().setHost(host).setPort(port).setAcceptWorkerNum(1).setRequestHandleWorkerNum(workerThreadNum).setBacklog(Integer.parseInt(System.getProperty(SystemProperties.PROP_NET_BACKLOG, "2048"))).build();
        NettyHttpServer httpServer = new NettyHttpServer(httpConfig);
        httpServer.addHttpAuthenticator(new HttpAuthenticator() {

            @Override
            public int check(String userName, String passwd) {
                StringBuilder tokenBuilder = new StringBuilder();
                tokenBuilder.append(userName).append(":").append(passwd);
                return simpleAuthentication.auth(tokenBuilder.toString()) ? 0 : ReturnCode.USER_FORBID.getCode();
            }
        });
        ExecutorService requestHandlerExecutor = Executors.newFixedThreadPool(Math.max(4, Runtime.getRuntime().availableProcessors() / 4), new PooledThreadFactory("request_handler"));
        finalizer.add(new Closeable() {

            @Override
            public void close() throws IOException {
                requestHandlerExecutor.shutdown();
            }
        });
        FileObjectSyncProcessor processor = new DefaultFileObjectSyncProcessor(connectionPool, pathMaker);
        DefaultFileObjectSynchronier fileSynchronizer = new DefaultFileObjectSynchronier(processor, serviceManager, 10, TimeUnit.SECONDS);
        fileSynchronizer.start();
        finalizer.add(fileSynchronizer);
        FileNodeStorer storer = new ZkFileNodeStorer(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), ZkFileCoordinatorPaths.COORDINATOR_FILESTORE);
        // 资源缓存器
        String diskGroup = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME);
        String rPath = zookeeperPaths.getBaseResourcesPath() + "/" + diskGroup + "/resource";
        ClusterResource clusterResource = ClusterResource.newBuilder().setCache(true).setClient(client).setListenPath(rPath).setPool(Executors.newSingleThreadExecutor()).build().start();
        // 资源选择策略
        // 获取限制值
        double diskRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_AVAILABLE_RATE);
        double diskForceRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_AVAILABLE_RATE);
        double diskwriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_WRITE_SPEED);
        double diskForcewriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_WRITE_SPEED);
        long diskRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_REMAIN_SIZE);
        long diskForceRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_REMAIN_SIZE);
        LimitServerResource lmit = new LimitServerResource();
        lmit.setDiskRemainRate(diskRemainRate);
        lmit.setDiskWriteValue(diskwriteValue);
        lmit.setForceDiskRemainRate(diskForceRemainRate);
        lmit.setForceWriteValue(diskForcewriteValue);
        lmit.setRemainWarnSize(diskRemainSize);
        lmit.setRemainForceSize(diskForceRemainSize);
        int centSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_RESOURCE_CENT_SIZE);
        long fileSize = Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_MAX_CAPACITY) / 1024;
        MachineResourceWriterSelector serviceSelector = new MachineResourceWriterSelector(connectionPool, storer, lmit, diskGroup, fileSize, centSize);
        // 生成备用选择器
        DuplicateNodeSelector bakSelect = new MinimalDuplicateNodeSelector(serviceManager, connectionPool);
        // 选择
        DuplicateNodeSelector nodeSelector = ResourceWriteSelector.newBuilder().setBakSelector(bakSelect).setDaemon(clusterResource).setGroupName(diskGroup).setStorageRegionManager(storageNameManager).setResourceSelector(serviceSelector).build();
        FileObjectFactory fileFactory = new DefaultFileObjectFactory(service, storer, nodeSelector, idManager, connectionPool);
        int closerThreadNum = Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_CLOSER_THREAD_NUM);
        DefaultFileObjectCloser fileCloser = new DefaultFileObjectCloser(closerThreadNum, fileSynchronizer, storer, connectionPool, pathMaker);
        finalizer.add(fileCloser);
        FileNodeSinkManager sinkManager = new ZkFileNodeSinkManager(client.usingNamespace(zookeeperPaths.getBaseClusterName().substring(1)), service, serviceManager, timeEventEmitter, storer, new RandomFileNodeSinkSelector(), fileCloser);
        sinkManager.start();
        finalizer.add(sinkManager);
        DataPoolFactory dataPoolFactory = new BlockingQueueDataPoolFactory(Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_DATA_POOL_CAPACITY));
        FileObjectSupplierFactory fileSupplierFactory = new DefaultFileObjectSupplierFactory(fileFactory, fileCloser, fileSynchronizer, sinkManager, timeEventEmitter);
        DiskWriter diskWriter = new DiskWriter(Configs.getConfiguration().GetConfig(RegionNodeConfigs.CONFIG_WRITER_WORKER_NUM), connectionPool, pathMaker);
        finalizer.add(diskWriter);
        DataEngineFactory engineFactory = new DefaultDataEngineFactory(dataPoolFactory, fileSupplierFactory, diskWriter);
        DefaultDataEngineManager engineManager = new DefaultDataEngineManager(storageNameManager, engineFactory);
        finalizer.add(engineManager);
        DefaultStorageRegionWriter writer = new DefaultStorageRegionWriter(engineManager);
        NettyHttpRequestHandler requestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
        requestHandler.addMessageHandler("POST", new WriteDataMessageHandler(writer));
        requestHandler.addMessageHandler("GET", new ReadDataMessageHandler());
        requestHandler.addMessageHandler("DELETE", new DeleteDataMessageHandler(zookeeperPaths, serviceManager, storageNameManager));
        httpServer.addContextHandler(URI_DATA_ROOT, requestHandler);
        NettyHttpRequestHandler snRequestHandler = new NettyHttpRequestHandler(requestHandlerExecutor);
        snRequestHandler.addMessageHandler("PUT", new CreateStorageRegionMessageHandler(storageNameManager));
        snRequestHandler.addMessageHandler("POST", new UpdateStorageRegionMessageHandler(storageNameManager));
        snRequestHandler.addMessageHandler("GET", new OpenStorageRegionMessageHandler(storageNameManager));
        snRequestHandler.addMessageHandler("DELETE", new DeleteStorageRegionMessageHandler(zookeeperPaths, storageNameManager, serviceManager));
        httpServer.addContextHandler(URI_STORAGE_REGION_ROOT, snRequestHandler);
        httpServer.start();
        finalizer.add(httpServer);
        serviceManager.registerService(service);
        finalizer.add(new Closeable() {

            @Override
            public void close() throws IOException {
                try {
                    serviceManager.unregisterService(service);
                } catch (Exception e) {
                    LOG.error("unregister service[{}] error", service, e);
                }
            }
        });
    } catch (Exception e) {
        LOG.error("launch server error!!!", e);
        System.exit(1);
    } finally {
        Runtime.getRuntime().addShutdownHook(finalizer);
    }
}
Also used : OpenStorageRegionMessageHandler(com.bonree.brfs.duplication.storageregion.handler.OpenStorageRegionMessageHandler) Closeable(java.io.Closeable) BlockingQueueDataPoolFactory(com.bonree.brfs.duplication.datastream.dataengine.impl.BlockingQueueDataPoolFactory) FileObjectSupplierFactory(com.bonree.brfs.duplication.datastream.file.FileObjectSupplierFactory) DefaultFileObjectSupplierFactory(com.bonree.brfs.duplication.datastream.file.DefaultFileObjectSupplierFactory) HttpAuthenticator(com.bonree.brfs.common.net.http.netty.HttpAuthenticator) TimeExchangeEventEmitter(com.bonree.brfs.common.timer.TimeExchangeEventEmitter) DefaultDataEngineFactory(com.bonree.brfs.duplication.datastream.dataengine.impl.DefaultDataEngineFactory) ZkFileNodeStorer(com.bonree.brfs.duplication.filenode.zk.ZkFileNodeStorer) FileNodeStorer(com.bonree.brfs.duplication.filenode.FileNodeStorer) ZkStorageRegionIdBuilder(com.bonree.brfs.duplication.storageregion.impl.ZkStorageRegionIdBuilder) CuratorFramework(org.apache.curator.framework.CuratorFramework) DefaultFileObjectSynchronier(com.bonree.brfs.duplication.datastream.file.sync.DefaultFileObjectSynchronier) DefaultFileObjectCloser(com.bonree.brfs.duplication.datastream.file.DefaultFileObjectCloser) DefaultFileObjectFactory(com.bonree.brfs.duplication.datastream.file.DefaultFileObjectFactory) FileObjectFactory(com.bonree.brfs.duplication.datastream.file.FileObjectFactory) HttpConfig(com.bonree.brfs.common.net.http.HttpConfig) ProcessFinalizer(com.bonree.brfs.common.process.ProcessFinalizer) WriteDataMessageHandler(com.bonree.brfs.duplication.datastream.handler.WriteDataMessageHandler) IDFilePathMaker(com.bonree.brfs.duplication.datastream.IDFilePathMaker) ZkFileNodeSinkManager(com.bonree.brfs.duplication.filenode.zk.ZkFileNodeSinkManager) TcpDiskNodeConnectionPool(com.bonree.brfs.duplication.datastream.connection.tcp.TcpDiskNodeConnectionPool) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) DefaultStorageRegionWriter(com.bonree.brfs.duplication.datastream.writer.DefaultStorageRegionWriter) DefaultFileObjectSupplierFactory(com.bonree.brfs.duplication.datastream.file.DefaultFileObjectSupplierFactory) DefaultFileObjectSyncProcessor(com.bonree.brfs.duplication.datastream.file.sync.DefaultFileObjectSyncProcessor) SimpleAuthentication(com.bonree.brfs.authentication.SimpleAuthentication) BlockingQueueDataPoolFactory(com.bonree.brfs.duplication.datastream.dataengine.impl.BlockingQueueDataPoolFactory) DataPoolFactory(com.bonree.brfs.duplication.datastream.dataengine.impl.DataPoolFactory) DataEngineFactory(com.bonree.brfs.duplication.datastream.dataengine.DataEngineFactory) DefaultDataEngineFactory(com.bonree.brfs.duplication.datastream.dataengine.impl.DefaultDataEngineFactory) ZkFileNodeStorer(com.bonree.brfs.duplication.filenode.zk.ZkFileNodeStorer) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) DefaultFileObjectSyncProcessor(com.bonree.brfs.duplication.datastream.file.sync.DefaultFileObjectSyncProcessor) FileObjectSyncProcessor(com.bonree.brfs.duplication.datastream.file.sync.FileObjectSyncProcessor) ZkFileNodeSinkManager(com.bonree.brfs.duplication.filenode.zk.ZkFileNodeSinkManager) FileNodeSinkManager(com.bonree.brfs.duplication.filenode.FileNodeSinkManager) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) AsyncTcpClientGroup(com.bonree.brfs.common.net.tcp.client.AsyncTcpClientGroup) DefaultFileObjectFactory(com.bonree.brfs.duplication.datastream.file.DefaultFileObjectFactory) ClusterResource(com.bonree.brfs.duplication.filenode.duplicates.ClusterResource) RandomFileNodeSinkSelector(com.bonree.brfs.duplication.filenode.zk.RandomFileNodeSinkSelector) UserModel(com.bonree.brfs.authentication.model.UserModel) ServiceManager(com.bonree.brfs.common.service.ServiceManager) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) NettyHttpRequestHandler(com.bonree.brfs.common.net.http.netty.NettyHttpRequestHandler) DefaultStorageRegionManager(com.bonree.brfs.duplication.storageregion.impl.DefaultStorageRegionManager) PooledThreadFactory(com.bonree.brfs.common.utils.PooledThreadFactory) CreateStorageRegionMessageHandler(com.bonree.brfs.duplication.storageregion.handler.CreateStorageRegionMessageHandler) ExecutorService(java.util.concurrent.ExecutorService) Service(com.bonree.brfs.common.service.Service) NettyHttpServer(com.bonree.brfs.common.net.http.netty.NettyHttpServer) IOException(java.io.IOException) IDFilePathMaker(com.bonree.brfs.duplication.datastream.IDFilePathMaker) FilePathMaker(com.bonree.brfs.duplication.datastream.FilePathMaker) ReadDataMessageHandler(com.bonree.brfs.duplication.datastream.handler.ReadDataMessageHandler) DefaultDataEngineManager(com.bonree.brfs.duplication.datastream.dataengine.impl.DefaultDataEngineManager) DeleteStorageRegionMessageHandler(com.bonree.brfs.duplication.storageregion.handler.DeleteStorageRegionMessageHandler) IOException(java.io.IOException) DefaultServiceManager(com.bonree.brfs.common.service.impl.DefaultServiceManager) DiskWriter(com.bonree.brfs.duplication.datastream.writer.DiskWriter) ZookeeperPaths(com.bonree.brfs.common.ZookeeperPaths) DeleteDataMessageHandler(com.bonree.brfs.duplication.datastream.handler.DeleteDataMessageHandler) ExecutorService(java.util.concurrent.ExecutorService) LimitServerResource(com.bonree.brfs.resourceschedule.model.LimitServerResource) RetryPolicy(org.apache.curator.RetryPolicy) StorageRegionIdBuilder(com.bonree.brfs.duplication.storageregion.StorageRegionIdBuilder) ZkStorageRegionIdBuilder(com.bonree.brfs.duplication.storageregion.impl.ZkStorageRegionIdBuilder) DuplicateNodeSelector(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNodeSelector) UpdateStorageRegionMessageHandler(com.bonree.brfs.duplication.storageregion.handler.UpdateStorageRegionMessageHandler)

Example 5 with ServerIDManager

use of com.bonree.brfs.server.identification.ServerIDManager in project BRFS by zhangnianli.

the class WatchDogJob method operation.

@Override
public void operation(JobExecutionContext context) throws Exception {
    LOG.debug("watch dog do it >>>>>>>>>>>>>>");
    JobDataMap data = context.getJobDetail().getJobDataMap();
    String zkHosts = data.getString(JobDataMapConstract.ZOOKEEPER_ADDRESS);
    String baseRoutPath = data.getString(JobDataMapConstract.BASE_ROUTE_PATH);
    String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
    if (BrStringUtils.isEmpty(dataPath) || BrStringUtils.isEmpty(baseRoutPath) || BrStringUtils.isEmpty(zkHosts)) {
        LOG.warn("config is empty !! skip watchdog");
        return;
    }
    ManagerContralFactory mcf = ManagerContralFactory.getInstance();
    ServerIDManager sim = mcf.getSim();
    StorageRegionManager snm = mcf.getSnm();
    List<StorageRegion> sns = snm.getStorageRegionList();
    long preTime = System.currentTimeMillis();
    LOG.info("Scan {} below data !!!", TimeUtils.formatTimeStamp(preTime));
    WatchDog.searchPreys(sim, sns, zkHosts, baseRoutPath, dataPath, preTime);
}
Also used : JobDataMap(org.quartz.JobDataMap) ServerIDManager(com.bonree.brfs.server.identification.ServerIDManager) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) StorageRegionManager(com.bonree.brfs.duplication.storageregion.StorageRegionManager) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Aggregations

ServerIDManager (com.bonree.brfs.server.identification.ServerIDManager)5 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)4 StorageRegionManager (com.bonree.brfs.duplication.storageregion.StorageRegionManager)4 Service (com.bonree.brfs.common.service.Service)3 ServiceManager (com.bonree.brfs.common.service.ServiceManager)3 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)3 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)3 SimpleAuthentication (com.bonree.brfs.authentication.SimpleAuthentication)2 UserModel (com.bonree.brfs.authentication.model.UserModel)2 ZookeeperPaths (com.bonree.brfs.common.ZookeeperPaths)2 ProcessFinalizer (com.bonree.brfs.common.process.ProcessFinalizer)2 DefaultServiceManager (com.bonree.brfs.common.service.impl.DefaultServiceManager)2 IOException (java.io.IOException)2 HttpConfig (com.bonree.brfs.common.net.http.HttpConfig)1 HttpAuthenticator (com.bonree.brfs.common.net.http.netty.HttpAuthenticator)1 NettyHttpRequestHandler (com.bonree.brfs.common.net.http.netty.NettyHttpRequestHandler)1 NettyHttpServer (com.bonree.brfs.common.net.http.netty.NettyHttpServer)1 AsyncTcpClientGroup (com.bonree.brfs.common.net.tcp.client.AsyncTcpClientGroup)1 TimeExchangeEventEmitter (com.bonree.brfs.common.timer.TimeExchangeEventEmitter)1 PooledThreadFactory (com.bonree.brfs.common.utils.PooledThreadFactory)1