This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new bb830ee6d3 Elasticsearch storage merge all management data indices
into one index `management` (#11328)
bb830ee6d3 is described below
commit bb830ee6d3c992aca128eeaf2f8841d2776faf2e
Author: Wan Kai <[email protected]>
AuthorDate: Thu Sep 14 17:20:32 2023 +0800
Elasticsearch storage merge all management data indices into one index
`management` (#11328)
---
docs/en/changes/changes.md | 2 +
docs/en/setup/backend/storages/elasticsearch.md | 2 +-
.../analysis/worker/ManagementStreamProcessor.java | 2 +-
.../StorageModuleElasticsearchProvider.java | 9 +-
.../plugin/elasticsearch/base/IndexController.java | 23 +++-
.../elasticsearch/base/ManagementCRUDEsDAO.java | 130 +++++++++++++++++++++
.../plugin/elasticsearch/base/ManagementEsDAO.java | 2 +-
.../elasticsearch/base/StorageEsInstaller.java | 10 +-
.../query/ContinuousProfilingPolicyEsDAO.java | 28 ++---
.../elasticsearch/query/UIMenuManagementEsDAO.java | 38 ++----
.../query/UITemplateManagementEsDAO.java | 104 +++++------------
11 files changed, 220 insertions(+), 130 deletions(-)
diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index 11d4a9b00c..813e28b213 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -8,6 +8,8 @@
* ElasticSearchClient: Add `deleteById` API.
* Fix Custom alarm rules are overwritten by 'resource/alarm-settings.yml'
* Support Kafka Monitoring.
+* [Breaking Change] Elasticsearch storage merge all management data indices
into one index `management`,
+ including `ui_template,ui_menu,continuous_profiling_policy`.
#### UI
diff --git a/docs/en/setup/backend/storages/elasticsearch.md
b/docs/en/setup/backend/storages/elasticsearch.md
index 44ffc53647..efe056297a 100644
--- a/docs/en/setup/backend/storages/elasticsearch.md
+++ b/docs/en/setup/backend/storages/elasticsearch.md
@@ -25,7 +25,7 @@ If you have concerns about SSPL/ELv2, choose the versions
before 7.11 or switch
By default, SkyWalking uses following indices for various telemetry data.
-* sw_ui_template (UI dashboard settings)
+* sw_management (All SkyWalking management data, e.g. UI dashboard settings,
UI Menu, Continuous profiling policy)
* sw_metrics-all-`${day-format}` (All metrics/meters generated through MAL and
OAL engines, and metadata of service/instance/endpoint)
* sw_log-`${day-format}` (Collected logs, exclude browser logs)
* sw_segment-`${day-format}` (Native trace segments)
diff --git
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/ManagementStreamProcessor.java
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/ManagementStreamProcessor.java
index 0c0e6e508f..d13a228ec4 100644
---
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/ManagementStreamProcessor.java
+++
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/worker/ManagementStreamProcessor.java
@@ -41,7 +41,7 @@ import java.util.Map;
/**
* ManagementProcessor represents the UI/CLI interactive process. They are
management data, which size is not huge and
- * time serious.
+ * time series.
*
* @since 8.0.0
*/
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/StorageModuleElasticsearchProvider.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/StorageModuleElasticsearchProvider.java
index d766b46d17..ba608fe065 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/StorageModuleElasticsearchProvider.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/StorageModuleElasticsearchProvider.java
@@ -24,6 +24,9 @@ import java.util.function.Function;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.oap.server.core.CoreModule;
import org.apache.skywalking.oap.server.core.config.ConfigService;
+import org.apache.skywalking.oap.server.core.management.ui.menu.UIMenu;
+import org.apache.skywalking.oap.server.core.management.ui.template.UITemplate;
+import
org.apache.skywalking.oap.server.core.profiling.continuous.storage.ContinuousProfilingPolicy;
import org.apache.skywalking.oap.server.core.storage.IBatchDAO;
import org.apache.skywalking.oap.server.core.storage.IHistoryDeleteDAO;
import org.apache.skywalking.oap.server.core.storage.StorageBuilderFactory;
@@ -217,9 +220,9 @@ public class StorageModuleElasticsearchProvider extends
ModuleProvider {
IProfileThreadSnapshotQueryDAO.class, new
ProfileThreadSnapshotQueryEsDAO(elasticSearchClient, config
.getProfileTaskQueryMaxSize()));
this.registerServiceImplementation(
- UITemplateManagementDAO.class, new
UITemplateManagementEsDAO(elasticSearchClient));
+ UITemplateManagementDAO.class, new
UITemplateManagementEsDAO(elasticSearchClient, new UITemplate.Builder()));
this.registerServiceImplementation(
- UIMenuManagementDAO.class, new
UIMenuManagementEsDAO(elasticSearchClient));
+ UIMenuManagementDAO.class, new
UIMenuManagementEsDAO(elasticSearchClient, new UIMenu.Builder()));
this.registerServiceImplementation(IEventQueryDAO.class, new
ESEventQueryDAO(elasticSearchClient));
@@ -237,7 +240,7 @@ public class StorageModuleElasticsearchProvider extends
ModuleProvider {
);
this.registerServiceImplementation(
IContinuousProfilingPolicyDAO.class,
- new ContinuousProfilingPolicyEsDAO(elasticSearchClient)
+ new ContinuousProfilingPolicyEsDAO(elasticSearchClient, new
ContinuousProfilingPolicy.Builder())
);
this.registerServiceImplementation(
IServiceLabelDAO.class,
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/IndexController.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/IndexController.java
index 5a5b8cfa9b..29f4211d9d 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/IndexController.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/IndexController.java
@@ -54,6 +54,9 @@ public enum IndexController {
private boolean enableCustomRouting = false;
public String getTableName(Model model) {
+ if (!model.isTimeSeries()) {
+ return "management";
+ }
if (!logicSharding) {
return model.isMetric() ? "metrics-all" :
(model.isRecord() && !model.isSuperDataset() ? "records-all" :
model.getName());
@@ -63,10 +66,13 @@ public enum IndexController {
}
/**
- * Generate the index doc ID. When a model is the aggregation storage
mode, the logicTableName is a part of new ID
+ * Generate the index doc ID. When a model is the merged storage mode, the
logicTableName is a part of new ID
* to avoid conflicts.
*/
public String generateDocId(Model model, String originalID) {
+ if (!model.isTimeSeries()) {
+ return this.generateDocId(model.getName(), originalID);
+ }
if (!logicSharding && model.isRecord() && !model.isSuperDataset()) {
return this.generateDocId(model.getName(), originalID);
}
@@ -111,6 +117,14 @@ public enum IndexController {
return columns;
}
+ /**
+ * All the management data would be merged in the same index, no
logicSharding.
+ */
+ public Map<String, Object> appendTableColumn4ManagementData(String
modelName, Map<String, Object> columns) {
+ columns.put(LogicIndicesRegister.MANAGEMENT_TABLE_NAME, modelName);
+ return columns;
+ }
+
public static class LogicIndicesRegister {
/**
@@ -132,6 +146,11 @@ public enum IndexController {
*/
public static final String RECORD_TABLE_NAME = "record_table";
+ /**
+ * The management data table name in merged physical storage.
+ */
+ public static final String MANAGEMENT_TABLE_NAME = "management_table";
+
public static String getPhysicalTableName(String logicName) {
return
Optional.ofNullable(LOGIC_INDICES_CATALOG.get(logicName)).orElse(logicName);
}
@@ -140,7 +159,7 @@ public enum IndexController {
LOGIC_INDICES_CATALOG.put(model.getName(), physicalName);
Map<String, ModelColumn> columns =
PHYSICAL_INDICES_COLUMNS.computeIfAbsent(
physicalName, v -> new HashMap<>());
- if (!IndexController.INSTANCE.logicSharding) {
+ if (!IndexController.INSTANCE.logicSharding ||
!model.isTimeSeries()) {
model.getColumns().forEach(modelColumn -> {
String columnName = modelColumn.getColumnName().getName();
if (columns.containsKey(columnName)) {
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/ManagementCRUDEsDAO.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/ManagementCRUDEsDAO.java
new file mode 100644
index 0000000000..8fc22535d9
--- /dev/null
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/ManagementCRUDEsDAO.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base;
+
+import java.io.IOException;
+import java.util.Map;
+import org.apache.skywalking.library.elasticsearch.requests.search.Query;
+import org.apache.skywalking.library.elasticsearch.requests.search.Search;
+import
org.apache.skywalking.library.elasticsearch.requests.search.SearchBuilder;
+import org.apache.skywalking.library.elasticsearch.response.search.SearchHit;
+import
org.apache.skywalking.library.elasticsearch.response.search.SearchResponse;
+import
org.apache.skywalking.oap.server.core.analysis.management.ManagementData;
+import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder;
+import
org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
+import org.apache.skywalking.oap.server.library.util.StringUtil;
+
+public abstract class ManagementCRUDEsDAO extends EsDAO {
+ private final StorageBuilder<ManagementData> storageBuilder;
+
+ public ManagementCRUDEsDAO(ElasticSearchClient client,
+ StorageBuilder<ManagementData> storageBuilder) {
+ super(client);
+ this.storageBuilder = storageBuilder;
+ }
+
+ /**
+ * @param modelName the name of the model
+ * @param managementData the data to create
+ * @return true if create success, false if already exist
+ * @throws IOException if any IO exception occurred
+ */
+ public boolean create(String modelName, ManagementData managementData)
throws IOException {
+ final String index =
+
IndexController.LogicIndicesRegister.getPhysicalTableName(modelName);
+
+ final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(modelName);
+ storageBuilder.entity2Storage(managementData, toStorage);
+ final String docId = IndexController.INSTANCE.generateDocId(modelName,
managementData.id().build());
+ final boolean exist = getClient().existDoc(modelName, docId);
+ if (exist) {
+ return false;
+ }
+ Map<String, Object> source =
+
IndexController.INSTANCE.appendTableColumn4ManagementData(modelName,
toStorage.obtain());
+ getClient().forceInsert(index, docId, source);
+ return true;
+ }
+
+ /**
+ * @param modelName the name of the model
+ * @param id the id of the data
+ * @return null if not found
+ * @throws IOException if any IO exception occurred
+ */
+ public ManagementData getById(String modelName, String id) throws
IOException {
+ if (StringUtil.isEmpty(id)) {
+ return null;
+ }
+ final String index =
+
IndexController.LogicIndicesRegister.getPhysicalTableName(modelName);
+ final String docId = IndexController.INSTANCE.generateDocId(modelName,
id);
+ final SearchBuilder search =
+ Search.builder().query(Query.ids(docId)).size(1);
+ final SearchResponse response = getClient().search(index,
search.build());
+
+ if (response.getHits().getHits().size() > 0) {
+
+ SearchHit data = response.getHits().getHits().get(0);
+ return storageBuilder.storage2Entity(new
ElasticSearchConverter.ToEntity(modelName, data.getSource()));
+ }
+ return null;
+ }
+
+ /**
+ * @param modelName the name of the model
+ * @param managementData the data to update
+ * @return true if update success, false if not found
+ * @throws IOException if any IO exception occurred
+ */
+ public boolean update(String modelName, ManagementData managementData)
throws IOException {
+ final String index =
+
IndexController.LogicIndicesRegister.getPhysicalTableName(modelName);
+
+ final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(modelName);
+ storageBuilder.entity2Storage(managementData, toStorage);
+ final String docId = IndexController.INSTANCE.generateDocId(modelName,
managementData.id().build());
+ final boolean exist = getClient().existDoc(modelName, docId);
+ if (!exist) {
+ return false;
+ }
+ Map<String, Object> source =
+
IndexController.INSTANCE.appendTableColumn4ManagementData(modelName,
toStorage.obtain());
+ getClient().forceUpdate(index, docId, source);
+ return true;
+ }
+
+ /**
+ * @param modelName the name of the model
+ * @param id the id of the data
+ * @return true if delete success, false if not found
+ * @throws IOException if any IO exception occurred
+ */
+ public boolean deleteById(String modelName, String id) throws IOException {
+ final String index =
+
IndexController.LogicIndicesRegister.getPhysicalTableName(modelName);
+ final String docId = IndexController.INSTANCE.generateDocId(modelName,
id);
+ final boolean exist = getClient().existDoc(modelName, docId);
+ if (!exist) {
+ return false;
+ }
+ getClient().deleteById(index, docId);
+ return true;
+ }
+}
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/ManagementEsDAO.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/ManagementEsDAO.java
index f0d0a10387..07d74c03ee 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/ManagementEsDAO.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/ManagementEsDAO.java
@@ -46,7 +46,7 @@ public class ManagementEsDAO extends EsDAO implements
IManagementDAO {
final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(model.getName());
storageBuilder.entity2Storage(managementData, toStorage);
Map<String, Object> source =
- IndexController.INSTANCE.appendTableColumn(model,
toStorage.obtain());
+
IndexController.INSTANCE.appendTableColumn4ManagementData(model.getName(),
toStorage.obtain());
getClient().forceInsert(tableName, docId, source);
}
}
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
index 5632d6d46e..39cc09e82e 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
@@ -266,7 +266,9 @@ public class StorageEsInstaller extends ModelInstaller {
//When adding a new model(with an analyzer) into an existed index by
update will be failed, if the index is without analyzer settings.
//To avoid this, add the analyzer settings to the template before index
creation.
private Map getAnalyzerSetting(Model model) throws StorageException {
- if (config.isLogicSharding() || !model.isTimeSeries()) {
+ if (!model.isTimeSeries()) {
+ return getAnalyzerSetting4MergedIndex(model);
+ } else if (config.isLogicSharding()) {
return getAnalyzerSettingByColumn(model);
} else if (model.isRecord() && model.isSuperDataset()) {
//SuperDataset doesn't merge index, the analyzer follow the column
config.
@@ -339,6 +341,12 @@ public class StorageEsInstaller extends ModelInstaller {
}
}
+ if (!model.isTimeSeries()) {
+ Map<String, Object> column = new HashMap<>();
+ column.put("type", "keyword");
+
properties.put(IndexController.LogicIndicesRegister.MANAGEMENT_TABLE_NAME,
column);
+ }
+
if ((model.isMetric() && !config.isLogicSharding())
|| (config.isLogicSharding() &&
IndexController.INSTANCE.isFunctionMetric(model))) {
Map<String, Object> column = new HashMap<>();
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/ContinuousProfilingPolicyEsDAO.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/ContinuousProfilingPolicyEsDAO.java
index 72ef40fde4..7fce8c141a 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/ContinuousProfilingPolicyEsDAO.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/ContinuousProfilingPolicyEsDAO.java
@@ -18,6 +18,7 @@
package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
+import
org.apache.skywalking.library.elasticsearch.requests.search.BoolQueryBuilder;
import org.apache.skywalking.library.elasticsearch.requests.search.Query;
import org.apache.skywalking.library.elasticsearch.requests.search.Search;
import
org.apache.skywalking.library.elasticsearch.requests.search.SearchBuilder;
@@ -25,32 +26,26 @@ import
org.apache.skywalking.library.elasticsearch.response.search.SearchHit;
import
org.apache.skywalking.library.elasticsearch.response.search.SearchResponse;
import
org.apache.skywalking.oap.server.core.profiling.continuous.storage.ContinuousProfilingPolicy;
import
org.apache.skywalking.oap.server.core.storage.profiling.continuous.IContinuousProfilingPolicyDAO;
+import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder;
import
org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.ElasticSearchConverter;
-import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.IndexController;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.ManagementCRUDEsDAO;
-public class ContinuousProfilingPolicyEsDAO extends EsDAO implements
IContinuousProfilingPolicyDAO {
- public ContinuousProfilingPolicyEsDAO(ElasticSearchClient client) {
- super(client);
+public class ContinuousProfilingPolicyEsDAO extends ManagementCRUDEsDAO
implements IContinuousProfilingPolicyDAO {
+ public ContinuousProfilingPolicyEsDAO(ElasticSearchClient client,
StorageBuilder storageBuilder) {
+ super(client, storageBuilder);
}
@Override
public void savePolicy(ContinuousProfilingPolicy policy) throws
IOException {
- final ContinuousProfilingPolicy.Builder builder = new
ContinuousProfilingPolicy.Builder();
- final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(ContinuousProfilingPolicy.INDEX_NAME);
- builder.entity2Storage(policy, toStorage);
-
- final boolean exist =
getClient().existDoc(ContinuousProfilingPolicy.INDEX_NAME, policy.id().build());
- if (exist) {
- getClient().forceUpdate(ContinuousProfilingPolicy.INDEX_NAME,
policy.id().build(), toStorage.obtain());
- } else {
- getClient().forceInsert(ContinuousProfilingPolicy.INDEX_NAME,
policy.id().build(), toStorage.obtain());
+ if (!super.create(ContinuousProfilingPolicy.INDEX_NAME, policy)) {
+ super.update(ContinuousProfilingPolicy.INDEX_NAME, policy);
}
}
@@ -58,8 +53,9 @@ public class ContinuousProfilingPolicyEsDAO extends EsDAO
implements IContinuous
public List<ContinuousProfilingPolicy> queryPolicies(List<String>
serviceIdList) throws IOException {
final String index =
IndexController.LogicIndicesRegister.getPhysicalTableName(ContinuousProfilingPolicy.INDEX_NAME);
- final SearchBuilder search = Search.builder()
- .query(Query.terms(ContinuousProfilingPolicy.SERVICE_ID,
serviceIdList))
+ final BoolQueryBuilder query =
Query.bool().must(Query.term(IndexController.LogicIndicesRegister.MANAGEMENT_TABLE_NAME,
ContinuousProfilingPolicy.INDEX_NAME));
+ query.must(Query.terms(ContinuousProfilingPolicy.SERVICE_ID,
serviceIdList));
+ final SearchBuilder search = Search.builder().query(query)
.size(serviceIdList.size());
return buildPolicies(getClient().search(index, search.build()));
@@ -75,4 +71,4 @@ public class ContinuousProfilingPolicyEsDAO extends EsDAO
implements IContinuous
return policies;
}
-}
\ No newline at end of file
+}
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UIMenuManagementEsDAO.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UIMenuManagementEsDAO.java
index 7801ad3f34..2b31b1b600 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UIMenuManagementEsDAO.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UIMenuManagementEsDAO.java
@@ -18,50 +18,26 @@
package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
-import org.apache.skywalking.library.elasticsearch.requests.search.Query;
-import org.apache.skywalking.library.elasticsearch.requests.search.Search;
-import
org.apache.skywalking.library.elasticsearch.requests.search.SearchBuilder;
-import org.apache.skywalking.library.elasticsearch.response.search.SearchHit;
-import
org.apache.skywalking.library.elasticsearch.response.search.SearchResponse;
import org.apache.skywalking.oap.server.core.management.ui.menu.UIMenu;
import
org.apache.skywalking.oap.server.core.storage.management.UIMenuManagementDAO;
+import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder;
import
org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
-import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.ElasticSearchConverter;
-import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
-import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.IndexController;
import java.io.IOException;
+import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.ManagementCRUDEsDAO;
-public class UIMenuManagementEsDAO extends EsDAO implements
UIMenuManagementDAO {
- public UIMenuManagementEsDAO(ElasticSearchClient client) {
- super(client);
+public class UIMenuManagementEsDAO extends ManagementCRUDEsDAO implements
UIMenuManagementDAO {
+ public UIMenuManagementEsDAO(ElasticSearchClient client, StorageBuilder
storageBuilder) {
+ super(client, storageBuilder);
}
@Override
public UIMenu getMenu(String id) throws IOException {
- final String index =
-
IndexController.LogicIndicesRegister.getPhysicalTableName(UIMenu.INDEX_NAME);
- final SearchBuilder search =
- Search.builder().query(Query.ids(id)).size(1);
- final SearchResponse response = getClient().search(index,
search.build());
-
- if (response.getHits().getHits().size() > 0) {
- UIMenu.Builder builder = new UIMenu.Builder();
- SearchHit data = response.getHits().getHits().get(0);
- return builder.storage2Entity(new
ElasticSearchConverter.ToEntity(UIMenu.INDEX_NAME, data.getSource()));
- }
- return null;
+ return (UIMenu) super.getById(UIMenu.INDEX_NAME, id);
}
@Override
public void saveMenu(UIMenu menu) throws IOException {
- try {
- final UIMenu.Builder builder = new UIMenu.Builder();
- final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(UIMenu.INDEX_NAME);
- builder.entity2Storage(menu, toStorage);
- getClient().forceInsert(UIMenu.INDEX_NAME, menu.id().build(),
toStorage.obtain());
- } catch (Exception e) {
- throw new IOException(e.getMessage(), e);
- }
+ super.create(UIMenu.INDEX_NAME, menu);
}
}
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UITemplateManagementEsDAO.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UITemplateManagementEsDAO.java
index a0719597b1..b3819d05a4 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UITemplateManagementEsDAO.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/UITemplateManagementEsDAO.java
@@ -18,16 +18,15 @@
package org.apache.skywalking.oap.server.storage.plugin.elasticsearch.query;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import
org.apache.skywalking.library.elasticsearch.requests.search.BoolQueryBuilder;
import org.apache.skywalking.library.elasticsearch.requests.search.Query;
import org.apache.skywalking.library.elasticsearch.requests.search.Search;
import
org.apache.skywalking.library.elasticsearch.requests.search.SearchBuilder;
-import org.apache.skywalking.library.elasticsearch.response.Document;
import org.apache.skywalking.library.elasticsearch.response.search.SearchHit;
import
org.apache.skywalking.library.elasticsearch.response.search.SearchResponse;
import org.apache.skywalking.oap.server.core.management.ui.template.UITemplate;
@@ -35,36 +34,24 @@ import
org.apache.skywalking.oap.server.core.query.input.DashboardSetting;
import org.apache.skywalking.oap.server.core.query.type.DashboardConfiguration;
import org.apache.skywalking.oap.server.core.query.type.TemplateChangeStatus;
import
org.apache.skywalking.oap.server.core.storage.management.UITemplateManagementDAO;
+import org.apache.skywalking.oap.server.core.storage.type.StorageBuilder;
import
org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.oap.server.library.util.BooleanUtils;
-import org.apache.skywalking.oap.server.library.util.StringUtil;
import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.ElasticSearchConverter;
-import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.IndexController;
+import
org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.ManagementCRUDEsDAO;
@Slf4j
-public class UITemplateManagementEsDAO extends EsDAO implements
UITemplateManagementDAO {
- public UITemplateManagementEsDAO(ElasticSearchClient client) {
- super(client);
+public class UITemplateManagementEsDAO extends ManagementCRUDEsDAO implements
UITemplateManagementDAO {
+ public UITemplateManagementEsDAO(ElasticSearchClient client,
StorageBuilder storageBuilder) {
+ super(client, storageBuilder);
}
@Override
- public DashboardConfiguration getTemplate(final String id) {
- if (StringUtil.isEmpty(id)) {
- return null;
- }
- final String index =
-
IndexController.LogicIndicesRegister.getPhysicalTableName(UITemplate.INDEX_NAME);
- final SearchBuilder search =
- Search.builder().query(Query.ids(id))
- .size(1);
- final SearchResponse response = getClient().search(index,
search.build());
-
- if (response.getHits().getHits().size() > 0) {
- UITemplate.Builder builder = new UITemplate.Builder();
- SearchHit data = response.getHits().getHits().get(0);
- return new DashboardConfiguration().fromEntity(
- builder.storage2Entity(new
ElasticSearchConverter.ToEntity(UITemplate.INDEX_NAME, data.getSource())));
+ public DashboardConfiguration getTemplate(final String id) throws
IOException {
+ UITemplate uiTemplate = (UITemplate)
super.getById(UITemplate.INDEX_NAME, id);
+ if (uiTemplate != null) {
+ return new DashboardConfiguration().fromEntity(uiTemplate);
}
return null;
}
@@ -72,6 +59,7 @@ public class UITemplateManagementEsDAO extends EsDAO
implements UITemplateManage
@Override
public List<DashboardConfiguration> getAllTemplates(final Boolean
includingDisabled) {
final BoolQueryBuilder boolQuery = Query.bool();
+
boolQuery.must(Query.term(IndexController.LogicIndicesRegister.MANAGEMENT_TABLE_NAME,
UITemplate.INDEX_NAME));
if (!includingDisabled) {
boolQuery.must(Query.term(
UITemplate.DISABLED,
@@ -93,74 +81,42 @@ public class UITemplateManagementEsDAO extends EsDAO
implements UITemplateManage
for (SearchHit searchHit : response.getHits()) {
Map<String, Object> sourceAsMap = searchHit.getSource();
- final UITemplate uiTemplate = builder.storage2Entity(new
ElasticSearchConverter.ToEntity(UITemplate.INDEX_NAME, sourceAsMap));
+ final UITemplate uiTemplate = builder.storage2Entity(
+ new ElasticSearchConverter.ToEntity(UITemplate.INDEX_NAME,
sourceAsMap));
configs.add(new DashboardConfiguration().fromEntity(uiTemplate));
}
return configs;
}
@Override
- public TemplateChangeStatus addTemplate(final DashboardSetting setting) {
- try {
- final UITemplate.Builder builder = new UITemplate.Builder();
- final UITemplate uiTemplate = setting.toEntity();
-
- final boolean exist = getClient().existDoc(UITemplate.INDEX_NAME,
uiTemplate.id().build());
- if (exist) {
- return
TemplateChangeStatus.builder().status(false).id(setting.getId()).message("Template
exists")
- .build();
- }
-
- final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(UITemplate.INDEX_NAME);
- builder.entity2Storage(uiTemplate, toStorage);
- getClient().forceInsert(UITemplate.INDEX_NAME,
uiTemplate.id().build(), toStorage.obtain());
+ public TemplateChangeStatus addTemplate(final DashboardSetting setting)
throws IOException {
+ final UITemplate uiTemplate = setting.toEntity();
+ if (super.create(UITemplate.INDEX_NAME, uiTemplate)) {
return
TemplateChangeStatus.builder().status(true).id(uiTemplate.getTemplateId()).build();
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- return
TemplateChangeStatus.builder().status(false).id(setting.getId()).message("Can't
add a new template")
- .build();
}
+ return
TemplateChangeStatus.builder().status(false).id(uiTemplate.getTemplateId())
+ .message("Template already exists").build();
}
@Override
- public TemplateChangeStatus changeTemplate(final DashboardSetting setting)
{
- try {
- final UITemplate.Builder builder = new UITemplate.Builder();
- final UITemplate uiTemplate = setting.toEntity();
-
- final boolean exist = getClient().existDoc(UITemplate.INDEX_NAME,
uiTemplate.id().build());
- if (!exist) {
- return
TemplateChangeStatus.builder().status(false).id(setting.getId())
- .message("Can't find the
template").build();
- }
-
- final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(UITemplate.INDEX_NAME);
- builder.entity2Storage(uiTemplate, toStorage);
- getClient().forceUpdate(UITemplate.INDEX_NAME,
uiTemplate.id().build(), toStorage.obtain());
- return
TemplateChangeStatus.builder().status(true).id(setting.getId()).build();
- } catch (Exception e) {
- log.error(e.getMessage(), e);
- return
TemplateChangeStatus.builder().status(false).id(setting.getId()).message("Can't
find the template")
- .build();
+ public TemplateChangeStatus changeTemplate(final DashboardSetting setting)
throws IOException {
+ final UITemplate uiTemplate = setting.toEntity();
+ if (super.update(UITemplate.INDEX_NAME, uiTemplate)) {
+ return
TemplateChangeStatus.builder().status(true).id(uiTemplate.getTemplateId()).build();
}
+ return
TemplateChangeStatus.builder().status(false).id(uiTemplate.getTemplateId())
+ .message("Can't find the template").build();
}
@Override
- public TemplateChangeStatus disableTemplate(final String id) {
- final Optional<Document> response =
getClient().get(UITemplate.INDEX_NAME, id);
- if (response.isPresent()) {
- final UITemplate.Builder builder = new UITemplate.Builder();
- final UITemplate uiTemplate = builder.storage2Entity(
- new ElasticSearchConverter.ToEntity(UITemplate.INDEX_NAME,
response.get().getSource()));
+ public TemplateChangeStatus disableTemplate(final String id) throws
IOException {
+ UITemplate uiTemplate = (UITemplate)
super.getById(UITemplate.INDEX_NAME, id);
+ if (uiTemplate != null) {
uiTemplate.setDisabled(BooleanUtils.TRUE);
-
- final ElasticSearchConverter.ToStorage toStorage = new
ElasticSearchConverter.ToStorage(UITemplate.INDEX_NAME);
- builder.entity2Storage(uiTemplate, toStorage);
- getClient().forceUpdate(UITemplate.INDEX_NAME,
uiTemplate.id().build(), toStorage.obtain());
+ super.update(UITemplate.INDEX_NAME, uiTemplate);
return TemplateChangeStatus.builder().status(true).id(id).build();
- } else {
- return
TemplateChangeStatus.builder().status(false).id(id).message("Can't find the
template")
- .build();
}
+ return
TemplateChangeStatus.builder().status(false).id(id).message("Can't find the
template")
+ .build();
}
}