2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
|
|
|
|
|
|
|
|
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
|
|
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
|
|
|
|
2017-01-26 19:29:51 +01:00
|
|
|
import java.io.Serializable;
|
2016-06-13 09:48:29 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
|
|
|
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
2016-12-26 23:12:33 +01:00
|
|
|
|
|
|
|
import com.liferay.portal.kernel.log.Log;
|
|
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
2016-06-13 09:48:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Jun 10, 2016
|
|
|
|
*/
|
2017-01-26 19:29:51 +01:00
|
|
|
public class GcoreEndpointReader implements Serializable{
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2017-01-26 19:29:51 +01:00
|
|
|
private static final long serialVersionUID = 7631710353375893823L;
|
2016-06-13 09:48:29 +02:00
|
|
|
private static final String ckanResource = "org.gcube.data.access.ckanconnector.CkanConnector";
|
|
|
|
private static final String serviceName = "CkanConnector";
|
|
|
|
private static final String serviceClass = "DataAccess";
|
2016-12-26 23:12:33 +01:00
|
|
|
private static final Log logger = LogFactoryUtil.getLog(GcoreEndpointReader.class);
|
2016-06-13 09:48:29 +02:00
|
|
|
private String ckanResourceEntyName;
|
2016-07-18 12:39:45 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
/**
|
2016-07-18 12:39:45 +02:00
|
|
|
* Instantiates a new gcore endpoint reader.
|
2016-06-13 09:48:29 +02:00
|
|
|
*
|
2016-07-18 12:39:45 +02:00
|
|
|
* @param scope the scope
|
|
|
|
* @throws Exception the exception
|
2016-06-13 09:48:29 +02:00
|
|
|
*/
|
2016-07-18 12:39:45 +02:00
|
|
|
public GcoreEndpointReader(String scope) throws Exception {
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2017-01-26 19:29:51 +01:00
|
|
|
String currentScope = ScopeProvider.instance.get();
|
2016-06-13 09:48:29 +02:00
|
|
|
try{
|
|
|
|
|
|
|
|
logger.info("set scope "+scope);
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
|
|
|
SimpleQuery query = queryFor(GCoreEndpoint.class);
|
|
|
|
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass));
|
|
|
|
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
|
|
|
|
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'",serviceName));
|
2018-02-06 16:56:42 +01:00
|
|
|
query.addCondition(String.format("$resource/Scopes/Scope/text()[.='%s']", scope)); // i.e. check the resource contains among the scopes this one
|
2016-06-13 09:48:29 +02:00
|
|
|
query.setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""+ckanResource+"\"]/text()");
|
|
|
|
|
|
|
|
logger.debug("submitting quey "+query.toString());
|
|
|
|
|
|
|
|
DiscoveryClient<String> client = client();
|
|
|
|
List<String> endpoints = client.submit(query);
|
2018-02-06 16:56:42 +01:00
|
|
|
if (endpoints == null || endpoints.isEmpty())
|
|
|
|
throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope);
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2018-02-06 16:56:42 +01:00
|
|
|
logger.debug("Found " + endpoints.size() + " matching resources");
|
2016-06-13 09:48:29 +02:00
|
|
|
|
|
|
|
this.ckanResourceEntyName = endpoints.get(0);
|
|
|
|
if(ckanResourceEntyName==null)
|
|
|
|
throw new Exception("Endpoint:"+ckanResource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope);
|
|
|
|
|
|
|
|
logger.info("found entyname "+ckanResourceEntyName+" for ckanResource: "+ckanResource);
|
|
|
|
|
|
|
|
}catch(Exception e){
|
2016-07-18 12:39:45 +02:00
|
|
|
String error = "An error occurred during GCoreEndpoint discovery, serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+scope +".";
|
|
|
|
logger.error(error, e);
|
|
|
|
throw new Exception(error);
|
2016-06-13 09:48:29 +02:00
|
|
|
}finally{
|
|
|
|
logger.info("scope provider reset");
|
2017-01-26 19:29:51 +01:00
|
|
|
ScopeProvider.instance.set(currentScope);
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the ckanResourceEntyName
|
|
|
|
*/
|
|
|
|
public String getCkanResourceEntyName() {
|
|
|
|
|
|
|
|
return ckanResourceEntyName;
|
|
|
|
}
|
2018-02-06 16:56:42 +01:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|