ref 8819: Extend The Algorithms Importer to Manage Many Processes as Black Boxes

https://support.d4science.org/issues/8819

Updated the support for Processes as Black Boxes

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@150998 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2017-07-11 17:01:42 +00:00
parent 942471cd66
commit 6244c81883
8 changed files with 228 additions and 41 deletions

13
pom.xml
View File

@ -42,11 +42,11 @@
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
<configDirectory>config</configDirectory> <configDirectory>config</configDirectory>
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory> <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<!-- Java --> <!-- Java -->
<maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.source>1.7</maven.compiler.source>
<!-- GWT configuration --> <!-- GWT configuration -->
<gwtVersion>2.6.1</gwtVersion> <gwtVersion>2.6.1</gwtVersion>
<gwtLogVersion>3.3.2</gwtLogVersion> <gwtLogVersion>3.3.2</gwtLogVersion>
@ -255,11 +255,8 @@
<!-- Social --> <!-- Social -->
<!-- <dependency> <!-- <dependency> <groupId>org.gcube.portal</groupId> <artifactId>social-networking-library</artifactId>
<groupId>org.gcube.portal</groupId> <scope>provided</scope> </dependency> -->
<artifactId>social-networking-library</artifactId>
<scope>provided</scope>
</dependency> -->
<dependency> <dependency>
<groupId>org.gcube.applicationsupportlayer</groupId> <groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId> <artifactId>aslsocial</artifactId>

View File

@ -15,10 +15,9 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.server.file.CodeRea
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectBuilder; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectBuilder;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectDeploy; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.generator.ProjectDeploy;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.BuildSAIDescriptor; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.is.BuildSAIDescriptor;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.AlgorithmNotification;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.CodeSave; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.CodeSave;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.FilesStorage;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.ProjectArchiver; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.ProjectArchiver;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.code.CodeData; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.code.CodeData;

View File

@ -58,8 +58,7 @@ public class AlgorithmGenerator {
return tempFile; return tempFile;
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage(),e);
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), throw new StatAlgoImporterServiceException(e.getLocalizedMessage(),
e); e);
} }

View File

@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletRequest;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.AlgorithmNotification; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.AlgorithmNotification;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.social.Recipient;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage.DeploySave;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData;
@ -41,13 +42,19 @@ public class ProjectDeploy {
public void deploy() throws StatAlgoImporterServiceException{ public void deploy() throws StatAlgoImporterServiceException{
InfoGenerator infoGenerator=new InfoGenerator(project, serviceCredentials); InfoGenerator infoGenerator=new InfoGenerator(project, serviceCredentials);
InfoData infoData=infoGenerator.readInfo(); InfoData infoData=infoGenerator.readInfo();
logger.debug("Deploy Save");
DeploySave deploySave=new DeploySave(serviceCredentials, project, infoData);
deploySave.save();
logger.debug("Send notify"); logger.debug("Send notify");
sendNotify(infoData); sendNotify(deploySave.getInfoText());
} }
private void sendNotify(InfoData infoData){ private void sendNotify(String body){
AlgorithmNotification notify = new AlgorithmNotification(httpServletRequest, AlgorithmNotification notify = new AlgorithmNotification(httpServletRequest,
serviceCredentials, project, recipients, infoData); serviceCredentials, recipients, body);
notify.run(); notify.run();
} }
} }

View File

@ -17,8 +17,6 @@ import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNot
import org.gcube.portal.notifications.bean.GenericItemBean; import org.gcube.portal.notifications.bean.GenericItemBean;
import org.gcube.portal.notifications.thread.MessageNotificationsThread; import org.gcube.portal.notifications.thread.MessageNotificationsThread;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials; import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -33,17 +31,15 @@ public class AlgorithmNotification extends Thread {
private static Logger logger = LoggerFactory.getLogger(AlgorithmNotification.class); private static Logger logger = LoggerFactory.getLogger(AlgorithmNotification.class);
private HttpServletRequest httpServletRequest; private HttpServletRequest httpServletRequest;
private ServiceCredentials serviceCredentials; private ServiceCredentials serviceCredentials;
private Project project;
private ArrayList<Recipient> recipients; private ArrayList<Recipient> recipients;
private InfoData infoData; private String body;
public AlgorithmNotification(HttpServletRequest httpServletRequest, ServiceCredentials serviceCredentials, public AlgorithmNotification(HttpServletRequest httpServletRequest, ServiceCredentials serviceCredentials,
Project project, ArrayList<Recipient> recipients, InfoData infoData) { ArrayList<Recipient> recipients, String body) {
this.serviceCredentials = serviceCredentials; this.serviceCredentials = serviceCredentials;
this.project = project;
this.recipients = recipients; this.recipients = recipients;
this.httpServletRequest = httpServletRequest; this.httpServletRequest = httpServletRequest;
this.infoData = infoData; this.body=body;
} }
@ -60,19 +56,6 @@ public class AlgorithmNotification extends Thread {
List<GenericItemBean> recipients = retrieveRecipients(); List<GenericItemBean> recipients = retrieveRecipients();
String subject = "[SAI] New software publication requested"; String subject = "[SAI] New software publication requested";
String body = "Username: " + serviceCredentials.getUserName() + "\nFull Name: "
+ serviceCredentials.getFullName() + "\nEmail: " + serviceCredentials.getEmail() + "\n\nin VRE: "
+ serviceCredentials.getScope() + "\n\nhas requested to publish the algorithm: " + "\nLanguage: "
+ infoData.getLanguage() + "\nAlgorithm Name: " + infoData.getAlgorithmName() + "\nClass Name: "
+ infoData.getClassName() + "\nAlgorithm Description: " + infoData.getAlgorithmDescription()
+ "\nAlgorithm Category: " + infoData.getAlgorithmCategory() + "\n\nInterpreter Version: "
+ infoData.getInterpreterVersion() + "\n\nwith the following jar: "
+ project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink() + "\n\nInstaller: "
+ "\n./addAlgorithm.sh " + infoData.getAlgorithmName() + " " + infoData.getAlgorithmCategory() + " "
+ infoData.getClassName() + " " + serviceCredentials.getScope() + " transducerers N "
+ project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink() + " \""
+ infoData.getAlgorithmDescription() + "\"";
String messageId; String messageId;

View File

@ -52,8 +52,7 @@ public class CodeSave {
return tempFile; return tempFile;
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage(),e);
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e); throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
} }
} }
@ -68,8 +67,7 @@ public class CodeSave {
Files.newInputStream(tempFile, StandardOpenOption.READ), file.getName(), ALGORITHM_DESCRIPTION, Files.newInputStream(tempFile, StandardOpenOption.READ), file.getName(), ALGORITHM_DESCRIPTION,
ALGORITHM_MIMETYPE, folderId); ALGORITHM_MIMETYPE, folderId);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage(),e);
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e); throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
} }
@ -78,8 +76,7 @@ public class CodeSave {
mainCode = new ItemDescription(mainCodeItem.getId(), mainCodeItem.getName(), mainCode = new ItemDescription(mainCodeItem.getId(), mainCodeItem.getName(),
mainCodeItem.getOwner().getPortalLogin(), mainCodeItem.getPath(), mainCodeItem.getType().name()); mainCodeItem.getOwner().getPortalLogin(), mainCodeItem.getPath(), mainCodeItem.getType().name());
} catch (InternalErrorException e) { } catch (InternalErrorException e) {
logger.error(e.getLocalizedMessage()); logger.error(e.getLocalizedMessage(),e);
e.printStackTrace();
throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
} }

View File

@ -0,0 +1,120 @@
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.List;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.statisticalalgorithmsimporter.server.util.ServiceCredentials;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.workspace.ItemDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Giancarlo Panichi
*
*
*/
public class DeploySave {
private static final String ADMIN_USER = "statistical.manager";
private static final String CODE_JAR_MIMETYPE = "application/java-archive";
private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar";
private static final String DESTINATION_FOLDER = "DataMinerAlgorithms";
private static final String TXT_MIMETYPE = "text/plain";
private static final String EXTENTION_TXT = ".txt";
public static final Logger logger = LoggerFactory.getLogger(DeploySave.class);
private FilesStorage filesStorage;
private ServiceCredentials serviceCredentials;
private Project project;
private InfoData infoData;
private String infoText;
public DeploySave(ServiceCredentials serviceCredentials, Project project, InfoData infoData) {
this.serviceCredentials = serviceCredentials;
this.project = project;
this.infoData = infoData;
this.infoText = null;
filesStorage = new FilesStorage();
}
public void save() throws StatAlgoImporterServiceException {
ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
InputStream codeJarInputStream = filesStorage.retrieveItemOnWorkspace(serviceCredentials.getUserName(),
codeJar.getId());
WorkspaceItem codeJarItem = filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, codeJarInputStream,
codeJar.getName(), CODE_JAR_DESCRIPTION, CODE_JAR_MIMETYPE, DESTINATION_FOLDER);
ItemDescription codeJarAdminCopy;
try {
codeJarAdminCopy = new ItemDescription(codeJarItem.getId(), codeJarItem.getName(),
codeJarItem.getOwner().getPortalLogin(), codeJarItem.getPath(), codeJarItem.getType().name());
codeJarAdminCopy.setPublicLink(codeJarItem.getPublicLink(false));
} catch (Throwable e) {
logger.error(e.getLocalizedMessage(), e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
createInfoText(codeJarAdminCopy);
try {
int codeJarNamelenght = codeJar.getName().length();
String codeJarName;
if (codeJarNamelenght > 4) {
codeJarName = codeJar.getName().substring(0, codeJarNamelenght - 4);
} else {
throw new StatAlgoImporterServiceException("Error in code jar name: " + codeJar.getName());
}
Path reportInstallTempFile = Files.createTempFile(codeJarName + "_install", EXTENTION_TXT);
List<String> lines = Arrays.asList(infoText.split("\\n"));
Files.write(reportInstallTempFile, lines, Charset.defaultCharset(), StandardOpenOption.WRITE);
logger.debug(reportInstallTempFile.toString());
InputStream reportInstallInputStream = Files.newInputStream(reportInstallTempFile);
filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, reportInstallInputStream,
codeJarName + "_install.txt", codeJarName + "_install.txt", TXT_MIMETYPE, DESTINATION_FOLDER);
} catch (IOException e) {
logger.error("Error writing report install information: " + e.getLocalizedMessage(), e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
}
}
private void createInfoText(ItemDescription codeJarAdminCopy) {
infoText = "Username: " + serviceCredentials.getUserName() + "\nFull Name: " + serviceCredentials.getFullName()
+ "\nEmail: " + serviceCredentials.getEmail() + "\n\nin VRE: " + serviceCredentials.getScope()
+ "\n\nhas requested to publish the algorithm: " + "\nLanguage: " + infoData.getLanguage()
+ "\nAlgorithm Name: " + infoData.getAlgorithmName() + "\nClass Name: " + infoData.getClassName()
+ "\nAlgorithm Description: " + infoData.getAlgorithmDescription() + "\nAlgorithm Category: "
+ infoData.getAlgorithmCategory() + "\n\nInterpreter Version: " + infoData.getInterpreterVersion()
+ "\n\nwith the following original jar: "
+ project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink() + "\nadmin copy jar: "
+ codeJarAdminCopy.getPublicLink() + "\n\nInstaller: " + "\n./addAlgorithm.sh "
+ infoData.getAlgorithmName() + " " + infoData.getAlgorithmCategory() + " " + infoData.getClassName()
+ " " + serviceCredentials.getScope() + " transducerers N " + codeJarAdminCopy.getPublicLink() + " \""
+ infoData.getAlgorithmDescription() + "\"";
}
public String getInfoText() {
return infoText;
}
}

View File

@ -281,6 +281,41 @@ public class FilesStorage {
} }
/**
*
* @param user
* User
* @param parentName
* Parent name
* @param name
* Name
* @return WorkspaceItem
* @throws StatAlgoImporterServiceException
* Exception
*/
public WorkspaceItem findInParentName(String user, String parentName, String name)
throws StatAlgoImporterServiceException {
Workspace ws;
try {
logger.info("Find by parent name: [user=" + user + ", parentName=" + parentName + ", name=" + name + "]");
ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem parentItem = ws.getItem(parentName);
if (!parentItem.isFolder()) {
throw new StatAlgoImporterServiceException("No valid folder: " + parentName + "!");
}
return ws.find(name, parentItem.getId());
} catch (Throwable e) {
logger.error("Find by parent name: " + e.getLocalizedMessage(), e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
}
/** /**
* *
* @param user * @param user
@ -398,6 +433,7 @@ public class FilesStorage {
ws = HomeLibrary.getUserWorkspace(user); ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem workSpaceItem = ws.getItem(folderId); WorkspaceItem workSpaceItem = ws.getItem(folderId);
if (!workSpaceItem.isFolder()) { if (!workSpaceItem.isFolder()) {
throw new StatAlgoImporterServiceException("Destination is not a folder!"); throw new StatAlgoImporterServiceException("Destination is not a folder!");
} }
@ -412,6 +448,55 @@ public class FilesStorage {
} }
} }
/**
*
* @param user
* User
* @param inputStream
* InputStream
* @param name
* Name
* @param description
* Description
* @param mimeType
* MimeType
* @param folderName
* Folder Path
* @return WorkspaceItem
* @throws StatAlgoImporterServiceException
* Exception
*/
public WorkspaceItem createItemOnWorkspaceHowAdmin(String user, InputStream inputStream, String name,
String description, String mimeType, String folderName) throws StatAlgoImporterServiceException {
Workspace ws;
try {
logger.info("Create item on workspace how admin: [user=" + user + ", name=" + name + ", description="
+ description + ", mimeType=" + mimeType + ", folderName=" + folderName + "]");
ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem root = ws.getRoot();
WorkspaceItem folderItem=ws.find(folderName, root.getId());
if (folderItem==null||!folderItem.isFolder()) {
throw new StatAlgoImporterServiceException("Destination "+folderName+" is not a valid folder!");
}
WorkspaceItem codeJar = ws.find(name, folderItem.getId());
if (codeJar == null) {
return ws.createExternalFile(name, description, mimeType, inputStream, folderItem.getId());
} else {
ws.updateItem(codeJar.getId(), inputStream);
return codeJar;
}
} catch (Throwable e) {
logger.error("Create item on workspace how admin: " + e.getLocalizedMessage(), e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
}
/** /**
* *
* @param user * @param user