mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-08-20 06:58:18 +00:00
* Fix #1814: Add migrate-all option to update ElasticSearch index mappings * Fix #1814: Add migrate-all option to update ElasticSearch index mappings
This commit is contained in:
parent
df6232ef52
commit
39e4163d6f
@ -88,6 +88,9 @@ drop-create )
|
|||||||
drop-create-all )
|
drop-create-all )
|
||||||
execute "drop" && execute "create" && execute "es-drop" && execute "es-create"
|
execute "drop" && execute "create" && execute "es-drop" && execute "es-create"
|
||||||
;;
|
;;
|
||||||
|
migrate-all )
|
||||||
|
execute "migrate" && execute "es-migrate"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
printUsage
|
printUsage
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -27,6 +27,7 @@ import org.elasticsearch.client.RestHighLevelClient;
|
|||||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||||
import org.elasticsearch.client.indices.GetIndexRequest;
|
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||||
|
import org.elasticsearch.client.indices.PutMappingRequest;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.openmetadata.catalog.Entity;
|
import org.openmetadata.catalog.Entity;
|
||||||
import org.openmetadata.catalog.entity.data.Dashboard;
|
import org.openmetadata.catalog.entity.data.Dashboard;
|
||||||
@ -84,6 +85,16 @@ public class ElasticSearchIndexDefinition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateIndexes() {
|
||||||
|
try {
|
||||||
|
for (ElasticSearchIndexType elasticSearchIndexType : ElasticSearchIndexType.values()) {
|
||||||
|
updateIndex(elasticSearchIndexType);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Failed to created Elastic Search indexes due to", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void dropIndexes() {
|
public void dropIndexes() {
|
||||||
try {
|
try {
|
||||||
for (ElasticSearchIndexType elasticSearchIndexType : ElasticSearchIndexType.values()) {
|
for (ElasticSearchIndexType elasticSearchIndexType : ElasticSearchIndexType.values()) {
|
||||||
@ -123,6 +134,32 @@ public class ElasticSearchIndexDefinition {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean updateIndex(ElasticSearchIndexType elasticSearchIndexType) {
|
||||||
|
try {
|
||||||
|
GetIndexRequest gRequest = new GetIndexRequest(elasticSearchIndexType.indexName);
|
||||||
|
gRequest.local(false);
|
||||||
|
boolean exists = client.indices().exists(gRequest, RequestOptions.DEFAULT);
|
||||||
|
String elasticSearchIndexMapping = getIndexMapping(elasticSearchIndexType);
|
||||||
|
if (exists) {
|
||||||
|
PutMappingRequest request = new PutMappingRequest(elasticSearchIndexType.indexName);
|
||||||
|
request.source(elasticSearchIndexMapping, XContentType.JSON);
|
||||||
|
AcknowledgedResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||||
|
LOG.info(elasticSearchIndexType.indexName + " Updated " + putMappingResponse.isAcknowledged());
|
||||||
|
} else {
|
||||||
|
CreateIndexRequest request = new CreateIndexRequest(elasticSearchIndexType.indexName);
|
||||||
|
request.mapping(elasticSearchIndexMapping, XContentType.JSON);
|
||||||
|
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
|
||||||
|
LOG.info(elasticSearchIndexType.indexName + " Created " + createIndexResponse.isAcknowledged());
|
||||||
|
}
|
||||||
|
setIndexStatus(elasticSearchIndexType, ElasticSearchIndexStatus.CREATED);
|
||||||
|
} catch (Exception e) {
|
||||||
|
setIndexStatus(elasticSearchIndexType, ElasticSearchIndexStatus.FAILED);
|
||||||
|
LOG.error("Failed to created Elastic Search indexes due to", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean deleteIndex(ElasticSearchIndexType elasticSearchIndexType) {
|
private boolean deleteIndex(ElasticSearchIndexType elasticSearchIndexType) {
|
||||||
try {
|
try {
|
||||||
DeleteIndexRequest request = new DeleteIndexRequest(elasticSearchIndexType.indexName);
|
DeleteIndexRequest request = new DeleteIndexRequest(elasticSearchIndexType.indexName);
|
||||||
|
@ -76,6 +76,7 @@ public final class TablesInitializer {
|
|||||||
null, SchemaMigrationOption.ES_CREATE.toString(), false, "Creates all the indexes in the elastic search");
|
null, SchemaMigrationOption.ES_CREATE.toString(), false, "Creates all the indexes in the elastic search");
|
||||||
OPTIONS.addOption(
|
OPTIONS.addOption(
|
||||||
null, SchemaMigrationOption.ES_DROP.toString(), false, "Drop all the indexes in the elastic search");
|
null, SchemaMigrationOption.ES_DROP.toString(), false, "Drop all the indexes in the elastic search");
|
||||||
|
OPTIONS.addOption(null, SchemaMigrationOption.ES_MIGRATE.toString(), false, "Update Elastic Search index mapping");
|
||||||
}
|
}
|
||||||
|
|
||||||
private TablesInitializer() {}
|
private TablesInitializer() {}
|
||||||
@ -207,6 +208,10 @@ public final class TablesInitializer {
|
|||||||
esIndexDefinition = new ElasticSearchIndexDefinition(client);
|
esIndexDefinition = new ElasticSearchIndexDefinition(client);
|
||||||
esIndexDefinition.createIndexes();
|
esIndexDefinition.createIndexes();
|
||||||
break;
|
break;
|
||||||
|
case ES_MIGRATE:
|
||||||
|
esIndexDefinition = new ElasticSearchIndexDefinition(client);
|
||||||
|
esIndexDefinition.updateIndexes();
|
||||||
|
break;
|
||||||
case ES_DROP:
|
case ES_DROP:
|
||||||
esIndexDefinition = new ElasticSearchIndexDefinition(client);
|
esIndexDefinition = new ElasticSearchIndexDefinition(client);
|
||||||
esIndexDefinition.dropIndexes();
|
esIndexDefinition.dropIndexes();
|
||||||
@ -230,7 +235,8 @@ public final class TablesInitializer {
|
|||||||
DROP("drop"),
|
DROP("drop"),
|
||||||
REPAIR("repair"),
|
REPAIR("repair"),
|
||||||
ES_DROP("es-drop"),
|
ES_DROP("es-drop"),
|
||||||
ES_CREATE("es-create");
|
ES_CREATE("es-create"),
|
||||||
|
ES_MIGRATE("es-migrate");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
@ -13,5 +13,5 @@
|
|||||||
while ! wget -O /dev/null -o /dev/null mysql:3306; do sleep 5; done
|
while ! wget -O /dev/null -o /dev/null mysql:3306; do sleep 5; done
|
||||||
cp /openmetadata.yaml /openmetadata-*/conf/openmetadata.yaml
|
cp /openmetadata.yaml /openmetadata-*/conf/openmetadata.yaml
|
||||||
cd /openmetadata-*/
|
cd /openmetadata-*/
|
||||||
./bootstrap/bootstrap_storage.sh drop-create-all
|
./bootstrap/bootstrap_storage.sh migrate-all
|
||||||
./bin/openmetadata-server-start.sh conf/openmetadata.yaml
|
./bin/openmetadata-server-start.sh conf/openmetadata.yaml
|
||||||
|
Loading…
x
Reference in New Issue
Block a user