Search in sources :

Example 1 with ReturnCode

use of com.bonree.brfs.common.ReturnCode 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 ReturnCode

use of com.bonree.brfs.common.ReturnCode in project BRFS by zhangnianli.

the class DefaultStorageNameStick method deleteData.

@Override
public boolean deleteData(DateTime startTime, DateTime endTime) {
    try {
        Service[] serviceList = regionNodeSelector.select(regionNodeSelector.serviceNum());
        if (serviceList.length == 0) {
            throw new BRFSException("none disknode!!!");
        }
        for (Service service : serviceList) {
            StringBuilder pathBuilder = new StringBuilder();
            pathBuilder.append(config.getDuplicateUrlRoot()).append("/").append(storageId).append("/").append(startTime.toString()).append("_").append(endTime.toString());
            URI uri = new URIBuilder().setScheme(config.getUrlSchema()).setHost(service.getHost()).setPort(service.getPort()).setPath(pathBuilder.toString()).build();
            HttpResponse response = null;
            try {
                response = client.executeDelete(uri, defaultHeaders);
            } catch (Exception e) {
                LOG.warn("delete data http request failed", e);
                continue;
            }
            if (response == null) {
                throw new Exception("can not get response for createStorageName!");
            }
            if (response.isReponseOK()) {
                return true;
            }
            String code = new String(response.getResponseBody(), StandardCharsets.UTF_8);
            ReturnCode returnCode = ReturnCode.checkCode(storageName, code);
            LOG.info("returnCode:" + returnCode);
        }
    } catch (Exception e) {
        LOG.error("delete data error", e);
    }
    return false;
}
Also used : ReturnCode(com.bonree.brfs.common.ReturnCode) Service(com.bonree.brfs.common.service.Service) HttpResponse(com.bonree.brfs.common.net.http.client.HttpResponse) BRFSException(com.bonree.brfs.common.exception.BRFSException) URI(java.net.URI) BRFSException(com.bonree.brfs.common.exception.BRFSException) IOException(java.io.IOException) URIBuilder(com.bonree.brfs.common.net.http.client.URIBuilder)

Example 3 with ReturnCode

use of com.bonree.brfs.common.ReturnCode 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)3 Service (com.bonree.brfs.common.service.Service)3 HandleResult (com.bonree.brfs.common.net.http.HandleResult)2 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)2 StorageNameNonexistentException (com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)2 BRFSException (com.bonree.brfs.common.exception.BRFSException)1 HttpResponse (com.bonree.brfs.common.net.http.client.HttpResponse)1 URIBuilder (com.bonree.brfs.common.net.http.client.URIBuilder)1 IOException (java.io.IOException)1 URI (java.net.URI)1