Search in sources :

Example 1 with SearchIndexStatistics

use of org.finra.herd.model.api.xml.SearchIndexStatistics in project herd by FINRAOS.

the class SearchIndexServiceImplTest method testCreateSearchIndexStatisticsNoIndexCreationDate.

@Test
public void testCreateSearchIndexStatisticsNoIndexCreationDate() {
    // Create a search index get settings response without the index creation date setting.
    ImmutableOpenMap<String, Settings> getIndexResponseSettings = ImmutableOpenMap.<String, Settings>builder().fPut(SEARCH_INDEX_NAME, Settings.builder().put(IndexMetaData.SETTING_INDEX_UUID, SEARCH_INDEX_STATISTICS_INDEX_UUID).build()).build();
    // Mock an index docs stats object.
    DocsStats mockedDocsStats = mock(DocsStats.class);
    when(mockedDocsStats.getCount()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS);
    when(mockedDocsStats.getDeleted()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS);
    // Get a search index settings created.
    SearchIndexStatistics response = searchIndexServiceImpl.createSearchIndexStatistics(getIndexResponseSettings.get(SEARCH_INDEX_NAME), mockedDocsStats, 0l);
    // Verify the external calls.
    verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
    // Validate the returned object.
    assertEquals(new SearchIndexStatistics(NO_SEARCH_INDEX_STATISTICS_CREATION_DATE, SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS, SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS, SEARCH_INDEX_STATISTICS_INDEX_UUID, 0l), response);
}
Also used : SearchIndexStatistics(org.finra.herd.model.api.xml.SearchIndexStatistics) DocsStats(org.elasticsearch.index.shard.DocsStats) Settings(org.elasticsearch.common.settings.Settings) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 2 with SearchIndexStatistics

use of org.finra.herd.model.api.xml.SearchIndexStatistics in project herd by FINRAOS.

the class SearchIndexServiceImpl method createSearchIndexStatistics.

/**
 * Creates a new search index statistics objects per specified parameters.
 *
 * @param settings the search index settings
 * @param docsStats the search index docs stats
 * @param indexCount the count of index
 *
 * @return the newly created search index statistics object
 */
protected SearchIndexStatistics createSearchIndexStatistics(Settings settings, DocsStats docsStats, long indexCount) {
    SearchIndexStatistics searchIndexStatistics = new SearchIndexStatistics();
    Long creationDate = settings.getAsLong(IndexMetaData.SETTING_CREATION_DATE, -1L);
    if (creationDate.longValue() != -1L) {
        DateTime creationDateTime = new DateTime(creationDate, DateTimeZone.UTC);
        searchIndexStatistics.setIndexCreationDate(HerdDateUtils.getXMLGregorianCalendarValue(creationDateTime.toDate()));
    }
    searchIndexStatistics.setIndexNumberOfActiveDocuments(docsStats.getCount());
    searchIndexStatistics.setIndexNumberOfDeletedDocuments(docsStats.getDeleted());
    searchIndexStatistics.setIndexUuid(settings.get(IndexMetaData.SETTING_INDEX_UUID));
    searchIndexStatistics.setIndexCount(indexCount);
    return searchIndexStatistics;
}
Also used : SearchIndexStatistics(org.finra.herd.model.api.xml.SearchIndexStatistics) DateTime(org.joda.time.DateTime)

Example 3 with SearchIndexStatistics

use of org.finra.herd.model.api.xml.SearchIndexStatistics in project herd by FINRAOS.

the class SearchIndexServiceTest method testGetSearchIndex.

@Test
public void testGetSearchIndex() {
    // Create a search index key.
    SearchIndexKey searchIndexKey = new SearchIndexKey(SEARCH_INDEX_NAME);
    // Create the search index entity.
    SearchIndexEntity searchIndexEntity = createTestSearchIndexEntity();
    // Mock some of the external call responses.
    @SuppressWarnings("unchecked") DocsStats mockedDocsStats = mock(DocsStats.class);
    java.util.Map<String, String> map = new HashMap<>();
    map.put(IndexMetaData.SETTING_INDEX_UUID, SEARCH_INDEX_STATISTICS_INDEX_UUID);
    map.put(IndexMetaData.SETTING_CREATION_DATE, Long.toString(SEARCH_INDEX_STATISTICS_CREATION_DATE.toGregorianCalendar().getTimeInMillis()));
    Settings settings = Settings.builder().put(map).build();
    // Mock the external calls.
    when(alternateKeyHelper.validateStringParameter("Search index name", SEARCH_INDEX_NAME)).thenReturn(SEARCH_INDEX_NAME);
    when(searchIndexDaoHelper.getSearchIndexEntity(searchIndexKey)).thenReturn(searchIndexEntity);
    when(indexFunctionsDao.getIndexSettings(SEARCH_INDEX_NAME)).thenReturn(settings);
    when(indexFunctionsDao.getIndexStats(SEARCH_INDEX_NAME)).thenReturn(mockedDocsStats);
    when(mockedDocsStats.getCount()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS);
    when(mockedDocsStats.getDeleted()).thenReturn(SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS);
    when(configurationHelper.getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class)).thenReturn("doc");
    when(indexFunctionsDao.getNumberOfTypesInIndex(any(), any())).thenReturn(0l);
    // Get a search index.
    SearchIndex response = searchIndexService.getSearchIndex(searchIndexKey);
    // Verify the external calls.
    verify(alternateKeyHelper).validateStringParameter("Search index name", SEARCH_INDEX_NAME);
    verify(searchIndexDaoHelper).getSearchIndexEntity(searchIndexKey);
    verify(mockedDocsStats).getCount();
    verify(mockedDocsStats).getDeleted();
    verify(indexFunctionsDao).getIndexSettings(SEARCH_INDEX_NAME);
    verify(indexFunctionsDao).getIndexStats(SEARCH_INDEX_NAME);
    verify(configurationHelper).getProperty(ConfigurationValue.ELASTICSEARCH_BDEF_DOCUMENT_TYPE, String.class);
    verify(indexFunctionsDao).getNumberOfTypesInIndex(any(), any());
    verifyNoMoreInteractions(alternateKeyHelper, businessObjectDefinitionDao, businessObjectDefinitionHelper, configurationDaoHelper, configurationHelper, indexFunctionsDao, searchIndexDao, searchIndexDaoHelper, searchIndexHelperService, searchIndexStatusDaoHelper, searchIndexTypeDaoHelper);
    // response.getSearchIndexStatistics().setIndexCreationDate(SEARCH_INDEX_STATISTICS_CREATION_DATE);
    // Validate the returned object.
    assertEquals(new SearchIndex(searchIndexKey, SEARCH_INDEX_TYPE_BDEF, SEARCH_INDEX_STATUS, SEARCH_INDEX_DEFAULT_ACTIVE_FLAG, new SearchIndexStatistics(SEARCH_INDEX_STATISTICS_CREATION_DATE, SEARCH_INDEX_STATISTICS_NUMBER_OF_ACTIVE_DOCUMENTS, SEARCH_INDEX_STATISTICS_NUMBER_OF_DELETED_DOCUMENTS, SEARCH_INDEX_STATISTICS_INDEX_UUID, 0l), USER_ID, CREATED_ON, UPDATED_ON), response);
}
Also used : SearchIndexStatistics(org.finra.herd.model.api.xml.SearchIndexStatistics) HashMap(java.util.HashMap) SearchIndexKey(org.finra.herd.model.api.xml.SearchIndexKey) SearchIndex(org.finra.herd.model.api.xml.SearchIndex) DocsStats(org.elasticsearch.index.shard.DocsStats) SearchIndexEntity(org.finra.herd.model.jpa.SearchIndexEntity) Settings(org.elasticsearch.common.settings.Settings) Test(org.junit.Test)

Aggregations

SearchIndexStatistics (org.finra.herd.model.api.xml.SearchIndexStatistics)3 Settings (org.elasticsearch.common.settings.Settings)2 DocsStats (org.elasticsearch.index.shard.DocsStats)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 SearchIndex (org.finra.herd.model.api.xml.SearchIndex)1 SearchIndexKey (org.finra.herd.model.api.xml.SearchIndexKey)1 SearchIndexEntity (org.finra.herd.model.jpa.SearchIndexEntity)1 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)1 DateTime (org.joda.time.DateTime)1