use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project ecs-dashboard by carone1.
the class ElasticNamespaceQuotaDAO method initNamespaceQuotaIndex.
/**
* @param collectionTime
*/
private void initNamespaceQuotaIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
namespacequotaIndexDayName = NAMESPACE_QUOTA_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(namespacequotaIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(namespacequotaIndexDayName);
ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
// Wait until deletion is done
while (!futureResult.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
elasticClient.admin().indices().create(new CreateIndexRequest(namespacequotaIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(namespacequotaIndexDayName).setType(QUOTA_NAMESPACE_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(QUOTA_NAMESPACE_INDEX_TYPE).startObject("properties").startObject(NamespaceQuota.BLOCK_SIZE).field("type", "long").endObject().startObject(NamespaceQuota.NOTIFICATION_SIZE).field("type", "long").endObject().startObject(NamespaceQuota.NAMESPACE).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceQuota.NAMESPACE + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
if (putMappingResponse.isAcknowledged()) {
LOGGER.info("Index Created: " + namespacequotaIndexDayName);
} else {
LOGGER.error("Index {" + namespacequotaIndexDayName + "} did not exist. " + "While attempting to create the index in ElasticSearch " + "Templates we were unable to get an acknowledgement.", namespacequotaIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + namespacequotaIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + namespacequotaIndexDayName + " " + e.getMessage());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project ecs-dashboard by carone1.
the class ElasticS3ObjectDAO method initS3ObjectIndex.
// =======================
// Private methods
// =======================
/**
* Init Object index
*/
private void initS3ObjectIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
s3ObjectIndexDayName = S3_OBJECT_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(s3ObjectIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(s3ObjectIndexDayName);
ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
// Wait until deletion is done
while (!futureResult.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
elasticClient.admin().indices().create(new CreateIndexRequest(s3ObjectIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(s3ObjectIndexDayName).setType(S3_OBJECT_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(S3_OBJECT_INDEX_TYPE).startObject("properties").startObject(LAST_MODIFIED_TAG).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(SIZE_TAG).field("type", "string").field("type", "long").endObject().startObject(KEY_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(KEY_TAG + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(ETAG_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NAMESPACE_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(BUCKET_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_NAME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(CUSTOM_GID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(CUSTOM_UID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(CUSTOM_MODIFIED_TIME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
if (putMappingResponse.isAcknowledged()) {
LOGGER.info("Index Created: " + s3ObjectIndexDayName);
} else {
LOGGER.error("Index {} did not exist. " + "While attempting to create the index from stored ElasticSearch " + "Templates we were unable to get an acknowledgement.", s3ObjectIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + s3ObjectIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + s3ObjectIndexDayName + " " + e.getMessage());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project ecs-dashboard by carone1.
the class ElasticS3ObjectDAO method initS3ObjectVersionIndex.
/**
* Init Object version index
*/
private void initS3ObjectVersionIndex(Date collectionTime) {
String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
s3ObjectVersionIndexDayName = S3_OBJECT_VERSION_INDEX_NAME + "-" + collectionDayString;
if (elasticClient.admin().indices().exists(new IndicesExistsRequest(s3ObjectVersionIndexDayName)).actionGet().isExists()) {
// Index already exists need to truncate it and recreate it
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(s3ObjectVersionIndexDayName);
ActionFuture<DeleteIndexResponse> futureResult = elasticClient.admin().indices().delete(deleteIndexRequest);
// Wait until deletion is done
while (!futureResult.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
elasticClient.admin().indices().create(new CreateIndexRequest(s3ObjectVersionIndexDayName)).actionGet();
try {
PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(s3ObjectVersionIndexDayName).setType(S3_OBJECT_VERSION_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(S3_OBJECT_VERSION_INDEX_TYPE).startObject("properties").startObject(LAST_MODIFIED_TAG).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().startObject(SIZE_TAG).field("type", "string").field("type", "long").endObject().startObject(KEY_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(KEY_TAG + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(ETAG_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NAMESPACE_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(BUCKET_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(VERSION_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(IS_LATEST_TAG).field("type", "boolean").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_ID_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(OWNER_NAME_TAG).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(COLLECTION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").endObject().endObject().startArray("dynamic_templates").startObject().startObject("notanalyzed").field("match", "*").field("match_mapping_type", "string").startObject("mapping").field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().endObject().endObject().endArray().endObject().endObject()).execute().actionGet();
if (putMappingResponse.isAcknowledged()) {
LOGGER.info("Index Created: " + s3ObjectVersionIndexDayName);
} else {
LOGGER.error("Index {} did not exist. " + "While attempting to create the index from stored ElasticSearch " + "Templates we were unable to get an acknowledgement.", s3ObjectVersionIndexDayName);
LOGGER.error("Error Message: {}", putMappingResponse.toString());
throw new RuntimeException("Unable to create index " + s3ObjectVersionIndexDayName);
}
} catch (IOException e) {
throw new RuntimeException("Unable to create index " + s3ObjectVersionIndexDayName + " " + e.getMessage());
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project chili-core by codingchili.
the class ElasticMap method clear.
@Override
public void clear(Handler<AsyncResult<Void>> handler) {
DeleteIndexResponse response = client.admin().indices().delete(new DeleteIndexRequest(context.database())).actionGet();
if (response.isAcknowledged()) {
client.admin().indices().refresh(new RefreshRequest(context.database()));
handler.handle(result());
context.onCollectionDropped();
} else {
handler.handle(error(new StorageFailureException()));
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest in project elasticsearch-jdbc by jprante.
the class AbstractColumnStrategyTest method afterMethod.
@AfterMethod
@Parameters({ "stopurl", "user", "password", "delete" })
public void afterMethod(String stopurl, String user, String password, @Optional String resourceName) throws Exception {
logger.info("remove table {}", resourceName);
if (resourceName == null || "".equals(resourceName)) {
return;
}
// before dropping tables, open read connection must be closed to avoid hangs in mysql/postgresql
logger.debug("closing reads...");
source.closeReading();
logger.debug("connecting for close...");
Connection connection = source.getConnectionForWriting();
if (connection == null) {
throw new IOException("no connection");
}
logger.debug("cleaning...");
// clean up tables
sqlScript(connection, resourceName);
logger.debug("closing writes...");
source.closeWriting();
// we can drop database by a magic 'stop' URL
source = newSource();
source.setUrl(stopurl).setUser(user).setPassword(password).setLocale(Locale.getDefault()).setTimeZone(TimeZone.getDefault());
try {
logger.info("connecting to stop URL...");
// activate stop URL
source.getConnectionForWriting();
} catch (Exception e) {
// exception is expected, ignore
}
// close open write connection
source.closeWriting();
logger.info("stopped");
// delete test index
try {
client("1").admin().indices().delete(new DeleteIndexRequest(index)).actionGet();
logger.info("index {} deleted", index);
} catch (Exception e) {
logger.warn(e.getMessage());
}
stopNodes();
}
Aggregations