Added dependency to the indexing-common library

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/social-networking/social-data-search-client@122929 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-02-08 16:38:44 +00:00
parent 22266ce2ed
commit 0b22c8f70d
10 changed files with 15 additions and 247 deletions

View File

@ -15,12 +15,12 @@ Feb 2016
Description
-----------
Social Data Search Client
${description}
Download information
--------------------
Source code is available from SVN:
https://svn.d4science.research-infrastructures.eu/gcube/trunk/socialnetworking/social-data-search-client
${scm.url}
Binaries can be downloaded from:
http://software.d4science.research-infrastructures.eu/

View File

@ -3,10 +3,10 @@
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>gCube Social Networking Library</Description>
<Class>Portal</Class>
<Description>${description}</Description>
<Class>${serviceClass}</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Version>${version}</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>

View File

@ -50,6 +50,11 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.socialnetworking</groupId>
<artifactId>social-data-indexing-common</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -16,6 +16,8 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder.Type;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.gcube.socialnetworking.social_data_indexing_common.utils.ElasticSearchRunningCluster;
import org.gcube.socialnetworking.social_data_indexing_common.utils.IndexFields;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@ -1,133 +0,0 @@
package org.gcube.socialnetworking.social_data_search_client;
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.socialnetworking.social_data_search_client.ex.NoElasticSearchRuntimeResourceException;
import org.gcube.socialnetworking.social_data_search_client.ex.ServiceEndPointException;
import org.gcube.socialnetworking.social_data_search_client.ex.TooManyRunningClustersException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Retrieve elasticsearch's running instance information in the infrastructure.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class ElasticSearchRunningCluster {
//logger
private static final Logger _log = LoggerFactory.getLogger(ElasticSearchRunningCluster.class);
//properties
private final static String RUNTIME_RESOURCE_NAME = "SocialPortalDataIndex";
private final static String PLATFORM_NAME = "ElasticSearch";
// retrieved data
private List<String> hosts = new ArrayList<String>();
private List<Integer> ports = new ArrayList<Integer>();
private String clusterName;
public ElasticSearchRunningCluster(String infrastructure) throws Exception{
try {
List<ServiceEndpoint> resources = getConfigurationFromIS(infrastructure);
if (resources.size() > 1) {
_log.error("Too many Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" in this scope");
throw new TooManyRunningClustersException("There exist more than 1 Runtime Resource in this scope having name "
+ RUNTIME_RESOURCE_NAME + " and Platform " + PLATFORM_NAME + ". Only one allowed per infrasrtucture.");
}
else if (resources.size() == 0){
_log.error("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Platform " + PLATFORM_NAME + " in this scope.");
throw new NoElasticSearchRuntimeResourceException();
}
else {
try{
_log.debug(resources.toString());
for (ServiceEndpoint res : resources) {
Iterator<AccessPoint> accessPointIterator = res.profile().accessPoints().iterator();
while (accessPointIterator.hasNext()) {
ServiceEndpoint.AccessPoint accessPoint = (ServiceEndpoint.AccessPoint) accessPointIterator
.next();
// add this host
hosts.add(accessPoint.address().split(":")[0]);
// save the port
int port = Integer.parseInt(accessPoint.address().split(":")[1]);
ports.add(port);
// save the name of the cluster (this should be unique)
clusterName = accessPoint.name();
}
}
}catch(Exception e ){
_log.error(e.toString());
throw new ServiceEndPointException();
}
}
} catch (Exception e) {
_log.error(e.toString());
throw e;
}
}
/**
* Retrieve endpoints information from IS
* @return list of endpoints for elasticsearch
* @throws Exception
*/
private List<ServiceEndpoint> getConfigurationFromIS(String infrastructure) throws Exception{
PortalContext context = PortalContext.getConfiguration();
String scope = "/";
if(infrastructure != null && !infrastructure.isEmpty())
scope += infrastructure;
else
scope += context.getInfrastructureName();
String currScope = ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_RESOURCE_NAME +"'");
query.addCondition("$resource/Profile/Platform/Name/text() eq '"+ PLATFORM_NAME +"'");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> toReturn = client.submit(query);
ScopeProvider.instance.set(currScope);
return toReturn;
}
public List<String> getHosts() {
return hosts;
}
public List<Integer> getPorts() {
return ports;
}
public String getClusterName() {
return clusterName;
}
}

View File

@ -1,37 +0,0 @@
package org.gcube.socialnetworking.social_data_search_client;
/**
* The fields used to build up the index.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class IndexFields {
// name of the index
public static final String INDEX_NAME = "social";
// table for comments
public static final String COMMENT_TABLE = "comments";
// table for feeds
public static final String FEED_TABLE = "feeds";
// table for enhanced feeds
public static final String EF_FEEDS_TABLE = "enhanced_feeds";
// comment table's fields
public static final String COMMENT_TEXT = "description";
public static final String COMMENT_PARENT_ID = "parent_id";
// feed table's fields
public static final String FEED_TEXT = "description";
public static final String FEED_TYPE = "type";
public static final String FEED_VRE_ID = "vre_id";
// enhanced feeds' fields
public static final String EF_ATTACHMENT_NAME = "attachments.name";
public static final String EF_FEED_TEXT = "feed.description";
public static final String EF_COMMENT_TEXT = "comments.text";
public static final String EF_PREVIEW_DESCRIPTION = "feed.linkTitle";
}

View File

@ -1,24 +0,0 @@
package org.gcube.socialnetworking.social_data_search_client.ex;
/**
* No elasticsearch cluster in the infrastructure found exception.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class NoElasticSearchRuntimeResourceException extends Exception {
private static final long serialVersionUID = -40748130477807648L;
private static final String DEFAULT_MESSAGE = "No ElasticSearch cluster instance for this scope!";
public NoElasticSearchRuntimeResourceException(){
super(DEFAULT_MESSAGE);
}
public NoElasticSearchRuntimeResourceException(String message) {
super(message);
}
}

View File

@ -1,22 +0,0 @@
package org.gcube.socialnetworking.social_data_search_client.ex;
/**
* Exception thrown when it is not possible retrieve information from the ServiceEndpoint
* related to ElasticSearch
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class ServiceEndPointException extends Exception {
private static final long serialVersionUID = 5378333924429281681L;
private static final String DEFAULT_MESSAGE = "Unable to retrieve information from ElasticSearch endpoint!";
public ServiceEndPointException(){
super(DEFAULT_MESSAGE);
}
public ServiceEndPointException(String string) {
super(string);
}
}

View File

@ -1,23 +0,0 @@
package org.gcube.socialnetworking.social_data_search_client.ex;
/**
* Too many clusters in this scope exception.
* @author Costantino Perciante at ISTI-CNR
* (costantino.perciante@isti.cnr.it)
*
*/
public class TooManyRunningClustersException extends Exception {
private static final long serialVersionUID = -4112724774153676227L;
private static final String DEFAULT_MESSAGE = "Too many ElasticSearch cluster instances for this scope!";
public TooManyRunningClustersException(){
super(DEFAULT_MESSAGE);
}
public TooManyRunningClustersException(String message) {
super(message);
}
}

View File

@ -1,8 +1,9 @@
package org.gcube.socialnetworking.social_data_search_client;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.portal.databook.shared.EnhancedFeed;
import org.junit.Test;
/**
@ -12,9 +13,8 @@ public class Tests
{
@Test
public void query() throws Exception{
SecurityTokenProvider.instance.set("422d795b-d978-41d5-abac-b1c8be90a632");
List<String> hosts = new ArrayList<String>();
hosts.add("localhost");
ElasticSearchClientImpl el = new ElasticSearchClientImpl("gcube");
// try to query