diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/batch/RemoveOldIndexOfEs86Batch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/batch/RemoveOldIndexOfEs86Batch.groovy new file mode 100644 index 000000000..076b33977 --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/batch/RemoveOldIndexOfEs86Batch.groovy @@ -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> indices = execCurl(cmds) + Pattern yearMonthPattern = Pattern.compile("\\d{6}") + Pattern yearMonthPattern1 = Pattern.compile("\\d{4}\\.\\d{2}") + List indexNeedDel = new ArrayList<>() + for (List 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> execCurl(String[] cmds) { + ProcessBuilder process = new ProcessBuilder(cmds) + Process p + try { + List 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 + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundCommittee.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundCommittee.groovy index d8edf839d..fc4fecc64 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundCommittee.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundCommittee.groovy @@ -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) { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy index 7dcd06e51..f3c36ebd8 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoi.groovy @@ -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) { diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy index be70b79e5..1a620af34 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/SeaweedAroundPoiSingal.groovy @@ -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() diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/YinlianLngLatAndAround.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/YinlianLngLatAndAround.groovy index 9cc7ab29d..4764ce68e 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/YinlianLngLatAndAround.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/temp/shenjian/poi/YinlianLngLatAndAround.groovy @@ -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()