use of com.bonree.brfs.schedulers.task.model.TaskModel 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);
}
use of com.bonree.brfs.schedulers.task.model.TaskModel 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.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TasksUtils method createCopyTask.
/**
* 概述:根据CRC校验任务,创建副本数校验任务
* @param taskName
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static String createCopyTask(String taskName) {
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
List<String> sNames = release.getTaskServerList(TaskType.SYSTEM_CHECK.name(), taskName);
if (sNames == null || sNames.isEmpty()) {
LOG.error("CRC task [{}] get serviceList is empty!!!", taskName);
return null;
}
TaskModel task = converyCopyTaskModel(release, taskName);
return createTask(release, sNames, TaskType.SYSTEM_CHECK.name(), task);
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TasksUtils method getErrorFile.
/**
* 概述:生成任务信息
* @param taskContents
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static TaskModel getErrorFile(List<TaskServerNodeModel> taskContents) {
if (taskContents == null || taskContents.isEmpty()) {
return null;
}
TaskResultModel tmpR;
List<AtomTaskResultModel> tmpRs;
Map<String, Map<String, AtomTaskModel>> rmap = new HashMap<>();
Map<String, AtomTaskModel> emap;
String snName;
String key;
AtomTaskModel atom;
Map<String, Integer> snMap = new HashMap<>();
for (TaskServerNodeModel serverModel : taskContents) {
tmpR = serverModel.getResult();
if (tmpR == null) {
continue;
}
tmpRs = tmpR.getAtoms();
if (tmpRs == null || tmpRs.isEmpty()) {
continue;
}
for (AtomTaskResultModel r : tmpRs) {
if (r == null) {
continue;
}
snName = r.getSn();
if (!rmap.containsKey(snName)) {
rmap.put(snName, new HashMap<>());
}
if (!snMap.containsKey(snName)) {
snMap.put(snName, r.getPartNum());
}
emap = rmap.get(snName);
key = r.getDataStartTime() + "_" + r.getDataStopTime();
long granule = TimeUtils.getMiles(r.getDataStopTime(), TimeUtils.TIME_MILES_FORMATE) - TimeUtils.getMiles(r.getDataStartTime(), TimeUtils.TIME_MILES_FORMATE);
if (!emap.containsKey(key)) {
atom = AtomTaskModel.getInstance(null, snName, CopyCheckJob.RECOVERY_CRC, r.getPartNum(), r.getDataStartTime(), r.getDataStopTime(), granule);
emap.put(key, atom);
}
atom = emap.get(key);
atom.addAllFiles(r.getFiles());
}
}
List<AtomTaskModel> tList = filterError(rmap, snMap);
if (tList == null || tList.isEmpty()) {
return null;
}
TaskModel tTask = new TaskModel();
tTask.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
tTask.setAtomList(tList);
tTask.setTaskState(TaskState.INIT.code());
tTask.setTaskType(TaskType.SYSTEM_COPY_CHECK.code());
return tTask;
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TasksUtils method createUserDeleteTask.
/**
* 概述:
* @param services
* @param zkPaths
* @param sn
* @param startTime
* @param endTime
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static ReturnCode createUserDeleteTask(List<Service> services, ZookeeperPaths zkPaths, StorageRegion sn, long startTime, long endTime, boolean isAll) {
if (services == null || services.isEmpty()) {
return ReturnCode.DELETE_DATA_ERROR;
}
if (sn == null) {
return ReturnCode.STORAGE_NONEXIST_ERROR;
}
String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
MetaTaskManagerInterface release = DefaultReleaseTask.getInstance();
release.setPropreties(zkAddresses, zkPaths.getBaseTaskPath(), zkPaths.getBaseLocksPath());
TaskTypeModel tmodel = release.getTaskTypeInfo(TaskType.USER_DELETE.name());
if (!tmodel.isSwitchFlag()) {
return ReturnCode.FORBID_DELETE_DATA_ERROR;
}
TaskModel task = TasksUtils.createUserDelete(sn, TaskType.USER_DELETE, isAll ? UserDeleteJob.DELETE_SN_ALL : UserDeleteJob.DELETE_PART, startTime, endTime);
if (task == null) {
return ReturnCode.DELETE_DATA_ERROR;
}
List<String> serverIds = CreateSystemTask.getServerIds(services);
String taskName = CreateSystemTask.updateTask(release, task, serverIds, TaskType.USER_DELETE);
if (!BrStringUtils.isEmpty(taskName)) {
return ReturnCode.SUCCESS;
} else {
return ReturnCode.DELETE_DATA_ERROR;
}
}
Aggregations