Search in sources :

Example 11 with EmailPool

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

the class MachineResourceWriterSelector method selectRandom.

/**
 * 随机选择
 * @param pool
 * @param map
 * @param sids
 * @param intValues
 * @param groupName
 * @param sn
 * @param num
 * @return
 */
public Collection<ResourceModel> selectRandom(DiskNodeConnectionPool pool, Map<String, ResourceModel> map, Set<String> sids, List<Pair<String, Integer>> intValues, String groupName, String sn, int num) {
    List<ResourceModel> resourceModels = new ArrayList<>();
    String key;
    String ip;
    ResourceModel tmp;
    DiskNodeConnection conn;
    // ip选中优先选择
    int tSize = map.size();
    // 按资源选择
    Random random = new Random();
    boolean sendFlag = System.currentTimeMillis() - repeatTime > INVERTTIME;
    repeatTime = sendFlag ? System.currentTimeMillis() : repeatTime;
    while (resourceModels.size() != num && resourceModels.size() != tSize && sids.size() != tSize) {
        key = WeightRandomPattern.getWeightRandom(intValues, random, sids);
        tmp = map.get(key);
        ip = tmp.getHost();
        if (pool != null) {
            conn = pool.getConnection(groupName, key);
            if (conn == null || !conn.isValid()) {
                LOG.warn("{} :[{}({})]is unused !!", groupName, key, ip);
                sids.add(key);
                continue;
            }
        }
        if (sendFlag) {
            EmailPool emailPool = EmailPool.getInstance();
            MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo()).setModel(this.getClass().getSimpleName() + "服务选择").setMessage("sr [" + sn + "]即将 在 " + key + "(" + ip + ") 服务 写入重复数据");
            emailPool.sendEmail(builder);
        }
        resourceModels.add(tmp);
        sids.add(tmp.getServerId());
    }
    return resourceModels;
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) EmailPool(com.bonree.brfs.email.EmailPool) DiskNodeConnection(com.bonree.brfs.duplication.datastream.connection.DiskNodeConnection) MailWorker(com.bonree.mail.worker.MailWorker)

Example 12 with EmailPool

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

the class MachineResourceWriterSelector method sendSelectEmail.

/**
 * 发送选择邮件
 * @param resourceModels
 * @param sn
 * @param num
 */
public void sendSelectEmail(Collection<ResourceModel> resourceModels, String sn, int num) {
    StringBuilder messageBuilder = new StringBuilder();
    messageBuilder.append("sr:[").append(sn).append("] 写入可供选择的服务少于需要的!! 可用服务 ").append(resourceModels.size()).append(", 需要 ").append(num).append("(文件分布见上下文表格)");
    Map<String, String> map = new HashMap<>();
    String part;
    String key;
    for (ResourceModel resource : resourceModels) {
        key = resource.getServerId() + "(" + resource.getHost() + ")";
        part = sn + "[path:" + resource.getMountedPoint(sn) + ", remainSize: " + resource.getLocalRemainSizeValue(sn) + "b]";
        map.put(key, part);
    }
    EmailPool emailPool = EmailPool.getInstance();
    MailWorker.Builder builder = MailWorker.newBuilder(emailPool.getProgramInfo());
    builder.setModel(this.getClass().getSimpleName() + "服务选择");
    builder.setMessage(messageBuilder.toString());
    if (!map.isEmpty()) {
        builder.setVariable(map);
    }
    emailPool.sendEmail(builder);
}
Also used : ResourceModel(com.bonree.brfs.resourceschedule.model.ResourceModel) EmailPool(com.bonree.brfs.email.EmailPool) MailWorker(com.bonree.mail.worker.MailWorker)

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