use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.
the class ResourceWriteSelector method getDuplicationNodes.
@Override
public DuplicateNode[] getDuplicationNodes(int storageId, int nums) {
long start = System.currentTimeMillis();
DuplicateNode[] duplicateNodes;
try {
StorageRegion sr = this.storageRegionManager.findStorageRegionById(storageId);
String srName = sr.getName();
if (sr == null) {
LOG.error("srid : {} is not exist !!!", storageId);
return new DuplicateNode[0];
}
// 获取资源信息
Collection<ResourceModel> resources = daemon.getClusterResources();
// 采集资源未上传则使用备用选择器
if (resources == null || resources.isEmpty()) {
LOG.warn("[{}] select resource list is empty !!!! use bak selector", groupName);
return this.bakSelector.getDuplicationNodes(storageId, nums);
}
// 过滤资源异常服务
Collection<ResourceModel> selectors = this.resourceSelector.filterService(resources, srName);
if (selectors == null || selectors.isEmpty()) {
LOG.error("[{}] none avaible server to selector !!!", groupName);
return new DuplicateNode[0];
}
// 按策略获取服务
Collection<ResourceModel> wins = this.resourceSelector.selector(selectors, srName, nums);
if (wins == null || wins.isEmpty()) {
LOG.error("[{}] no service can write !!!", groupName);
return new DuplicateNode[0];
}
if (wins.size() != nums) {
LOG.warn("[{}] service can write !!!need {} but give {} ", groupName, nums, wins.size());
}
duplicateNodes = new DuplicateNode[wins.size()];
Iterator<ResourceModel> iterator = wins.iterator();
int i = 0;
StringBuilder sBuild = new StringBuilder();
sBuild.append("select service -> ");
ResourceModel next;
while (iterator.hasNext()) {
next = iterator.next();
duplicateNodes[i] = new DuplicateNode(groupName, next.getServerId());
i++;
sBuild.append(i).append(":").append(next.getServerId()).append("(").append(next.getHost()).append(", remainSize").append(next.getLocalRemainSizeValue(srName)).append("b ), ");
}
LOG.info("{}", sBuild.toString());
return duplicateNodes;
} finally {
long stop = System.currentTimeMillis();
LOG.info("resource select node time: {} ms", (stop - start));
}
}
use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.
the class RandomAvailable method selectAvailableServers.
@Override
public List<Pair<String, Integer>> selectAvailableServers(int scene, String storageName, List<String> exceptionServerList, int centSize) {
if (resourceMap.isEmpty()) {
return null;
}
List<ResourceModel> tmp = convertList(resourceMap, exceptionServerList, scene, limit, storageName);
if (tmp.isEmpty()) {
return null;
}
List<Pair<String, Double>> values = new ArrayList<Pair<String, Double>>();
if (0 == scene) {
int index = Math.abs(new Random().nextInt()) % tmp.size();
}
if (BrStringUtils.isEmpty(storageName)) {
return null;
}
String server = null;
double sum = 0.0;
Pair<String, Double> tmpResource = null;
for (ResourceModel ele : tmp) {
server = ele.getServerId();
if (1 == scene) {
sum = ele.getDiskRemainValue(storageName) + ele.getDiskWriteValue(storageName);
} else if (2 == scene) {
sum = ele.getDiskReadValue(storageName);
} else {
continue;
}
tmpResource = new Pair<String, Double>(server, sum);
values.add(tmpResource);
}
if (values == null || values.isEmpty()) {
return null;
}
return converDoublesToIntegers(values, centSize);
}
Aggregations