Merge branch 'script_gj' of http://gitlab.fangjia.com/dev0/main into script_gj

This commit is contained in:
2021-12-28 17:50:11 +08:00
5 changed files with 95 additions and 4 deletions
@@ -0,0 +1,91 @@
package com.fangjia.script.temp.shenjian.batch
import com.fangjia.script.BaseBatch
import com.fangjia.script.BatchOwner
import com.fangjia.script.Watcher
import org.apache.http.client.utils.DateUtils
import java.util.regex.Matcher
import java.util.regex.Pattern
/**
* 只保留86机器最近一个月索引
*/
@BatchOwner(Watcher.ShenJian)
class RemoveOldIndexOfEs86 extends BaseBatch {
static void main(String[] args) {
runBatch(new RemoveOldIndexOfEs86(), args)
}
@Override
void process(Object args) {
String url = "http://192.168.0.86:9200/_cat/indices"
// 必须分开写,不能有空格
String[] cmds = ["curl", "-XGET", url, "--user", "elastic:goojia123456"]
List<List<String>> indices = execCurl(cmds)
Pattern yearMonthPattern = Pattern.compile("\\d{6}")
Pattern yearMonthPattern1 = Pattern.compile("\\d{4}\\.\\d{2}")
List<String> indexNeedDel = new ArrayList<>()
for (List<String> index : indices) {
String name = index.get(2)
// 忽略系统索引
if (name.startsWith(".")) {
continue
}
// 匹配含有年月的索引
Matcher matcher = yearMonthPattern.matcher(name)
if (matcher.find()) {
String date = matcher.group()
if (dateBeforeCurrMonth(date)) {
indexNeedDel.add(name)
}
continue
}
matcher = yearMonthPattern1.matcher(name)
if (matcher.find()) {
String date = matcher.group()
if (dateBeforeCurrMonth(date)) {
indexNeedDel.add(name)
}
}
}
for (String index : indexNeedDel) {
println "删除索引" + index
String urlPrefix = "http://192.168.0.86:9200/"
cmds = ["curl", "-XDELETE", urlPrefix + index, "--user", "elastic:goojia123456"]
execCurl(cmds)
}
}
static List<List<String>> execCurl(String[] cmds) {
ProcessBuilder process = new ProcessBuilder(cmds)
Process p
try {
List<String> result = new ArrayList<>()
p = process.start()
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()))
String line = null
while ((line = reader.readLine()) != null) {
result.add(line.split("{1} +"))
}
return result
} catch (IOException e) {
e.printStackTrace()
}
return null
}
def boolean dateBeforeCurrMonth(String date) {
String dateCurr = DateUtils.formatDate(new Date(), "yyyyMM");
if (date.contains(dateCurr)) {
return false
}
dateCurr = DateUtils.formatDate(new Date(), "yyyy.MM");
if (date.contains(dateCurr)) {
return false
}
return true
}
}
@@ -22,7 +22,7 @@ import java.util.concurrent.Executors
class SeaweedAroundCommittee {
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
static ExecutorService executorService = Executors.newFixedThreadPool(30)
static void main(String[] args) {
@@ -28,7 +28,7 @@ import java.util.concurrent.Executors
class SeaweedAroundPoi extends BaseBatch {
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
static ExecutorService executorService = Executors.newFixedThreadPool(30)
static void main(String[] args) {
@@ -28,7 +28,7 @@ import java.util.concurrent.Executors
class SeaweedAroundPoiSingal {
static DBCollection conn136 = MongoUtils.getCollectionByName("fangjia", "seaweed_poi_sync", "192.168.0.136", 27017)
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
static void main(String[] args) {
def types = listAllType()
@@ -14,7 +14,7 @@ import org.apache.commons.collections.CollectionUtils
*/
class YinlianLngLatAndAround {
static final def URL = "http://192.168.0.19:38080/FangJiaDataService/saveAmapPoi"
static final def URL = "http://192.168.0.100:38080/FangJiaDataService/saveAmapPoi"
static void main(String[] args) {
this.getAround()