Fabio Sinibaldi 2017-12-05 17:18:13 +00:00
parent 598f433134
commit 630ecf765b
5 changed files with 32 additions and 47 deletions

View File

@ -3,14 +3,18 @@ package org.gcube.data.transfer.service.transfers;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.gcube.data.transfer.model.ServiceConstants;
import org.gcube.data.transfer.model.TransferCapabilities;
import org.gcube.data.transfer.service.transfers.engine.CapabilitiesProvider;
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
import org.gcube.data.transfer.service.transfers.engine.faults.PluginNotFoundException;
import lombok.extern.slf4j.Slf4j;
@ -21,7 +25,8 @@ public class Capabilities {
@Inject
CapabilitiesProvider provider;
@Inject
PluginManager plugins;
@GET
@ -38,5 +43,17 @@ public class Capabilities {
}
}
@GET
@Path("pluginInfo/{pluginId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPluginInfo(@PathParam("pluginId") String pluginID) {
log.trace("Getting plugin info for plugin ID : {} ",pluginID);
try{
return Response.ok(plugins.getPluginInfo(pluginID),MediaType.APPLICATION_JSON).build();
}catch(PluginNotFoundException e) {
throw new WebApplicationException("Plugin "+pluginID+" has not been found",Status.NOT_FOUND);
}catch(Throwable t) {
throw new WebApplicationException("Unexpected error. ",t,Status.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -162,16 +162,15 @@ public class REST {
@GET
@Produces("*/*")
public Response getFile(@PathParam("destinationId") String destinationId,
@PathParam("subPath") String subPath,
public Response getFile(
@QueryParam("descriptor") @DefaultValue("false") Boolean getDescriptor) {
String pathString="<"+destinationID+">/"+subPath;
log.info("Received GET request at {} , descriptor option is {} ",pathString,getDescriptor);
try{
if(getDescriptor) return Response.ok(persistence.getDescriptor(destinationId, subPath), MediaType.APPLICATION_JSON_TYPE).build();
if(getDescriptor) return Response.ok(persistence.getDescriptor(destinationID, subPath), MediaType.APPLICATION_JSON_TYPE).build();
File persisted= persistence.getPersistedFile(destinationId, subPath);
File persisted= persistence.getPersistedFile(destinationID, subPath);
if(!persisted.exists()) throw new WebApplicationException("File "+pathString+" doesn't exists.",Status.NOT_FOUND);
if(persisted.isDirectory()) throw new WebApplicationException("The selected path "+pathString+" is a directory.",Status.BAD_REQUEST);
String mt = new MimetypesFileTypeMap().getContentType(persisted);
@ -184,12 +183,11 @@ public class REST {
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public DeletionReport deleteFile(@PathParam("destinationId") String destinationId,
@PathParam("subPath") String subPath) {
public DeletionReport deleteFile() {
String pathString="<"+destinationID+">/"+subPath;
log.info("Received DELETE request at {}",pathString);
try{
return persistence.delete(destinationId, subPath);
return persistence.delete(destinationID, subPath);
}catch(DestinationAccessException e) {
throw new WebApplicationException("Unable to access selected path "+pathString,e,Status.INTERNAL_SERVER_ERROR);
}

View File

@ -6,6 +6,7 @@ import org.gcube.data.transfer.model.ExecutionReport;
import org.gcube.data.transfer.model.PluginDescription;
import org.gcube.data.transfer.model.PluginInvocation;
import org.gcube.data.transfer.plugin.fails.PluginException;
import org.gcube.data.transfer.plugin.fails.PluginExecutionException;
import org.gcube.data.transfer.service.transfers.engine.faults.PluginNotFoundException;
public interface PluginManager {
@ -13,4 +14,5 @@ public interface PluginManager {
public Map<String,PluginDescription> getInstalledPlugins();
public ExecutionReport execute(PluginInvocation invocation,String transferredFile)throws PluginException, PluginNotFoundException;
public void shutdown();
public Object getPluginInfo(String pluginID) throws PluginNotFoundException, PluginExecutionException;
}

View File

@ -61,42 +61,5 @@ public class CapabilitiesProviderImpl implements CapabilitiesProvider {
return new TransferCapabilities(id,hostName,port,meansOfTransfer,plugins,persistenceProvider.getAvaileblContextIds());
}
// private static String getHostname() throws Exception {
// String OS = System.getProperty("os.name").toLowerCase();
// log.debug("Getting hostname..");
// String hostName=null;
// if (OS.indexOf("win") >= 0) {
// log.debug("Detected windows..");
// hostName=System.getenv("COMPUTERNAME");
// if(hostName==null || hostName.equals("")){
// log.debug("System env not found, trying via hostname command..");
// hostName=execReadToString("hostname");
// }
// } else
// if (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0) {
// log.debug("Detected linux..");
// hostName= System.getenv("HOSTNAME");
// if(hostName==null || hostName.equals("")){
// log.debug("System env not found, trying via hostname command..");
// hostName=execReadToString("hostname -f");
// }
// if(hostName==null || hostName.equals("")){
// log.debug("Hostname command didn't work, trying via hostname file..");
// hostName=execReadToString("cat /etc/hostname");
// }
// }else throw new Exception("OS not detected");
// return hostName;
// }
// public static String execReadToString(String execCommand) throws IOException {
// Process proc = Runtime.getRuntime().exec(execCommand);
// try (InputStream stream = proc.getInputStream()) {
// try (Scanner s = new Scanner(stream).useDelimiter("\\A")) {
// return s.hasNext() ? s.next() : "";
// }
// }
// }
}

View File

@ -12,6 +12,7 @@ import org.gcube.data.transfer.model.PluginInvocation;
import org.gcube.data.transfer.plugin.AbstractPlugin;
import org.gcube.data.transfer.plugin.AbstractPluginFactory;
import org.gcube.data.transfer.plugin.fails.PluginException;
import org.gcube.data.transfer.plugin.fails.PluginExecutionException;
import org.gcube.data.transfer.plugin.model.DataTransferContext;
import org.gcube.data.transfer.service.transfers.engine.PluginManager;
import org.gcube.data.transfer.service.transfers.engine.faults.PluginNotFoundException;
@ -87,6 +88,7 @@ public class PluginManagerImpl implements PluginManager {
private AbstractPluginFactory getFactory(String pluginId) throws PluginNotFoundException{
log.debug("Getting factory by ID {} ",pluginId);
for(AbstractPluginFactory factory:abstractFactoryLoader){
if(factory.getID().equals(pluginId)) return factory;
}
@ -109,6 +111,9 @@ public class PluginManagerImpl implements PluginManager {
installedPlugins=null;
}
@Override
public Object getPluginInfo(String pluginID) throws PluginNotFoundException, PluginExecutionException {
return getFactory(pluginID).getInfo();
}
}