Java 类org.elasticsearch.client.AdminClient 实例源码

项目:escommons    文件:ElasticsearchClientWrapperImplTest.java   
@Test
public void testCreateIndexWithoutSettings() {
    // Test data
    final String indexName = "Index_Name";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
项目:escommons    文件:ElasticsearchClientWrapperImplTest.java   
@Test
public void testCreateIndex() {
    // Test data
    final String indexName = "Index_Name";
    final Map<String, Object> settings = Collections.singletonMap("settings_key", "settings_value");
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final CreateIndexRequestBuilder createIndexRequestBuilder = createMock(CreateIndexRequestBuilder.class);
    final CreateIndexResponse createIndexResponse = createMock(CreateIndexResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareCreate(indexName)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.setSettings(settings)).andReturn(createIndexRequestBuilder);
    expect(createIndexRequestBuilder.get()).andReturn(createIndexResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.createIndex(indexName, settings);
    // Verify
    verifyAll();
    assertEquals(createIndexResponse.isAcknowledged(), result);
}
项目:escommons    文件:ElasticsearchClientWrapperImplTest.java   
@Test
public void testRefreshIndex() {
    // Test data
    final String indexName = "Index_Name";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final RefreshRequestBuilder refreshRequestBuilder = createMock(RefreshRequestBuilder.class);
    final PutMappingResponse putMappingResponse = createMock(PutMappingResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareRefresh(indexName)).andReturn(refreshRequestBuilder);
    expect(refreshRequestBuilder.get()).andReturn(createMock(RefreshResponse.class));
    // Replay
    replayAll();
    // Run test scenario
    elasticsearchClientWrapper.refreshIndex(indexName);
    // Verify
    verifyAll();
}
项目:escommons    文件:ElasticsearchClientWrapperImplTest.java   
@Test
public void testAddAlias() {
    //Test data
    final String indexName = "index";
    final String aliasName = "alias";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final IndicesAliasesRequestBuilder indicesAliasesRequestBuilder = createMock(IndicesAliasesRequestBuilder.class);
    final IndicesAliasesResponse indicesAliasesResponse = createMock(IndicesAliasesResponse.class);
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareAliases()).andReturn(indicesAliasesRequestBuilder);
    expect(indicesAliasesRequestBuilder.addAlias(indexName, aliasName)).andReturn(indicesAliasesRequestBuilder);
    expect(indicesAliasesRequestBuilder.get()).andReturn(indicesAliasesResponse);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.addAlias(indexName, aliasName);
    //Verify
    verifyAll();
    assertEquals(indicesAliasesResponse.isAcknowledged(), result);
}
项目:escommons    文件:ElasticsearchClientWrapperImplTest.java   
@Test
public void testDeleteIndex() {
    //Test data
    final String indexName = "index";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final DeleteIndexRequestBuilder deleteIndexRequestBuilder = createMock(DeleteIndexRequestBuilder.class);
    final DeleteIndexResponse deleteIndexResponse = createMock(DeleteIndexResponse.class);
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareDelete(indexName)).andReturn(deleteIndexRequestBuilder);
    expect(deleteIndexRequestBuilder.get()).andReturn(deleteIndexResponse);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.deleteIndex(indexName);
    //Verify
    verifyAll();
    assertEquals(deleteIndexResponse.isAcknowledged(), result);
}
项目:escommons    文件:ElasticsearchClientWrapperImplTest.java   
@Test
public void testIndexExists() {
    //Test data
    final String indexName = "index";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final IndicesExistsRequestBuilder indicesExistsRequestBuilder = createMock(IndicesExistsRequestBuilder.class);
    final IndicesExistsResponse indicesExistsResponse = createMock(IndicesExistsResponse.class);
    final boolean exists = new Random().nextBoolean();
    //Reset
    resetAll();
    //Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.prepareExists(indexName)).andReturn(indicesExistsRequestBuilder);
    expect(indicesExistsRequestBuilder.get()).andReturn(indicesExistsResponse);
    expect(indicesExistsResponse.isExists()).andReturn(exists);
    //Replay
    replayAll();
    //Run test scenario
    final boolean result = elasticsearchClientWrapper.indexExists(indexName);
    //Verify
    verifyAll();
    assertEquals(exists, result);
}
项目:es-service-parent    文件:IndexTransaction.java   
/**
 * 删除索引
 * 
 * @param index_type
 */
public boolean deleteIndex(String index_type) {
    try {
        AdminClient adminClient = ESClient.getClient().admin();
        if (adminClient.indices().prepareExists(index_type).execute().actionGet().isExists()) {
            ESClient.getClient().admin().indices().delete(new DeleteIndexRequest(index_type));
        }
        if (adminClient.indices().prepareExists(index_type + "_1").execute().actionGet()
                .isExists()) {
            ESClient.getClient().admin().indices()
                    .delete(new DeleteIndexRequest(index_type + "_1"));
        }
        if (adminClient.indices().prepareExists(index_type + "_2").execute().actionGet()
                .isExists()) {
            ESClient.getClient().admin().indices()
                    .delete(new DeleteIndexRequest(index_type + "_2"));
        }
        return true;
    } catch (Exception e) {
        log.error("delete index fail,indexname:{}", index_type);
    }
    return false;
}
项目:bts    文件:ElasticTest.java   
public static void main(String[] args)
{
    Node node = nodeBuilder().node();
    Client client = node.client();

    AdminClient ac = client.admin();

    client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
    ElasticTest t = new ElasticTest();
    t.initRiver(client);
    // t.initRiver(client);
    // t.getContributionsByCandName(client, "aaew_corpus_aaew_full", 0);
    t.search(client);
    // // on shutdown
    // // Configuration
    // ClientConfig clientConfig = new
    // ClientConfig.Builder("http://localhost:9200").multiThreaded(true).build();
    //
    // // Construct a new Jest client according to configuration via factory
    // JestClientFactory factory = new JestClientFactory();
    // factory.setClientConfig(clientConfig);
    // JestClient clientj = factory.getObject();
    // clientj.
    node.close();

}
项目:metron    文件:ElasticsearchColumnMetadataDaoTest.java   
/**
 * @param indices The names of all indices that will exist.
 * @param mappings The index mappings.
 * @return An object to test.
 */
public ElasticsearchColumnMetadataDao setup(
        String[] indices,
        ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {

  AdminClient adminClient = mock(AdminClient.class);
  IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
  GetIndexRequestBuilder getIndexRequestBuilder = mock(GetIndexRequestBuilder.class);
  GetIndexResponse getIndexResponse = mock(GetIndexResponse.class);
  ActionFuture getMappingsActionFuture = mock(ActionFuture.class);
  GetMappingsResponse getMappingsResponse = mock(GetMappingsResponse.class);

  // setup the mocks so that a set of indices are available to the DAO
  when(adminClient.indices()).thenReturn(indicesAdminClient);
  when(indicesAdminClient.prepareGetIndex()).thenReturn(getIndexRequestBuilder);
  when(getIndexRequestBuilder.setFeatures()).thenReturn(getIndexRequestBuilder);
  when(getIndexRequestBuilder.get()).thenReturn(getIndexResponse);
  when(getIndexResponse.getIndices()).thenReturn(indices);

  // setup the mocks so that a set of mappings are available to the DAO
  when(indicesAdminClient.getMappings(any())).thenReturn(getMappingsActionFuture);
  when(getMappingsActionFuture.actionGet()).thenReturn(getMappingsResponse);
  when(getMappingsResponse.getMappings()).thenReturn(mappings);

  return new ElasticsearchColumnMetadataDao(adminClient);
}
项目:alfa    文件:LogCleanerTest.java   
private void SetupMocks(Client client, IndicesAdminClient indicesAdminClient, ImmutableOpenMap<String, IndexMetaData> indicesMap) {
    AdminClient adminClient = mock(AdminClient.class);
    ClusterAdminClient clusterAdminClient = mock(ClusterAdminClient.class);

    @SuppressWarnings("unchecked")
    ActionFuture<ClusterStateResponse> actionFuture = ((ActionFuture<ClusterStateResponse>) mock(ActionFuture.class));
    ClusterStateResponse response = mock(ClusterStateResponse.class);
    ClusterState state = mock(ClusterState.class);
    MetaData metaData = mock(MetaData.class);

    when(client.admin()).thenReturn(adminClient);
    when(adminClient.indices()).thenReturn(indicesAdminClient);
    when(adminClient.cluster()).thenReturn(clusterAdminClient);
    when(clusterAdminClient.state(Mockito.any(ClusterStateRequest.class))).thenReturn(actionFuture);
    when(actionFuture.actionGet()).thenReturn(response);
    when(response.getState()).thenReturn(state);
    when(state.getMetaData()).thenReturn(metaData);
    when(metaData.getIndices()).thenReturn(indicesMap);
}
项目:escommons    文件:ElasticsearchClientWrapperImplTest.java   
@Test
public void testPutMapping() {
    // Test data
    final String indexName = "Index_Name";
    final String documentType = "documentType";
    final String mappings = "mappings";
    final AdminClient adminClient = createMock(AdminClient.class);
    final IndicesAdminClient indicesAdminClient = createMock(IndicesAdminClient.class);
    final PutMappingRequestBuilder putMappingRequestBuilder = createMock(PutMappingRequestBuilder.class);
    final PutMappingResponse putMappingResponse = createMock(PutMappingResponse.class);
    // Reset
    resetAll();
    // Expectations
    expect(esClient.admin()).andReturn(adminClient);
    expect(adminClient.indices()).andReturn(indicesAdminClient);
    expect(indicesAdminClient.preparePutMapping(indexName)).andReturn(putMappingRequestBuilder);
    expect(putMappingRequestBuilder.setType(documentType)).andReturn(putMappingRequestBuilder);
    expect(putMappingRequestBuilder.setSource(mappings)).andReturn(putMappingRequestBuilder);
    expect(putMappingRequestBuilder.get()).andReturn(putMappingResponse);
    // Replay
    replayAll();
    // Run test scenario
    final boolean result = elasticsearchClientWrapper.putMapping(indexName, documentType, mappings);
    // Verify
    verifyAll();
    assertEquals(putMappingResponse.isAcknowledged(), result);
}
项目:servicebuilder    文件:Indexer.java   
private static boolean isIndexingRunning(AdminClient client, String indexName) {
    IndicesStatsResponse indicesStatsResponse = client.indices()
                                                      .prepareStats(indexName)
                                                      .all()
                                                      .execute()
                                                      .actionGet();

    return indicesStatsResponse.getTotal().getIndexing().getTotal().getIndexCurrent() > INTEGER_ZERO;
}
项目:hawkular-apm    文件:AnalyticsServiceElasticsearch.java   
private static boolean refresh(String index) {
    try {
        AdminClient adminClient = client.getClient().admin();
        RefreshRequestBuilder refreshRequestBuilder = adminClient.indices().prepareRefresh(index);
        adminClient.indices().refresh(refreshRequestBuilder.request()).actionGet();
        return true;
    } catch (IndexMissingException t) {
        // Ignore, as means that no traces have
        // been stored yet
        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("Index [%s] not found, unable to proceed.", index);
        }
        return false;
    }
}
项目:hopsworks    文件:ElasticController.java   
/**
 * Checks if a given index exists in elastic
 * <p/>
 * @param client
 * @param indexName
 * @return
 */
private boolean indexExists(Client client, String indexName) {
  AdminClient admin = client.admin();
  IndicesAdminClient indices = admin.indices();

  IndicesExistsRequestBuilder indicesExistsRequestBuilder = indices.
      prepareExists(indexName);

  IndicesExistsResponse response = indicesExistsRequestBuilder
      .execute()
      .actionGet();

  return response.isExists();
}
项目:hopsworks    文件:ElasticController.java   
/**
 * Checks if a given data type exists. It is a given that the index exists
 * <p/>
 * @param client
 * @param typeName
 * @return
 */
private boolean typeExists(Client client, String indexName, String typeName) {
  AdminClient admin = client.admin();
  IndicesAdminClient indices = admin.indices();

  ActionFuture<TypesExistsResponse> action = indices.typesExists(
      new TypesExistsRequest(
          new String[]{indexName}, typeName));

  TypesExistsResponse response = action.actionGet();

  return response.isExists();
}
项目:usergrid    文件:EsIndexCacheImpl.java   
private String[] getIndexesFromEs(final String aliasName){
    final AdminClient adminClient = this.provider.getClient().admin();
         //remove write alias, can only have one
    ImmutableOpenMap<String, List<AliasMetaData>> aliasMap =
        adminClient.indices().getAliases( new GetAliasesRequest( aliasName ) ).actionGet().getAliases();
    return aliasMap.keys().toArray( String.class );
}
项目:usergrid    文件:EsEntityIndexImpl.java   
private void addAlias(String indexName) {
    Timer.Context timer = updateAliasTimer.time();
    try {
        Boolean isAck;

        final AdminClient adminClient = esProvider.getClient().admin();

        String[] indexNames = getIndexes(AliasType.Write);

        int count = 0;
        IndicesAliasesRequestBuilder aliasesRequestBuilder = adminClient.indices().prepareAliases();
        for (String currentIndex : indexNames) {
            aliasesRequestBuilder.removeAlias(currentIndex, alias.getWriteAlias());
            count++;
        }
        if (count > 0) {
            isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
            logger.info("Removed Index Name from Alias=[{}] ACK=[{}]", alias, isAck);
        }
        aliasesRequestBuilder = adminClient.indices().prepareAliases();
        //Added For Graphite Metrics
        //add write alias
        aliasesRequestBuilder.addAlias(indexName, alias.getWriteAlias());
        //Added For Graphite Metrics
        // add read alias
        aliasesRequestBuilder.addAlias(indexName, alias.getReadAlias());

        isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
        logger.info("Created new read and write aliases ACK=[{}]", isAck);
        aliasCache.invalidate(alias);

    } catch (Exception e) {
        logger.warn("Failed to create alias ", e);
    } finally {
        timer.stop();
    }
}
项目:musicbrainz-elasticsearch    文件:TestMusicAlbumJob.java   
@Before
public void checkElasticSearchHealth() throws Throwable {
    AdminClient admin = client.admin();
    ClusterAdminClient cluster = admin.cluster();
    ClusterHealthRequest request = new ClusterHealthRequest().waitForGreenStatus();
    ActionFuture<ClusterHealthResponse> health = cluster.health(request);
    ClusterHealthResponse healthResponse = health.get();
    assertEquals(ClusterHealthStatus.GREEN, healthResponse.getStatus());

    Operation operation = sequenceOf(StaticDataOperations.ALL_STATIC_DATA_ROWS,
            ArtistU2Operations.RELEASE_GROUP_U2_ROWS);
    DbSetup dbSetup = new DbSetup(new DataSourceDestination(dataSource),
            operation);
    dbSetup.launch();
}
项目:elasticsearch_my    文件:AbstractClient.java   
@Override
public final AdminClient admin() {
    return admin;
}
项目:elasticsearch-java-client    文件:DummyClient.java   
@Override
public AdminClient admin() {
    // TODO Auto-generated method stub
    return null;
}
项目:egov-search    文件:AbstractNodeIntegrationTest.java   
protected AdminClient adminClient() {
    return node.client().admin();
}
项目:metron    文件:ElasticsearchColumnMetadataDao.java   
/**
 * @param adminClient The Elasticsearch admin client.
 */
public ElasticsearchColumnMetadataDao(AdminClient adminClient) {
  this.adminClient = adminClient;
}
项目:elasticsearch_my    文件:ESIntegTestCase.java   
/**
 * Returns a random admin client. This client can either be a node or a transport client pointing to any of
 * the nodes in the cluster.
 */
protected AdminClient admin() {
    return client().admin();
}
项目:elasticsearch-sample-plugin-audit    文件:ElasticsearchIntegrationTest.java   
/**
 * Returns a random admin client. This client can either be a node or a transport client pointing to any of
 * the nodes in the cluster.
 */
protected AdminClient admin() {
    return client().admin();
}
项目:elasticsearch-cluster-runner    文件:ElasticsearchClusterRunner.java   
/**
 * Return an elasticsearch admin client.
 *
 * @return
 */
public AdminClient admin() {
    return client().admin();
}