ref 11724: SAI - Update to StorageHUB

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

Updated to StorageHub 

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@171353 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2018-09-07 10:37:27 +00:00
parent edc1c9fc72
commit f83cde44ab
7 changed files with 52 additions and 71 deletions

View File

@ -729,10 +729,11 @@ public class StatAlgoImporterServiceImpl extends RemoteServiceServlet implements
if (saiDescriptor != null && saiDescriptor.getPoolManagerConfig() != null if (saiDescriptor != null && saiDescriptor.getPoolManagerConfig() != null
&& saiDescriptor.getPoolManagerConfig().isEnable()) { && saiDescriptor.getPoolManagerConfig().isEnable()) {
logger.info("Deploy On PoolManager"); logger.info("Deploy On PoolManager");
logger.debug("CodeJarAdminCopy for PoolManager: " + deploySave.getCodeJarAdminCopy()); ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
logger.debug("CodeJarAdminCopy for PoolManager: " + codeJar);
DataMinerPoolManager poolManager = new DataMinerPoolManager(serviceCredentials); DataMinerPoolManager poolManager = new DataMinerPoolManager(serviceCredentials);
String operationId = poolManager.deployAlgorithm(project, deploySave.getInfoData(), String operationId = poolManager.deployAlgorithm(project, deploySave.getInfoData(),
deploySave.getCodeJarAdminCopy()); codeJar);
logger.info("Deploy operationId: " + operationId); logger.info("Deploy operationId: " + operationId);
return operationId; return operationId;
} else { } else {

View File

@ -14,7 +14,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.exception.St
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.MainCode; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.MainCode;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBashEdit; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBashEdit;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBlackBox; //import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportBlackBox;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportREdit; import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.ProjectSupportREdit;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -88,7 +88,10 @@ public class CodeReader {
* TODO * TODO
* *
* Check how if open a project after another already open if we write this code we create a lock * Check how if open a project after another already open if we write this code we create a lock
* this create a lock on workspace when we save the project * this create a lock on workspace when we save the project.
* The Workspace does not have a fix for this issue,
* so I add this exception how workaround.
*
* *
* if (project.getProjectConfig().getProjectSupport() * if (project.getProjectConfig().getProjectSupport()
* instanceof ProjectSupportBlackBox) { * instanceof ProjectSupportBlackBox) {

View File

@ -491,6 +491,7 @@ public class AlgorithmGenerator {
} }
} }
//TODO
private String retrieveMainScriptRelativePath() { private String retrieveMainScriptRelativePath() {
logger.debug("ProjectInfo: " + project); logger.debug("ProjectInfo: " + project);
String projectPath = project.getProjectFolder().getFolder().getPath(); String projectPath = project.getProjectFolder().getFolder().getPath();

View File

@ -637,7 +637,7 @@ public class ProjectBuilder {
FilesStorage filesStorage = new FilesStorage(); FilesStorage filesStorage = new FilesStorage();
ItemDescription codeJarItemDescription; ItemDescription codeJarItemDescription;
;
try { try {
codeJarItemDescription = filesStorage.createItemOnWorkspace(serviceCredentials.getUserName(), codeJarItemDescription = filesStorage.createItemOnWorkspace(serviceCredentials.getUserName(),

View File

@ -1,14 +1,5 @@
package org.gcube.portlets.user.statisticalalgorithmsimporter.server.storage; 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.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;
@ -24,43 +15,43 @@ import org.slf4j.LoggerFactory;
* *
*/ */
public class DeploySave { public class DeploySave {
private static final String ADMIN_USER = "statistical.manager"; //private static final String ADMIN_USER = "statistical.manager";
private static final String CODE_JAR_MIMETYPE = "application/java-archive"; //private static final String CODE_JAR_MIMETYPE = "application/java-archive";
private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar"; //private static final String CODE_JAR_DESCRIPTION = "Statistical Algorithm Jar";
private static final String DESTINATION_FOLDER = "DataMinerAlgorithms"; //private static final String DESTINATION_FOLDER = "DataMinerAlgorithms";
private static final String TXT_MIMETYPE = "text/plain"; //private static final String TXT_MIMETYPE = "text/plain";
private static final String EXTENTION_TXT = ".txt"; //private static final String EXTENTION_TXT = ".txt";
public static final Logger logger = LoggerFactory.getLogger(DeploySave.class); public static final Logger logger = LoggerFactory.getLogger(DeploySave.class);
private FilesStorage filesStorage; //private FilesStorage filesStorage;
private ServiceCredentials serviceCredentials; private ServiceCredentials serviceCredentials;
private Project project; private Project project;
private InfoData infoData; private InfoData infoData;
private String infoText; private String infoText;
private ItemDescription codeJarAdminCopy; //private ItemDescription codeJarAdminCopy;
public DeploySave(ServiceCredentials serviceCredentials, Project project, InfoData infoData) { public DeploySave(ServiceCredentials serviceCredentials, Project project, InfoData infoData) {
this.serviceCredentials = serviceCredentials; this.serviceCredentials = serviceCredentials;
this.project = project; this.project = project;
this.infoData = infoData; this.infoData = infoData;
this.infoText = null; this.infoText = null;
this.codeJarAdminCopy = null; //this.codeJarAdminCopy = null;
filesStorage = new FilesStorage(); //filesStorage = new FilesStorage();
} }
public void save() throws StatAlgoImporterServiceException { public void save() throws StatAlgoImporterServiceException {
ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar(); //ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
InputStream codeJarInputStream = filesStorage.retrieveItemOnWorkspace(serviceCredentials.getUserName(), //InputStream codeJarInputStream = filesStorage.retrieveItemOnWorkspace(serviceCredentials.getUserName(),
codeJar.getId()); // codeJar.getId());
codeJarAdminCopy = filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, codeJarInputStream, codeJar.getName(), //codeJarAdminCopy = filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, codeJarInputStream, codeJar.getName(),
CODE_JAR_DESCRIPTION, CODE_JAR_MIMETYPE, DESTINATION_FOLDER); // CODE_JAR_DESCRIPTION, CODE_JAR_MIMETYPE, DESTINATION_FOLDER);
createInfoText(); createInfoText();
/*
try { try {
int codeJarNamelenght = codeJar.getName().length(); int codeJarNamelenght = codeJar.getName().length();
String codeJarName; String codeJarName;
@ -75,6 +66,7 @@ public class DeploySave {
List<String> lines = Arrays.asList(infoText.split("\\n")); List<String> lines = Arrays.asList(infoText.split("\\n"));
Files.write(reportInstallTempFile, lines, Charset.defaultCharset(), StandardOpenOption.WRITE); Files.write(reportInstallTempFile, lines, Charset.defaultCharset(), StandardOpenOption.WRITE);
logger.debug(reportInstallTempFile.toString()); logger.debug(reportInstallTempFile.toString());
InputStream reportInstallInputStream = Files.newInputStream(reportInstallTempFile); InputStream reportInstallInputStream = Files.newInputStream(reportInstallTempFile);
filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, reportInstallInputStream, filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, reportInstallInputStream,
@ -84,10 +76,13 @@ public class DeploySave {
logger.error("Error writing report install information: " + e.getLocalizedMessage(), e); logger.error("Error writing report install information: " + e.getLocalizedMessage(), e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e); throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
} }
*/
} }
private void createInfoText() { private void createInfoText() {
ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
infoText = "Username: " + serviceCredentials.getUserName() + "\nFull Name: " + serviceCredentials.getFullName() infoText = "Username: " + serviceCredentials.getUserName() + "\nFull Name: " + serviceCredentials.getFullName()
+ "\nEmail: " + serviceCredentials.getEmail() + "\n\nin VRE: " + serviceCredentials.getScope() + "\nEmail: " + serviceCredentials.getEmail() + "\n\nin VRE: " + serviceCredentials.getScope()
+ "\n\nhas requested to publish the algorithm: " + "\nLanguage: " + infoData.getLanguage() + "\n\nhas requested to publish the algorithm: " + "\nLanguage: " + infoData.getLanguage()
@ -95,10 +90,10 @@ public class DeploySave {
+ "\nAlgorithm Description: " + infoData.getAlgorithmDescription() + "\nAlgorithm Category: " + "\nAlgorithm Description: " + infoData.getAlgorithmDescription() + "\nAlgorithm Category: "
+ infoData.getAlgorithmCategory() + "\n\nInterpreter Version: " + infoData.getInterpreterVersion() + infoData.getAlgorithmCategory() + "\n\nInterpreter Version: " + infoData.getInterpreterVersion()
+ "\n\nwith the following original jar: " + "\n\nwith the following original jar: "
+ project.getProjectTarget().getProjectDeploy().getCodeJar().getPublicLink() + "\nadmin copy jar: " + codeJar.getPublicLink() + "\nadmin copy jar: "
+ codeJarAdminCopy.getPublicLink() + "\n\nInstaller: " + "\n./addAlgorithm.sh " + codeJar.getPublicLink() + "\n\nInstaller: " + "\n./addAlgorithm.sh "
+ infoData.getAlgorithmName() + " " + infoData.getAlgorithmCategory() + " " + infoData.getClassName() + infoData.getAlgorithmName() + " " + infoData.getAlgorithmCategory() + " " + infoData.getClassName()
+ " " + serviceCredentials.getScope() + " transducerers N " + codeJarAdminCopy.getPublicLink() + " \"" + " " + serviceCredentials.getScope() + " transducerers N " + codeJar.getPublicLink() + " \""
+ infoData.getAlgorithmDescription() + "\""; + infoData.getAlgorithmDescription() + "\"";
} }
@ -106,9 +101,9 @@ public class DeploySave {
return infoText; return infoText;
} }
public ItemDescription getCodeJarAdminCopy() { /*public ItemDescription getCodeJarAdminCopy() {
return codeJarAdminCopy; return codeJarAdminCopy;
} }*/
public InfoData getInfoData() { public InfoData getInfoData() {
return infoData; return infoData;

View File

@ -14,7 +14,6 @@ import java.util.List;
import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.HomeLibrary;
import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.ExternalFile;
import org.gcube.common.storagehub.client.StreamDescriptor; import org.gcube.common.storagehub.client.StreamDescriptor;
import org.gcube.common.storagehub.client.dsl.FileContainer; import org.gcube.common.storagehub.client.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer; import org.gcube.common.storagehub.client.dsl.FolderContainer;
@ -355,7 +354,6 @@ public class FilesStorage {
/** /**
* *
* TODO
* *
* @param user * @param user
* User * User
@ -374,25 +372,14 @@ public class FilesStorage {
*/ */
public void saveItemOnWorkspace(String user, InputStream inputStream, String name, String description, public void saveItemOnWorkspace(String user, InputStream inputStream, String name, String description,
String mimeType, String folderId) throws StatAlgoImporterServiceException { String mimeType, String folderId) throws StatAlgoImporterServiceException {
Workspace ws;
try { try {
logger.info("Save item on workspace: [user=" + user + ", name=" + name + ", description=" + description logger.info("Save item on workspace: [user=" + user + ", name=" + name + ", description=" + description
+ ", mimeType=" + mimeType + ", folderId=" + folderId + "]"); + ", mimeType=" + mimeType + ", folderId=" + folderId + "]");
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(folderId);
ws = HomeLibrary.getUserWorkspace(user); FolderContainer folderContainer = openResolver.asFolder();
folderContainer.uploadFile(inputStream, name, description);
WorkspaceItem workSpaceItem = ws.getItem(folderId);
if (!workSpaceItem.isFolder()) {
throw new StatAlgoImporterServiceException("Destination is not a folder!");
}
WorkspaceItem projectItem = ws.find(name, folderId);
if (projectItem == null) {
ws.createExternalFile(name, description, mimeType, inputStream, folderId);
} else {
ws.updateItem(projectItem.getId(), inputStream);
}
return; return;
} catch (Throwable e) { } catch (Throwable e) {
@ -403,8 +390,7 @@ public class FilesStorage {
} }
/** /**
* *
* TODO
* *
* @param user * @param user
* User * User
@ -424,24 +410,20 @@ public class FilesStorage {
*/ */
public ItemDescription createItemOnWorkspace(String user, InputStream inputStream, String name, String description, public ItemDescription createItemOnWorkspace(String user, InputStream inputStream, String name, String description,
String mimeType, String folderId) throws StatAlgoImporterServiceException { String mimeType, String folderId) throws StatAlgoImporterServiceException {
Workspace ws;
try { try {
logger.info("Create item on workspace: [user=" + user + ", name=" + name + ", description=" + description logger.info("Create item on workspace: [user=" + user + ", name=" + name + ", description=" + description
+ ", mimeType=" + mimeType + ", folderId=" + folderId + "]"); + ", mimeType=" + mimeType + ", folderId=" + folderId + "]");
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(folderId);
ws = HomeLibrary.getUserWorkspace(user); FolderContainer folderContainer = openResolver.asFolder();
FileContainer fileContainerNew = folderContainer.uploadFile(inputStream, name, description);
AbstractFileItem fileCreated = fileContainerNew.get();
WorkspaceItem workSpaceItem = ws.getItem(folderId); ItemDescription itemDescription = new ItemDescription(fileCreated.getId(), fileCreated.getName(),
fileCreated.getOwner(), fileCreated.getPath(), fileCreated.getClass().getSimpleName());
if (!workSpaceItem.isFolder()) { itemDescription.setPublicLink(fileContainerNew.getPublicLink().toString());
throw new StatAlgoImporterServiceException("Destination is not a folder!");
}
ExternalFile workspaceItem = ws.createExternalFile(name, description, mimeType, inputStream, folderId);
ItemDescription itemDescription = new ItemDescription(workspaceItem.getId(), workspaceItem.getName(),
workspaceItem.getOwner().getPortalLogin(), workspaceItem.getPath(), workspaceItem.getType().name());
itemDescription.setPublicLink(workspaceItem.getPublicLink(false));
return itemDescription; return itemDescription;
} catch (Throwable e) { } catch (Throwable e) {
@ -453,7 +435,7 @@ public class FilesStorage {
/** /**
* *
* TODO *
* *
* @param user * @param user
* User * User
@ -471,13 +453,13 @@ public class FilesStorage {
* @throws StatAlgoImporterServiceException * @throws StatAlgoImporterServiceException
* Exception * Exception
*/ */
/*
public ItemDescription createItemOnWorkspaceHowAdmin(String user, InputStream inputStream, String name, public ItemDescription createItemOnWorkspaceHowAdmin(String user, InputStream inputStream, String name,
String description, String mimeType, String folderName) throws StatAlgoImporterServiceException { String description, String mimeType, String folderName) throws StatAlgoImporterServiceException {
Workspace ws; Workspace ws;
try { try {
logger.info("Create item on workspace how admin: [user=" + user + ", name=" + name + ", description=" logger.info("Create item on workspace how admin: [user=" + user + ", name=" + name + ", description="
+ description + ", mimeType=" + mimeType + ", folderName=" + folderName + "]"); + description + ", mimeType=" + mimeType + ", folderName=" + folderName + "]");
ws = HomeLibrary.getUserWorkspace(user); ws = HomeLibrary.getUserWorkspace(user);
WorkspaceItem root = ws.getRoot(); WorkspaceItem root = ws.getRoot();
WorkspaceItem folderItem = ws.find(folderName, root.getId()); WorkspaceItem folderItem = ws.find(folderName, root.getId());
@ -513,7 +495,7 @@ public class FilesStorage {
throw new StatAlgoImporterServiceException(e.getLocalizedMessage()); throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
} }
} }*/
/** /**
* *

View File

@ -86,7 +86,6 @@ public class ItemDescription implements Serializable {
if(itemDescription!=null && id.compareTo(itemDescription.getId())==0 && if(itemDescription!=null && id.compareTo(itemDescription.getId())==0 &&
name.compareTo(itemDescription.getName())==0 && name.compareTo(itemDescription.getName())==0 &&
owner.compareTo(itemDescription.getOwner())==0 && owner.compareTo(itemDescription.getOwner())==0 &&
path.compareTo(itemDescription.getPath())==0 &&
type.compareTo(itemDescription.getType())==0 type.compareTo(itemDescription.getType())==0
){ ){
return true; return true;