Search in sources :

Example 1 with ResourceModel

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;
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel)

Example 2 with ResourceModel

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;
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with ResourceModel

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);
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) Pair(com.bonree.brfs.common.utils.Pair)

Example 4 with ResourceModel

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;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Type(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent.Type) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) ExecutorService(java.util.concurrent.ExecutorService) ChildData(org.apache.curator.framework.recipes.cache.ChildData) ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) IOException(java.io.IOException)

Example 5 with ResourceModel

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();
    }
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) Pair(com.bonree.brfs.common.utils.Pair) Test(org.junit.Test)

Aggregations

ResourceModel (com.bonree.brfs.resourceschedule.model.ResourceModel)17 Pair (com.bonree.brfs.common.utils.Pair)8 Test (org.junit.Test)6 DiskNodeConnection (com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)2 EmailPool (com.bonree.brfs.email.EmailPool)2 MailWorker (com.bonree.mail.worker.MailWorker)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 DuplicateNode (com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode)1 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)1 LimitServerResource (com.bonree.brfs.resourceschedule.model.LimitServerResource)1 NetStatModel (com.bonree.brfs.resourceschedule.model.NetStatModel)1 PatitionStatModel (com.bonree.brfs.resourceschedule.model.PatitionStatModel)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 ChildData (org.apache.curator.framework.recipes.cache.ChildData)1 PathChildrenCacheEvent (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent)1 Type (org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent.Type)1