Search in sources :

Example 6 with EmailPool

use of com.bonree.brfs.email.EmailPool in project BRFS by zhangnianli.

the class GatherResourceJob method sendWarnEmail.

public void sendWarnEmail(ResourceModel resource, LimitServerResource limit) {
    Map<String, Long> remainSize = resource.getLocalRemainSizeValue();
    String mountPoint;
    long remainsize;
    Map<String, String> map = new HashMap<>();
    for (Map.Entry<String, Long> entry : remainSize.entrySet()) {
        mountPoint = entry.getKey();
        remainsize = entry.getValue();
        if (remainsize < limit.getRemainForceSize()) {
            map.put(mountPoint, "磁盘剩余量低于限制值 " + limit.getRemainForceSize() + ", 当前剩余值为" + remainsize + " 服务即将参与拒绝写入服务");
        } else if (remainsize < limit.getRemainWarnSize()) {
            map.put(mountPoint, "磁盘剩余量低于警告值 " + limit.getRemainWarnSize() + ", 当前剩余值为" + remainsize);
        }
    }
    long currentTime = System.currentTimeMillis();
    if (!map.isEmpty() && (currentTime - preTime) > INVERTTIME) {
        EmailPool emailPool = EmailPool.getInstance();
        MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
        builder.setModel(this.getClass().getSimpleName() + "模块服务告警");
        builder.setMessage(resource.getServerId() + "(" + resource.getHost() + ") 磁盘资源即将不足");
        builder.setVariable(map);
        emailPool.sendEmail(builder);
        preTime = currentTime;
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EmailPool(com.bonree.brfs.email.EmailPool) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JobDataMap(org.quartz.JobDataMap) MailWorker(com.bonree.mail.worker.MailWorker)

Example 7 with EmailPool

use of com.bonree.brfs.email.EmailPool in project BRFS by zhangnianli.

the class ServerChangeTaskGenetor method genChangeSummary.

private void genChangeSummary(Service service, ChangeType type) {
    String firstID = service.getServiceId();
    List<StorageRegion> snList = snManager.getStorageRegionList();
    List<String> currentServers = getCurrentServers(serverManager);
    LOG.info("fetch all storageRegion:" + snList);
    for (StorageRegion snModel : snList) {
        if (snModel.getReplicateNum() > 1) {
            // TODO 此处需要判断是否配置了sn恢复
            String secondID = idManager.getOtherSecondID(firstID, snModel.getId());
            if (!StringUtils.isEmpty(secondID)) {
                try {
                    ChangeSummary tsm = new ChangeSummary(snModel.getId(), genChangeID(), type, secondID, currentServers);
                    String jsonStr = JsonUtils.toJsonString(tsm);
                    String snTaskNode = ZKPaths.makePath(changesPath, String.valueOf(snModel.getId()), tsm.getChangeID());
                    client.createPersistent(snTaskNode, true, jsonStr.getBytes(StandardCharsets.UTF_8));
                    LOG.info("generator a change record:" + jsonStr + ", for storageRegion:" + snModel);
                    if (ChangeType.REMOVE == type) {
                        EmailPool emailPool = EmailPool.getInstance();
                        emailPool.sendEmail(MailWorker.newBuilder(emailPool.getProgramInfo()).setMessage(jsonStr));
                    }
                } catch (Exception e) {
                    LOG.error("generator a change record failed for storageRegion:" + snModel, e);
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : EmailPool(com.bonree.brfs.email.EmailPool) StorageRegion(com.bonree.brfs.duplication.storageregion.StorageRegion)

Example 8 with EmailPool

use of com.bonree.brfs.email.EmailPool 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) + "");
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) TaskType(com.bonree.brfs.common.task.TaskType) EmailPool(com.bonree.brfs.email.EmailPool) MetaTaskManagerInterface(com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) TaskState(com.bonree.brfs.common.task.TaskState) JobExecutionException(org.quartz.JobExecutionException) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException)

Example 9 with EmailPool

use of com.bonree.brfs.email.EmailPool in project BRFS by zhangnianli.

the class QuartzOperationStateWithZKTask method execute.

@Override
public void execute(JobExecutionContext context) {
    int currentIndex = -1;
    JobDataMap data = null;
    String serverId = null;
    String taskTypeName = null;
    String taskName = null;
    boolean isSuccess = true;
    try {
        data = context.getJobDetail().getJobDataMap();
        int repeatCount = data.getInt(JobDataMapConstract.TASK_REPEAT_RUN_COUNT);
        taskName = data.getString(JobDataMapConstract.TASK_NAME);
        serverId = data.getString(JobDataMapConstract.SERVER_ID);
        int taskType = data.getInt(JobDataMapConstract.TASK_TYPE);
        taskTypeName = TaskType.valueOf(taskType).name();
        // 设置当前任务执行
        if (!data.containsKey(JobDataMapConstract.CURRENT_INDEX)) {
            data.put(JobDataMapConstract.CURRENT_INDEX, repeatCount + "");
            TaskStateLifeContral.updateTaskRunState(serverId, taskName, taskTypeName);
            LOG.info("task {}-{} run", taskTypeName, taskName);
        }
        currentIndex = data.getInt(JobDataMapConstract.CURRENT_INDEX);
        LOG.debug("taskType [{}],taskname [{}],batch id[{}], data :[{}]", taskTypeName, taskName, currentIndex, data.getString(currentIndex + ""));
        operation(context);
    } catch (Exception e) {
        context.put("ExceptionMessage", e.getMessage());
        caughtException(context);
        isSuccess = false;
        LOG.error("task {}-{} happen exception:{}", taskTypeName, taskName, e);
        EmailPool emailPool = EmailPool.getInstance();
        MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
        builder.setModel(this.getClass().getSimpleName() + " execute 模块服务发生问题");
        builder.setException(e);
        ManagerContralFactory mcf = ManagerContralFactory.getInstance();
        builder.setMessage(mcf.getGroupName() + "(" + mcf.getServerId() + ")服务 执行任务时发生问题");
        builder.setVariable(data.getWrappedMap());
        emailPool.sendEmail(builder);
    } finally {
        if (data == null) {
            return;
        }
        LOG.debug("operation batch id {}", currentIndex);
        try {
            // 更新任务状态
            TaskResultModel resultTask = new TaskResultModel();
            resultTask.setSuccess(isSuccess);
            TaskStateLifeContral.updateMapTaskMessage(context, resultTask);
            // 更新要操作的批次
            if (currentIndex > 1) {
                data.put(JobDataMapConstract.CURRENT_INDEX, (currentIndex - 1) + "");
            // 最后一次更新任务信息
            } else if (currentIndex == 1) {
                String result = data.getString(JobDataMapConstract.TASK_RESULT);
                TaskResultModel tResult = new TaskResultModel();
                if (!BrStringUtils.isEmpty(result)) {
                    tResult = JsonUtils.toObjectQuietly(result, TaskResultModel.class);
                }
                TaskStateLifeContral.updateTaskStatusByCompelete(serverId, taskName, taskTypeName, tResult);
                data.put(JobDataMapConstract.CURRENT_INDEX, (currentIndex - 1) + "");
                LOG.info("task {}-{}:{} end!!", taskTypeName, taskName, tResult.isSuccess());
            }
        } catch (Exception e) {
            LOG.error("execute error", e);
            EmailPool emailPool = EmailPool.getInstance();
            MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
            builder.setModel(this.getClass().getSimpleName() + "模块服务发生问题");
            builder.setException(e);
            builder.setMessage("更新任务发生错误");
            builder.setVariable(data.getWrappedMap());
            emailPool.sendEmail(builder);
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) EmailPool(com.bonree.brfs.email.EmailPool) ManagerContralFactory(com.bonree.brfs.schedulers.ManagerContralFactory) TaskResultModel(com.bonree.brfs.schedulers.task.model.TaskResultModel) UnableToInterruptJobException(org.quartz.UnableToInterruptJobException)

Example 10 with EmailPool

use of com.bonree.brfs.email.EmailPool in project BRFS by zhangnianli.

the class DefaultSchedulersManager method addTask.

@Override
public boolean addTask(String taskpoolkey, SumbitTaskInterface task) throws ParamsErrorException {
    checkParams(taskpoolkey, task);
    BaseSchedulerInterface pool = taskPoolMap.get(taskpoolkey);
    if (pool == null) {
        return false;
    }
    try {
        return pool.addTask(task);
    } catch (Exception e) {
        LOG.error("add task error {},{},{}", taskpoolkey, task.getClassInstanceName(), e);
        EmailPool emailPool = EmailPool.getInstance();
        MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
        builder.setMessage("添加" + taskpoolkey + "任务发生异常 !!");
        builder.setVariable(task.getTaskContent());
        builder.setException(e);
        builder.setModel(this.getClass().getSimpleName());
        emailPool.sendEmail(builder);
        return false;
    }
}
Also used : BaseSchedulerInterface(com.bonree.brfs.schedulers.task.manager.BaseSchedulerInterface) EmailPool(com.bonree.brfs.email.EmailPool) ParamsErrorException(com.bonree.brfs.schedulers.exception.ParamsErrorException)

Aggregations

EmailPool (com.bonree.brfs.email.EmailPool)12 ManagerContralFactory (com.bonree.brfs.schedulers.ManagerContralFactory)7 JobDataMap (org.quartz.JobDataMap)6 UnableToInterruptJobException (org.quartz.UnableToInterruptJobException)4 TaskType (com.bonree.brfs.common.task.TaskType)3 MetaTaskManagerInterface (com.bonree.brfs.schedulers.task.manager.MetaTaskManagerInterface)3 MailWorker (com.bonree.mail.worker.MailWorker)3 CuratorClient (com.bonree.brfs.common.zookeeper.curator.CuratorClient)2 StorageRegion (com.bonree.brfs.duplication.storageregion.StorageRegion)2 ResourceModel (com.bonree.brfs.resourceschedule.model.ResourceModel)2 TaskResultModel (com.bonree.brfs.schedulers.task.model.TaskResultModel)2 IOException (java.io.IOException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 HashedMap (org.apache.commons.collections.map.HashedMap)2 Service (com.bonree.brfs.common.service.Service)1 ServiceManager (com.bonree.brfs.common.service.ServiceManager)1 TaskState (com.bonree.brfs.common.task.TaskState)1 JsonException (com.bonree.brfs.common.utils.JsonUtils.JsonException)1 DiskNodeClient (com.bonree.brfs.disknode.client.DiskNodeClient)1 TcpDiskNodeClient (com.bonree.brfs.disknode.client.TcpDiskNodeClient)1