任务分配算法,主要是轮询然后是 MAP利用数据结构, KEY里封装对象 再追加list 如
Map> old_map = new HashMap();
old_map.get(same.getIsoCode()).add(nodeSame.getCountryIp());
对于任务分配 非常有帮助
/*
* Zenlayer.com Inc.
* Copyright (c) 2014-2019 All Rights Reserved.
*/
package com.zenlayer.ad.nodetool;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.exception.GeoIp2Exception;
import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.record.City;
import com.maxmind.geoip2.record.Continent;
import com.maxmind.geoip2.record.Country;
import com.maxmind.geoip2.record.Location;
import com.maxmind.geoip2.record.Postal;
import com.maxmind.geoip2.record.Subdivision;
import com.zenlayer.ad.jedis.RedisClient;
import com.zenlayer.ad.mapper.SnmpMapper;
import com.zenlayer.util.DataTransformation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @author jack.li
* @date 2019-10-30 18:07:30
* @version $ Id: NodeToolService.java, v 0.1 admin Exp $
*<1> 采用新的分配节点任务,按区域划分,通过IP自动获取所在地区 (BMC 交换机的分配方式)
*
*<2> 按着IP,平均分配到所有存活的节点上
*/
@Component("nodeToolService")
public class NodeToolService {
@Resource
RedisClient redisclient;
@Autowired
private SnmpMapper snmpMapper;
@Autowired
NodeIdcService nodeIdcService;
//默认洛杉机的节点,备份采集所有失败的交换机
public static String laxIp = "68.8.8.194";
public boolean getSnmpAll() throws IOException, GeoIp2Exception {
//1 所有内网IP 不进行地址解析, 2 另外分配所有失败交换机的备选节点
List