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