Search in sources :

Example 11 with ResourceModel

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

the class MachineResourceWriterSelectorTest method testSelect.

@Test
public void testSelect() {
    String groupName = "a";
    int centSize = 100;
    MachineResourceWriterSelector selector = new MachineResourceWriterSelector(null, null, null, groupName, 5, centSize);
    int num = 3;
    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);
        resourceModelMap.put(String.valueOf(i), obj);
        numList.add(new Pair<>(String.valueOf(i), 100));
    }
    Collection<ResourceModel> wins = selector.selectNode(null, resourceModelMap, numList, groupName, num);
    show(wins);
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) Pair(com.bonree.brfs.common.utils.Pair) Test(org.junit.Test)

Example 12 with ResourceModel

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

the class MachineResourceWriterSelector method selectNode.

/**
 * 服务选择
 * @param intValues
 * @param num
 * @return
 */
public List<ResourceModel> selectNode(DiskNodeConnectionPool pool, Map<String, ResourceModel> map, List<Pair<String, Integer>> intValues, String groupName, int num) {
    List<ResourceModel> resourceModels = new ArrayList<>();
    String key;
    String ip;
    ResourceModel tmp;
    DiskNodeConnection conn;
    // ip选中优先选择
    Set<String> ips = new HashSet<>();
    List<String> uneedServices = new ArrayList<>();
    int tSize = map.size();
    // 按资源选择
    while (resourceModels.size() != num && resourceModels.size() != tSize && uneedServices.size() != tSize) {
        key = WeightRandomPattern.getWeightRandom(intValues, new Random(), uneedServices);
        tmp = map.get(key);
        ip = tmp.getHost();
        if (pool != null) {
            conn = pool.getConnection(groupName, key);
            if (conn == null || !conn.isValid()) {
                LOG.warn("{} :[{}({})]is unused !!", groupName, key, ip);
                uneedServices.add(key);
                continue;
            }
        }
        // 不同ip的添加
        if (ips.add(ip)) {
            resourceModels.add(tmp);
        } else {
            LOG.info("{} is selectd !! get next", ip);
        }
        uneedServices.add(tmp.getServerId());
    }
    return resourceModels;
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection)

Example 13 with ResourceModel

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

the class MachineResourceWriterSelector method selectRandom.

/**
 * 随机选择
 * @param pool
 * @param map
 * @param sids
 * @param intValues
 * @param groupName
 * @param sn
 * @param num
 * @return
 */
public Collection<ResourceModel> selectRandom(DiskNodeConnectionPool pool, Map<String, ResourceModel> map, Set<String> sids, List<Pair<String, Integer>> intValues, String groupName, String sn, int num) {
    List<ResourceModel> resourceModels = new ArrayList<>();
    String key;
    String ip;
    ResourceModel tmp;
    DiskNodeConnection conn;
    // ip选中优先选择
    int tSize = map.size();
    // 按资源选择
    Random random = new Random();
    boolean sendFlag = System.currentTimeMillis() - repeatTime > INVERTTIME;
    repeatTime = sendFlag ? System.currentTimeMillis() : repeatTime;
    while (resourceModels.size() != num && resourceModels.size() != tSize && sids.size() != tSize) {
        key = WeightRandomPattern.getWeightRandom(intValues, random, sids);
        tmp = map.get(key);
        ip = tmp.getHost();
        if (pool != null) {
            conn = pool.getConnection(groupName, key);
            if (conn == null || !conn.isValid()) {
                LOG.warn("{} :[{}({})]is unused !!", groupName, key, ip);
                sids.add(key);
                continue;
            }
        }
        if (sendFlag) {
            EmailPool emailPool = EmailPool.getInstance();
            MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo()).setModel(this.getClass().getSimpleName() + "服务选择").setMessage("sr [" + sn + "]即将 在 " + key + "(" + ip + ") 服务 写入重复数据");
            emailPool.sendEmail(builder);
        }
        resourceModels.add(tmp);
        sids.add(tmp.getServerId());
    }
    return resourceModels;
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) EmailPool(com.bonree.brfs.email.EmailPool) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection) MailWorker(com.bonree.mail.worker.MailWorker)

Example 14 with ResourceModel

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

the class MachineResourceWriterSelector method filterService.

@Override
public Collection<ResourceModel> filterService(Collection<ResourceModel> resourceModels, String sn) {
    // 无资源
    if (resourceModels == null || resourceModels.isEmpty()) {
        LOG.warn("no resource to selector");
        return null;
    }
    Set<ResourceModel> wins = new HashSet<>();
    long diskRemainSize;
    int numSize = this.storer == null ? 0 : this.storer.fileNodeSize();
    List<ResourceModel> washroom = new ArrayList<>();
    // 将已经满足条件的服务过滤
    for (ResourceModel wash : resourceModels) {
        diskRemainSize = wash.getLocalRemainSizeValue(sn);
        if (diskRemainSize < this.limit.getRemainForceSize()) {
            LOG.warn("First sn: {} {}({}), path: {} remainsize: {}, force:{} !! will refused", sn, wash.getServerId(), wash.getHost(), wash.getMountedPoint(sn), diskRemainSize, this.limit.getRemainForceSize());
            continue;
        }
        washroom.add(wash);
    }
    if (washroom.isEmpty()) {
        return null;
    }
    int size = washroom.size();
    // 预测值,假设现在所有正在写的文件大小为0,并且每个磁盘节点都写入。通过现有写入的文件的数×配置的文件大小即可得单个数据节点写入数据的大小
    long writeSize = numSize * fileSize / size;
    for (ResourceModel resourceModel : washroom) {
        diskRemainSize = resourceModel.getLocalRemainSizeValue(sn) - writeSize;
        if (diskRemainSize < this.limit.getRemainForceSize()) {
            LOG.warn("Second sn: {} {}({}), path: {} remainsize: {}, force:{} !! will refused", sn, resourceModel.getServerId(), resourceModel.getHost(), resourceModel.getMountedPoint(sn), diskRemainSize, this.limit.getRemainForceSize());
            continue;
        }
        if (diskRemainSize < this.limit.getRemainWarnSize()) {
            LOG.warn("sn: {} {}({}), path: {} remainsize: {}, force:{} !! will full", sn, resourceModel.getServerId(), resourceModel.getHost(), resourceModel.getMountedPoint(sn), diskRemainSize, this.limit.getRemainForceSize());
        }
        wins.add(resourceModel);
    }
    return wins;
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel)

Example 15 with ResourceModel

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

the class MachineResourceWriterSelector method sendSelectEmail.

/**
 * 发送选择邮件
 * @param resourceModels
 * @param sn
 * @param num
 */
public void sendSelectEmail(Collection<ResourceModel> resourceModels, String sn, int num) {
    StringBuilder messageBuilder = new StringBuilder();
    messageBuilder.append("sr:[").append(sn).append("] 写入可供选择的服务少于需要的!! 可用服务 ").append(resourceModels.size()).append(", 需要 ").append(num).append("(文件分布见上下文表格)");
    Map<String, String> map = new HashMap<>();
    String part;
    String key;
    for (ResourceModel resource : resourceModels) {
        key = resource.getServerId() + "(" + resource.getHost() + ")";
        part = sn + "[path:" + resource.getMountedPoint(sn) + ", remainSize: " + resource.getLocalRemainSizeValue(sn) + "b]";
        map.put(key, part);
    }
    EmailPool emailPool = EmailPool.getInstance();
    MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
    builder.setModel(this.getClass().getSimpleName() + "服务选择");
    builder.setMessage(messageBuilder.toString());
    if (!map.isEmpty()) {
        builder.setVariable(map);
    }
    emailPool.sendEmail(builder);
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) EmailPool(com.bonree.brfs.email.EmailPool) MailWorker(com.bonree.mail.worker.MailWorker)

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