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
&& saiDescriptor.getPoolManagerConfig().isEnable()) {
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);
String operationId = poolManager.deployAlgorithm(project, deploySave.getInfoData(),
deploySave.getCodeJarAdminCopy());
codeJar);
logger.info("Deploy operationId: " + operationId);
return operationId;
} 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.Project;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -88,7 +88,10 @@ public class CodeReader {
* TODO
*
* 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()
* instanceof ProjectSupportBlackBox) {

View File

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

View File

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

View File

@ -1,14 +1,5 @@
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.shared.exception.StatAlgoImporterServiceException;
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.info.InfoData;
@ -24,43 +15,43 @@ import org.slf4j.LoggerFactory;
*
*/
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";
//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 FilesStorage filesStorage;
private ServiceCredentials serviceCredentials;
private Project project;
private InfoData infoData;
private String infoText;
private ItemDescription codeJarAdminCopy;
//private ItemDescription codeJarAdminCopy;
public DeploySave(ServiceCredentials serviceCredentials, Project project, InfoData infoData) {
this.serviceCredentials = serviceCredentials;
this.project = project;
this.infoData = infoData;
this.infoText = null;
this.codeJarAdminCopy = null;
filesStorage = new FilesStorage();
//this.codeJarAdminCopy = null;
//filesStorage = new FilesStorage();
}
public void save() throws StatAlgoImporterServiceException {
ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
//ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
InputStream codeJarInputStream = filesStorage.retrieveItemOnWorkspace(serviceCredentials.getUserName(),
codeJar.getId());
//InputStream codeJarInputStream = filesStorage.retrieveItemOnWorkspace(serviceCredentials.getUserName(),
// codeJar.getId());
codeJarAdminCopy = filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, codeJarInputStream, codeJar.getName(),
CODE_JAR_DESCRIPTION, CODE_JAR_MIMETYPE, DESTINATION_FOLDER);
//codeJarAdminCopy = filesStorage.createItemOnWorkspaceHowAdmin(ADMIN_USER, codeJarInputStream, codeJar.getName(),
// CODE_JAR_DESCRIPTION, CODE_JAR_MIMETYPE, DESTINATION_FOLDER);
createInfoText();
/*
try {
int codeJarNamelenght = codeJar.getName().length();
String codeJarName;
@ -75,6 +66,7 @@ public class DeploySave {
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,
@ -84,10 +76,13 @@ public class DeploySave {
logger.error("Error writing report install information: " + e.getLocalizedMessage(), e);
throw new StatAlgoImporterServiceException(e.getLocalizedMessage(), e);
}
*/
}
private void createInfoText() {
ItemDescription codeJar = project.getProjectTarget().getProjectDeploy().getCodeJar();
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()
@ -95,10 +90,10 @@ public class DeploySave {
+ "\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 "
+ codeJar.getPublicLink() + "\nadmin copy jar: "
+ codeJar.getPublicLink() + "\n\nInstaller: " + "\n./addAlgorithm.sh "
+ infoData.getAlgorithmName() + " " + infoData.getAlgorithmCategory() + " " + infoData.getClassName()
+ " " + serviceCredentials.getScope() + " transducerers N " + codeJarAdminCopy.getPublicLink() + " \""
+ " " + serviceCredentials.getScope() + " transducerers N " + codeJar.getPublicLink() + " \""
+ infoData.getAlgorithmDescription() + "\"";
}
@ -106,9 +101,9 @@ public class DeploySave {
return infoText;
}
public ItemDescription getCodeJarAdminCopy() {
/*public ItemDescription getCodeJarAdminCopy() {
return codeJarAdminCopy;
}
}*/
public InfoData getInfoData() {
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.workspace.Workspace;
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.dsl.FileContainer;
import org.gcube.common.storagehub.client.dsl.FolderContainer;
@ -355,7 +354,6 @@ public class FilesStorage {
/**
*
* TODO
*
* @param user
* User
@ -374,25 +372,14 @@ public class FilesStorage {
*/
public void saveItemOnWorkspace(String user, InputStream inputStream, String name, String description,
String mimeType, String folderId) throws StatAlgoImporterServiceException {
Workspace ws;
try {
logger.info("Save item on workspace: [user=" + user + ", name=" + name + ", description=" + description
+ ", mimeType=" + mimeType + ", folderId=" + folderId + "]");
StorageHubClient shc = new StorageHubClient();
OpenResolver openResolver = shc.open(folderId);
ws = HomeLibrary.getUserWorkspace(user);
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);
}
FolderContainer folderContainer = openResolver.asFolder();
folderContainer.uploadFile(inputStream, name, description);
return;
} catch (Throwable e) {
@ -404,7 +391,6 @@ public class FilesStorage {
/**
*
* TODO
*
* @param user
* User
@ -424,24 +410,20 @@ public class FilesStorage {
*/
public ItemDescription createItemOnWorkspace(String user, InputStream inputStream, String name, String description,
String mimeType, String folderId) throws StatAlgoImporterServiceException {
Workspace ws;
try {
logger.info("Create item on workspace: [user=" + user + ", name=" + name + ", description=" + description
+ ", 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);
WorkspaceItem workSpaceItem = ws.getItem(folderId);
AbstractFileItem fileCreated = fileContainerNew.get();
if (!workSpaceItem.isFolder()) {
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));
ItemDescription itemDescription = new ItemDescription(fileCreated.getId(), fileCreated.getName(),
fileCreated.getOwner(), fileCreated.getPath(), fileCreated.getClass().getSimpleName());
itemDescription.setPublicLink(fileContainerNew.getPublicLink().toString());
return itemDescription;
} catch (Throwable e) {
@ -453,7 +435,7 @@ public class FilesStorage {
/**
*
* TODO
*
*
* @param user
* User
@ -471,13 +453,13 @@ public class FilesStorage {
* @throws StatAlgoImporterServiceException
* Exception
*/
/*
public ItemDescription 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());
@ -513,7 +495,7 @@ public class FilesStorage {
throw new StatAlgoImporterServiceException(e.getLocalizedMessage());
}
}
}*/
/**
*

View File

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