Search in sources :

Example 6 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)

Example 7 with ResourceModel

use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.

the class MachineResourceWriterSelectorTest method testFiler01.

@Test
public void testFiler01() {
    String groupName = "a";
    int centSize = 100;
    LimitServerResource limit = new LimitServerResource();
    limit.setForceWriteValue(0.9);
    limit.setForceDiskRemainRate(0.01);
    limit.setDiskWriteValue(0.8);
    limit.setDiskRemainRate(0.05);
    limit.setRemainForceSize(20000000);
    limit.setRemainWarnSize(20000000);
    MachineResourceWriterSelector selector = new MachineResourceWriterSelector(null, null, limit, groupName, 5, centSize);
    int num = 1;
    List<ResourceModel> list = new ArrayList<>();
    List<Pair<String, Integer>> numList = new ArrayList<>();
    ResourceModel obj;
    String mount = "tmp";
    Map<String, Double> remainRateMap = new HashMap<>();
    remainRateMap.put("tmp", 0.04);
    Map<String, Double> writValue = new HashMap<>();
    writValue.put("tmp", 0.999);
    String sn = "sn";
    Map<String, String> snMap = new HashMap<>();
    snMap.put(sn, mount);
    for (int i = 0; i < num; i++) {
        obj = new ResourceModel();
        obj.setHost("192.168.3." + i);
        obj.setDiskSize(20000000L);
        obj.setServerId(String.valueOf(i));
        obj.setLocalDiskRemainRate(remainRateMap);
        obj.setDiskWriteValue(writValue);
        obj.setStorageNameOnPartitionMap(snMap);
        list.add(obj);
        numList.add(new Pair<>(String.valueOf(i), 100));
    }
    Collection<ResourceModel> wins = selector.filterService(list, sn);
    show(wins);
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) LimitServerResource(com.bonree.brfs.resourceschedule.model.LimitServerResource) Pair(com.bonree.brfs.common.utils.Pair) Test(org.junit.Test)

Example 8 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 9 with ResourceModel

use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.

the class GatherResource method calcResource.

/**
 * 概述:计算本机可用指标
 * @param base
 * @param stat
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static ResourceModel calcResource(BaseServerModel base, ServerStatModel stat) {
    ResourceModel obj = new ResourceModel();
    obj.setServerId(base.getServerId());
    Map<String, PatitionStatModel> patMap = stat.getPatitionStatInfoMap();
    Map<String, String> snToPat = base.getSnToDiskMap();
    long totalDisk = base.getTotalPatitionSize();
    long remain = 0;
    String sn = null;
    String mount = null;
    PatitionStatModel pat = null;
    NetStatModel net = null;
    for (Map.Entry<String, Long> entry : stat.getSnRemainSizeMap().entrySet()) {
        sn = entry.getKey();
        remain = entry.getValue();
        mount = snToPat.get(sn);
        // 没有挂载点的数据为最低
        if (mount == null) {
            obj.putClientSNRead(sn, 0.0);
            obj.putClientSNWrite(sn, 0.0);
            continue;
        }
        pat = patMap.get(mount);
        // 无磁盘状态信息的数据为最低
        if (pat == null) {
            obj.putClientSNRead(sn, 0.0);
            obj.putClientSNWrite(sn, 0.0);
            continue;
        }
        // 1.计算写请求 磁盘剩余率 +I/O请求
        double wValue = (double) remain / totalDisk + (pat.getWriteMaxSpeed() - pat.getWriteSpeed() / pat.getCount()) / pat.getWriteMaxSpeed();
        double rValue = (double) (pat.getReadMaxSpeed() - pat.getReadSpeed() / pat.getCount()) / pat.getReadMaxSpeed();
        double remainValue = (double) remain / (pat.getRemainSize() + pat.getUsedSize());
        obj.putClientSNRead(sn, rValue);
        obj.putClientSNWrite(sn, wValue);
        obj.putSnRemainRate(sn, remainValue);
    }
    return null;
}
Also used : PatitionStatModel(com.bonree.brfs.resourceschedule.model.PatitionStatModel) NetStatModel(com.bonree.brfs.resourceschedule.model.NetStatModel) ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 10 with ResourceModel

use of com.bonree.brfs.resourceschedule.model.ResourceModel in project BRFS by zhangnianli.

the class MachineResourceWriterSelectorTest method testSelect02.

@Test
public void testSelect02() {
    String groupName = "a";
    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.3." + i);
        obj.setServerId(String.valueOf(i));
        list.add(obj);
        numList.add(new Pair<>(String.valueOf(i), 100));
        resourceModelMap.put(String.valueOf(i), obj);
    }
    Collection<ResourceModel> wins = selector.selectNode(null, resourceModelMap, numList, groupName, 3);
    show(wins);
}
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