Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Upgrade of Elastic Search Client #571

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion chop/webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,12 @@
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.0.0</version>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.4.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -380,12 +385,22 @@
<artifactId>shiro-all</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>6.5.1</version>
</dependency>

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport</artifactId>
<version>4.1.11.Final</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.apache.usergrid.chop.webapp.dao.model.BasicRun;
import org.apache.usergrid.chop.webapp.dao.model.BasicRunResult;
import org.apache.usergrid.chop.webapp.elasticsearch.Util;

import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.index.IndexNotFoundException;
//import org.elasticsearch.indices.IndexMissingException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand Down Expand Up @@ -109,8 +109,7 @@ public Response next(

try {
next = runDao.getNextRunNumber( commitId );
}
catch ( IndexMissingException e ) {
} catch (IndexNotFoundException e) {
LOG.warn( "Got an index missing exception while looking up the next run number." );
return Response.ok( 0 ).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.apache.usergrid.chop.webapp.elasticsearch.Util;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;


Expand Down Expand Up @@ -67,7 +69,7 @@ public boolean save( Commit commit ) throws IOException {

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( "modules", "commit", commit.getId() )
.setRefresh( true )
// .setRefresh(true)
.setSource(
jsonBuilder()
.startObject()
Expand All @@ -78,8 +80,7 @@ public boolean save( Commit commit ) throws IOException {
)
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// isCreated();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.usergrid.chop.webapp.elasticsearch.Util;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;

import java.io.IOException;
Expand Down Expand Up @@ -64,7 +65,7 @@ public boolean save( Module module ) throws IOException {

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, module.getId() )
.setRefresh( true )
// .setRefresh( true )
.setSource(
jsonBuilder()
.startObject()
Expand All @@ -77,8 +78,7 @@ public boolean save( Module module ) throws IOException {
)
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// isCreated();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;

import java.io.IOException;
Expand All @@ -50,7 +51,7 @@ public boolean save( Note note ) throws IOException {

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, note.getId() )
.setRefresh( true )
// .setRefresh( true )
.setSource(
jsonBuilder()
.startObject()
Expand All @@ -62,7 +63,7 @@ public boolean save( Note note ) throws IOException {
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// isCreated();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;

import java.io.IOException;
Expand Down Expand Up @@ -71,7 +72,7 @@ public boolean save( final ProviderParams pp ) throws IOException {

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, pp.getUsername() )
.setRefresh( true )
// .setRefresh( true )
.setSource(
jsonBuilder()
.startObject()
Expand All @@ -86,7 +87,7 @@ public boolean save( final ProviderParams pp ) throws IOException {
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// .isCreated();
}

/**
Expand Down Expand Up @@ -159,10 +160,10 @@ public List<ProviderParams> getAll() {
public boolean delete( String username ) {
DeleteResponse response = elasticSearchClient.getClient()
.prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, username )
.setRefresh( true )
// .setRefresh( true )
.execute()
.actionGet();

return response.isFound();
return !response.getResult().equals(RestStatus.NOT_FOUND);//response.isFound();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.inQuery;
//import static org.elasticsearch.index.query.QueryBuilders.inQuery;
import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
Expand Down Expand Up @@ -76,7 +77,7 @@ public boolean save( Run run ) throws IOException {

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, run.getId() )
.setRefresh( true )
// .setRefresh( true )
.setSource(
jsonBuilder()
.startObject()
Expand Down Expand Up @@ -104,8 +105,7 @@ public boolean save( Run run ) throws IOException {
)
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// response.isCreated();
}


Expand All @@ -117,11 +117,10 @@ public boolean save( Run run ) throws IOException {
public boolean delete( Run run ) {
DeleteResponse response = elasticSearchClient.getClient()
.prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, run.getId() )
.setRefresh( true )
// .setRefresh( true )
.execute()
.actionGet();

return response.isFound();
return !response.getResult().equals(RestStatus.NOT_FOUND);// .isFound()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;

import java.io.IOException;
Expand Down Expand Up @@ -70,7 +71,7 @@ public boolean save( RunResult runResult ) throws IOException {

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, runResult.getId() )
.setRefresh( true )
// .setRefresh( true )
.setSource(
jsonBuilder()
.startObject()
Expand All @@ -86,7 +87,7 @@ public boolean save( RunResult runResult ) throws IOException {
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// .isCreated();
}


Expand All @@ -100,11 +101,11 @@ public boolean delete( String id ) {

DeleteResponse response = elasticSearchClient.getClient()
.prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, id )
.setRefresh( true )
// .setRefresh( true )
.execute()
.actionGet();

return response.isFound();
return !response.getResult().equals(RestStatus.NOT_FOUND);//response.isFound();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;

import java.io.IOException;
Expand Down Expand Up @@ -65,7 +66,7 @@ public boolean save( Runner runner, String user, String commitId, String moduleI

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, runner.getUrl() )
.setRefresh( true )
// .setRefresh( true )
.setSource(
jsonBuilder()
.startObject()
Expand All @@ -82,8 +83,7 @@ public boolean save( Runner runner, String user, String commitId, String moduleI
)
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// .isCreated();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;

import java.io.IOException;
Expand Down Expand Up @@ -73,7 +74,7 @@ public boolean save( User user ) throws IOException {

IndexResponse response = elasticSearchClient.getClient()
.prepareIndex( DAO_INDEX_KEY, DAO_TYPE_KEY, user.getUsername() )
.setRefresh( true )
// .setRefresh( true )
.setSource(
jsonBuilder()
.startObject()
Expand All @@ -83,7 +84,7 @@ public boolean save( User user ) throws IOException {
.execute()
.actionGet();

return response.isCreated();
return response.getResult().equals(RestStatus.CREATED);// .isCreated();
}

/**
Expand Down Expand Up @@ -160,10 +161,9 @@ public boolean delete( String username ) {

DeleteResponse response = elasticSearchClient.getClient()
.prepareDelete( DAO_INDEX_KEY, DAO_TYPE_KEY, username )
.setRefresh( true )
// .setRefresh( true )
.execute()
.actionGet();

return response.isFound();
return !response.getResult().equals(RestStatus.NOT_FOUND);// response.isFound();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
import com.google.inject.Singleton;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -65,16 +66,16 @@ public Client start() {
host = elasticSearchFig.getTransportHost();
clusterName = elasticSearchFig.getClusterName();

Settings settings = ImmutableSettings.settingsBuilder().put( "cluster.name", clusterName ).build();
LOG.info( "Connecting Elasticsearch on {}", elasticSearchFig.getTransportHost() + ":" +
elasticSearchFig.getTransportPort() );
Settings settings = Settings.builder().put("cluster.name", clusterName).build();
LOG.info("Connecting Elasticsearch on {}",
elasticSearchFig.getTransportHost() + ":" + elasticSearchFig.getTransportPort());
nodeList = getNodeList();
TransportClient transportClient = new TransportClient( settings );
TransportClient transportClient = new PreBuiltTransportClient(settings);
for ( ElasticSearchNode elasticSearchNode : nodeList ) {
LOG.debug( "Adding transport address with host {} and port {}", elasticSearchNode.getTransportHost()
, elasticSearchNode.getTransportPort() );
transportClient.addTransportAddress( new InetSocketTransportAddress( elasticSearchNode.getTransportHost(),
elasticSearchNode.getTransportPort() ) );
LOG.debug("Adding transport address with host {} and port {}", elasticSearchNode.getTransportHost(),
elasticSearchNode.getTransportPort());
transportClient.addTransportAddress(new InetSocketTransportAddress(
new InetSocketAddress(elasticSearchNode.getTransportHost(), elasticSearchNode.getTransportPort())));
}

client = transportClient;
Expand Down
Loading