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;
}
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);
}
Aggregations