Search in sources :

Example 6 with HandleResult

use of com.bonree.brfs.common.net.http.HandleResult in project BRFS by zhangnianli.

the class DeleteMessageHandler method handle.

@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    try {
        String filePath = diskContext.getConcreteFilePath(msg.getPath());
        Map<String, String> params = msg.getParams();
        LOG.info("delete params--{}", params);
        DeleteData data = new DeleteData();
        data.setForceClose(params.containsKey("force") ? true : false);
        data.setRecursive(params.containsKey("recursive") ? true : false);
        LOG.info("deleting path[{}], force[{}], recursive[{}]", filePath, data.isForceClose(), data.isRecursive());
        File targetFile = new File(filePath);
        if (targetFile.isFile()) {
            try {
                closeFile(targetFile, data.isForceClose());
                result.setSuccess(true);
            } catch (Exception e) {
                result.setSuccess(false);
                result.setCause(e);
                return;
            }
        } else {
            try {
                closeDir(targetFile, data.isRecursive(), data.isForceClose());
                result.setSuccess(true);
            } catch (Exception e) {
                result.setSuccess(false);
                result.setCause(e);
                return;
            }
        }
    } catch (Exception e) {
        LOG.error("delete message error", e);
        result.setSuccess(false);
    } finally {
        callback.completed(result);
    }
}
Also used : DeleteData(com.bonree.brfs.disknode.server.handler.data.DeleteData) HandleResult(com.bonree.brfs.common.net.http.HandleResult) File(java.io.File)

Example 7 with HandleResult

use of com.bonree.brfs.common.net.http.HandleResult in project BRFS by zhangnianli.

the class FlushMessageHandler method handle.

@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
    HandleResult result = new HandleResult();
    String filePath = null;
    try {
        filePath = diskContext.getConcreteFilePath(msg.getPath());
        LOG.info("flush file[{}]", filePath);
        writerManager.flushFile(filePath);
        result.setSuccess(true);
    } catch (FileNotFoundException e) {
        result.setSuccess(false);
    } finally {
        callback.completed(result);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) HandleResult(com.bonree.brfs.common.net.http.HandleResult)

Example 8 with HandleResult

use of com.bonree.brfs.common.net.http.HandleResult 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 9 with HandleResult

use of com.bonree.brfs.common.net.http.HandleResult in project BRFS by zhangnianli.

the class WriteDataMessageHandler method handle.

@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
    WriteDataMessage writeMsg;
    try {
        writeMsg = ProtoStuffUtils.deserializeThrowable(msg.getContent(), WriteDataMessage.class);
        DataItem[] items = writeMsg.getItems();
        LOG.debug("Writing DataItem[{}]", items.length);
        if (items == null || items.length == 0) {
            callback.completed(new HandleResult(true));
            return;
        }
        writer.write(writeMsg.getStorageNameId(), items, new DataWriteCallback(callback));
    } catch (Exception e) {
        LOG.error("handle write data message error", e);
        callback.completed(new HandleResult(false));
    }
}
Also used : WriteDataMessage(com.bonree.brfs.common.write.data.WriteDataMessage) DataItem(com.bonree.brfs.common.write.data.DataItem) HandleResult(com.bonree.brfs.common.net.http.HandleResult) JsonException(com.bonree.brfs.common.utils.JsonUtils.JsonException)

Example 10 with HandleResult

use of com.bonree.brfs.common.net.http.HandleResult in project BRFS by zhangnianli.

the class CreateStorageRegionMessageHandler method handleMessage.

@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
    LOG.info("create storage region[{}] with attrs {}", msg.getName(), msg.getAttributes());
    try {
        StorageRegionConfig config = new StorageRegionConfig();
        config.update(msg.getAttributes());
        StorageRegion node = storageRegionManager.createStorageRegion(msg.getName(), config);
        LOG.info("created region[{}]", node);
        callback.completed(new HandleResult(true));
    } catch (Exception e) {
        callback.completed(new HandleResult(false));
    }
}
Also used : StorageRegionConfig(com.bonree.brfs.duplication.storageregion.StorageRegionConfig) HandleResult(com.bonree.brfs.common.net.http.HandleResult) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Aggregations

HandleResult (com.bonree.brfs.common.net.http.HandleResult)15 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)5 RecordFileWriter (com.bonree.brfs.disknode.data.write.RecordFileWriter)4 WriteWorker (com.bonree.brfs.disknode.data.write.worker.WriteWorker)4 File (java.io.File)4 Service (com.bonree.brfs.common.service.Service)3 ReturnCode (com.bonree.brfs.common.ReturnCode)2 StorageRegionConfig (com.bonree.brfs.duplication.storageregion.StorageRegionConfig)2 StorageNameNonexistentException (com.bonree.brfs.duplication.storageregion.exception.StorageNameNonexistentException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 FileObjectSyncState (com.bonree.brfs.common.filesync.FileObjectSyncState)1 JsonException (com.bonree.brfs.common.utils.JsonUtils.JsonException)1 DataItem (com.bonree.brfs.common.write.data.DataItem)1 WriteDataMessage (com.bonree.brfs.common.write.data.WriteDataMessage)1 DiskNodeClient (com.bonree.brfs.disknode.client.DiskNodeClient)1 ByteConsumer (com.bonree.brfs.disknode.client.DiskNodeClient.ByteConsumer)1 HttpDiskNodeClient (com.bonree.brfs.disknode.client.HttpDiskNodeClient)1 RecordElement (com.bonree.brfs.disknode.data.write.record.RecordElement)1