Search in sources :

Example 1 with StorageNameNonexistentException

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

the class DeleteStorageRegionMessageHandler method handleMessage.

@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
    StorageRegion region = storageRegionManager.findStorageRegionByName(msg.getName());
    if (region == null) {
        callback.completed(new HandleResult(false));
        return;
    }
    boolean deleted;
    HandleResult result = new HandleResult();
    try {
        List<Service> services = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
        if (region.isEnable()) {
            result.setSuccess(false);
            result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
            callback.completed(result);
            return;
        }
        ReturnCode code = TasksUtils.createUserDeleteTask(services, zkPaths, region, region.getCreateTime(), System.currentTimeMillis(), true);
        if (!ReturnCode.SUCCESS.equals(code)) {
            result.setSuccess(false);
            result.setData(BrStringUtils.toUtf8Bytes(code.name()));
        } else {
            deleted = storageRegionManager.removeStorageRegion(msg.getName());
            result.setSuccess(deleted);
            if (deleted) {
                LOG.info("clean all data for " + msg.getName());
            } else {
                result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
            }
        }
    } catch (StorageNameNonexistentException e) {
        result.setSuccess(false);
        result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_NONEXIST_ERROR.name()));
    } catch (Exception e) {
        result.setSuccess(false);
        result.setData(BrStringUtils.toUtf8Bytes(ReturnCode.STORAGE_REMOVE_ERROR.name()));
    }
    callback.completed(result);
}
Also used : ReturnCode(com.bonree.brfs.common.ReturnCode) Service(com.bonree.brfs.common.service.Service) HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)

Example 2 with StorageNameNonexistentException

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

the class DeleteDataMessageHandler method handle.

@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    List<String> deleteInfo = Splitter.on("/").omitEmptyStrings().trimResults().splitToList(msg.getPath());
    if (deleteInfo.size() != 2) {
        result.setSuccess(false);
        result.setCause(new IllegalArgumentException(msg.getPath()));
        callback.completed(result);
        return;
    }
    int storageId = Integer.parseInt(deleteInfo.get(0));
    LOG.info("DELETE data for storage[{}]", storageId);
    StorageRegion sn = storageNameManager.findStorageRegionById(storageId);
    if (sn == null) {
        result.setSuccess(false);
        result.setCause(new StorageNameNonexistentException(storageId));
        callback.completed(result);
        LOG.info("storage[{}] is null", storageId);
        return;
    }
    List<String> times = Splitter.on("_").omitEmptyStrings().trimResults().splitToList(deleteInfo.get(1));
    ReturnCode code = checkTime(times.get(0), times.get(1), sn.getCreateTime(), Duration.parse(sn.getFilePartitionDuration()).toMillis());
    if (!ReturnCode.SUCCESS.equals(code)) {
        result.setSuccess(false);
        result.setData(BrStringUtils.toUtf8Bytes(code.name()));
        callback.completed(result);
        LOG.info("DELETE DATE Fail storage[{}] reason : {}", storageId, code.name());
        return;
    }
    long startTime = DateTime.parse(times.get(0)).getMillis();
    long endTime = DateTime.parse(times.get(1)).getMillis();
    LOG.info("DELETE DATA [{}-->{}]", times.get(0), times.get(1));
    List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
    code = TasksUtils.createUserDeleteTask(serviceList, zkPaths, sn, startTime, endTime, false);
    result.setSuccess(ReturnCode.SUCCESS.equals(code));
    result.setData(BrStringUtils.toUtf8Bytes(code.name()));
    callback.completed(result);
}
Also used : ReturnCode(com.bonree.brfs.common.ReturnCode) Service(com.bonree.brfs.common.service.Service) HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) StorageNameNonexistentException(com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)

Aggregations

ReturnCode (com.bonree.brfs.common.ReturnCode)2 HandleResult (com.bonree.brfs.common.net.http.HandleResult)2 Service (com.bonree.brfs.common.service.Service)2 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)2 StorageNameNonexistentException (com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)2