Search in sources :

Example 6 with Pair

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

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

the class CheckCycleJob method createSingleTask.

// /**
// * 概述:填补时间
// * @param snList
// * @param startTime
// * @return
// * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
// */
// public Map<String, Long> fixTimes(List<StorageRegion> snList, long startTime) {
// if ((snList == null) || (startTime <= 0L)) {
// return null;
// }
// Map<String,Long> fixMap = new HashMap<String,Long>();
// long crGra;
// String snName;
// long granule;
// for (StorageRegion sn : snList) {
// granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
// crGra = sn.getCreateTime() - sn.getCreateTime()%granule;
// snName = sn.getName();
// LOG.info("<fixTimes> sn {}, cTime:{}, time:{}", snName,crGra,startTime);
// if (crGra <= startTime) {
// fixMap.put(snName, Long.valueOf(startTime));
// }
// }
// return fixMap;
// }
/**
 * 概述:创建单个任务
 * @param release
 * @param needSns
 * @param services
 * @param taskType
 * @param sourceTimes
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public void createSingleTask(MetaTaskManagerInterface release, List<StorageRegion> needSns, List<Service> services, TaskType taskType, Map<String, Long> sourceTimes) throws Exception {
    Map losers = CopyCountCheck.collectLossFile(needSns, services, sourceTimes);
    Pair pair = CreateSystemTask.creatTaskWithFiles(sourceTimes, losers, needSns, taskType, CopyCheckJob.RECOVERY_NUM, 0L);
    if (pair == null) {
        LOG.warn("create pair is empty !!!!");
        return;
    }
    TaskModel task = (TaskModel) pair.getFirst();
    String taskName = null;
    if (task != null) {
        List<String> servers = CreateSystemTask.getServerIds(services);
        taskName = CreateSystemTask.updateTask(release, task, servers, TaskType.SYSTEM_COPY_CHECK);
    }
    if (!BrStringUtils.isEmpty(taskName)) {
        LOG.info("create {} {} task successfull !!!", taskType, taskName);
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) JobDataMap(org.quartz.JobDataMap) TaskModel(com.bonree.brfs.schedulers.task.model.TaskModel) Pair(com.bonree.brfs.common.utils.Pair)

Example 8 with Pair

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

the class DefaultReleaseTask method getServerStatus.

@Override
public List<Pair<String, Integer>> getServerStatus(String taskType, String taskName) {
    List<Pair<String, Integer>> serverStatus = new ArrayList<>();
    List<String> childeServers = getTaskServerList(taskType, taskName);
    if (childeServers == null || childeServers.isEmpty()) {
        return serverStatus;
    }
    Pair<String, Integer> stat;
    int iStat;
    TaskServerNodeModel tmpServer;
    for (String child : childeServers) {
        stat = new Pair<>();
        tmpServer = getTaskServerContentNodeInfo(taskType, taskName, child);
        stat.setFirst(child);
        iStat = tmpServer == null ? -3 : tmpServer.getTaskState();
        stat.setSecond(iStat);
        serverStatus.add(stat);
    }
    return serverStatus;
}
Also used : TaskServerNodeModel(com.bonree.brfs.schedulers.task.model.TaskServerNodeModel) ArrayList(java.util.ArrayList) Pair(com.bonree.brfs.common.utils.Pair)

Example 9 with Pair

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

the class CopyCountCheck method calcCopyCount.

/**
 * 概述:
 * @param snFiles
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static Map<StorageRegion, Pair<List<String>, List<String>>> calcCopyCount(Map<StorageRegion, List<String>> snFiles) {
    if (snFiles == null || snFiles.isEmpty()) {
        return null;
    }
    StorageRegion sn;
    List files;
    Map fileCopyCount;
    Pair<List<String>, List<String>> result;
    Map<StorageRegion, Pair<List<String>, List<String>>> copyMap = new HashMap<StorageRegion, Pair<List<String>, List<String>>>();
    for (Map.Entry<StorageRegion, List<String>> entry : snFiles.entrySet()) {
        sn = entry.getKey();
        files = entry.getValue();
        if (files == null || files.isEmpty()) {
            continue;
        }
        fileCopyCount = calcFileCount(files);
        if (fileCopyCount == null || fileCopyCount.isEmpty()) {
            continue;
        }
        result = filterLoser(fileCopyCount, sn.getReplicateNum());
        if (result == null) {
            continue;
        }
        copyMap.put(sn, result);
    }
    return copyMap;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashedMap(org.apache.commons.collections.map.HashedMap) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion) Pair(com.bonree.brfs.common.utils.Pair)

Example 10 with Pair

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

the class CreateSystemTask method creatTaskWithFiles.

/**
 * 概述:创建单个类型任务
 * @param snTimes
 * @param needSn
 * @param taskType
 * @return
 * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
 */
public static Pair<TaskModel, Map<String, Long>> creatTaskWithFiles(final Map<String, Long> snTimes, final Map<String, List<String>> snFiles, List<StorageRegion> needSn, TaskType taskType, String taskOperation, long globalTTL) {
    if (needSn == null || snTimes == null) {
        return null;
    }
    String snName;
    long startTime;
    long endTime;
    long currentTime = System.currentTimeMillis();
    List<AtomTaskModel> sumAtoms = new ArrayList<>();
    long ttl;
    Map<String, Long> lastSnTimes = new HashMap<>(snTimes);
    List<String> files = null;
    AtomTaskModel atom;
    long cGraTime;
    long granule = 0;
    for (StorageRegion sn : needSn) {
        granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
        cGraTime = currentTime - (currentTime % granule);
        snName = sn.getName();
        // 获取开始时间
        if (snTimes.containsKey(snName)) {
            startTime = snTimes.get(snName);
        } else {
            continue;
        }
        // 获取有效的过期时间
        ttl = getTTL(sn, taskType, globalTTL);
        endTime = startTime + granule;
        // 当ttl小于等于0 的sn 跳过
        if (ttl < 0) {
            LOG.debug("sn {} don't to create task !!!", snName);
            continue;
        }
        // 当未达到过期的跳过
        if (cGraTime - startTime < ttl || cGraTime - endTime < ttl) {
            LOG.debug("it's not time to check {}", snName);
            continue;
        }
        // 当前粒度不允许操作
        if (cGraTime == startTime) {
            LOG.warn("current time is forbid to check !!!");
            continue;
        }
        // 当无文件不操作
        if (snFiles != null) {
            files = snFiles.get(snName);
        }
        if (files != null && !files.isEmpty()) {
            atom = AtomTaskModel.getInstance(files, snName, taskOperation, sn.getReplicateNum(), startTime, endTime, granule);
            sumAtoms.add(atom);
        }
        lastSnTimes.put(snName, endTime);
    }
    if (sumAtoms == null || sumAtoms.isEmpty()) {
        return new Pair<>(null, lastSnTimes);
    }
    TaskModel task = TaskModel.getInitInstance(taskType, "1", 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)

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