// Path: server/src/main/java/com/cloudwise/sap/niping/SapConfiguration.java
// @Data
// public class SapConfiguration {
//     @JsonProperty("monitor")
//     private MonitorConfiguration monitorConfiguration;
// 
//     @JsonProperty("job")
//     private JobConfiguration jobConfiguration;
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/common/entity/Monitor.java
// @Data
// @Builder
// @EqualsAndHashCode(callSuper = true)
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Monitor extends AbstractEntity {
// 
//     private static final long serialVersionUID = 6732242760258530600L;
//     private String monitorId;
//     private String version;
//     private String name;
//     private String country;
//     private String province;
//     private String city;
//     private String isp;
//     private String area;
//     private String ip;
//     private String nipingT;
//     private int status;
//     private List<String> runningTaskIds;
// 
//     @JsonIgnore
//     private boolean isUsable;
// 
//     public enum Status {
//         active(1), inactive(0);
// 
//         @Getter
//         private int status;
// 
//         Status(int status) {this.status = status;}
//     }
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/dao/MonitorDao.java
// @Service
// @UseStringTemplate3StatementLocator
// public interface MonitorDao {
//     @SqlQuery("SELECT COUNT(1) FROM SNM_MONITOR WHERE MONITOR_ID = :monitorId")
//     int countMonitor(@Bind("monitorId") String monitorId);
// 
//     @SqlUpdate("INSERT INTO SNM_MONITOR (MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME) " +
//             " VALUES (:monitorId, :version, :accountId, :name, :country, :province, :city, :isp, :area, :ip, :nipingT, :status, :creationTime, :modifiedTime)")
//     void insertMonitor(@BindBean Monitor monitor);
// 
//     @SqlUpdate("UPDATE SNM_MONITOR SET STATUS = :status, MODIFIED_TIME = :modifiedTime")
//     void updateAllMonitorsStatus(@Bind("status") int status, @Bind("modifiedTime") Date modifiedTime);
// 
//     @SqlUpdate("UPDATE SNM_MONITOR SET STATUS = :status, MODIFIED_TIME = :modifiedTime WHERE MONITOR_ID IN (<monitorIds>)")
//     void updateMonitorsStatus(@BindIn("monitorIds") List<String> monitorIds, @Bind("status") int status, @Bind("modifiedTime") Date modifiedTime);
// 
//     @SqlUpdate("UPDATE SNM_MONITOR SET ACCOUNT_ID = :accountId, VERSION = :version, NAME = :name, COUNTRY = :country, PROVINCE = :province, CITY = :city, ISP = :isp, AREA = :area, " +
//             " IP = :ip, NIPING_T = :nipingT, MODIFIED_TIME = :modifiedTime WHERE MONITOR_ID = :monitorId")
//     void updateMonitorNiping(@BindBean Monitor monitor);
// 
//     @SqlQuery("SELECT MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME FROM SNM_MONITOR " +
//             " WHERE ACCOUNT_ID = :accountId AND STATUS = :monitorEnableStatus")
//     @RegisterMapper(MonitorMapper.class)
//     List<Monitor> selectByAccountId( @Bind("accountId") String accountId,  @Bind("monitorEnableStatus") int status);
// 
// 
//     @SqlQuery("SELECT MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME FROM SNM_MONITOR " +
//             " WHERE ACCOUNT_ID = :accountId")
//     @RegisterMapper(MonitorMapper.class)
//     List<Monitor> selectAllByAccountId( @Bind("accountId") String accountId);
// 
//     @SqlQuery("SELECT SNM_MONITOR.MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME FROM SNM_MONITOR INNER JOIN SNM_MONITOR_TASK " +
//             " ON SNM_MONITOR.MONITOR_ID = SNM_MONITOR_TASK.MONITOR_ID" +
//             " WHERE ACCOUNT_ID = :accountId AND TASK_ID = :taskId <condition>")
//     @RegisterMapper(MonitorMapper.class)
//     List<Monitor> selectMonitors(@Bind("accountId") String accountId, @Bind("taskId") String taskId, @Define("condition") String condition);
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/exception/NiPingException.java
// @Data
// public class NiPingException extends Exception {
//     private int code;
//     private String errorMessage;
// 
//     public NiPingException(Result errorResult) {
//         this.code = errorResult.getCode();
//         this.errorMessage = errorResult.getMessage();
//     }
// }


import com.cloudwise.sap.niping.SapConfiguration;
import com.cloudwise.sap.niping.common.entity.Monitor;
import com.cloudwise.sap.niping.dao.MonitorDao;
import com.cloudwise.sap.niping.exception.NiPingException;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.FailsafeException;
import net.jodah.failsafe.RetryPolicy;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.skife.jdbi.v2.exceptions.DBIException;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.cloudwise.sap.niping.common.constant.Result.DBError;
package com.cloudwise.sap.niping.service;




@Slf4j
public class MonitorService {

    @Inject
// Path: server/src/main/java/com/cloudwise/sap/niping/SapConfiguration.java
// @Data
// public class SapConfiguration {
//     @JsonProperty("monitor")
//     private MonitorConfiguration monitorConfiguration;
// 
//     @JsonProperty("job")
//     private JobConfiguration jobConfiguration;
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/common/entity/Monitor.java
// @Data
// @Builder
// @EqualsAndHashCode(callSuper = true)
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class Monitor extends AbstractEntity {
// 
//     private static final long serialVersionUID = 6732242760258530600L;
//     private String monitorId;
//     private String version;
//     private String name;
//     private String country;
//     private String province;
//     private String city;
//     private String isp;
//     private String area;
//     private String ip;
//     private String nipingT;
//     private int status;
//     private List<String> runningTaskIds;
// 
//     @JsonIgnore
//     private boolean isUsable;
// 
//     public enum Status {
//         active(1), inactive(0);
// 
//         @Getter
//         private int status;
// 
//         Status(int status) {this.status = status;}
//     }
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/dao/MonitorDao.java
// @Service
// @UseStringTemplate3StatementLocator
// public interface MonitorDao {
//     @SqlQuery("SELECT COUNT(1) FROM SNM_MONITOR WHERE MONITOR_ID = :monitorId")
//     int countMonitor(@Bind("monitorId") String monitorId);
// 
//     @SqlUpdate("INSERT INTO SNM_MONITOR (MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME) " +
//             " VALUES (:monitorId, :version, :accountId, :name, :country, :province, :city, :isp, :area, :ip, :nipingT, :status, :creationTime, :modifiedTime)")
//     void insertMonitor(@BindBean Monitor monitor);
// 
//     @SqlUpdate("UPDATE SNM_MONITOR SET STATUS = :status, MODIFIED_TIME = :modifiedTime")
//     void updateAllMonitorsStatus(@Bind("status") int status, @Bind("modifiedTime") Date modifiedTime);
// 
//     @SqlUpdate("UPDATE SNM_MONITOR SET STATUS = :status, MODIFIED_TIME = :modifiedTime WHERE MONITOR_ID IN (<monitorIds>)")
//     void updateMonitorsStatus(@BindIn("monitorIds") List<String> monitorIds, @Bind("status") int status, @Bind("modifiedTime") Date modifiedTime);
// 
//     @SqlUpdate("UPDATE SNM_MONITOR SET ACCOUNT_ID = :accountId, VERSION = :version, NAME = :name, COUNTRY = :country, PROVINCE = :province, CITY = :city, ISP = :isp, AREA = :area, " +
//             " IP = :ip, NIPING_T = :nipingT, MODIFIED_TIME = :modifiedTime WHERE MONITOR_ID = :monitorId")
//     void updateMonitorNiping(@BindBean Monitor monitor);
// 
//     @SqlQuery("SELECT MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME FROM SNM_MONITOR " +
//             " WHERE ACCOUNT_ID = :accountId AND STATUS = :monitorEnableStatus")
//     @RegisterMapper(MonitorMapper.class)
//     List<Monitor> selectByAccountId( @Bind("accountId") String accountId,  @Bind("monitorEnableStatus") int status);
// 
// 
//     @SqlQuery("SELECT MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME FROM SNM_MONITOR " +
//             " WHERE ACCOUNT_ID = :accountId")
//     @RegisterMapper(MonitorMapper.class)
//     List<Monitor> selectAllByAccountId( @Bind("accountId") String accountId);
// 
//     @SqlQuery("SELECT SNM_MONITOR.MONITOR_ID, VERSION, ACCOUNT_ID, NAME, COUNTRY, PROVINCE, CITY, ISP, AREA, IP, NIPING_T, STATUS, CREATION_TIME, MODIFIED_TIME FROM SNM_MONITOR INNER JOIN SNM_MONITOR_TASK " +
//             " ON SNM_MONITOR.MONITOR_ID = SNM_MONITOR_TASK.MONITOR_ID" +
//             " WHERE ACCOUNT_ID = :accountId AND TASK_ID = :taskId <condition>")
//     @RegisterMapper(MonitorMapper.class)
//     List<Monitor> selectMonitors(@Bind("accountId") String accountId, @Bind("taskId") String taskId, @Define("condition") String condition);
// }
// 
// Path: server/src/main/java/com/cloudwise/sap/niping/exception/NiPingException.java
// @Data
// public class NiPingException extends Exception {
//     private int code;
//     private String errorMessage;
// 
//     public NiPingException(Result errorResult) {
//         this.code = errorResult.getCode();
//         this.errorMessage = errorResult.getMessage();
//     }
// }


// Path: server/src/main/java/com/cloudwise/sap/niping/service/MonitorService.java
import com.cloudwise.sap.niping.SapConfiguration;
import com.cloudwise.sap.niping.common.entity.Monitor;
import com.cloudwise.sap.niping.dao.MonitorDao;
import com.cloudwise.sap.niping.exception.NiPingException;
import com.google.common.collect.Sets;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.Failsafe;
import net.jodah.failsafe.FailsafeException;
import net.jodah.failsafe.RetryPolicy;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.skife.jdbi.v2.exceptions.DBIException;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.cloudwise.sap.niping.common.constant.Result.DBError;

package com.cloudwise.sap.niping.service;




@Slf4j
public class MonitorService {

    @Inject
    private MonitorDao monitorDao;