Search in sources :

Example 26 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project ecs-dashboard by carone1.

the class ElasticNamespaceDetailDAO method initNamespaceDetailIndex.

private void initNamespaceDetailIndex(Date collectionTime) {
    String collectionDayString = DATA_DATE_FORMAT.format(collectionTime);
    namespacedetailIndexDayName = NAMESPACE_DETAIL_INDEX_NAME + "-" + collectionDayString;
    if (elasticClient.admin().indices().exists(new IndicesExistsRequest(namespacedetailIndexDayName)).actionGet().isExists()) {
        // Index already exists need to truncate it and recreate it
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(namespacedetailIndexDayName);
        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(namespacedetailIndexDayName)).actionGet();
    try {
        PutMappingResponse putMappingResponse = elasticClient.admin().indices().preparePutMapping(namespacedetailIndexDayName).setType(DETAIL_NAMESPACE_INDEX_TYPE).setSource(XContentFactory.jsonBuilder().prettyPrint().startObject().startObject(DETAIL_NAMESPACE_INDEX_TYPE).startObject("properties").startObject(NamespaceDetail.ID).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.LINK).field("type", "string").endObject().startObject(NamespaceDetail.NAME).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.NAME + ANALYZED_TAG).field("type", "string").field("index", ANALYZED_INDEX).endObject().startObject(NamespaceDetail.DEFAULT_DATA_SERVCIES_VPOOL).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.ALLOWED_VPOOLS_LIST).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.DISALLOWED_VPOOLS_LIST).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.NAMESPACE_ADMINS).field("type", "string").field("index", NOT_ANALYZED_INDEX).endObject().startObject(NamespaceDetail.IS_ENCRYPTION_ENABLED).field("type", "boolean").endObject().startObject(NamespaceDetail.DEFAULT_BUCKET_BLOCK_SIZE).field("type", "long").endObject().startObject(NamespaceDetail.USER_MAPPING).field("type", "string").endObject().startObject(NamespaceDetail.IS_STALE_ALLOWED).field("type", "boolean").endObject().startObject(NamespaceDetail.IS_COMPLIANCE_ENABLED).field("type", "boolean").endObject().startObject(NamespaceDetail.EXTERNAL_GROUP_ADMINS).field("type", "string").endObject().startObject(NamespaceDetail.GLOBAL).field("type", "boolean").endObject().startObject(NamespaceDetail.INACTIVE).field("type", "boolean").endObject().startObject(NamespaceDetail.REMOTE).field("type", "boolean").endObject().startObject(NamespaceDetail.INTERNAL).field("type", "boolean").endObject().startObject(NamespaceDetail.VDC).field("type", "string").endObject().startObject(NamespaceDetail.CREATION_TIME).field("type", "date").field("format", "strict_date_optional_time||epoch_millis").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: " + namespacedetailIndexDayName);
        } else {
            LOGGER.error("Index {" + namespacedetailIndexDayName + "} did not exist. " + "While attempting to create the index in ElasticSearch " + "Templates we were unable to get an acknowledgement.", namespacedetailIndexDayName);
            LOGGER.error("Error Message: {}", putMappingResponse.toString());
            throw new RuntimeException("Unable to create index " + namespacedetailIndexDayName);
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to create index " + namespacedetailIndexDayName + " " + 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 IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest 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 28 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest 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 29 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest 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 30 with IndicesExistsRequest

use of org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest in project alien4cloud by alien4cloud.

the class EsDaoCrudTest method assertIndexExists.

private void assertIndexExists(String indexName, boolean expected) throws InterruptedException, ExecutionException {
    final ActionFuture<IndicesExistsResponse> indexExistFuture = nodeClient.admin().indices().exists(new IndicesExistsRequest(indexName));
    final IndicesExistsResponse response = indexExistFuture.get();
    assertEquals(expected, response.isExists());
}
Also used : IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) IndicesExistsRequest(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)

Aggregations

IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)34 Test (org.junit.Test)13 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)12 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)12 IOException (java.io.IOException)10 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)10 IndicesExistsResponse (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse)10 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)9 Matchers.containsString (org.hamcrest.Matchers.containsString)9 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 SQLTransportIntegrationTest (io.crate.integrationtests.SQLTransportIntegrationTest)2 PartitionName (io.crate.metadata.PartitionName)2 BytesRef (org.apache.lucene.util.BytesRef)2 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)2 TypesExistsRequest (org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest)2 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)2 FailedException (backtype.storm.topology.FailedException)1 ConsoleLogger (com.creditease.monitor.log.ConsoleLogger)1 TransportHookProxy (com.creditease.uav.hook.esclient.transport.TransportHookProxy)1 TitanException (com.thinkaurelius.titan.core.TitanException)1