healchow commented on code in PR #4238:
URL: https://github.com/apache/incubator-inlong/pull/4238#discussion_r875524696
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/es/ElasticsearchConfig.java:
##########
@@ -104,4 +104,45 @@ private void setEsAuth(RestClientBuilder builder) {
logger.error("set es auth error ", e);
}
}
+
+ public void setHost(String arg) {
Review Comment:
Just add the `@Data` annotation in the class, no need to add every set and
get methods.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/es/ElasticsearchResourceOperator.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.inlong.manager.service.resource.es;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.inlong.manager.common.enums.GlobalConstants;
+import org.apache.inlong.manager.common.enums.SinkStatus;
+import org.apache.inlong.manager.common.enums.SinkType;
+import org.apache.inlong.manager.common.exceptions.WorkflowException;
+import org.apache.inlong.manager.common.pojo.sink.SinkInfo;
+import org.apache.inlong.manager.common.pojo.sink.es.ElasticsearchColumnInfo;
+import org.apache.inlong.manager.common.pojo.sink.es.ElasticsearchSinkDTO;
+import org.apache.inlong.manager.common.pojo.sink.es.ElasticsearchTableInfo;
+import org.apache.inlong.manager.dao.entity.StreamSinkFieldEntity;
+import org.apache.inlong.manager.dao.mapper.StreamSinkFieldEntityMapper;
+import org.apache.inlong.manager.service.resource.SinkResourceOperator;
+import org.apache.inlong.manager.service.sink.StreamSinkService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ElasticSearch resource operator
+ */
+@Service
+public class ElasticsearchResourceOperator implements SinkResourceOperator {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(ElasticsearchResourceOperator.class);
+ @Autowired
+ private StreamSinkService sinkService;
+ @Autowired
+ private StreamSinkFieldEntityMapper sinkFieldMapper;
+
+ @Override
+ public Boolean accept(SinkType sinkType) {
+ return SinkType.ELASTICSEARCH == sinkType;
+ }
+
+ /**
+ * Create ES index according to the groupId and ES config
+ */
+ @Override
+ public void createSinkResource(SinkInfo sinkInfo) {
+ if (sinkInfo == null) {
+ LOGGER.warn("sink info was null, skip to create resource");
+ return;
+ }
+
+ if
(SinkStatus.CONFIG_SUCCESSFUL.getCode().equals(sinkInfo.getStatus())) {
+ LOGGER.warn("sink resource [" + sinkInfo.getId() + "] already
success, skip to create");
+ return;
+ } else if
(GlobalConstants.DISABLE_CREATE_RESOURCE.equals(sinkInfo.getEnableCreateResource()))
{
+ LOGGER.warn("create resource was disabled, skip to create for [" +
sinkInfo.getId() + "]");
+ return;
+ }
+
+ this.createIndex(sinkInfo);
+ }
+
+ private void createIndex(SinkInfo sinkInfo) {
+ LOGGER.info("begin to create ES Index for sinkId={}",
sinkInfo.getId());
+
+ List<StreamSinkFieldEntity> fieldList =
sinkFieldMapper.selectBySinkId(sinkInfo.getId());
+ if (CollectionUtils.isEmpty(fieldList)) {
+ LOGGER.warn("no ES fields found, skip to create table for
sinkId={}", sinkInfo.getId());
Review Comment:
`no es fields found, skip to create index for sinkId={}`
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/es/ElasticsearchApi.java:
##########
@@ -76,7 +93,157 @@ public boolean indexExists(String indexName) throws
IOException {
return getEsClient().indices().exists(getIndexRequest,
RequestOptions.DEFAULT);
}
+ /**
+ * Create index
+ *
+ * @param indexName The index name of elasticsearch
+ * @return void
+ * @throws IOException The exception may throws
+ */
+ public void createIndex(String indexName) throws IOException {
+ CreateIndexRequest createIndexRequest = new
CreateIndexRequest(indexName);
+
+ CreateIndexResponse createIndexResponse = getEsClient().indices()
+ .create(createIndexRequest, RequestOptions.DEFAULT);
+ LOG.info("create es index: {}", createIndexResponse.isAcknowledged());
Review Comment:
Maybe adding more log info is good to locate problem.
##########
inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/resource/es/ElasticsearchApi.java:
##########
@@ -76,7 +93,157 @@ public boolean indexExists(String indexName) throws
IOException {
return getEsClient().indices().exists(getIndexRequest,
RequestOptions.DEFAULT);
}
+ /**
+ * Create index
+ *
+ * @param indexName The index name of elasticsearch
+ * @return void
Review Comment:
Returns void is unnecessary.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]