use of com.bonree.brfs.schedulers.ManagerContralFactory in project BRFS by zhangnianli.
the class CreateSystemTaskJob method operation.
@Override
public void operation(JobExecutionContext context) {
LOG.info("create system task working");
// 判断是否有恢复任务,有恢复任务则不进行创建
JobDataMap data = context.getJobDetail().getJobDataMap();
long checkTtl = data.getLong(JobDataMapConstract.CHECK_TTL);
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
// 获取开启的任务名称
List<TaskType> switchList = mcf.getTaskOn();
if (switchList == null || switchList.isEmpty()) {
LOG.warn("switch on task is empty !!!");
return;
}
// 获取可用服务
String groupName = mcf.getGroupName();
ServiceManager sm = mcf.getSm();
// 2.设置可用服务
List<String> serverIds = CreateSystemTask.getServerIds(sm, groupName);
if (serverIds == null || serverIds.isEmpty()) {
LOG.warn("{} available server list is null", groupName);
return;
}
// 3.获取storageName
StorageRegionManager snm = mcf.getSnm();
List<StorageRegion> snList = snm.getStorageRegionList();
if (snList == null || snList.isEmpty()) {
LOG.info("skip create system task !!! because storageName is null !!!");
return;
}
TaskModel task;
String taskName;
TaskTypeModel tmodel;
long ttl = 0;
Pair<TaskModel, TaskTypeModel> result;
List<String> srs = TaskStateLifeContral.getSRs(snm);
for (TaskType taskType : switchList) {
if (TaskType.SYSTEM_COPY_CHECK.equals(taskType) || TaskType.USER_DELETE.equals(taskType)) {
continue;
}
TaskStateLifeContral.watchSR(release, srs, taskType.name());
if (TaskType.SYSTEM_DELETE.equals(taskType)) {
ttl = 0;
} else if (TaskType.SYSTEM_CHECK.equals(taskType)) {
ttl = checkTtl;
}
tmodel = release.getTaskTypeInfo(taskType.name());
if (tmodel == null) {
tmodel = new TaskTypeModel();
tmodel.setSwitchFlag(true);
LOG.warn("taskType{} is switch but metadata is null");
}
result = CreateSystemTask.createSystemTask(tmodel, taskType, snList, ttl);
if (result == null) {
LOG.warn("create sys task is empty {}", taskType.name());
continue;
}
task = result.getFirst();
taskName = CreateSystemTask.updateTask(release, task, serverIds, taskType);
if (!BrStringUtils.isEmpty(taskName)) {
LOG.info("create {} {} task successfull !!!", taskType.name(), taskName);
release.setTaskTypeModel(taskType.name(), tmodel);
}
}
}
use of com.bonree.brfs.schedulers.ManagerContralFactory in project BRFS by zhangnianli.
the class WatchDogJob method operation.
@Override
public void operation(JobExecutionContext context) throws Exception {
LOG.debug("watch dog do it >>>>>>>>>>>>>>");
JobDataMap data = context.getJobDetail().getJobDataMap();
String zkHosts = data.getString(JobDataMapConstract.ZOOKEEPER_ADDRESS);
String baseRoutPath = data.getString(JobDataMapConstract.BASE_ROUTE_PATH);
String dataPath = data.getString(JobDataMapConstract.DATA_PATH);
if (BrStringUtils.isEmpty(dataPath) || BrStringUtils.isEmpty(baseRoutPath) || BrStringUtils.isEmpty(zkHosts)) {
LOG.warn("config is empty !! skip watchdog");
return;
}
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
ServerIDManager sim = mcf.getSim();
StorageRegionManager snm = mcf.getSnm();
List<StorageRegion> sns = snm.getStorageRegionList();
long preTime = System.currentTimeMillis();
LOG.info("Scan {} below data !!!", TimeUtils.formatTimeStamp(preTime));
WatchDog.searchPreys(sim, sns, zkHosts, baseRoutPath, dataPath, preTime);
}
use of com.bonree.brfs.schedulers.ManagerContralFactory in project BRFS by zhangnianli.
the class GatherResourceJob method getStorageNameIdWithName.
/**
* 概述:获取storageName关系
* @return
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
private Map<Integer, String> getStorageNameIdWithName() {
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
StorageRegionManager snm = mcf.getSnm();
List<StorageRegion> sns = snm.getStorageRegionList();
Map<Integer, String> snToId = new ConcurrentHashMap<>();
if (sns == null || sns.isEmpty()) {
return snToId;
}
int id;
String name;
for (StorageRegion sn : sns) {
if (sn == null) {
continue;
}
name = sn.getName();
if (BrStringUtils.isEmpty(name)) {
continue;
}
id = sn.getId();
if (snToId.containsKey(id)) {
continue;
}
snToId.put(id, name);
}
return snToId;
}
use of com.bonree.brfs.schedulers.ManagerContralFactory 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.ManagerContralFactory in project BRFS by zhangnianli.
the class CycleJobWithZKTask method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
int taskTypeCode = 0;
int batchSize = 10;
String currentTaskName = null;
int batchIndex = 0;
TaskType taskType = null;
String serverId = null;
JobDataMap data = context.getJobDetail().getJobDataMap();
boolean isSuccess = true;
try {
// 获取当前的任务信息
taskTypeCode = data.getInt(JobDataMapConstract.TASK_TYPE);
taskType = TaskType.valueOf(taskTypeCode);
batchSize = data.getInt(JobDataMapConstract.BATCH_SIZE);
if (!data.containsKey(JobDataMapConstract.CURRENT_TASK_NAME)) {
data.put(JobDataMapConstract.CURRENT_TASK_NAME, "");
}
serverId = data.getString(JobDataMapConstract.SERVER_ID);
currentTaskName = data.getString(JobDataMapConstract.CURRENT_TASK_NAME);
if (!data.containsKey(JobDataMapConstract.CURRENT_INDEX)) {
data.put(JobDataMapConstract.CURRENT_INDEX, "0");
LOG.info("task:{}-{} start", taskType.name(), currentTaskName);
}
batchIndex = data.getInt(JobDataMapConstract.CURRENT_INDEX);
LOG.debug("current :{}, batchId : {}", currentTaskName, batchIndex);
if (batchSize == 0) {
batchSize = 10;
}
if (batchIndex >= 1) {
operation(context);
}
} catch (Exception e) {
LOG.info("happend Exception :{}", e);
context.put("ExceptionMessage", e.getMessage());
caughtException(context);
isSuccess = false;
EmailPool emailPool = EmailPool.getInstance();
MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
builder.setModel(this.getClass().getSimpleName() + "模块服务发生问题");
builder.setException(e);
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
builder.setMessage(mcf.getGroupName() + "(" + mcf.getServerId() + ")服务 执行任务时发生问题");
builder.setVariable(data.getWrappedMap());
emailPool.sendEmail(builder);
} finally {
// 判断是否有恢复任务,有恢复任务则不进行创建
if (WatchSomeThingJob.getState(WatchSomeThingJob.RECOVERY_STATUSE)) {
LOG.warn("rebalance task is running !! skip check copy task");
return;
}
if (batchIndex >= 1) {
LOG.debug("batch ID :{} {} {} {} {}", batchIndex, taskType, currentTaskName, serverId, isSuccess ? TaskState.RUN : TaskState.EXCEPTION);
TaskResultModel resultTask = new TaskResultModel();
resultTask.setSuccess(isSuccess);
TaskStateLifeContral.updateMapTaskMessage(context, resultTask);
}
// 最后一次执行更新任务状态并处理任务
if (batchIndex == 1) {
String result = data.getString(JobDataMapConstract.TASK_RESULT);
TaskResultModel tResult = new TaskResultModel();
if (!BrStringUtils.isEmpty(result)) {
tResult = JsonUtils.toObjectQuietly(result, TaskResultModel.class);
}
TaskState state = isSuccess && tResult.isSuccess() ? TaskState.FINISH : TaskState.EXCEPTION;
LOG.info("task:{}-{}-{} end !", taskType.name(), currentTaskName, state.name());
LOG.debug("batch ID :{} {} {} {} {}", batchIndex, taskType, currentTaskName, serverId, state);
TaskStateLifeContral.updateTaskStatusByCompelete(serverId, currentTaskName, taskType.name(), tResult);
data.put(JobDataMapConstract.CURRENT_INDEX, (batchIndex - 1) + "");
data.put(JobDataMapConstract.TASK_RESULT, "");
data.put(JobDataMapConstract.CURRENT_TASK_NAME, "");
data.put(JobDataMapConstract.CURRENT_INDEX, (batchIndex - 1) + "");
} else if (batchIndex <= 0) {
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
MetaTaskManagerInterface release = mcf.getTm();
// 创建任务
createBatchData(release, data, serverId, taskType, batchSize, 3);
} else {
// 更新任务状态
data.put(JobDataMapConstract.CURRENT_INDEX, (batchIndex - 1) + "");
}
}
}
Aggregations