use of com.bonree.brfs.common.task.TaskType in project BRFS by zhangnianli.
the class InitTaskManager method createAndStartThreadPool.
// /**
// * 概述:创建任务执行线程池
// * @param manager
// * @param zkPaths
// * @param config
// * @throws ParamsErrorException
// * @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
// */
// public static void createTaskOperationManager(SchedulerManagerInterface manager, ZookeeperPaths zkPaths,ResourceTaskConfig config) throws ParamsErrorException{
// // 1.创建执行线程池
// Properties prop = DefaultBaseSchedulers.createSimplePrope(1, 1000);
// manager.createTaskPool(TASK_OPERATION_MANAGER, prop);
// manager.startTaskPool(TASK_OPERATION_MANAGER);
//
// }
/**
* 概述:根据switchMap 创建线程池
* @param manager
* @throws ParamsErrorException
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
private static void createAndStartThreadPool(SchedulerManagerInterface manager, ResourceTaskConfig config) throws ParamsErrorException {
Map<String, Boolean> switchMap = config.getTaskPoolSwitchMap();
Map<String, Integer> sizeMap = config.getTaskPoolSizeMap();
Properties prop;
String poolName;
int count = 0;
int size;
for (TaskType taskType : TaskType.values()) {
poolName = taskType.name();
if (!switchMap.containsKey(poolName)) {
continue;
}
if (!switchMap.get(poolName)) {
continue;
}
size = sizeMap.get(poolName);
if (size == 0) {
LOG.warn("pool :{} config pool size is 0 ,will change to 1", poolName);
size = 1;
}
prop = DefaultBaseSchedulers.createSimplePrope(size, 1000l);
boolean createState = manager.createTaskPool(poolName, prop);
if (createState) {
manager.startTaskPool(poolName);
}
count++;
}
LOG.info("pool :{} count: {} started !!!", manager.getAllPoolKey(), count);
}
use of com.bonree.brfs.common.task.TaskType in project BRFS by zhangnianli.
the class InitTaskManager method initManager.
/**
* 概述:初始化任务服务系统
* @throws ParamsErrorException
* @user <a href=mailto:zhucg@bonree.com>朱成岗</a>
*/
public static void initManager(ResourceTaskConfig managerConfig, ZookeeperPaths zkPath, ServiceManager sm, StorageRegionManager snm, ServerIDManager sim, CuratorClient client) throws Exception {
managerConfig.printDetail();
ManagerContralFactory mcf = ManagerContralFactory.getInstance();
String serverId = sim.getFirstServerID();
mcf.setServerId(serverId);
mcf.setGroupName(Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_DATA_SERVICE_GROUP_NAME));
double diskRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_AVAILABLE_RATE);
double diskForceRemainRate = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_AVAILABLE_RATE);
double diskwriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_WRITE_SPEED);
double diskForcewriteValue = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_WRITE_SPEED);
long diskRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_DISK_REMAIN_SIZE);
long diskForceRemainSize = Configs.getConfiguration().GetConfig(ResourceConfigs.CONFIG_LIMIT_FORCE_DISK_REMAIN_SIZE);
LimitServerResource lmit = new LimitServerResource();
lmit.setDiskRemainRate(diskRemainRate);
lmit.setDiskWriteValue(diskwriteValue);
lmit.setForceDiskRemainRate(diskForceRemainRate);
lmit.setForceWriteValue(diskForcewriteValue);
lmit.setRemainWarnSize(diskRemainSize);
lmit.setRemainForceSize(diskForceRemainSize);
mcf.setLimitServerResource(lmit);
// 工厂类添加服务管理
mcf.setSm(sm);
// 工厂类添加storageName管理服务
mcf.setSnm(snm);
// 1.工厂类添加调度管理
SchedulerManagerInterface manager = DefaultSchedulersManager.getInstance();
mcf.setStm(manager);
// 工厂类添加发布接口
MetaTaskManagerInterface release = DefaultReleaseTask.getInstance();
if (release == null) {
LOG.error("Meta task is empty");
System.exit(1);
}
String zkAddresses = Configs.getConfiguration().GetConfig(CommonConfigs.CONFIG_ZOOKEEPER_ADDRESSES);
release.setPropreties(zkAddresses, zkPath.getBaseTaskPath(), zkPath.getBaseLocksPath());
if (client == null) {
LOG.error("zk client is empty");
System.exit(1);
}
mcf.setClient(client);
mcf.setTm(release);
// 工厂类添加任务可执行接口
RunnableTaskInterface run = DefaultRunnableTask.getInstance();
TaskExecutablePattern limit = TaskExecutablePattern.parse(managerConfig);
run.setLimitParameter(limit);
mcf.setRt(run);
mcf.setZkPath(zkPath);
mcf.setSim(sim);
// 创建任务线程池
if (managerConfig.isTaskFrameWorkSwitch()) {
// 1.创建任务管理服务
createMetaTaskManager(manager, zkPath, managerConfig, serverId);
// 2.启动任务线程池
List<TaskType> tasks = managerConfig.getSwitchOnTaskType();
if (tasks == null || tasks.isEmpty()) {
LOG.warn("switch task on but task type list is empty !!!");
return;
}
createAndStartThreadPool(manager, managerConfig);
if (tasks.contains(TaskType.SYSTEM_COPY_CHECK)) {
SumbitTaskInterface copyJob = createCopySimpleTask(managerConfig.getExecuteTaskIntervalTime(), TaskType.SYSTEM_COPY_CHECK.name(), serverId, CopyRecoveryJob.class.getCanonicalName(), zkAddresses, zkPath.getBaseRoutePath(), Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_DATA_ROOT));
manager.addTask(TaskType.SYSTEM_COPY_CHECK.name(), copyJob);
}
mcf.setTaskOn(tasks);
// 3.创建执行任务线程池
createOperationPool(managerConfig, zkPath, tasks, true);
}
if (managerConfig.isResourceFrameWorkSwitch()) {
// 创建资源调度服务
createResourceManager(manager, zkPath, managerConfig);
}
}
use of com.bonree.brfs.common.task.TaskType in project BRFS by zhangnianli.
the class ResourceTaskConfig method getSwitchOnTaskType.
public List<TaskType> getSwitchOnTaskType() {
List<TaskType> collect = new ArrayList<TaskType>();
if (taskPoolSwitchMap == null || taskPoolSwitchMap.isEmpty()) {
return null;
}
String task = null;
TaskType taskType = null;
for (Map.Entry<String, Boolean> entry : this.taskPoolSwitchMap.entrySet()) {
task = entry.getKey();
if (entry.getValue() && !BrStringUtils.isEmpty(task)) {
taskType = TaskType.valueOf(task);
if (taskType != null) {
collect.add(taskType);
}
}
}
return collect;
}
use of com.bonree.brfs.common.task.TaskType 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