use of com.enonic.xp.repository.IndexSettings in project xp by enonic.
the class NodeRepositoryServiceImpl method getDefaultSettings.
private IndexSettings getDefaultSettings(final RepositoryId repositoryId, final IndexType indexType) {
final IndexSettings defaultSettings = DEFAULT_INDEX_RESOURCE_PROVIDER.getSettings(repositoryId, indexType);
if (SystemConstants.SYSTEM_REPO_ID.equals(repositoryId)) {
return defaultSettings;
}
try {
final String numberOfReplicasString = indexServiceInternal.getIndexSettings(SystemConstants.SYSTEM_REPO_ID, IndexType.VERSION).getNode().get("index.number_of_replicas").textValue();
final int numberOfReplicas = Integer.parseInt(numberOfReplicasString);
final ObjectNode indexNodeObject = (ObjectNode) defaultSettings.getNode().get("index");
indexNodeObject.put("number_of_replicas", numberOfReplicas);
} catch (Exception e) {
LOG.warn("Failed to retrieve number of replicas from [" + IndexNameResolver.resolveStorageIndexName(SystemConstants.SYSTEM_REPO_ID) + "]");
}
return defaultSettings;
}
use of com.enonic.xp.repository.IndexSettings in project xp by enonic.
the class IndexServiceImplTest method getIndexSettings.
@Test
public void getIndexSettings() throws Exception {
this.indexService.updateIndexSettings(UpdateIndexSettingsParams.create().repository(TEST_REPO_ID).settings("{\"index\": {\"number_of_replicas\": 2}}").build());
final IndexSettings indexSettings = this.indexService.getIndexSettings(TEST_REPO_ID, IndexType.SEARCH);
assertEquals("\"2\"", indexSettings.getNode().get("index.number_of_replicas").toString());
}
use of com.enonic.xp.repository.IndexSettings in project xp by enonic.
the class IndexServiceImplTest method getIndexSettings_empty.
@Test
public void getIndexSettings_empty() throws Exception {
final IndexSettings indexSettings = this.indexService.getIndexSettings(TEST_REPO_ID, IndexType.SEARCH);
assertNull(indexSettings.getNode().get("index.invalid_path"));
}
use of com.enonic.xp.repository.IndexSettings in project xp by enonic.
the class IndexServiceInternalImpl method createIndex.
@Override
public void createIndex(final com.enonic.xp.repo.impl.index.CreateIndexRequest request) {
final String indexName = request.getIndexName();
final IndexSettings indexSettings = request.getIndexSettings();
LOG.info("creating index {}", indexName);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
createIndexRequest.settings(indexSettings.getAsString());
if (request.getMappings() != null) {
for (Map.Entry<IndexType, IndexMapping> mappingEntry : request.getMappings().entrySet()) {
createIndexRequest.mapping(mappingEntry.getKey().isDynamicTypes() ? ES_DEFAULT_INDEX_TYPE_NAME : mappingEntry.getKey().getName(), mappingEntry.getValue().getAsString());
}
}
try {
final CreateIndexResponse createIndexResponse = client.admin().indices().create(createIndexRequest).actionGet(CREATE_INDEX_TIMEOUT);
LOG.info("Index {} created with status {}", indexName, createIndexResponse.isAcknowledged());
} catch (ElasticsearchException e) {
throw new IndexException("Failed to create index: " + indexName, e);
}
}
use of com.enonic.xp.repository.IndexSettings in project xp by enonic.
the class IndexServiceImpl method getSearchIndexSettings.
private IndexSettings getSearchIndexSettings(final RepositoryId repositoryId) {
final IndexSettings defaultIndexSettings = DEFAULT_INDEX_RESOURCE_PROVIDER.getSettings(repositoryId, IndexType.SEARCH);
final Repository repositoryEntry = repositoryEntryService.getRepositoryEntry(repositoryId);
if (repositoryEntry != null) {
final IndexSettings indexSettings = repositoryEntry.getSettings().getIndexSettings(IndexType.SEARCH);
if (indexSettings != null) {
return new IndexSettings(JsonHelper.merge(defaultIndexSettings.getNode(), indexSettings.getNode()));
}
}
return defaultIndexSettings;
}
Aggregations