Search in sources :

Example 1 with StorageNameExistException

use of com.bonree.brfs.duplication.storageregion.exception.StorageNameExistException in project BRFS by zhangnianli.

the class DefaultStorageRegionManager method createStorageRegion.

@Override
public StorageRegion createStorageRegion(String regionName, StorageRegionConfig config) throws Exception {
    if (exists(regionName)) {
        throw new StorageNameExistException(regionName);
    }
    String regionPath = buildRegionPath(regionName);
    try {
        StorageRegion region = StorageRegion.newBuilder().setName(regionName).setId(idBuilder.createRegionId()).setCreateTime(System.currentTimeMillis()).setEnable(true).setReplicateNum(config.getReplicateNum()).setDataTtl(config.getDataTtl()).setFileCapacity(config.getFileCapacity()).setFilePartitionDuration(config.getFilePartitionDuration()).build();
        zkClient.create().forPath(regionPath, JsonUtils.toJsonBytes(region));
        return region;
    } catch (NodeExistsException e) {
        throw new StorageNameExistException(regionName);
    } catch (Exception e) {
        LOG.error("create storage name node error", e);
        throw e;
    }
}
Also used : StorageNameExistException(com.bonree.brfs.duplication.storageregion.exception.StorageNameExistException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) StorageNameExistException(com.bonree.brfs.duplication.storageregion.exception.StorageNameExistException) StorageNameRemoveException(com.bonree.brfs.duplication.storageregion.exception.StorageNameRemoveException) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Aggregations

StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)1 StorageNameExistException (com.bonree.brfs.duplication.storageregion.exception.StorageNameExistException)1 StorageNameNonexistentException (com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)1 StorageNameRemoveException (com.bonree.brfs.duplication.storageregion.exception.StorageNameRemoveException)1 ExecutionException (java.util.concurrent.ExecutionException)1 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)1 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)1