summaryrefslogtreecommitdiff
path: root/src/main/java/com/geedge/scheduler/IpScheduler.java
blob: b13641db2cfee2bdd461858beae338f20768931a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
package com.geedge.scheduler;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.net.Ipv4Util;
import cn.hutool.core.net.MaskBit;
import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.StrUtil;
import com.geedge.common.constant.TsgObject;
import com.geedge.common.enums.AddressFormat;
import com.geedge.common.util.TsgUtil;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * TODO
 *
 * @Classname Scheduler
 * @Date 2024/1/2 11:31
 * @Author wWei
 */
@Slf4j
@Component
public class IpScheduler {
    public static List<String> excludeList = new ArrayList<>();

    @Value("${tsg.object.ip.excludeValue}")
    public void setExcludeList(String values) {
        if (StrUtil.isBlank(values)) {
            return;
        }
        excludeList = Arrays.asList(values.split(","));
    }

    @Value("${tsg.object.ip.cyberghostvpn_serverip.id}")
    private Integer cyberghostvpnServeripId;
    @Value("${tsg.object.ip.cyberghostvpn_serverip.name}")
    private String cyberghostvpnServeripName;
    @Value("${tsg.object.ip.cyberghostvpn_serverip.update.enable}")
    private Boolean cyberghostvpnServeripUpdateEnable;
    @Value("${tsg.object.ip.cyberghostvpn_serverip.update.sql}")
    private String cyberghostvpnServeripSql;
    @Value("${tsg.object.ip.cyberghostvpn_serverip.delete.enable}")
    private Boolean cyberghostvpnServeripDeleteEnable;
    @Value("${tsg.object.ip.cyberghostvpn_serverip.delete.offsetSecond}")
    private Integer cyberghostvpnServeripOffsetSecond;
    public Counter cyberghostvpnServeripCounter = Counter.build("cyberghostvpn_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.cyberghostvpn_serverip.update.cron}")
    public void updateCyberghostvpn() {
        executeUpdate(cyberghostvpnServeripId, cyberghostvpnServeripName, cyberghostvpnServeripUpdateEnable, cyberghostvpnServeripSql, cyberghostvpnServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.cyberghostvpn_serverip.delete.cron}")
    public void deleteCyberghostvpn() {
        executeDelete(cyberghostvpnServeripId, cyberghostvpnServeripDeleteEnable, cyberghostvpnServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.hotspotvpn_serverip.id}")
    private Integer hotspotvpnServeripId;
    @Value("${tsg.object.ip.hotspotvpn_serverip.name}")
    private String hotspotvpnServeripName;
    @Value("${tsg.object.ip.hotspotvpn_serverip.update.enable}")
    private Boolean hotspotvpnServeripUpdateEnable;
    @Value("${tsg.object.ip.hotspotvpn_serverip.update.sql}")
    private String hotspotvpnServeripSql;
    @Value("${tsg.object.ip.hotspotvpn_serverip.delete.enable}")
    private Boolean hotspotvpnServeripDeleteEnable;
    @Value("${tsg.object.ip.hotspotvpn_serverip.delete.offsetSecond}")
    private Integer hotspotvpnServeripOffsetSecond;
    public Counter hotspotvpnServeripCounter = Counter.build("hotspotvpn_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.hotspotvpn_serverip.update.cron}")
    public void updateHotspotvpn() {
        executeUpdate(hotspotvpnServeripId, hotspotvpnServeripName, hotspotvpnServeripUpdateEnable, hotspotvpnServeripSql, hotspotvpnServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.hotspotvpn_serverip.delete.cron}")
    public void deleteHotspotvpn() {
        executeDelete(hotspotvpnServeripId, hotspotvpnServeripDeleteEnable, hotspotvpnServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.ipvanishvpn_serverip.id}")
    private Integer ipvanishvpnServeripId;
    @Value("${tsg.object.ip.ipvanishvpn_serverip.name}")
    private String ipvanishvpnServeripName;
    @Value("${tsg.object.ip.ipvanishvpn_serverip.update.enable}")
    private Boolean ipvanishvpnServeripUpdateEnable;
    @Value("${tsg.object.ip.ipvanishvpn_serverip.update.sql}")
    private String ipvanishvpnServeripSql;
    @Value("${tsg.object.ip.ipvanishvpn_serverip.delete.enable}")
    private Boolean ipvanishvpnServeripDeleteEnable;
    @Value("${tsg.object.ip.ipvanishvpn_serverip.delete.offsetSecond}")
    private Integer ipvanishvpnServeripOffsetSecond;
    public Counter ipvanishvpnServeripCounter = Counter.build("ipvanishvpn_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.ipvanishvpn_serverip.update.cron}")
    public void updateIpvanishvpn() {
        executeUpdate(ipvanishvpnServeripId, ipvanishvpnServeripName, ipvanishvpnServeripUpdateEnable, ipvanishvpnServeripSql, ipvanishvpnServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.ipvanishvpn_serverip.delete.cron}")
    public void deleteIpvanishvpn() {
        executeDelete(ipvanishvpnServeripId, ipvanishvpnServeripDeleteEnable, ipvanishvpnServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.geckovpn_serverip.id}")
    private Integer geckovpnServeripId;
    @Value("${tsg.object.ip.geckovpn_serverip.name}")
    private String geckovpnServeripName;
    @Value("${tsg.object.ip.geckovpn_serverip.update.enable}")
    private Boolean geckovpnServeripUpdateEnable;
    @Value("${tsg.object.ip.geckovpn_serverip.update.sql}")
    private String geckovpnServeripSql;
    @Value("${tsg.object.ip.geckovpn_serverip.delete.enable}")
    private Boolean geckovpnServeripDeleteEnable;
    @Value("${tsg.object.ip.geckovpn_serverip.delete.offsetSecond}")
    private Integer geckovpnServeripOffsetSecond;
    public Counter geckovpnServeripCounter = Counter.build("geckovpn_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.geckovpn_serverip.update.cron}")
    public void updateGeckovpn() {
        executeUpdate(geckovpnServeripId, geckovpnServeripName, geckovpnServeripUpdateEnable, geckovpnServeripSql, geckovpnServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.geckovpn_serverip.delete.cron}")
    public void deleteGeckovpn() {
        executeDelete(geckovpnServeripId, geckovpnServeripDeleteEnable, geckovpnServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.ivacyvpn_serverip.id}")
    private Integer ivacyvpnServeripId;
    @Value("${tsg.object.ip.ivacyvpn_serverip.name}")
    private String ivacyvpnServeripName;
    @Value("${tsg.object.ip.ivacyvpn_serverip.update.enable}")
    private Boolean ivacyvpnServeripUpdateEnable;
    @Value("${tsg.object.ip.ivacyvpn_serverip.update.sql}")
    private String ivacyvpnServeripSql;
    @Value("${tsg.object.ip.ivacyvpn_serverip.delete.enable}")
    private Boolean ivacyvpnServeripDeleteEnable;
    @Value("${tsg.object.ip.ivacyvpn_serverip.delete.offsetSecond}")
    private Integer ivacyvpnServeripOffsetSecond;
    public Counter ivacyvpnServeripCounter = Counter.build("ivacyvpn_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.ivacyvpn_serverip.update.cron}")
    public void updateIvacyvpn() {
        executeUpdate(ivacyvpnServeripId, ivacyvpnServeripName, ivacyvpnServeripUpdateEnable, ivacyvpnServeripSql, ivacyvpnServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.ivacyvpn_serverip.delete.cron}")
    public void deleteIvacyvpn() {
        executeDelete(ivacyvpnServeripId, ivacyvpnServeripDeleteEnable, ivacyvpnServeripOffsetSecond);
    }


    @Value("${tsg.object.ip.turbovpn_serverip.id}")
    private Integer turbovpnServeripId;
    @Value("${tsg.object.ip.turbovpn_serverip.name}")
    private String turbovpnServeripName;
    @Value("${tsg.object.ip.turbovpn_serverip.update.enable}")
    private Boolean turbovpnServeripUpdateEnable;
    @Value("${tsg.object.ip.turbovpn_serverip.update.sql}")
    private String turbovpnServeripSql;
    @Value("${tsg.object.ip.turbovpn_serverip.delete.enable}")
    private Boolean turbovpnServeripDeleteEnable;
    @Value("${tsg.object.ip.turbovpn_serverip.delete.offsetSecond}")
    private Integer turbovpnServeripOffsetSecond;
    public Counter turbovpnServeripCounter = Counter.build("turbovpn_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.turbovpn_serverip.update.cron}")
    public void updateTurbovpn() {
        executeUpdate(turbovpnServeripId, turbovpnServeripName, turbovpnServeripUpdateEnable, turbovpnServeripSql, turbovpnServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.turbovpn_serverip.delete.cron}")
    public void deleteTurbovpn() {
        executeDelete(turbovpnServeripId, turbovpnServeripDeleteEnable, turbovpnServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.vpnunlimited_serverip.id}")
    private Integer vpnunlimitedServeripId;
    @Value("${tsg.object.ip.vpnunlimited_serverip.name}")
    private String vpnunlimitedServeripName;
    @Value("${tsg.object.ip.vpnunlimited_serverip.update.enable}")
    private Boolean vpnunlimitedServeripUpdateEnable;
    @Value("${tsg.object.ip.vpnunlimited_serverip.update.sql}")
    private String vpnunlimitedServeripSql;
    @Value("${tsg.object.ip.vpnunlimited_serverip.delete.enable}")
    private Boolean vpnunlimitedServeripDeleteEnable;
    @Value("${tsg.object.ip.vpnunlimited_serverip.delete.offsetSecond}")
    private Integer vpnunlimitedServeripOffsetSecond;
    public Counter vpnunlimitedServeripCounter = Counter.build("vpnunlimited_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.vpnunlimited_serverip.update.cron}")
    public void updateVpnunlimited() {
        executeUpdate(vpnunlimitedServeripId, vpnunlimitedServeripName, vpnunlimitedServeripUpdateEnable, vpnunlimitedServeripSql, vpnunlimitedServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.vpnunlimited_serverip.delete.cron}")
    public void deleteVpnunlimited() {
        executeDelete(vpnunlimitedServeripId, vpnunlimitedServeripDeleteEnable, vpnunlimitedServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.windscribevpn_serverip.id}")
    private Integer windscribevpnServeripId;
    @Value("${tsg.object.ip.windscribevpn_serverip.name}")
    private String windscribevpnServeripName;
    @Value("${tsg.object.ip.windscribevpn_serverip.update.enable}")
    private Boolean windscribevpnServeripUpdateEnable;
    @Value("${tsg.object.ip.windscribevpn_serverip.update.sql}")
    private String windscribevpnServeripSql;
    @Value("${tsg.object.ip.windscribevpn_serverip.delete.enable}")
    private Boolean windscribevpnServeripDeleteEnable;
    @Value("${tsg.object.ip.windscribevpn_serverip.delete.offsetSecond}")
    private Integer windscribevpnServeripOffsetSecond;
    public Counter windscribevpnServeripCounter = Counter.build("windscribevpn_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.windscribevpn_serverip.update.cron}")
    public void updateWindscribevpn() {
        executeUpdate(windscribevpnServeripId, windscribevpnServeripName, windscribevpnServeripUpdateEnable, windscribevpnServeripSql, windscribevpnServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.windscribevpn_serverip.delete.cron}")
    public void deleteWindscribevpn() {
        executeDelete(windscribevpnServeripId, windscribevpnServeripDeleteEnable, windscribevpnServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.vpn4fame_serverip.id}")
    private Integer vpn4fameServeripId;
    @Value("${tsg.object.ip.vpn4fame_serverip.name}")
    private String vpn4fameServeripName;
    @Value("${tsg.object.ip.vpn4fame_serverip.update.enable}")
    private Boolean vpn4fameServeripUpdateEnable;
    @Value("${tsg.object.ip.vpn4fame_serverip.update.sql}")
    private String vpn4fameServeripSql;
    @Value("${tsg.object.ip.vpn4fame_serverip.delete.enable}")
    private Boolean vpn4fameServeripDeleteEnable;
    @Value("${tsg.object.ip.vpn4fame_serverip.delete.offsetSecond}")
    private Integer vpn4fameServeripOffsetSecond;
    public Counter vpn4fameServeripCounter = Counter.build("vpn4fame_serverip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.vpn4fame_serverip.update.cron}")
    public void updateVpn4fame() {
        executeUpdate(vpn4fameServeripId, vpn4fameServeripName, vpn4fameServeripUpdateEnable, vpn4fameServeripSql, vpn4fameServeripCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.vpn4fame_serverip.delete.cron}")
    public void deleteVpn4fame() {
        executeDelete(vpn4fameServeripId, vpn4fameServeripDeleteEnable, vpn4fameServeripOffsetSecond);
    }

    @Value("${tsg.object.ip.protonvpn_ip.id}")
    private Integer protonvpnIpId;
    @Value("${tsg.object.ip.protonvpn_ip.name}")
    private String protonvpnIpName;
    @Value("${tsg.object.ip.protonvpn_ip.update.enable}")
    private Boolean protonvpnIpUpdateEnable;
    @Value("${tsg.object.ip.protonvpn_ip.update.sql}")
    private String protonvpnIpSql;
    @Value("${tsg.object.ip.protonvpn_ip.delete.enable}")
    private Boolean protonvpnIpDeleteEnable;
    @Value("${tsg.object.ip.protonvpn_ip.delete.offsetSecond}")
    private Integer protonvpnIpOffsetSecond;
    public Counter protonvpnIpCounter = Counter.build("protonvpn_ip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.protonvpn_ip.update.cron}")
    public void updateProtonvpn() {
        executeUpdate(protonvpnIpId, protonvpnIpName, protonvpnIpUpdateEnable, protonvpnIpSql, protonvpnIpCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.protonvpn_ip.delete.cron}")
    public void deleteProtonvpn() {
        executeDelete(protonvpnIpId, protonvpnIpDeleteEnable, protonvpnIpOffsetSecond);
    }

    @Value("${tsg.object.ip.expressvpn_ip.id}")
    private Integer expressvpnIpId;
    @Value("${tsg.object.ip.expressvpn_ip.name}")
    private String expressvpnIpName;
    @Value("${tsg.object.ip.expressvpn_ip.update.enable}")
    private Boolean expressvpnIpUpdateEnable;
    @Value("${tsg.object.ip.expressvpn_ip.update.sql}")
    private String expressvpnIpSql;
    @Value("${tsg.object.ip.expressvpn_ip.delete.enable}")
    private Boolean expressvpnIpDeleteEnable;
    @Value("${tsg.object.ip.expressvpn_ip.delete.offsetSecond}")
    private Integer expressvpnIpOffsetSecond;
    public Counter expressvpnIpCounter = Counter.build("expressvpn_ip_counter", "COUNTER HELP").register(CollectorRegistry.defaultRegistry);

    @Scheduled(cron = "${tsg.object.ip.expressvpn_ip.update.cron}")
    public void updateExpressvpn() {
        executeUpdate(expressvpnIpId, expressvpnIpName, expressvpnIpUpdateEnable, expressvpnIpSql, expressvpnIpCounter);
    }

    @Scheduled(cron = "${tsg.object.ip.expressvpn_ip.delete.cron}")
    public void deleteExpressvpn() {
        executeDelete(expressvpnIpId, expressvpnIpDeleteEnable, expressvpnIpOffsetSecond);
    }


    private static void executeUpdate(Integer id, String name, Boolean enable, String sql, Counter counter) {
        log.info("{}: started update task.", id);
        if (BooleanUtil.isFalse(enable)) {
            log.warn("{}: interrupted update task. enable: {}", id, enable);
            return;
        }
        try {
            Stopwatch watch = Stopwatch.createStarted();
            List<Record> data = Db.find(sql);
            log.info("{}: query knowledge base content, cost {} seconds", id, watch.elapsed(TimeUnit.SECONDS));
            watch.reset().start();
            List<Map<String, Object>> items = Lists.newArrayList();
            row:
            for (Record record : data) {
                Map<String, Object> item = Maps.newHashMap();
                String addressFormat = record.get("addrFormat");
                String ip1 = record.get("ip1");
                for (String excludeItem : excludeList) {
                    if (excludeItem.equals(ip1)) {
                        continue row;
                    }
                    if (excludeItem.endsWith("*") && ip1.startsWith(excludeItem.replace("*", ""))) {
                        continue row;
                    }
                }
                String ip2 = record.get("ip2");
                Map<String, Object> ip = Maps.newHashMap();
                if (AddressFormat.CIDR.getValue().equalsIgnoreCase(addressFormat)) {
                    int maskBit = Integer.parseInt(ip2);
                    String mask = MaskBit.get(Integer.parseInt(ip2));
                    String beginIpStr = Ipv4Util.getBeginIpStr(ip1, maskBit);
                    String ipMask = Ipv4Util.formatIpBlock(beginIpStr, mask);
                    ip.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_IP_IP_CIDR, ipMask);
                } else if (AddressFormat.RANGE.getValue().equalsIgnoreCase(addressFormat)) {
                    ip.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_IP_IP_RANGE, ip1 + "-" + ip2);
                } else {
                    ip.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_IP_IP_ADDRESS, ip1);
                }
                ip.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_IP_PORT_RANGE, TsgObject.VALUE_OBJECT_MEMBER_ITEMS_IP_PORT_RANGE);
                InetAddress inetAddress = InetAddress.getByName(ip1);
                if (inetAddress instanceof Inet4Address) {
                    ip.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_IP_ADDR_TYPE, 4);
                } else if (inetAddress instanceof Inet6Address) {
                    ip.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_IP_ADDR_TYPE, 6);
                } else {
                    continue;
                }
                item.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_OP, TsgObject.VALUE_OBJECT_MEMBER_ITEMS_OP_ADD);
                item.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS_IP, ip);
                items.add(item);
            }
            Map<String, Object> member = Maps.newHashMap();
            member.put(TsgObject.KEY_OBJECT_MEMBER_TYPE, TsgObject.VALUE_OBJECT_MEMBER_TYPE_1);
            member.put(TsgObject.KEY_OBJECT_MEMBER_ITEMS, items);

            Map<String, Object> obj = Maps.newHashMap();
            obj.put(TsgObject.KEY_OBJECT_NAME, name);
            obj.put(TsgObject.KEY_OBJECT_TYPE, TsgObject.VALUE_OBJECT_TYPE_IP);
            obj.put(TsgObject.KEY_OBJECT_MEMBER, member);

            Map<String, Object> body = Maps.newHashMap();
            body.put(TsgObject.KEY_VSYS_ID, TsgObject.VALUE_VSYS_ID_1);
            body.put(TsgObject.KEY_OBJECT, obj);
            log.info("{}: build api params, items size: {}, cost {} seconds", id, items.size(), watch.elapsed(TimeUnit.SECONDS));
            if (items.isEmpty()) {
                return;
            }
            TsgUtil.updateObjectById(id, body);
            counter.inc(items.size());
        } catch (Exception e) {
            log.error("{}: failed to execute update task. message: {}", id, e.getMessage());
            throw new RuntimeException(e);
        }
    }

    private static void executeDelete(Integer id, Boolean enable, Integer offsetSecond) {
        log.info("{}: started delete task.", id);
        if (BooleanUtil.isFalse(enable)) {
            log.warn("{}: interrupted delete task. enable: {}", id, enable);
            return;
        }
        try {
            DateTime dateTime = DateUtil.offsetSecond(new Date(), offsetSecond).setTimeZone(TimeZone.getTimeZone("UTC"));
            String datetimeZ = DateUtil.format(dateTime, DatePattern.UTC_PATTERN);
            Map<String, Object> form = Maps.newHashMap();
            form.put(TsgObject.KEY_OBJECT_TYPE, TsgObject.VALUE_OBJECT_TYPE_IP);
            form.put(TsgObject.KEY_VSYS_ID, TsgObject.VALUE_VSYS_ID_1);
            form.put(TsgObject.KEY_CREATED_BEFORE, datetimeZ);
            TsgUtil.deleteItemOfObjectById(id, form);
        } catch (Exception e) {
            log.error("{}: failed to execute delete task. message: {}", id, e.getMessage());
            throw new RuntimeException(e);
        }
    }
}