Search in sources :

Example 1 with CuratorClient

use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.

the class ZookeeperUserOperation method updateUser.

@Override
public void updateUser(UserModel user) {
    CuratorClient client = CuratorClient.getClientInstance(zkUrl);
    try {
        String userNode = basePath + SEPARATOR + user.getUserName();
        String jsonStr = JSON.toJSONString(user);
        client.setData(userNode, jsonStr.getBytes());
    } finally {
        client.close();
    }
}
Also used : CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Example 2 with CuratorClient

use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.

the class TaskGenetor method genChangeSummary.

private void genChangeSummary(String zkUrl, ChangeType type) {
    CuratorClient client = CuratorClient.getClientInstance(zkUrl);
    try {
        String changeServerId = "aaaaa";
        List<StorageName> snList = getStorageCache();
        for (StorageName snModel : snList) {
            if (snModel.getReplications() > 1 && snModel.isRecover()) {
                List<String> currentServers = getCurrentServers();
                ChangeSummary tsm = new ChangeSummary(snModel.getIndex(), Calendar.getInstance().getTimeInMillis() / 1000, type, changeServerId, currentServers);
                String snPath = basePath + SEPARATOR + snModel.getIndex();
                String jsonStr = JSON.toJSONString(tsm);
                if (!client.checkExists(snPath)) {
                    client.createPersistent(snPath, false);
                }
                String snTaskNode = snPath + SEPARATOR + tsm.getCreateTime();
                client.createPersistent(snTaskNode, false, jsonStr.getBytes());
            }
        }
    } finally {
        client.close();
    }
}
Also used : StorageName(com.bonree.brfs.server.StorageName) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Example 3 with CuratorClient

use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.

the class StorageSequenceGenetor method getIncreSequence.

public Integer getIncreSequence() {
    int sequence = 0;
    CuratorClient client = null;
    try {
        client = CuratorClient.getClientInstance(zkUrl);
        String node = basePath + SEPARATOR + STORAGE_INDEX_NODE;
        ZKIncreSequence genExecutor = new ZKIncreSequence(node);
        CuratorLocksClient<Integer> lockClient = new CuratorLocksClient<Integer>(client, basePath + SEPARATOR + LOCKS_PATH, genExecutor, "genSingleIdentification");
        sequence = lockClient.execute();
    } catch (Exception e) {
        LOG.error("getSingleIdentification error!", e);
    } finally {
        if (client != null) {
            client.close();
        }
    }
    return sequence;
}
Also used : CuratorLocksClient(com.bonree.brfs.common.zookeeper.curator.locking.CuratorLocksClient) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Example 4 with CuratorClient

use of com.bonree.brfs.common.zookeeper.curator.CuratorClient 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 5 with CuratorClient

use of com.bonree.brfs.common.zookeeper.curator.CuratorClient in project BRFS by zhangnianli.

the class InitServer method main.

public static void main(String[] args) {
    try {
        String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
        CuratorClient client = CuratorClient.getClientInstance(zkAddresses);
        ZookeeperPaths zookeeperPaths = ZookeeperPaths.create(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_CLUSTER_NAME), zkAddresses);
        CuratorCacheFactory.init(zkAddresses);
        String passwd = null;
        Scanner sc = new Scanner(System.in);
        Thread.sleep(500);
        while (true) {
            System.out.println("please input root user's password:");
            passwd = sc.nextLine();
            if (StringUtils.isEmpty(passwd)) {
                System.out.println("password is empty!!");
            } else if (passwd.length() < 5) {
                System.out.println("password less 5 size!!");
            } else {
                System.out.println("password setup successfully!!");
                break;
            }
        }
        SimpleAuthentication authentication = SimpleAuthentication.getAuthInstance(zookeeperPaths.getBaseUserPath(), zookeeperPaths.getBaseLocksPath(), client.getInnerClient());
        UserModel user = new UserModel("root", passwd, (byte) 0);
        authentication.createUser(user);
        System.out.println("init server successfully!!");
        sc.close();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : UserModel(com.bonree.brfs.authentication.model.UserModel) Scanner(java.util.Scanner) ZookeeperPaths(com.bonree.brfs.common.ZookeeperPaths) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) SimpleAuthentication(com.bonree.brfs.authentication.SimpleAuthentication)

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