use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TaskStateLifeContral method updateTaskStatusByCompelete.
/**
* 概述:更新任务状态
* @param serverId
* @param taskname
* @param taskType
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static void updateTaskStatusByCompelete(String serverId, String taskname, String taskType, TaskResultModel taskResult) {
if (BrStringUtils.isEmpty(taskname)) {
LOG.warn("task name is empty !!! {} {} {}", taskType, taskname, serverId);
return;
}
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
TaskServerNodeModel sTask = release.getTaskServerContentNodeInfo(taskType, taskname, serverId);
if (sTask == null) {
LOG.debug("server task is null !!! {} {} {}", taskType, taskname, serverId);
sTask = new TaskServerNodeModel();
}
LOG.debug("TaskMessage complete sTask :{}", JsonUtils.toJsonStringQuietly(sTask));
sTask.setResult(taskResult);
if (BrStringUtils.isEmpty(sTask.getTaskStartTime())) {
sTask.setTaskStartTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
}
sTask.setTaskStopTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
TaskState status = taskResult == null ? TaskState.EXCEPTION : taskResult.isSuccess() ? TaskState.FINISH : TaskState.EXCEPTION;
sTask.setTaskState(status.code());
release.updateServerTaskContentNode(serverId, taskname, taskType, sTask);
LOG.info("Complete server task :{} - {} - {} - {}", taskType, taskname, serverId, TaskState.valueOf(sTask.getTaskState()).name());
// 更新TaskContent
List<Pair<String, Integer>> cStatus = release.getServerStatus(taskType, taskname);
if (cStatus == null || cStatus.isEmpty()) {
return;
}
LOG.debug("complete c List {}", cStatus);
int cstat;
boolean isException = false;
int finishCount = 0;
int size = cStatus.size();
for (Pair<String, Integer> pair : cStatus) {
cstat = pair.getSecond();
if (TaskState.EXCEPTION.code() == cstat) {
isException = true;
finishCount += 1;
} else if (TaskState.FINISH.code() == cstat) {
finishCount += 1;
}
}
if (finishCount != size) {
return;
}
TaskModel task = release.getTaskContentNodeInfo(taskType, taskname);
if (task == null) {
LOG.debug("task is null !!! {} {} {}", taskType, taskname);
task = new TaskModel();
task.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
}
if (isException) {
task.setTaskState(TaskState.EXCEPTION.code());
} else {
task.setTaskState(TaskState.FINISH.code());
}
release.updateTaskContentNode(task, taskType, taskname);
LOG.info("complete task :{} - {} - {}", taskType, taskname, TaskState.valueOf(task.getTaskState()).name());
if (TaskType.SYSTEM_CHECK.name().equals(taskType) && isException) {
TaskModel cTask = TasksUtils.converyCopyTaskModel(release, taskname);
if (cTask == null) {
LOG.error("[{}]:[{}] task can't recovery !!!", taskType, taskname);
return;
}
String str = TasksUtils.createCopyTask(release, taskname, cTask);
if (BrStringUtils.isEmpty(str)) {
boolean flag = release.setTransferTask(taskType, taskname);
LOG.info("[{}] task [{}] find error ,transfer task create {} ", taskType, taskname, flag ? "succefull !!!" : " fail !!!");
} else {
LOG.info("[{}]:[{}] find error create copy task [{}] to recovery ", taskType, taskname, str);
}
}
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class TasksUtils method createUserDelete.
/**
* 概述:创建可执行任务信息
* @param sn storageName信息
* @param taskType 任务类型
* @param opertationContent 执行的内容,暂时无用
* @param startTime 要操作数据的开始时间 -1标识为sn的创建时间
* @param endTime 要操作数据的结束时间。
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static TaskModel createUserDelete(final StorageRegion sn, final TaskType taskType, final String opertationContent, final long startTime, final long endTime) {
if (sn == null || taskType == null) {
return null;
}
TaskModel task = new TaskModel();
List<AtomTaskModel> storageAtoms = new ArrayList<>();
if (endTime == 0 || startTime >= endTime) {
return null;
}
long granule = Duration.parse(sn.getFilePartitionDuration()).toMillis();
String snName = sn.getName();
long startHour;
long endHour = endTime - endTime % granule;
// 删除sn
boolean isALL = UserDeleteJob.DELETE_SN_ALL.equals(opertationContent);
if (isALL) {
startHour = sn.getCreateTime() - sn.getCreateTime() % granule;
} else {
startHour = startTime - startTime % granule;
}
// 若是删除sn时,创建时间与删除时间间隔较短时,结束时间向后退
if (startHour == endHour) {
endHour = endHour + granule;
}
if (startHour >= endHour) {
return null;
}
AtomTaskModel atom = AtomTaskModel.getInstance(null, snName, opertationContent, sn.getReplicateNum(), startHour, endHour, granule);
storageAtoms.add(atom);
task.setAtomList(storageAtoms);
task.setTaskState(TaskState.INIT.code());
task.setCreateTime(TimeUtils.formatTimeStamp(System.currentTimeMillis(), TimeUtils.TIME_MILES_FORMATE));
task.setTaskType(taskType.code());
return task;
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class CycleJobWithZKTask method createBatchData.
public void createBatchData(MetaTaskManagerInterface release, JobDataMap data, String serverId, TaskType taskType, int batchSize, int limitCount) {
// 从zk获取任务信息最后一次执行成功的 若任务为空则返回
Pair<String, TaskModel> taskPair = TaskStateLifeContral.getCurrentOperationTask(release, taskType.name(), serverId, limitCount);
if (taskPair == null) {
LOG.info("{} task queue is empty !!!", taskType.name());
return;
}
// 将当前的任务分成批次执行
TaskModel task = TaskStateLifeContral.changeRunTaskModel(taskPair.getSecond());
String currentTaskName = taskPair.getFirst();
if (BrStringUtils.isEmpty(currentTaskName)) {
LOG.info("{} {} task behind is empty !!!", taskType.name());
return;
}
Map<String, String> batchDatas = BatchTaskFactory.createBatch(task, batchSize);
// 若批次为空则更新任务状态
if (batchDatas == null || batchDatas.isEmpty()) {
LOG.info("batch data is empty !! update task :{} {}", taskType.name(), currentTaskName);
TaskStateLifeContral.updateTaskStatusByCompelete(serverId, currentTaskName, taskType.name(), new TaskResultModel());
data.put(JobDataMapConstract.CURRENT_TASK_NAME, "");
data.put(JobDataMapConstract.CURRENT_INDEX, 0 + "");
return;
}
data.putAll(batchDatas);
data.put(JobDataMapConstract.CURRENT_TASK_NAME, currentTaskName);
// 更新zk任务状态
TaskStateLifeContral.updateTaskRunState(serverId, currentTaskName, taskType.name());
}
use of com.bonree.brfs.schedulers.task.model.TaskModel in project BRFS by zhangnianli.
the class CopyCheckJob method operation.
@Override
public void operation(JobExecutionContext context) throws Exception {
LOG.info("createCheck Copy Job working");
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
StorageRegionManager snm = mcf.getSnm();
ServiceManager sm = mcf.getSm();
List<String> srs = TaskStateLifeContral.getSRs(snm);
TaskStateLifeContral.watchSR(release, srs, TaskType.SYSTEM_COPY_CHECK.name());
// 判断是否有恢复任务,有恢复任务则不进行创建
if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
LOG.warn("rebalance task is running !! skip check copy task");
return;
}
String taskType = TaskType.SYSTEM_COPY_CHECK.name();
List<Service> services = sm.getServiceListByGroup(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
if (services == null || services.isEmpty()) {
LOG.warn("skip create {} task, because service is empty", taskType);
return;
}
List<StorageRegion> snList = snm.getStorageRegionList();
if (snList == null || snList.isEmpty()) {
LOG.warn("storagename list is null");
return;
}
// 1.获取sn创建任务的实际那
TaskTypeModel tmodel = release.getTaskTypeInfo(taskType);
if (tmodel == null) {
tmodel = new TaskTypeModel();
tmodel.setSwitchFlag(true);
release.setTaskTypeModel(taskType, tmodel);
}
Map<String, Long> sourceTimes = tmodel.getSnTimes();
LOG.debug("update init sn time :{}", sourceTimes);
// 2.过滤不符合副本校验的sn信息
List<StorageRegion> needSns = CopyCountCheck.filterSn(snList, services.size());
// 3.针对第一次出现的sn补充时间
sourceTimes = CopyCountCheck.repairTime(sourceTimes, needSns);
Map<String, List<String>> losers = CopyCountCheck.collectLossFile(needSns, services, sourceTimes);
LOG.info("update before sn time :{}", sourceTimes);
Pair<TaskModel, Map<String, Long>> pair = CreateSystemTask.creatTaskWithFiles(sourceTimes, losers, needSns, TaskType.SYSTEM_COPY_CHECK, RECOVERY_NUM, 0);
if (pair == null) {
LOG.warn("create pair is empty !!!!");
return;
}
TaskModel task = 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);
}
sourceTimes = pair.getSecond();
// 更新sn临界信息
tmodel = release.getTaskTypeInfo(taskType);
if (tmodel == null) {
tmodel = new TaskTypeModel();
tmodel.setSwitchFlag(true);
LOG.warn("taskType {} metadata loss create against !!", taskType);
}
tmodel.putAllSnTimes(sourceTimes);
release.setTaskTypeModel(taskType, tmodel);
LOG.debug("update sn time {}", sourceTimes);
createTransferTasks(release);
}
use of com.bonree.brfs.schedulers.task.model.TaskModel 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);
}
}
Aggregations