2018-12-05 16:58:44 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.datatransfer.resolver.services;
|
|
|
|
|
|
|
|
import java.net.URI;
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
import javax.ws.rs.PathParam;
|
2018-12-14 11:53:50 +01:00
|
|
|
import javax.ws.rs.WebApplicationException;
|
2018-12-05 16:58:44 +01:00
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
|
2019-05-16 12:54:20 +02:00
|
|
|
import org.gcube.common.scope.impl.ScopeBean;
|
2018-12-12 15:38:44 +01:00
|
|
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
2019-05-16 12:54:20 +02:00
|
|
|
import org.gcube.datatransfer.resolver.caches.LoadingMapOfScopeCache;
|
2018-12-05 16:58:44 +01:00
|
|
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2018-12-17 15:52:31 +01:00
|
|
|
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
|
|
|
|
2018-12-05 16:58:44 +01:00
|
|
|
/**
|
2022-03-31 10:52:52 +02:00
|
|
|
* The AnalyticsGetResolver to resolve an Analytics URL
|
|
|
|
*
|
|
|
|
* See more at
|
|
|
|
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver
|
2018-12-05 16:58:44 +01:00
|
|
|
*
|
2022-03-24 17:33:54 +01:00
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Mar 24, 2022
|
2018-12-05 16:58:44 +01:00
|
|
|
*/
|
2019-02-19 15:18:19 +01:00
|
|
|
@Path("analytics")
|
2018-12-05 16:58:44 +01:00
|
|
|
public class AnalyticsGetResolver {
|
|
|
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(AnalyticsGetResolver.class);
|
2018-12-12 15:38:44 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
private static final String ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL = "org.gcube.portlets.user.dataminermanager.server.DataMinerManagerServiceImpl";
|
2018-12-12 15:38:44 +01:00
|
|
|
|
|
|
|
private static final String APPLICATION_PROFILE = "ApplicationProfile";
|
|
|
|
|
2018-12-13 12:39:55 +01:00
|
|
|
private static String helpURI = "https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#Analytics_Resolver";
|
2018-12-12 15:38:44 +01:00
|
|
|
|
|
|
|
private static final String ANALYTICS_EXECUTOR_PORTLET_NAME = "Analytics Executor";
|
2018-12-05 16:58:44 +01:00
|
|
|
|
|
|
|
/**
|
2018-12-13 11:09:08 +01:00
|
|
|
* Resolve analytics url.
|
2018-12-05 16:58:44 +01:00
|
|
|
*
|
2022-03-31 10:52:52 +02:00
|
|
|
* See more at
|
|
|
|
* https://gcube.wiki.gcube-system.org/gcube/URI_Resolver#HTTP_GET:_Resolve_an_Analytics_URL
|
|
|
|
*
|
2022-03-24 17:33:54 +01:00
|
|
|
* @param req the req
|
2018-12-12 15:38:44 +01:00
|
|
|
* @param vreName the vre name
|
2018-12-13 11:09:08 +01:00
|
|
|
* @return the response
|
2022-03-24 17:33:54 +01:00
|
|
|
* @throws WebApplicationException the web application exception
|
2018-12-05 16:58:44 +01:00
|
|
|
*/
|
|
|
|
@GET
|
|
|
|
@Path("/get/{vreName}")
|
2022-03-24 17:33:54 +01:00
|
|
|
public Response resolveAnalyticsURL(@Context HttpServletRequest req, @PathParam("vreName") String vreName)
|
|
|
|
throws WebApplicationException {
|
|
|
|
logger.info(this.getClass().getSimpleName() + " GET starts...");
|
2018-12-05 16:58:44 +01:00
|
|
|
try {
|
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
if (vreName == null || vreName.isEmpty()) {
|
2018-12-05 16:58:44 +01:00
|
|
|
logger.error("The path parameter 'vreName' not found or empty in the path");
|
2022-03-24 17:33:54 +01:00
|
|
|
throw ExceptionManager.badRequestException(req, "Mandatory path parameter 'vreName' not found or empty",
|
|
|
|
this.getClass(), helpURI);
|
2018-12-05 16:58:44 +01:00
|
|
|
}
|
|
|
|
|
2019-05-16 12:54:20 +02:00
|
|
|
ScopeBean fullScopeBean = null;
|
2018-12-17 11:48:18 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
// CHECKING IF THE INPUT VRE NAME IS REGISTRED IN THE INFRASTRUCTURE...
|
|
|
|
try {
|
2019-05-16 12:54:20 +02:00
|
|
|
fullScopeBean = LoadingMapOfScopeCache.get(vreName);
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (ExecutionException | InvalidCacheLoadException e) {
|
|
|
|
logger.error("Error on getting the fullscope from cache for vreName " + vreName, e);
|
|
|
|
throw ExceptionManager.wrongParameterException(req,
|
|
|
|
"Error on getting full scope for the VRE name " + vreName
|
|
|
|
+ ". Is it registered as VRE in the D4Science Infrastructure System?",
|
|
|
|
this.getClass(), helpURI);
|
2018-12-17 11:48:18 +01:00
|
|
|
}
|
|
|
|
ApplicationProfileReader reader = null;
|
2022-03-24 17:33:54 +01:00
|
|
|
try {
|
|
|
|
reader = new ApplicationProfileReader(fullScopeBean.toString(), APPLICATION_PROFILE,
|
|
|
|
ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Error on reading the " + APPLICATION_PROFILE + " with APPID: "
|
|
|
|
+ ORG_GCUBE_PORTLETS_USER_DATAMINERMANAGER_SERVER_DATA_MINER_MANAGER_SERVICE_IMPL, e);
|
|
|
|
throw ExceptionManager.internalErrorException(req, "Error on reading the Application Profile for the "
|
|
|
|
+ ANALYTICS_EXECUTOR_PORTLET_NAME + ". Please contact the support", this.getClass(), helpURI);
|
2018-12-05 16:58:44 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
// READ THE DATAMINER URL PORTLET FROM APPLICATION PROFRILE IN THE SCOPE
|
|
|
|
// fullScope
|
2018-12-17 11:48:18 +01:00
|
|
|
String analyticsExecutorEndPoint = reader.getApplicationProfile().getUrl();
|
2022-03-24 17:33:54 +01:00
|
|
|
// CHECKING THE QUERY STRING
|
|
|
|
String queryString = req.getQueryString() != null ? req.getQueryString() : "";
|
2018-12-17 11:48:18 +01:00
|
|
|
String analitycsExecutorURL = String.format("%s?%s", analyticsExecutorEndPoint, queryString);
|
2022-03-24 17:33:54 +01:00
|
|
|
logger.info("Resolving the request with the " + ANALYTICS_EXECUTOR_PORTLET_NAME + " URL: "
|
|
|
|
+ analitycsExecutorURL);
|
2018-12-17 11:48:18 +01:00
|
|
|
return Response.seeOther(new URI(analitycsExecutorURL)).build();
|
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
} catch (Exception e) {
|
2018-12-14 11:53:50 +01:00
|
|
|
|
2022-03-24 17:33:54 +01:00
|
|
|
if (!(e instanceof WebApplicationException)) {
|
|
|
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
2018-12-14 14:26:37 +01:00
|
|
|
String error = "Error occurred on resolving the Analytics URL. Please, contact the support!";
|
2022-03-24 17:33:54 +01:00
|
|
|
if (e.getCause() != null)
|
|
|
|
error += "\n\nCaused: " + e.getCause().getMessage();
|
2018-12-14 11:53:50 +01:00
|
|
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), helpURI);
|
|
|
|
}
|
2022-03-24 17:33:54 +01:00
|
|
|
// ALREADY MANAGED AS WebApplicationException
|
2018-12-14 11:53:50 +01:00
|
|
|
logger.error("Exception:", e);
|
|
|
|
throw (WebApplicationException) e;
|
2018-12-05 16:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|