Search in sources :

Example 11 with CuratorClient

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

the class ZookeeperUserOperation method getUser.

@Override
public UserModel getUser(String userName) {
    CuratorClient client = CuratorClient.getClientInstance(zkUrl);
    try {
        String userNode = basePath + SEPARATOR + userName;
        String jsonStr = new String(client.getData(userNode));
        UserModel user = JSON.parseObject(jsonStr, UserModel.class);
        return user;
    } finally {
        client.close();
    }
}
Also used : UserModel(com.bonree.brfs.authentication.model.UserModel) CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Example 12 with CuratorClient

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

the class ZookeeperUserOperation method deleteUser.

@Override
public void deleteUser(String userName) {
    if (org.apache.commons.lang3.StringUtils.equals(userName, ROOT_USER)) {
        LOG.warn("can not delete: " + ROOT_USER);
        return;
    }
    CuratorClient client = CuratorClient.getClientInstance(zkUrl);
    try {
        String userNode = basePath + SEPARATOR + userName;
        client.delete(userNode, false);
    } finally {
        client.close();
    }
}
Also used : CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Example 13 with CuratorClient

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

the class ZookeeperUserOperation method createUser.

@Override
public void createUser(UserModel user) {
    CuratorClient client = CuratorClient.getClientInstance(zkUrl);
    try {
        String userNode = basePath + SEPARATOR + user.getUserName();
        String jsonStr = JSON.toJSONString(user);
        if (!client.checkExists(userNode)) {
            client.createPersistent(userNode, false, jsonStr.getBytes());
        } else {
            LOG.warn("the user:" + user.getUserName() + " is exist!");
        }
    } finally {
        client.close();
    }
}
Also used : CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient)

Example 14 with CuratorClient

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

the class TaskManager method publishTask.

public static void publishTask() {
    BalanceSummary task = new BalanceSummary();
    task.setServerId("server1");
    task.setStorageIndex(1);
    task.setOutputServers(Lists.asList("server2", new String[] { "server3", "server4" }));
    task.setInputServers(Lists.asList("server2", new String[] { "server3", "server4" }));
    task.setTaskType(1);
    task.setRuntime(new Date().getTime() / 1000);
    String jsonStr = JSON.toJSONString(task);
    CuratorClient client = CuratorClient.getClientInstance(zkUrl);
    if (!client.checkExists(basePath)) {
        client.createPersistent(basePath, true);
    }
    // 创建该SN下面的子任务
    if (!client.checkExists(basePath + SEPARATOR + taskQueue + SEPARATOR + task.getStorageIndex()))
        client.createPersistent(basePath + SEPARATOR + taskQueue + SEPARATOR + task.getStorageIndex(), true);
    client.createPersistentSequential(basePath + SEPARATOR + taskQueue + SEPARATOR + task.getStorageIndex() + SEPARATOR + task.getStorageIndex() + "_", false, jsonStr.getBytes());
    client.close();
}
Also used : CuratorClient(com.bonree.brfs.common.zookeeper.curator.CuratorClient) Date(java.util.Date)

Example 15 with CuratorClient

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

the class AuthenticationTest method testOpt.

public static void testOpt() throws InterruptedException {
    String basePath = "/brfs/wz/auth/user";
    String zkUrl = "192.168.101.86:2181";
    CuratorClient client = CuratorClient.getClientInstance(zkUrl);
    if (!client.checkExists(basePath)) {
        client.createPersistent(basePath, true);
    }
    client.close();
    SimpleAuthentication authentication = SimpleAuthentication.getAuthInstance(basePath, zkUrl);
    UserModel user = new UserModel("weizheng3", "weizheng3", (byte) 66);
    user.setDescription("weizheng3");
    authentication.createUser(user);
    Thread.sleep(1000);
    System.out.println(authentication.auth("weizheng3:weizheng3"));
    user.setPasswd("wz3");
    authentication.updateUser(user);
    Thread.sleep(1000);
    System.out.println(authentication.auth("weizheng3:wz3"));
    authentication.deleteUser("weizheng3");
    Thread.sleep(1000);
    System.out.println(authentication.auth("weizheng3:wz3"));
    Thread.sleep(Long.MAX_VALUE);
}
Also used : UserModel(com.bonree.brfs.authentication.model.UserModel) 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