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);
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations