Search in sources :

Example 1 with EsHadoopIllegalStateException

use of org.elasticsearch.hadoop.EsHadoopIllegalStateException in project elasticsearch-hadoop by elastic.

the class RestClientTest method testMainInfoWithClusterTooOld.

@Test
public void testMainInfoWithClusterTooOld() {
    String response = "{\n" + "\"name\": \"node\",\n" + "\"cluster_name\": \"cluster\",\n" + "\"version\": {\n" + "  \"number\": \"2.0.0\"\n" + "},\n" + "\"tagline\": \"You Know, for Search\"\n" + "}";
    NetworkClient mock = Mockito.mock(NetworkClient.class);
    Mockito.when(mock.execute(Mockito.any(SimpleRequest.class), Mockito.eq(true))).thenReturn(new SimpleResponse(201, new FastByteArrayInputStream(new BytesArray(response)), "localhost:9200"));
    RestClient client = new RestClient(new TestSettings(), mock);
    try {
        client.mainInfo();
        fail("Shouldn't operate on main version that is too old.");
    } catch (EsHadoopIllegalStateException e) {
        assertEquals("Invalid major version [2.0.0]. Version is lower than minimum required version [6.x].", e.getMessage());
    }
}
Also used : BytesArray(org.elasticsearch.hadoop.util.BytesArray) FastByteArrayInputStream(org.elasticsearch.hadoop.util.FastByteArrayInputStream) EsHadoopIllegalStateException(org.elasticsearch.hadoop.EsHadoopIllegalStateException) TestSettings(org.elasticsearch.hadoop.util.TestSettings) Test(org.junit.Test)

Example 2 with EsHadoopIllegalStateException

use of org.elasticsearch.hadoop.EsHadoopIllegalStateException in project elasticsearch-hadoop by elastic.

the class ObjectUtils method instantiate.

@SuppressWarnings("unchecked")
public static <T> T instantiate(String className, ClassLoader loader) {
    Assert.hasText(className, "No class name given");
    ClassLoader cl = (loader != null ? loader : ObjectUtils.class.getClassLoader());
    Class<?> clz = null;
    try {
        clz = cl.loadClass(className);
    } catch (ClassNotFoundException e) {
        throw new EsHadoopIllegalStateException(String.format("Cannot load class [%s]", className), e);
    }
    try {
        return (T) clz.newInstance();
    } catch (Exception ex) {
        throw new EsHadoopIllegalStateException(String.format("Cannot instantiate class [%s]", className), ex);
    }
}
Also used : EsHadoopIllegalStateException(org.elasticsearch.hadoop.EsHadoopIllegalStateException) EsHadoopIllegalStateException(org.elasticsearch.hadoop.EsHadoopIllegalStateException) EsHadoopIllegalArgumentException(org.elasticsearch.hadoop.EsHadoopIllegalArgumentException)

Example 3 with EsHadoopIllegalStateException

use of org.elasticsearch.hadoop.EsHadoopIllegalStateException in project elasticsearch-hadoop by elastic.

the class BulkEntryWriterTest method testWriteBulkEntryWithHandlersThatCorrectsData.

@Test
public void testWriteBulkEntryWithHandlersThatCorrectsData() {
    BytesRef response = new BytesRef();
    response.add("abcdefg".getBytes());
    BulkCommand command = Mockito.mock(BulkCommand.class);
    Mockito.when(command.write(1)).thenThrow(new EsHadoopIllegalStateException("Things broke"));
    Mockito.when(command.write(10)).thenReturn(response);
    Settings settings = new TestSettings();
    settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLERS, "fix");
    settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLER + ".fix", CorrectingHandler.class.getName());
    BulkEntryWriter bulkEntryWriter = new BulkEntryWriter(settings, command);
    BytesRef value = bulkEntryWriter.writeBulkEntry(1);
    Assert.assertNotNull("Skipped values should be null", value);
    Assert.assertEquals(7, response.length());
    Assert.assertArrayEquals("abcdefg".getBytes(), response.toString().getBytes());
}
Also used : EsHadoopIllegalStateException(org.elasticsearch.hadoop.EsHadoopIllegalStateException) TestSettings(org.elasticsearch.hadoop.util.TestSettings) BytesRef(org.elasticsearch.hadoop.util.BytesRef) Settings(org.elasticsearch.hadoop.cfg.Settings) TestSettings(org.elasticsearch.hadoop.util.TestSettings) Test(org.junit.Test)

Example 4 with EsHadoopIllegalStateException

use of org.elasticsearch.hadoop.EsHadoopIllegalStateException in project elasticsearch-hadoop by elastic.

the class BulkEntryWriterTest method testWriteBulkEntryWithHandlersThatPassMessages.

@Test
public void testWriteBulkEntryWithHandlersThatPassMessages() {
    BulkCommand command = Mockito.mock(BulkCommand.class);
    Mockito.when(command.write(1)).thenThrow(new EsHadoopIllegalStateException("Things broke"));
    Settings settings = new TestSettings();
    settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLERS, "marco,polo,skip");
    settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLER + ".marco", MarcoHandler.class.getName());
    settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLER + ".polo", PoloHandler.class.getName());
    settings.setProperty(SerializationHandlerLoader.ES_WRITE_DATA_ERROR_HANDLER + ".skip", NothingToSeeHereHandler.class.getName());
    BulkEntryWriter bulkEntryWriter = new BulkEntryWriter(settings, command);
    BytesRef value = bulkEntryWriter.writeBulkEntry(1);
    Assert.assertNull("Skipped values should be null", value);
}
Also used : EsHadoopIllegalStateException(org.elasticsearch.hadoop.EsHadoopIllegalStateException) TestSettings(org.elasticsearch.hadoop.util.TestSettings) Settings(org.elasticsearch.hadoop.cfg.Settings) TestSettings(org.elasticsearch.hadoop.util.TestSettings) BytesRef(org.elasticsearch.hadoop.util.BytesRef) Test(org.junit.Test)

Example 5 with EsHadoopIllegalStateException

use of org.elasticsearch.hadoop.EsHadoopIllegalStateException in project elasticsearch-hadoop by elastic.

the class RestClient method mainInfo.

public ClusterInfo mainInfo() {
    Response response = execute(GET, "", true);
    Map<String, Object> result = parseContent(response.body(), null);
    if (result == null) {
        throw new EsHadoopIllegalStateException("Unable to retrieve elasticsearch main cluster info.");
    }
    String clusterName = result.get("cluster_name").toString();
    String clusterUUID = (String) result.get("cluster_uuid");
    @SuppressWarnings("unchecked") Map<String, String> versionBody = (Map<String, String>) result.get("version");
    if (versionBody == null || !StringUtils.hasText(versionBody.get("number"))) {
        throw new EsHadoopIllegalStateException("Unable to retrieve elasticsearch version.");
    }
    String versionNumber = versionBody.get("number");
    EsMajorVersion major = EsMajorVersion.parse(versionNumber);
    if (major.before(EsMajorVersion.V_6_X)) {
        throw new EsHadoopIllegalStateException("Invalid major version [" + major + "]. " + "Version is lower than minimum required version [" + EsMajorVersion.V_6_X + "].");
    } else if (major.onOrAfter(V_6_X)) {
        String tagline = result.get("tagline").toString();
        if (ELASTICSEARCH_TAGLINE.equals(tagline) == false) {
            LOG.warn("Could not verify server is Elasticsearch! Invalid main action response body format [tag].");
        }
        if (major.onOrAfter(V_7_X)) {
            String buildFlavor = versionBody.get("build_flavor");
            if (ELASTICSEARCH_BUILD_FLAVOR.equals(buildFlavor) == false) {
                LOG.warn("Could not verify server is Elasticsearch! Invalid main action response body format [build_flavor].");
            }
            List<String> productHeader = response.getHeaders(ELASTIC_PRODUCT_HEADER);
            boolean validElasticsearchHeader = productHeader != null && productHeader.size() == 1 && productHeader.get(0).equals(ELASTIC_PRODUCT_HEADER_VALUE);
            boolean verifyServer = (major.on(V_7_X) && major.parseMinorVersion(versionNumber) >= 14) || major.onOrAfter(V_8_X);
            if (validElasticsearchHeader == false) {
                if (verifyServer) {
                    throw new EsHadoopTransportException("Connected, but could not verify server is Elasticsearch. Response missing [" + ELASTIC_PRODUCT_HEADER + "] header. Please check that you are connecting to an Elasticsearch instance, and " + "that any networking filters are preserving that header.");
                } else {
                    LOG.warn("Could not verify server is Elasticsearch! ES-Hadoop will require server validation when connecting to an " + "Elasticsearch cluster if that Elasticsearch cluster is v7.14 and up.");
                }
            }
        }
    }
    return new ClusterInfo(new ClusterName(clusterName, clusterUUID), EsMajorVersion.parse(versionNumber));
}
Also used : EsMajorVersion(org.elasticsearch.hadoop.util.EsMajorVersion) ClusterInfo(org.elasticsearch.hadoop.util.ClusterInfo) EsHadoopIllegalStateException(org.elasticsearch.hadoop.EsHadoopIllegalStateException) ClusterName(org.elasticsearch.hadoop.util.ClusterName) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map)

Aggregations

EsHadoopIllegalStateException (org.elasticsearch.hadoop.EsHadoopIllegalStateException)21 TestSettings (org.elasticsearch.hadoop.util.TestSettings)8 Test (org.junit.Test)8 Settings (org.elasticsearch.hadoop.cfg.Settings)7 IOException (java.io.IOException)3 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)3 BytesRef (org.elasticsearch.hadoop.util.BytesRef)3 Map (java.util.Map)2 ExecException (org.apache.pig.backend.executionengine.ExecException)2 EsHadoopIllegalArgumentException (org.elasticsearch.hadoop.EsHadoopIllegalArgumentException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 BindException (java.net.BindException)1 ServerSocket (java.net.ServerSocket)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ResourceSchema (org.apache.pig.ResourceSchema)1 ExecJob (org.apache.pig.backend.executionengine.ExecJob)1 DataByteArray (org.apache.pig.data.DataByteArray)1 Tuple (org.apache.pig.data.Tuple)1