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();
}
}
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();
}
}
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();
}
}
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();
}
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);
}
Aggregations