Search in sources :

Example 11 with Pair

use of com.bonree.brfs.common.utils.Pair in project BRFS by zhangnianli.

the class CreateSystemTask method creatSingleTask.

/**
 * 概述:创建单个类型任务
 * @param snTimes
 * @param needSn
 * @param taskType
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static Pair<TaskModel, Map<String, Long>> creatSingleTask(final Map<String, Long> snTimes, List<StorageRegion> needSn, TaskType taskType, long globalTTL) {
    String snName;
    long cTime;
    long startTime;
    long endTime;
    long currentTime = System.currentTimeMillis();
    List<AtomTaskModel> sumAtoms = new ArrayList<>();
    long ttl;
    Map<String, Long> lastSnTimes = new HashMap<>(snTimes);
    long cGraTime;
    long granule = 0;
    AtomTaskModel atom;
    for (StorageRegion sn : needSn) {
        granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
        cGraTime = currentTime - currentTime % granule;
        snName = sn.getName();
        cTime = sn.getCreateTime();
        // 获取开始时间
        if (snTimes.containsKey(snName)) {
            startTime = snTimes.get(snName);
        } else {
            startTime = cTime - cTime % granule;
        }
        // 获取有效的过期时间
        ttl = getTTL(sn, taskType, globalTTL);
        endTime = startTime + granule;
        LOG.debug("sn : {} ,ttl:{}, taskType,", sn.getName(), ttl, taskType.name());
        // 当ttl小于等于0 的sn 跳过
        if (ttl <= 0) {
            LOG.debug("sn {} don't to create task !!!", snName);
            continue;
        }
        // 当未达到过期的跳过
        if (cGraTime - startTime < ttl || cGraTime - endTime < ttl) {
            continue;
        }
        // 当前粒度不允许操作
        if (cGraTime == startTime) {
            continue;
        }
        atom = AtomTaskModel.getInstance(null, snName, "", sn.getReplicateNum(), startTime, endTime, granule);
        if (atom == null) {
            continue;
        }
        sumAtoms.add(atom);
        lastSnTimes.put(snName, endTime);
    }
    if (sumAtoms.isEmpty()) {
        return null;
    }
    TaskModel task = TaskModel.getInitInstance(taskType, "", granule);
    task.putAtom(sumAtoms);
    return new Pair<>(task, lastSnTimes);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel) AtomTaskModel(com.bonree.brfs.schedulers.task.model.AtomTaskModel) Pair(com.bonree.brfs.common.utils.Pair)

Example 12 with Pair

use of com.bonree.brfs.common.utils.Pair 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)

Example 13 with Pair

use of com.bonree.brfs.common.utils.Pair 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 14 with Pair

use of com.bonree.brfs.common.utils.Pair 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

Pair (com.bonree.brfs.common.utils.Pair)14 ResourceModel (com.bonree.brfs.resourceschedule.model.ResourceModel)8 Test (org.junit.Test)6 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)4 TaskModel (com.bonree.brfs.schedulers.task.model.TaskModel)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 AtomTaskModel (com.bonree.brfs.schedulers.task.model.AtomTaskModel)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 HashedMap (org.apache.commons.collections.map.HashedMap)2 LimitServerResource (com.bonree.brfs.resourceschedule.model.LimitServerResource)1 TaskServerNodeModel (com.bonree.brfs.schedulers.task.model.TaskServerNodeModel)1 Map (java.util.Map)1 JobDataMap (org.quartz.JobDataMap)1