use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class ResourceDuplicateNodeSelector method getRandom.
/**
* 概述:随机返回数据节点
* @param storageId
* @param nums
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
private DuplicateNode[] getRandom(int storageId, int nums) {
List<Service> serviceList = serviceManager.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
if (serviceList.isEmpty()) {
LOG.info("[DUP] seviceList is empty");
return new DuplicateNode[0];
}
List<DuplicateNode> nodes = new ArrayList<DuplicateNode>();
while (!serviceList.isEmpty() && nodes.size() < nums) {
Service service = serviceList.remove(rand.nextInt(serviceList.size()));
DuplicateNode node = new DuplicateNode(service.getServiceGroup(), service.getServiceId());
DiskNodeConnection conn = connectionPool.getConnection(node.getGroup(), node.getId());
if (conn == null || conn.getClient() == null) {
continue;
}
nodes.add(node);
}
DuplicateNode[] result = new DuplicateNode[nodes.size()];
return nodes.toArray(result);
}
use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class MultiRecover3 method consumerQueue.
private Runnable consumerQueue() {
return new Runnable() {
@Override
public void run() {
try {
FileRecoverMeta fileRecover = null;
while (fileRecover != null || !overFlag) {
if (status.get().equals(TaskStatus.CANCEL)) {
break;
} else if (status.get().equals(TaskStatus.PAUSE)) {
LOG.info("task pause!!!");
Thread.sleep(1000);
} else if (status.get().equals(TaskStatus.RUNNING)) {
fileRecover = fileRecoverQueue.poll(1, TimeUnit.SECONDS);
if (fileRecover != null) {
// String localDir = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getReplica() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
String remoteDir = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getPot() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
// String localFilePath = dataDir + FileUtils.FILE_SEPARATOR + localDir + FileUtils.FILE_SEPARATOR + fileRecover.getFileName();
Service service = serviceManager.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), fileRecover.getFirstServerID());
boolean success = false;
while (true) {
if (status.get().equals(TaskStatus.PAUSE)) {
LOG.info("task pause!!!");
Thread.sleep(1000);
continue;
}
if (status.get().equals(TaskStatus.CANCEL)) {
break;
}
// if (!diskClient.isExistFile(service.getHost(), service.getPort(), logicPath)) {
success = secureCopyTo(service, fileRecover.getFilePath(), remoteDir, fileRecover.getFileName());
// }
if (success) {
break;
}
}
currentCount += 1;
detail.setCurentCount(currentCount);
detail.setProcess(detail.getCurentCount() / (double) detail.getTotalDirectories());
updateDetail(selfNode, detail);
if (success) {
// BalanceRecord record = new BalanceRecord(fileRecover.getFileName(), idManager.getSecondServerID(balanceSummary.getStorageIndex()),
// fileRecover.getFirstServerID());
// fileRecover.getSimpleWriter().writeRecord(record.toString());
}
LOG.info("update:" + selfNode + "-------------" + detail);
}
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}
use of com.bonree.brfs.common.service.Service in project BRFS by zhangnianli.
the class VirtualRecover3 method consumerQueue.
private Runnable consumerQueue() {
return new Runnable() {
@Override
public void run() {
try {
FileRecoverMeta fileRecover = null;
while (fileRecover != null || !overFlag) {
if (status.get().equals(TaskStatus.CANCEL)) {
break;
}
fileRecover = fileRecoverQueue.poll(100, TimeUnit.MILLISECONDS);
if (fileRecover != null) {
String logicPath = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getReplica() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
String remoteDir = storageName + FileUtils.FILE_SEPARATOR + fileRecover.getPot() + FileUtils.FILE_SEPARATOR + fileRecover.getTime();
String localFilePath = dataDir + FileUtils.FILE_SEPARATOR + logicPath + FileUtils.FILE_SEPARATOR + fileRecover.getFileName();
boolean success = false;
LOG.info("transfer :" + fileRecover);
String firstID = fileRecover.getFirstServerID();
Service service = serviceManager.getServiceById(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME), firstID);
while (true) {
// if (!diskClient.isExistFile(service.getHost(), service.getPort(), logicPath)) {
success = sucureCopyTo(service, localFilePath, remoteDir, fileRecover.getFileName());
// }
if (success) {
break;
}
}
currentCount += 1;
detail.setCurentCount(currentCount);
detail.setProcess(detail.getCurentCount() / (double) detail.getTotalDirectories());
updateDetail(selfNode, detail);
if (success) {
// BalanceRecord record = new BalanceRecord(fileRecover.getFileName(), idManager.getSecondServerID(balanceSummary.getStorageIndex()), fileRecover.getFirstServerID());
// fileRecover.getSimpleWriter().writeRecord(record.toString());
}
LOG.info("update:" + selfNode + "-------------" + detail);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
}
use of com.bonree.brfs.common.service.Service 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.service.Service in project BRFS by zhangnianli.
the class DefaultServiceManager method updateService.
@Override
public void updateService(String group, String serviceId, String payload) throws Exception {
LOG.info("update service payload for service[{}, {}, {}]", group, serviceId, payload);
Service service = getServiceById(group, serviceId);
if (service == null) {
throw new Exception("No service{group=" + group + ", id=" + serviceId + "} is found!");
}
service.setPayload(payload);
serviceDiscovery.updateService(buildFrom(service));
}
Aggregations