use of com.bonree.brfs.common.net.http.HandleResult in project BRFS by zhangnianli.
the class UpdateStorageRegionMessageHandler method handleMessage.
@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
LOG.info("update storage region[{}] with attrs {}", msg.getName(), msg.getAttributes());
StorageRegion region = storageRegionManager.findStorageRegionByName(msg.getName());
if (region == null) {
callback.completed(new HandleResult(false));
return;
}
try {
StorageRegionConfig config = new StorageRegionConfig(region);
config.update(msg.getAttributes());
storageRegionManager.updateStorageRegion(msg.getName(), config);
callback.completed(new HandleResult(true));
} catch (Exception e) {
LOG.error("remove nonexist storage region");
callback.completed(new HandleResult(false));
}
}
use of com.bonree.brfs.common.net.http.HandleResult in project BRFS by zhangnianli.
the class OpenStorageRegionMessageHandler method handleMessage.
@Override
public void handleMessage(StorageRegionMessage msg, HandleResultCallback callback) {
LOG.info("open storage region[{}]", msg.getName());
StorageRegion node = storageRegionManager.findStorageRegionByName(msg.getName());
if (node == null || !node.isEnable()) {
callback.completed(new HandleResult(false));
return;
}
HandleResult result = new HandleResult();
result.setSuccess(true);
result.setData(Ints.toByteArray(node.getId()));
callback.completed(result);
}
use of com.bonree.brfs.common.net.http.HandleResult in project BRFS by zhangnianli.
the class ReadMessageHandler method handle.
@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
HandleResult result = new HandleResult();
try {
String filePath = diskContext.getConcreteFilePath(msg.getPath());
File dataFile = new File(filePath);
if (!dataFile.exists() || !dataFile.isFile()) {
result.setSuccess(false);
return;
}
String offsetParam = msg.getParams().get(PARAM_READ_OFFSET);
String lengthParam = msg.getParams().get(PARAM_READ_LENGTH);
int offset = offsetParam == null ? 0 : Integer.parseInt(offsetParam);
int length = (int) (lengthParam == null ? fileFormater.maxBodyLength() : Integer.parseInt(lengthParam));
length = (int) Math.min(length, dataFile.length() - 11);
LOG.info("read data offset[{}], size[{}] from file[{}]", offset, length, filePath);
byte[] data = null;
if (length < READ_LENGTH_LIMIT) {
data = Files.asByteSource(new File(filePath)).slice(fileFormater.absoluteOffset(offset), length).read();
} else {
data = DataFileReader.readFile(filePath, fileFormater.absoluteOffset(offset), length);
}
result.setSuccess(data.length != length ? false : true);
result.setData(data);
} catch (Exception e) {
LOG.error("read 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 WriteMessageHandler method handle.
@Override
public void handle(HttpMessage msg, HandleResultCallback callback) {
try {
String realPath = diskContext.getConcreteFilePath(msg.getPath());
LOG.debug("writing to file [{}]", realPath);
Pair<RecordFileWriter, WriteWorker> binding = writerManager.getBinding(realPath, false);
if (binding == null) {
// 运行到这,可能时打开文件时失败,导致写数据节点找不到writer
LOG.warn("no file writer is found, maybe the file[{}] is not opened.", realPath);
callback.completed(new HandleResult(false));
return;
}
binding.second().put(new DataWriteTask(binding, msg, callback));
} catch (Exception e) {
LOG.error("EEEERRRRRR", e);
HandleResult handleResult = new HandleResult();
handleResult.setSuccess(false);
handleResult.setCause(e);
callback.completed(handleResult);
}
}
use of com.bonree.brfs.common.net.http.HandleResult 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);
}
Aggregations