git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineSmartExecutor@149352 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
6d617d97d6
commit
92b9382eeb
|
@ -1,19 +1,15 @@
|
||||||
package org.gcube.dataanalysis.executor.nodes.transducers;
|
package org.gcube.dataanalysis.executor.nodes.transducers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.gcube.contentmanagement.graphtools.utils.MathFunctions;
|
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
|
import org.gcube.dataanalysis.ecoengine.datatypes.PrimitiveType;
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.ServiceType;
|
import org.gcube.dataanalysis.ecoengine.datatypes.ServiceType;
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;
|
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.PrimitiveTypes;
|
||||||
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.ServiceParameters;
|
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.ServiceParameters;
|
||||||
import org.gcube.dataanalysis.ecoengine.interfaces.StandardLocalInfraAlgorithm;
|
import org.gcube.dataanalysis.ecoengine.interfaces.StandardLocalInfraAlgorithm;
|
||||||
import org.gcube.dataanalysis.ecoengine.utils.ZipTools;
|
|
||||||
import org.gcube.dataanalysis.executor.util.DataTransferer;
|
import org.gcube.dataanalysis.executor.util.DataTransferer;
|
||||||
import org.gcube.dataanalysis.executor.util.InfraRetrieval;
|
import org.gcube.dataanalysis.executor.util.InfraRetrieval;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -22,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class WebApplicationPublisher extends StandardLocalInfraAlgorithm{
|
public class WebApplicationPublisher extends StandardLocalInfraAlgorithm{
|
||||||
//private static String MainPageParam = "MainPage";
|
//private static String MainPageParam = "MainPage";
|
||||||
|
private static final String DATA_TRANSFER_PERSISTENCE_ID = "data-transfer-service";
|
||||||
private static String FileParam = "ZipFile";
|
private static String FileParam = "ZipFile";
|
||||||
private String transferServiceAddress = "";
|
private String transferServiceAddress = "";
|
||||||
private int transferServicePort = 0;
|
private int transferServicePort = 0;
|
||||||
|
@ -58,53 +55,12 @@ public class WebApplicationPublisher extends StandardLocalInfraAlgorithm{
|
||||||
throw new Exception ("Service parameters are not set - please contact the Administrators");
|
throw new Exception ("Service parameters are not set - please contact the Administrators");
|
||||||
if (fileAbsolutePath==null || fileAbsolutePath.trim().length()==0)
|
if (fileAbsolutePath==null || fileAbsolutePath.trim().length()==0)
|
||||||
throw new Exception ("No file has been provided to the process");
|
throw new Exception ("No file has been provided to the process");
|
||||||
// if (mainPage==null || mainPage.trim().length()==0)
|
|
||||||
// throw new Exception ("Please provide a valid main page");
|
|
||||||
|
|
||||||
File f = new File(fileAbsolutePath);
|
|
||||||
String fileName = f.getName();
|
|
||||||
|
|
||||||
//unzip the file
|
|
||||||
LOGGER.debug("Package is in file "+fileName);
|
|
||||||
|
|
||||||
boolean mkdir = folder.mkdir();
|
|
||||||
LOGGER.debug("Sandbox {} generated: {} ",folder.getAbsolutePath(), mkdir);
|
|
||||||
LOGGER.debug("Unzipping package into {}",folder.getAbsolutePath());
|
|
||||||
ZipTools.unZip(f.getAbsolutePath(), folder.getAbsolutePath());
|
|
||||||
// f.delete();
|
|
||||||
LOGGER.debug("Package unzipped and original file deleted");
|
|
||||||
|
|
||||||
File[] webappfiles = folder.listFiles();
|
|
||||||
//get all files for the upload
|
|
||||||
String prefix = "/"+folder.getName()+"/";
|
|
||||||
|
|
||||||
Map<String,String> allfiles = getFilesPaths(webappfiles,prefix);
|
|
||||||
|
|
||||||
//discover the dataTransfer service with Apache
|
|
||||||
getTransferInfo(config.getGcubeScope());
|
getTransferInfo(config.getGcubeScope());
|
||||||
String remoteFolder = "/var/www/html";
|
|
||||||
//upload every file
|
|
||||||
int nfiles = allfiles.size();
|
|
||||||
float step = 80f/(float)nfiles;
|
|
||||||
float initialStatus=status;
|
|
||||||
int i=0;
|
|
||||||
for (String key:allfiles.keySet()){
|
|
||||||
status=(float)MathFunctions.roundDecimal(initialStatus+(float)i*step,2);
|
|
||||||
String subpath = allfiles.get(key);
|
|
||||||
subpath = subpath.substring(0,subpath.lastIndexOf("/"));
|
|
||||||
String remotePath = remoteFolder+subpath+"/";
|
|
||||||
LOGGER.debug("Uploading {} -> {}",key,remotePath);
|
|
||||||
|
|
||||||
long transferout = DataTransferer.transferFileToService(scope, username, transferServiceAddress, transferServicePort, key, remotePath).getTransferedBytes();
|
DataTransferer.transferFileToService(scope, username, transferServiceAddress, transferServicePort, fileAbsolutePath, "", DATA_TRANSFER_PERSISTENCE_ID , true,uuid);
|
||||||
if (transferout<=0){
|
|
||||||
throw new Exception("Error transferring files to the infrastructure ");
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
String producedPage = "http://"+transferServiceAddress+"/"+uuid+"/";
|
String producedPage = "http://"+transferServiceAddress+"/"+uuid+"/";
|
||||||
if (webappfiles.length==1 && webappfiles[0].isDirectory()){
|
|
||||||
producedPage = producedPage + webappfiles[0].getName()+"/";
|
|
||||||
}
|
|
||||||
LOGGER.debug("Entry point of the page "+producedPage);
|
LOGGER.debug("Entry point of the page "+producedPage);
|
||||||
|
|
||||||
//get URL
|
//get URL
|
||||||
|
@ -124,7 +80,7 @@ public class WebApplicationPublisher extends StandardLocalInfraAlgorithm{
|
||||||
status = 100;
|
status = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String,String> getFilesPaths(File[] toexplore, String prefix){
|
/* private Map<String,String> getFilesPaths(File[] toexplore, String prefix){
|
||||||
Map<String,String> toreturn = new HashMap<String,String> ();
|
Map<String,String> toreturn = new HashMap<String,String> ();
|
||||||
for (File toex:toexplore){
|
for (File toex:toexplore){
|
||||||
if (toex.isDirectory()){
|
if (toex.isDirectory()){
|
||||||
|
@ -135,13 +91,13 @@ public class WebApplicationPublisher extends StandardLocalInfraAlgorithm{
|
||||||
}
|
}
|
||||||
|
|
||||||
return toreturn;
|
return toreturn;
|
||||||
}
|
}*/
|
||||||
@Override
|
@Override
|
||||||
protected void setInputParameters() {
|
protected void setInputParameters() {
|
||||||
|
|
||||||
inputs.add(new PrimitiveType(File.class.getName(), null, PrimitiveTypes.FILE, FileParam, "Zip file containing the Web site"));
|
inputs.add(new PrimitiveType(File.class.getName(), null, PrimitiveTypes.FILE, FileParam, "Zip file containing the Web site"));
|
||||||
inputs.add(new ServiceType(ServiceParameters.USERNAME,"ServiceUserName","The final user Name"));
|
inputs.add(new ServiceType(ServiceParameters.USERNAME,"ServiceUserName","The final user Name"));
|
||||||
// addStringInput(MainPageParam, "Main page of the website", "index.html");
|
//inputs.add(MainPageParam, "Main page of the website", "index.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -163,7 +119,7 @@ public class WebApplicationPublisher extends StandardLocalInfraAlgorithm{
|
||||||
LOGGER.debug("Found {} services",apacheAddress.size());
|
LOGGER.debug("Found {} services",apacheAddress.size());
|
||||||
LOGGER.debug("Apache address: {}",apacheServiceAddress);
|
LOGGER.debug("Apache address: {}",apacheServiceAddress);
|
||||||
|
|
||||||
List<String> dataTransferAddress = InfraRetrieval.retrieveService("agent-service", scope);
|
List<String> dataTransferAddress = InfraRetrieval.retrieveService("data-transfer-service", scope);
|
||||||
|
|
||||||
if (dataTransferAddress.size()==0)
|
if (dataTransferAddress.size()==0)
|
||||||
throw new Exception("Data Transfer services are not available in scope "+scope);
|
throw new Exception("Data Transfer services are not available in scope "+scope);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package org.gcube.dataanalysis.executor.util;
|
package org.gcube.dataanalysis.executor.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.data.transfer.library.DataTransferClient;
|
import org.gcube.data.transfer.library.DataTransferClient;
|
||||||
import org.gcube.data.transfer.library.TransferResult;
|
import org.gcube.data.transfer.library.TransferResult;
|
||||||
import org.gcube.data.transfer.model.Destination;
|
import org.gcube.data.transfer.model.Destination;
|
||||||
|
import org.gcube.data.transfer.model.PluginInvocation;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -17,8 +20,12 @@ public class DataTransferer {
|
||||||
return transferFileToService(scope, username, host, port, fileAbsolutePath, remoteFolder, null);
|
return transferFileToService(scope, username, host, port, fileAbsolutePath, remoteFolder, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the number of transferred bytes
|
|
||||||
public static TransferResult transferFileToService(String scope, String username, String host, int port, String fileAbsolutePath, String remoteFolder, String destinationId) throws Exception {
|
public static TransferResult transferFileToService(String scope, String username, String host, int port, String fileAbsolutePath, String remoteFolder, String destinationId) throws Exception {
|
||||||
|
return transferFileToService(scope, username, host, port, fileAbsolutePath, remoteFolder, destinationId, false, null );
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the number of transferred bytes
|
||||||
|
public static TransferResult transferFileToService(String scope, String username, String host, int port, String fileAbsolutePath, String remoteFolder, String destinationId, boolean decompress, String decompressedFilefolderDestination) throws Exception {
|
||||||
logger.debug("Transferring file {} to {}:{} " , fileAbsolutePath, host, port );
|
logger.debug("Transferring file {} to {}:{} " , fileAbsolutePath, host, port );
|
||||||
|
|
||||||
DataTransferClient client=DataTransferClient.getInstanceByEndpoint("http://"+host+":"+port);
|
DataTransferClient client=DataTransferClient.getInstanceByEndpoint("http://"+host+":"+port);
|
||||||
|
@ -30,13 +37,23 @@ public class DataTransferer {
|
||||||
//String localfolder = localFile.getParent();
|
//String localfolder = localFile.getParent();
|
||||||
String file = localFile.getName();
|
String file = localFile.getName();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Destination dest=new Destination(file);
|
Destination dest=new Destination(file);
|
||||||
dest.setSubFolder(remoteFolder);
|
dest.setSubFolder(remoteFolder);
|
||||||
|
|
||||||
if(destinationId!=null)
|
if(destinationId!=null)
|
||||||
dest.setPersistenceId(destinationId);
|
dest.setPersistenceId(destinationId);
|
||||||
|
|
||||||
TransferResult transferResult = client.localFile(localFile,dest);
|
TransferResult transferResult = null;
|
||||||
|
if(decompress){
|
||||||
|
Map<String,String> params=new HashMap<>();
|
||||||
|
params.put("DELETE_ARCHIVE", Boolean.FALSE.toString());
|
||||||
|
if (decompressedFilefolderDestination!=null)
|
||||||
|
params.put("DESTINATION", decompressedFilefolderDestination);
|
||||||
|
transferResult = client.localFile(localFile,dest, new PluginInvocation("DECOMPRESS",params));
|
||||||
|
} else
|
||||||
|
transferResult = client.localFile(localFile,dest);
|
||||||
|
|
||||||
logger.debug("Transferring...");
|
logger.debug("Transferring...");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue