use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class WatchDogJob method operation.
@Override
public void operation(JobExecutionContext context) throws Exception {
LOG.debug("watch dog do it >>>>>>>>>>>>>>");
JobDataMap data = context.getJobDetail().getJobDataMap();
String zkHosts = data.getString(JobDataMapConstract.ZOOKEEPER_ADDRESS);
String baseRoutPath = data.getString(JobDataMapConstract.BASE_ROUTE_PATH);
String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
if (BrStringUtils.isEmpty(dataPath) || BrStringUtils.isEmpty(baseRoutPath) || BrStringUtils.isEmpty(zkHosts)) {
LOG.warn("config is empty !! skip watchdog");
return;
}
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
ServerIDManager sim = mcf.getSim();
StorageRegionManager snm = mcf.getSnm();
List<StorageRegion> sns = snm.getStorageRegionList();
long preTime = System.currentTimeMillis();
LOG.info("Scan {} below data !!!", TimeUtils.formatTimeStamp(preTime));
WatchDog.searchPreys(sim, sns, zkHosts, baseRoutPath, dataPath, preTime);
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class GatherResourceJob method getStorageNameIdWithName.
/**
* 概述:获取storageName关系
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
private Map<Integer, String> getStorageNameIdWithName() {
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
StorageRegionManager snm = mcf.getSnm();
List<StorageRegion> sns = snm.getStorageRegionList();
Map<Integer, String> snToId = new ConcurrentHashMap<>();
if (sns == null || sns.isEmpty()) {
return snToId;
}
int id;
String name;
for (StorageRegion sn : sns) {
if (sn == null) {
continue;
}
name = sn.getName();
if (BrStringUtils.isEmpty(name)) {
continue;
}
id = sn.getId();
if (snToId.containsKey(id)) {
continue;
}
snToId.put(id, name);
}
return snToId;
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion in project BRFS by zhangnianli.
the class ServerChangeTaskGenetor method genChangeSummary.
private void genChangeSummary(Service service, ChangeType type) {
String firstID = service.getServiceId();
List<StorageRegion> snList = snManager.getStorageRegionList();
List<String> currentServers = getCurrentServers(serverManager);
LOG.info("fetch all storageRegion:" + snList);
for (StorageRegion snModel : snList) {
if (snModel.getReplicateNum() > 1) {
// TODO 此处需要判断是否配置了sn恢复
String secondID = idManager.getOtherSecondID(firstID, snModel.getId());
if (!StringUtils.isEmpty(secondID)) {
try {
ChangeSummary tsm = new ChangeSummary(snModel.getId(), genChangeID(), type, secondID, currentServers);
String jsonStr = JsonUtils.toJsonString(tsm);
String snTaskNode = ZKPaths.makePath(changesPath, String.valueOf(snModel.getId()), tsm.getChangeID());
client.createPersistent(snTaskNode, true, jsonStr.getBytes(StandardCharsets.UTF_8));
LOG.info("generator a change record:" + jsonStr + ", for storageRegion:" + snModel);
if (ChangeType.REMOVE == type) {
EmailPool emailPool = EmailPool.getInstance();
emailPool.sendEmail(MailWorker.newBuilder(emailPool.getProgramInfo()).setMessage(jsonStr));
}
} catch (Exception e) {
LOG.error("generator a change record failed for storageRegion:" + snModel, e);
e.printStackTrace();
}
}
}
}
}
use of com.bonree.brfs.duplication.storageregion.StorageRegion 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.duplication.storageregion.StorageRegion 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));
}
}
Aggregations