Search in sources :

Example 26 with DeleteIndexRequest

use of 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());
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 27 with DeleteIndexRequest

use of 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());
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 28 with DeleteIndexRequest

use of 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());
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Example 29 with DeleteIndexRequest

use of 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()));
    }
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)

Example 30 with DeleteIndexRequest

use of 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();
}
Also used : Connection(java.sql.Connection) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) IOException(java.io.IOException) IOException(java.io.IOException) SQLException(java.sql.SQLException) AfterMethod(org.testng.annotations.AfterMethod) Parameters(org.testng.annotations.Parameters)

Aggregations

DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)37 IOException (java.io.IOException)15 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)15 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)13 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)12 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)9 ArrayList (java.util.ArrayList)6 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)6 List (java.util.List)5 Row1 (io.crate.data.Row1)3 OneRowActionListener (io.crate.execution.support.OneRowActionListener)3 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)3 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)3 MultiSearchRequest (org.elasticsearch.action.search.MultiSearchRequest)3 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 FutureActionListener (io.crate.action.FutureActionListener)2 Row (io.crate.data.Row)2 RowConsumer (io.crate.data.RowConsumer)2 DependencyCarrier (io.crate.planner.DependencyCarrier)2 Plan (io.crate.planner.Plan)2