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