Search in sources :

Example 16 with ResourceModel

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));
    }
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) DuplicateNode(com.bonree.brfs.duplication.filenode.duplicates.DuplicateNode) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 17 with ResourceModel

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

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