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