org.elasticsearch.common.settings.SettingsException Java Examples

The following examples show how to use org.elasticsearch.common.settings.SettingsException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlobEnvironment.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
/**
 * Validates a given blobs data path
 */
public void validateBlobsPath(File blobsPath) {
    if (blobsPath.exists()) {
        if (blobsPath.isFile()) {
            throw new SettingsException(
                    String.format(Locale.ENGLISH, "blobs path '%s' is a file, must be a directory", blobsPath.getAbsolutePath()));
        }
        if (!blobsPath.canWrite()) {
            throw new SettingsException(
                    String.format(Locale.ENGLISH, "blobs path '%s' is not writable", blobsPath.getAbsolutePath()));
        }
    } else {
        try {
            Files.createDirectories(blobsPath.toPath());
        } catch (IOException e) {
            throw new SettingsException(
                    String.format(Locale.ENGLISH, "blobs path '%s' could not be created", blobsPath.getAbsolutePath()));
        }
    }
}
 
Example #2
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * リトライ処理中の特定例外処理からContinueRetryが投げられた後、リトライ処理に移行すること.
 */
@Test
public void リトライ処理中の特定例外処理からContinueRetryが投げられた後_リトライ処理に移行すること() {
    TestRequest requestMock = Mockito.spy(new TestRequest());

    NodeDisconnectedException toBeThrown = Mockito.mock(NodeDisconnectedException.class);

    Mockito.doThrow(toBeThrown) // 初回リクエスト
            .doThrow(toBeThrown) // リトライ1回目
            .doThrow(new SettingsException("foo")) // リトライ2回目. この時は、 #onParticularError()でリトライ継続のために
                                                   // ContinueRetryが投げられる.
            .doThrow(toBeThrown) // リトライ3回目
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    // 初回 + リトライ3回 + 処理成功で、5回呼ばれるはず.
    Mockito.verify(requestMock, Mockito.times(5)).doProcess();
    Mockito.verify(requestMock, Mockito.times(1)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #3
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 初回リクエストの特定例外処理からContinueRetryが投げられた後、リトライ処理に移行すること.
 */
@Test
public void 初回リクエストの特定例外処理からContinueRetryが投げられた後_リトライ処理に移行すること() {
    TestRequest requestMock = Mockito.spy(new TestRequest());

    NodeDisconnectedException toBeThrown = Mockito.mock(NodeDisconnectedException.class);

    Mockito.doThrow(new SettingsException("foo")) // 初回リクエスト
            .doThrow(toBeThrown) // リトライ1回目
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    Mockito.verify(requestMock, Mockito.times(3)).doProcess();
    Mockito.verify(requestMock, Mockito.times(1)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #4
Source File: BlobIndicesService.java    From crate with Apache License 2.0 6 votes vote down vote up
static boolean ensureExistsAndWritable(Path blobsPath) {
    if (Files.exists(blobsPath)) {
        if (!Files.isDirectory(blobsPath)) {
            throw new SettingsException(
                String.format(Locale.ENGLISH, "blobs path '%s' is a file, must be a directory", blobsPath));
        }
        if (!Files.isWritable(blobsPath)) {
            throw new SettingsException(
                String.format(Locale.ENGLISH, "blobs path '%s' is not writable", blobsPath));
        }
    } else {
        try {
            Files.createDirectories(blobsPath);
        } catch (IOException e) {
            throw new SettingsException(
                String.format(Locale.ENGLISH, "blobs path '%s' could not be created", blobsPath));
        }
    }
    return true;
}
 
Example #5
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsIndex_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsIndex_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsIndexImpl esIndexObject = Mockito.spy(new EsIndexImpl("dummy", "", 0, 0, null));

    // EsIndex#asyncIndexSearch()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esIndexObject)
            .asyncIndexSearch(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    DcSearchResponse result = esIndexObject.search("dummyRoutingId", (Map<String, Object>) null);
    assertNull(result);
}
 
Example #6
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_putMappingメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_putMappingメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncPutMapping()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncPutMapping(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esTypeObject.putMapping(null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof SettingsException);
        assertTrue(e.getCause().getCause() instanceof IndexMissingException);
    }
}
 
Example #7
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_deleteメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_deleteメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncDelete()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncDelete(Mockito.anyString(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.delete("dummyId", 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof SettingsException);
        assertTrue(e.getCause().getCause() instanceof IndexMissingException);
    }
}
 
Example #8
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncSearch()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncSearch(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    DcSearchResponse result = esTypeObject.search(null);
    assertTrue(result.isNullResponse());
}
 
Example #9
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_updateメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_updateメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、IndexMissingExceptionを投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    (OpType) Mockito.anyObject(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.update("dummyId", null, 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof SettingsException);
        assertTrue(e.getCause().getCause() instanceof IndexMissingException);
    }
}
 
Example #10
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_getメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_getメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncGet()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexMissingException(new Index("dummy")));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncGet(Mockito.anyString(), Mockito.anyBoolean());
    // メソッド呼び出し
    DcGetResponse result = esTypeObject.get("dummyId", true);
    assertNull(result);
}
 
Example #11
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * リトライ処理中の特定例外処理からContinueRetryが投げられた後、リトライ処理に移行すること.
 */
@Test
public void リトライ処理中の特定例外処理からContinueRetryが投げられた後_リトライ処理に移行すること() {
    TestRequest requestMock = Mockito.spy(new TestRequest());

    NodeDisconnectedException toBeThrown = Mockito.mock(NodeDisconnectedException.class);

    Mockito.doThrow(toBeThrown) // 初回リクエスト
            .doThrow(toBeThrown) // リトライ1回目
            .doThrow(new SettingsException("foo")) // リトライ2回目. この時は、 #onParticularError()でリトライ継続のために
                                                   // ContinueRetryが投げられる.
            .doThrow(toBeThrown) // リトライ3回目
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    // 初回 + リトライ3回 + 処理成功で、5回呼ばれるはず.
    Mockito.verify(requestMock, Mockito.times(5)).doProcess();
    Mockito.verify(requestMock, Mockito.times(1)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #12
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * 初回リクエストの特定例外処理からContinueRetryが投げられた後、リトライ処理に移行すること.
 */
@Test
public void 初回リクエストの特定例外処理からContinueRetryが投げられた後_リトライ処理に移行すること() {
    TestRequest requestMock = Mockito.spy(new TestRequest());

    NodeDisconnectedException toBeThrown = Mockito.mock(NodeDisconnectedException.class);

    Mockito.doThrow(new SettingsException("foo")) // 初回リクエスト
            .doThrow(toBeThrown) // リトライ1回目
            .doReturn(SUCCESS_RESPONSE)
            .when(requestMock)
            .doProcess();

    String result = requestMock.doRequest();
    assertEquals(SUCCESS_RESPONSE, result);
    Mockito.verify(requestMock, Mockito.times(3)).doProcess();
    Mockito.verify(requestMock, Mockito.times(1)).onParticularError(Mockito.any(ElasticsearchException.class));
}
 
Example #13
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsIndex_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsIndex_searchメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsIndexImpl esIndexObject = Mockito.spy(new EsIndexImpl("dummy", "", 0, 0, null));

    // EsIndex#asyncIndexSearch()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexNotFoundException("dummy"));
    Mockito.doThrow(toBeThrown)
            .when(esIndexObject)
            .asyncIndexSearch(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    DcSearchResponse result = esIndexObject.search("dummyRoutingId", (Map<String, Object>) null);
    assertNull(result);
}
 
Example #14
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_putMappingメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_putMappingメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncPutMapping()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexNotFoundException("dummy"));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncPutMapping(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    try {
        esTypeObject.putMapping(null);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof SettingsException);
        assertTrue(e.getCause().getCause() instanceof IndexNotFoundException);
    }
}
 
Example #15
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_deleteメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_deleteメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncDelete()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexNotFoundException("dummy"));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncDelete(Mockito.anyString(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.delete("dummyId", 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof SettingsException);
        assertTrue(e.getCause().getCause() instanceof IndexNotFoundException);
    }
}
 
Example #16
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_searchメソッドで初回にIndexNotFoundExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_searchメソッドで初回にIndexNotFoundExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncSearch()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexNotFoundException("dummy"));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncSearch(Mockito.anyMapOf(String.class, Object.class));
    // メソッド呼び出し
    DcSearchResponse result = esTypeObject.search(null);
    assertTrue(result.isNullResponse());
}
 
Example #17
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_updateメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_updateメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncIndex()が呼ばれた場合に、IndexMissingExceptionを投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexNotFoundException("dummy"));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncIndex(Mockito.anyString(), Mockito.anyMapOf(String.class, Object.class),
                    (OpType) Mockito.anyObject(), Mockito.anyLong());
    // メソッド呼び出し
    try {
        esTypeObject.update("dummyId", null, 1);
        fail("EsClientException should be thrown.");
    } catch (EsClientException.EsIndexMissingException e) {
        assertTrue(e.getCause() instanceof SettingsException);
        assertTrue(e.getCause().getCause() instanceof IndexNotFoundException);
    }
}
 
Example #18
Source File: EsRetryOnParticularErrorTest.java    From io with Apache License 2.0 6 votes vote down vote up
/**
 * EsType_getメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト.
 */
@Test
public void EsType_getメソッドで初回にIndexMissingExceptionを根本原因に持つ例外が投げられた場合のテスト() {
    PowerMockito.mockStatic(EsClientException.class);
    EsTypeImpl esTypeObject = Mockito.spy(new EsTypeImpl("dummy", "Test", "TestRoutingId", 0, 0, null));

    // EsType#asyncGet()が呼ばれた場合に、IndexMissingExceptionを根本原因に持つ例外を投げる。
    // 送出する例外オブジェクトを作成
    SettingsException toBeThrown = new SettingsException("foo", new IndexNotFoundException("dummy"));
    Mockito.doThrow(toBeThrown)
            .when(esTypeObject)
            .asyncGet(Mockito.anyString(), Mockito.anyBoolean());
    // メソッド呼び出し
    DcGetResponse result = esTypeObject.get("dummyId", true);
    assertNull(result);
}
 
Example #19
Source File: ClusterStatsData.java    From elasticsearch-prometheus-exporter with Apache License 2.0 6 votes vote down vote up
/**
 * Try to extract and parse value from settings for given key.
 * First it tries to parse it as a RatioValue (pct) then as byte size value.
 * It assigns parsed value to corresponding argument references (passed via array hack).
 * If parsing fails the method fires exception, however, this should not happen - we rely on Elasticsearch
 * to already have parsed and validated these values before. Unless we screwed something up...
 */
private void parseValue(Settings s, String key, Long[] bytesPointer, Double[] pctPointer) {
    String value = s.get(key);
    if (value != null && pctPointer[0] == null) {
        try {
            pctPointer[0] = RatioValue.parseRatioValue(s.get(key, null)).getAsPercent();
        } catch (SettingsException | ElasticsearchParseException | NullPointerException e1) {
            if (bytesPointer[0] == null) {
                try {
                    bytesPointer[0] = s.getAsBytesSize(key, null).getBytes();
                } catch (SettingsException | ElasticsearchParseException | NullPointerException e2) {
                    // TODO(lvlcek): log.debug("This went wrong, but 'Keep Calm and Carry On'")
                    // We should avoid using logs in this class (due to perf impact), instead we should
                    // consider moving this logic to some static helper class/method going forward.
                }
            }
        }
    }
}
 
Example #20
Source File: AzureStorageServiceTests.java    From crate with Apache License 2.0 5 votes vote down vote up
public void testProxyNoHost() {
    final Settings settings = Settings.builder()
        .put(buildClientCredSettings())
        .put("proxy_port", 8080)
        .put("proxy_type", randomFrom("socks", "http"))
        .build();
    final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
    assertEquals("Azure Proxy type has been set but proxy host or port is not defined.", e.getMessage());
}
 
Example #21
Source File: AzureStorageServiceTests.java    From crate with Apache License 2.0 5 votes vote down vote up
public void testProxyNoPort() {
    final Settings settings = Settings.builder()
        .put(buildClientCredSettings())
        .put("proxy_host", "127.0.0.1")
        .put("proxy_type", randomFrom("socks", "http"))
        .build();

    final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
    assertEquals("Azure Proxy type has been set but proxy host or port is not defined.", e.getMessage());
}
 
Example #22
Source File: InternalSettingsPreparerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testErrorWithDuplicateSettingInConfigFile() throws Exception {
    HashMap<String, String> settings = new HashMap<>();
    settings.put("path.home", ".");
    Path config = PathUtils.get(getClass().getResource("config_invalid").toURI());
    settings.put("path.conf", config.toString());
    expectedException.expect(SettingsException.class);
    expectedException.expectMessage("Failed to load settings from");
    expectedException.expectCause(Matchers.hasProperty("message", containsString("Duplicate field 'stats.enabled'")));
    InternalSettingsPreparer.prepareEnvironment(Settings.EMPTY, settings, config, () -> "node1");
}
 
Example #23
Source File: AzureStorageServiceTests.java    From crate with Apache License 2.0 5 votes vote down vote up
public void testProxyNoType() {
    final Settings settings = Settings.builder()
        .put(buildClientCredSettings())
        .put("proxy_host", "127.0.0.1")
        .put("proxy_port", 8080)
        .build();

    final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
    assertEquals("Azure Proxy port or host have been set but proxy type is not defined.", e.getMessage());
}
 
Example #24
Source File: AzureStorageServiceTests.java    From crate with Apache License 2.0 5 votes vote down vote up
public void testProxyWrongHost() {
    final Settings settings = Settings.builder()
        .put(buildClientCredSettings())
        .put("proxy_type", randomFrom("socks", "http"))
        .put("proxy_host", "thisisnotavalidhostorwehavebeensuperunlucky")
        .put("proxy_port", 8080)
        .build();

    final SettingsException e = expectThrows(SettingsException.class,
                                             () -> storageServiceWithSettings(settings));
    assertEquals("Azure proxy host is unknown.", e.getMessage());
}
 
Example #25
Source File: GeoSettingsApplier.java    From crate with Apache License 2.0 5 votes vote down vote up
private static void applyDistanceErrorPct(Map<String, Object> mapping, Settings geoSettings) {
    try {
        Float errorPct = geoSettings.getAsFloat("distance_error_pct", null);
        if (errorPct != null) {
            mapping.put("distance_error_pct", errorPct);
        }
    } catch (SettingsException e) {
        throw new IllegalArgumentException(
            String.format(Locale.ENGLISH, "Value '%s' of setting distance_error_pct is not a float value", geoSettings.get("distance_error_pct"))
        );
    }
}
 
Example #26
Source File: Netty4HttpServerTransport.java    From crate with Apache License 2.0 5 votes vote down vote up
static Netty4CorsConfig buildCorsConfig(Settings settings) {
    if (SETTING_CORS_ENABLED.get(settings) == false) {
        return Netty4CorsConfigBuilder.forOrigins().disable().build();
    }
    String origin = SETTING_CORS_ALLOW_ORIGIN.get(settings);
    final Netty4CorsConfigBuilder builder;
    if (Strings.isNullOrEmpty(origin)) {
        builder = Netty4CorsConfigBuilder.forOrigins();
    } else if (origin.equals(ANY_ORIGIN)) {
        builder = Netty4CorsConfigBuilder.forAnyOrigin();
    } else {
        try {
            Pattern p = RestUtils.checkCorsSettingForRegex(origin);
            if (p == null) {
                builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin));
            } else {
                builder = Netty4CorsConfigBuilder.forPattern(p);
            }
        } catch (PatternSyntaxException e) {
            throw new SettingsException("Bad regex in [" + SETTING_CORS_ALLOW_ORIGIN.getKey() + "]: [" + origin + "]", e);
        }
    }
    if (SETTING_CORS_ALLOW_CREDENTIALS.get(settings)) {
        builder.allowCredentials();
    }
    String[] strMethods = Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_METHODS.get(settings), ",");
    HttpMethod[] methods = Arrays.stream(strMethods)
        .map(HttpMethod::valueOf)
        .toArray(HttpMethod[]::new);
    return builder.allowedRequestMethods(methods)
        .maxAge(SETTING_CORS_MAX_AGE.get(settings))
        .allowedRequestHeaders(Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_HEADERS.get(settings), ","))
        .shortCircuit()
        .build();
}
 
Example #27
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public String onParticularError(ElasticsearchException e) {
    if (e instanceof EsExceptionForTest) {
        return ON_ERROR_RESPONSE;
    }
    if (e instanceof SettingsException) {
        throw new ContinueRetry();
    }
    throw e;
}
 
Example #28
Source File: AbstractRetryableEsRequestTest.java    From io with Apache License 2.0 5 votes vote down vote up
@Override
public String onParticularError(ElasticsearchException e) {
    if (e instanceof EsExceptionForTest) {
        return ON_ERROR_RESPONSE;
    }
    if (e instanceof SettingsException) {
        throw new ContinueRetry();
    }
    throw e;
}
 
Example #29
Source File: ThreadPool.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
/**
 * A thread pool size can also be unbounded and is represented by -1, which is not supported by SizeValue (which only supports positive numbers)
 */
private SizeValue getAsSizeOrUnbounded(Settings settings, String setting, SizeValue defaultValue) throws SettingsException {
    if ("-1".equals(settings.get(setting))) {
        return null;
    }
    return parseSizeValue(settings.get(setting), defaultValue);
}
 
Example #30
Source File: LogConfigurator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
static void loadConfig(Path file, Settings.Builder settingsBuilder) {
    try {
        settingsBuilder.loadFromPath(file);
    } catch (SettingsException | NoClassDefFoundError e) {
        // ignore
    }
}