use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.
the class GatherResource method calcResourceValue.
/**
* 概述:计算resource
* @param cluster
* @param stat
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static ResourceModel calcResourceValue(final BaseMetaServerModel cluster, final StatServerModel stat, String serverId, String ip) {
ResourceModel obj = new ResourceModel();
Map<String, Double> cacheMap = null;
long cacheNum = 0L;
double cpuValue = (1 - stat.getCpuRate()) * stat.getCpuCoreCount() / cluster.getCpuCoreCount();
double memoryValue = (1 - stat.getMemoryRate()) * stat.getMemorySize() / cluster.getMemoryTotalSize();
double diskRemainRate = stat.getTotalDiskSize() == 0 ? 0.0 : (double) stat.getRemainDiskSize() / stat.getTotalDiskSize();
obj.setServerId(serverId);
obj.setHost(ip);
obj.setCpuRate(stat.getCpuRate());
obj.setMemoryRate(stat.getMemoryRate());
obj.setDiskSize(stat.getTotalDiskSize());
obj.setCpuValue(cpuValue);
obj.setMemoryValue(memoryValue);
obj.setDiskRemainRate(diskRemainRate);
// 磁盘剩余
cacheNum = cluster.getDiskTotalSize();
cacheMap = CalcUtils.divDataDoubleMap(stat.getPartitionRemainSizeMap(), cacheNum);
obj.setDiskRemainValue(cacheMap);
// 设置磁盘剩余sizemap
obj.setLocalDiskRemainRate(calcRemainRate(stat.getPartitionRemainSizeMap(), stat.getPartitionTotalSizeMap()));
obj.setLocalRemainSizeValue(stat.getPartitionRemainSizeMap());
obj.setLocalSizeValue(stat.getPartitionTotalSizeMap());
// 磁盘读
cacheNum = cluster.getDiskReadMaxSpeed();
cacheMap = CalcUtils.divDiffDataDoubleMap(stat.getPartitionReadSpeedMap(), cacheNum);
obj.setDiskReadValue(cacheMap);
// 磁盘写
cacheNum = cluster.getDiskWriteMaxSpeed();
cacheMap = CalcUtils.divDiffDataDoubleMap(stat.getPartitionWriteSpeedMap(), cacheNum);
obj.setDiskWriteValue(cacheMap);
// 网卡接收
cacheNum = cluster.getNetRxMaxSpeed();
double netRS = (double) stat.getNetRSpeed() / cacheNum;
obj.setNetRxValue(netRS);
// 网卡发送
cacheNum = cluster.getNetTxMaxSpeed();
double netTS = stat.getNetTSpeed() / cacheNum;
obj.setNetTxValue(netTS);
obj.setStorageNameOnPartitionMap(stat.getStorageNameOnPartitionMap());
return obj;
}
use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.
the class RandomAvailable method convertList.
public List<ResourceModel> convertList(Map<String, ResourceModel> resourceMap, List<String> errors, int sence, LimitServerResource limit, String snName) {
List<ResourceModel> resources = new ArrayList<ResourceModel>();
if (resourceMap.isEmpty()) {
return resources;
}
String serverId = null;
ResourceModel r = null;
double remainValue = 0.0;
for (Map.Entry<String, ResourceModel> entry : resourceMap.entrySet()) {
serverId = entry.getKey();
if (errors != null && errors.contains(serverId)) {
continue;
}
if (sence == 1) {
remainValue = entry.getValue().getDiskRemainValue(snName);
if (remainValue <= limit.getDiskRemainRate()) {
continue;
}
}
r = entry.getValue();
if (r == null) {
continue;
}
resources.add(r);
}
return resources;
}
use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.
the class MachineResourceWriterSelector method covertValues.
public List<Pair<String, Integer>> covertValues(Collection<ResourceModel> resources, String path, int centSize) {
List<Pair<String, Double>> values = new ArrayList<>();
Pair<String, Double> tmpResource;
double sum;
String server;
for (ResourceModel resource : resources) {
server = resource.getServerId();
// 参数调整,disk写入io大的权重低
sum = resource.getDiskRemainValue(path) + 1 - resource.getDiskWriteValue(path);
tmpResource = new Pair<>(server, sum);
values.add(tmpResource);
}
return converDoublesToIntegers(values, centSize);
}
use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.
the class ResourceDuplicateNodeSelector method start.
/**
* 概述:启动监听
* @return
* @throws Exception
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public ResourceDuplicateNodeSelector start() throws Exception {
ExecutorService pool = Executors.newSingleThreadExecutor();
pathCache.start(StartMode.BUILD_INITIAL_CACHE);
pathCache.getListenable().addListener(new PathChildrenCacheListener() {
@Override
public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
Type type = event.getType();
ChildData data = event.getData();
if (data == null) {
LOG.warn("Event : {} ,ChildData is null", type);
return;
}
byte[] content = data.getData();
if (content == null || content.length == 0) {
LOG.warn("Event : {} ,Byte data is null", type);
return;
}
ResourceModel resource = JsonUtils.toObjectQuietly(content, ResourceModel.class);
if (resource == null) {
LOG.warn("Event : {} , Convert data is null", type);
return;
}
String str = JsonUtils.toJsonString(resource);
if (Type.CHILD_ADDED == type) {
available.add(resource);
} else if (Type.CHILD_REMOVED == type) {
available.remove(resource);
} else if (Type.CHILD_UPDATED == type) {
available.update(resource);
} else {
LOG.warn("event : {}, content:{}", type, str);
}
}
}, pool);
return this;
}
use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.
the class MachineResourceWriterSelectorTest method testSendEmail.
@Test
@SuppressWarnings("all")
public void testSendEmail() {
String groupName = "a";
String sn = "11";
int centSize = 100;
MachineResourceWriterSelector selector = new MachineResourceWriterSelector(null, null, null, groupName, 5, centSize);
int num = 2;
List<ResourceModel> list = new ArrayList<>();
List<Pair<String, Integer>> numList = new ArrayList<>();
ResourceModel obj;
Map<String, ResourceModel> resourceModelMap = new HashMap<>();
for (int i = 0; i < num; i++) {
obj = new ResourceModel();
obj.setHost("192.168.1.1");
obj.setServerId(String.valueOf(i));
list.add(obj);
numList.add(new Pair<>(String.valueOf(i), 100));
resourceModelMap.put(String.valueOf(i), obj);
}
selector.sendSelectEmail(list, sn, num);
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Aggregations