Compare commits

..

40 Commits

Author SHA1 Message Date
Roberto Cirillo ae9bc3ba23 increase upper bound range on storage-manager-core dep 2024-11-12 12:25:52 +01:00
Roberto Cirillo 00d3ec9ac6 remove snapshot 2024-11-12 10:52:32 +01:00
Roberto Cirillo ee5c0d5f71 remove snapshot 2024-11-12 10:52:18 +01:00
Roberto Cirillo e0fa9185eb passed to jdk11 and gcube-bom 4 2024-11-12 10:41:58 +01:00
Roberto Cirillo fbfe1ffa11 add common-security dep 2024-11-12 09:54:38 +01:00
Roberto Cirillo 585878e58b update gcube-bom to 4 2024-11-12 09:42:11 +01:00
Roberto Cirillo a5470a0fd4 moved to version 4
Merge branch 'master' into v3.0.1-SNAP
2024-11-12 09:38:17 +01:00
Roberto Cirillo 4a93158e34 upgrade deps range, removed resource-plugin from pom 2023-02-17 09:53:14 +01:00
Roberto Cirillo 78ab0e203f removed maven-resources plugin declaration from pom. Fix copyTest Junit 2022-07-28 14:35:46 +02:00
Roberto Cirillo 857fd1bdf8 removed ScopeProvider and several deprecated classes 2022-07-27 14:32:50 +02:00
Roberto Cirillo ad8aef1b52 gitignore added 2022-07-26 16:43:33 +02:00
Roberto Cirillo 9d4f0a750f added gitignore 2022-07-22 09:40:06 +02:00
Roberto Cirillo 96c6762757 update to 2.5.4 v 2022-07-07 10:38:23 +02:00
Roberto Cirillo 5cb2251385 replace slf4j-log4j with slf4j-api 2022-07-07 10:34:01 +02:00
Roberto Cirillo 92028eded9 fix pom version 2022-06-30 16:55:19 +02:00
Roberto Cirillo 140fb10dc9 update to 2.5.4-SNAPSHOT to bypass LATEST bom defined in etics version 2022-06-30 16:53:39 +02:00
Roberto Cirillo 4d76042cb3 fix fillConnectionFields method; update some JUnit Test classes 2021-11-19 12:41:39 +01:00
Roberto Cirillo 7fd4e6c0c1 Merge branch 'master' into v3.0.1-SNAP 2021-11-19 10:05:59 +01:00
Roberto Cirillo e09b50bb4d Merge branch 'v3.0.1-SNAP' of https://code-repo.d4science.org/gCubeSystem/storage-manager-wrapper into v3.0.1-SNAP 2021-11-19 09:40:32 +01:00
Roberto Cirillo e400df9c60 commented getSize JUnitTest 2021-11-18 17:48:28 +01:00
Roberto Cirillo 0794d5dda8 move storage-manager-core range to 4.0.0 2021-11-18 17:38:38 +01:00
Roberto Cirillo 40680c3e4e refactorying ISClientConnector class 2021-11-18 17:34:10 +01:00
Roberto Cirillo 0e612d3467 Update 'CHANGELOG.md'
removed SNAPSHOT
2021-10-08 09:32:20 +02:00
Roberto Cirillo b15a9ce64c Update 'pom.xml'
removed SNAPSHOT
2021-10-08 09:31:59 +02:00
Roberto Cirillo c3386d6a3f Update 'CHANGELOG.md'
moved to snapshot
2021-10-08 09:27:49 +02:00
Roberto Cirillo 6f4e939a12 Update 'pom.xml'
moved to snapshot
2021-10-08 09:27:27 +02:00
Roberto Cirillo 76ee09b1be removed SNAPSHOT from version 2021-10-07 10:26:04 +02:00
Roberto Cirillo af22df8613 moved version from 2.6.1 to 3.0.0-SNAPSHOT 2021-10-07 10:24:11 +02:00
Roberto Cirillo c9228d5e25 change version from 3.1.0-SNAPSHOT to 4.0.0-SNAPSHOT 2021-10-07 09:24:31 +02:00
Roberto Cirillo a235ed76a7 convert getHttp to getHttps method 2021-10-07 09:16:42 +02:00
Roberto Cirillo 16e017eda1 update to version 3.1.0 2021-08-04 16:16:06 +02:00
Roberto Cirillo 6cc15a5f55 refactoring code JUnitTest 2021-05-13 09:26:13 +02:00
Roberto Cirillo 56754bfb50 add entry to changelog 2021-03-12 17:21:45 +01:00
Roberto Cirillo dfb11e63dc fix JUnit tests; upgrade JUnit to 4.12 version 2021-03-12 17:20:09 +01:00
Roberto Cirillo 8a5cbc8ed3 removed http protocol; deprecated old smp classes update to version
3.0.1-SNAPSHOT
2021-02-25 15:58:20 +01:00
roberto cirillo 83fce2b7e2 Added ServiceEndpoint coordinates as costants.
Now the serviceEndpoint coordinates are DataStorage - StorageManager-S3
as reported in #20505
2021-02-04 15:51:13 +01:00
roberto cirillo bbe67f9419 update storage-manager-core range to 3.0.0-SNAPSHOT 2021-01-08 18:08:08 +01:00
roberto cirillo c6819e84a5 Added new constructor in order to specify the Backend as input
parameter;
upgraded to version: 3.0.0-SNAPSHOT
2021-01-08 17:06:34 +01:00
roberto cirillo 3fc8eda0a5 retrieve new parameters from ServiceEndpoint: backendToken, region 2020-12-22 17:59:21 +01:00
roberto cirillo bd082de4f2 added feature for retrieving a generic credential from a backend that is
not mongodb
2020-11-19 15:12:56 +01:00
51 changed files with 590 additions and 1672 deletions

7
.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
/target/
/.classpath
/*.project
/.settings
/.idea/target/
/src/test/resources/
/.idea/

View File

@ -1,12 +1,27 @@
# Changelog for storage-manager-wrapper
## [v2.6.1] 2021-09-10
## [v4.0.0]
* removed slf4j implementations, added slf4j-simple;
* Discovering serviceEndpoint with category Storage
* moved version from 3.1.0-SNAPSHOT to 4.0.0-SNAPSHOT
* upgrade to gcube-bom 3 and ScopeProvider removed
* removed environment variable scope
* passed to jdk11 and gcube-bom 4.0
## [v3.0.1-SNAPSHOT]
* removed http protocol;
* deprecated old smp classes
* fix JUnitTests
* upgrade JUnit to 4.12
## [v3.0.0] 2021-09-10
* bug fix #20505
* update gcub-bom version
* Change serviceEndpoint Category from DataStorage to Storage
* bugfix #20505
* adding new constructor with the backendType as input parameter
* retrieving specific backend credentials if a specific backend si specified as input parameter
* moved from 2.6.1 to 3.0.0-SNAPSHOT
## [v2.5.3] 2019-03-20
* Added wrapper for HomeLibrary configuration related to the new preproduction infrastructure

View File

@ -1,16 +0,0 @@
v 2.2.0 (21-04-2015)
* change smp protocol
v 2.1.0 (01-04-2014)
* support MongoDB backend with authentication
v 2.0.1 (29-05-2013)
* bug fix incident: connection pending #606
v 2.0.0 (19-05-2013)
* added move, copy and link operations
*FWS integration
v 1.0.2 (15-01-2013)
* Integration with new gCube release 2.12.0 version system
v 1.0.1 (11-10-2012)
* added VOLATILE area
v. 1.0.0 (04-05-2012)
* First release

View File

@ -1,2 +0,0 @@
${gcube.license}

View File

@ -1 +0,0 @@
* Roberto Cirillo (roberto.cirillo@isti.cnr.it), CNR Pisa, Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo"

Binary file not shown.

View File

@ -1,55 +0,0 @@
<ReleaseNotes>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-5-1" date="2019-03-20">
<Change>Added HomeLibrary wrapper configuration for the new preproduction infrastructure</Change>
<Change>Added new Costants class for Junit package</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-5-1" date="2018-10-11">
<Change>Constants definition moved on storage-manager-core Castants class</Change>
<Change>Added new Costants class for Junit package</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-5-0" date="2017-10-15">
<Change>Added new JUnit Test classes</Change>
<Change>update JUnit Test Classes</Change>
<Change>delete old method for retrieving remote phrase used by old smp protocol classes</Change>
<Change></Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-3-1" date="2016-01-14">
<Change>dinamically load "write concern"" and ""read preference" options</Change>
<Change>add method for decrypt an id</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-3-0" date="2016-01-14">
<Change>dinamically load smpConnection handler</Change>
<Change>add method for decrypt an id</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-2-1" date="2015-07-01">
<Change>update JUnit test for smp uri without payload</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-2-0" date="2015-04-21">
<Change>change smp protocol</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-1-0" date="2014-04-01">
<Change>support MongoDB backend with authentication</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.2-0-3" date="2014-02-12">
<Change>Integration with new gCube release 3.0.0 version system</Change>
<Change>Java7 refactoring</Change>
</Changeset>
<Changeset component="${build.finalName}" date="2013-05-29">
<Change>Integration with new gCube release 2.15.0 version system</Change>
<Change>bugfix on pending connections</Change>
</Changeset>
<Changeset component="${build.finalName}" date="2013-04-29">
<Change>Integration with new gCube release 2.14.0 version system</Change>
<Change>FWS integration</Change>
<Change>added move, copy and link operations</Change>
</Changeset>
<Changeset component="${build.finalName}" date="2013-01-15">
<Change>Integration with new gCube release 2.12.0 version system</Change>
</Changeset>
<Changeset component="org.gcube.content-management.storage-manager-wrapper.1-0-1" date="2012-10-11">
<Change>Added VOLATILE area</Change>
</Changeset>
<Changeset component="${build.finalName}" date="2012-05-04">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,32 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>ContentManagement</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

View File

@ -1 +0,0 @@
${scm.url}

78
pom.xml
View File

@ -3,26 +3,28 @@
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath />
</parent>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
<version>2.6.1</version>
<version>4.0.0</version>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<properties>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<distroDirectory>${project.basedir}/distro</distroDirectory>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>2.0.1</version>
<version>4.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -32,7 +34,7 @@
<dependency>
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-core</artifactId>
<version>[2.13.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<version>[4.0.0-SNAPSHOT, 5.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -59,71 +61,29 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-security</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-assembly-plugin</artifactId> -->
<!-- <configuration> -->
<!-- <descriptors> -->
<!-- <descriptor>${distroDirectory}/descriptor.xml</descriptor> -->
<!-- </descriptors> -->
<!-- </configuration> -->
<!-- <executions> -->
<!-- <execution> -->
<!-- <id>servicearchive</id> -->
<!-- <phase>install</phase> -->
<!-- <goals> -->
<!-- <goal>single</goal> -->
<!-- </goals> -->
<!-- </execution> -->
<!-- </executions> -->
<!-- </plugin> -->
</plugins>
</build>
</project>

View File

@ -2,35 +2,15 @@ package org.gcube.common.scope.impl;
import java.util.Set;
import org.gcube.common.scope.api.ScopeProvider;
/**
* Check the validity of a given scope
* Utility class
* @author Roberto Cirillo (ISTI-CNR)
*
*/
public class ServiceMapScannerMediator {
/**
* The validation has been removed
* @param scope
* @return
*/
@Deprecated
public static boolean isValid(String scope){
// log.debug("validating scope "+scope);
String currentScope=ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
try{
new ScopedServiceMap().scope();
}catch(Exception e){
return false;
}finally{
ScopeProvider.instance.set(currentScope);
}
return true;
}
public static Set<String> getScopeKeySet(){

View File

@ -1,155 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
//import org.gcube.common.core.scope.GCUBEScope;
//import org.gcube.common.core.scope.GCUBEScopeManager;
import org.gcube.contentmanager.storageclient.model.protocol.smp.Handler;
/**
* Utility methods for content URI creation and manipulation.
* @author Fabio Simeoni (University of Strathclyde)
* @author Roberto Cirillo (ISTI-CNR)
*
*/
public class URIs {
static {
Handler.activateProtocol();
}
/**Scheme of cms URIs.*/
public static final String PROTOCOL="smp";
/**
* Indicates whether a URI is a valid content URI.
* @param uri the URI.
* @throws URISyntaxException if the URI fails validation.
*/
public static void validate(URI uri) throws URISyntaxException {
if (!PROTOCOL.equals(uri.getScheme()) ||
uri.getAuthority()==null ||
uri.getPath()==null ||
uri.getPath().length()<2)
throw new IllegalArgumentException(new URISyntaxException(uri.toString(),"uri is not a well-formed content URI"));
}
/**
* Constructs a content URI from a collection identifiers and one or more node identifiers.
* @param collectionID the collection identifier.
* @param identifiers the node identifiers.
* @return the URI.
* @throws IllegalArgumentException if the input is <code>null</code> or empty.
*/
public static URI make(String collectionID, String ... identifiers) throws IllegalArgumentException {
if (collectionID==null || identifiers==null || identifiers.length==0)
throw new IllegalArgumentException("null or empty input");
StringBuilder path = new StringBuilder();
for (Object id : identifiers)
path.append("/"+id.toString());
URI uri = null;
try {
uri = new URI(PROTOCOL,collectionID,path.toString(),null);
}
catch(URISyntaxException e) {
throw new RuntimeException("error in generation uri with "+PROTOCOL+","+collectionID+","+path,e);
}
return uri;
}
/**
* Returns the collection identifier in a <code>sm</code> URI.
* @param uri the URI.
* @return the identifier.
* @throws URISyntaxException if the URI is not a content URI.
*/
public static String collectionID(URI uri) throws URISyntaxException {
validate(uri);
return uri.getAuthority();
}
/**
* Returns the document identifier in a content URI.
* @param uri the URI.
* @return the identifier.
* @throws URISyntaxException if the URI is not a content URI.
*/
public static String documentID(URI uri) throws URISyntaxException {
validate(uri);
String p = uri.getPath().substring(1);
if (p.endsWith("/"))
p = p.substring(0,p.length()-1);
int index = p.indexOf("/");
return p.substring(0,index>0?index:p.length());
}
/**
* Returns the identifier of the node identified by a content URI.
* @param uri the URI.
* @return the identifier.
* @throws URISyntaxException if the URI is not a content URI.
*/
public static String nodeID(URI uri) throws URISyntaxException {
validate(uri);
return uri.getPath().substring(uri.getPath().lastIndexOf("/")+1);
}
/**
* Returns the identifiers in a content URI.
* @param uri the URI.
* @return the identifiers.
* @throws URISyntaxException if the URI is not a content URI.
*/
public static String[] nodeIDs(URI uri) throws URISyntaxException {
validate(uri);
List<String> ids = new ArrayList<String>();
for (String s : uri.getPath().substring(1).split("/")) //will be validated here
ids.add(s);
return ids.toArray(new String[0]);
}
/**
* Returns a content URI for the parent of the node identified by another content URI.
* @param uri the input URI.
* @return the parent URI.
* @throws URISyntaxException if the input URI is not a content URL.
*/
public static URI parentURI(URI uri) throws URISyntaxException {
validate(uri);
String u = uri.getPath();
return make(uri.getAuthority(),u.substring(1,u.lastIndexOf("/")).split("/"));
}
/**
* Returns a content URI for the document of the node identified by another content URI.
* @param uri the input URI.
* @return the document URI.
* @throws URISyntaxException if the input URI is not a content URI.
*/
public static URI documentURI(URI uri) throws URISyntaxException {
validate(uri);
return make(uri.getAuthority(),documentID(uri));
}
/**
* Returns a URL connection in a given scope.
* @param uri a content URI.
* @param scope the scope.
* @return the connection.
* @throws IOException if the connections could not be established.
* @throws URISyntaxException if the URI is not a content URI or if the protocol handler for the <code>smp</code> scheme is not active.
* @deprecated since 2.3.1. Use {@link URLConnection} normally in current scope.
*/
public static URLConnection connection(URI uri, String scope) throws IOException, URISyntaxException {
validate(uri);
URLConnection connection = uri.toURL().openConnection();
return connection;
}
}

View File

@ -1,39 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol.smp;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
/**
* A handler for the <code>smp</code> protocol.
* @author Fabio Simeoni (University of Strathclyde)
* @author Roberto Cirillo (ISTI-CNR)
*
*/
public class Handler extends URLStreamHandler {
/**{@inheritDoc}*/
@Override
protected URLConnection openConnection(URL u) throws IOException {
return SMPURLConnectionFactory.getSmp(u);
}
/**
* Registers the protocol with the JVM.
*/
public static void activateProtocol() {
String pkgs_name="java.protocol.handler.pkgs";
String pkgs = System.getProperty(pkgs_name);
String pkg = "org.gcube.contentmanager.storageclient.model.protocol";
if (pkgs==null)
pkgs = pkg ;
else if (!pkgs.contains(pkg))
pkgs = pkgs+"|"+pkg;
System.setProperty(pkgs_name, pkgs);
}
}

View File

@ -1,60 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol.smp;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanager.storageclient.wrapper.ISClientConnector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An extension of URLConnection used for smp url
* @author Roberto Cirillo (ISTI-CNR)
*
*/
public abstract class SMPConnection extends URLConnection {
Logger logger= LoggerFactory.getLogger(SMPURLConnection.class);
public SMPConnection(URL url) {
super(url);
}
public abstract URLConnection init(URL url);
/**{@inheritDoc}*/
@Override
public synchronized void connect() throws IOException {
connected=true;
}
@Override
public abstract InputStream getInputStream() throws IOException;
protected abstract InputStream storageClient(String url) throws Exception;
/**
* This method has been moved in Configuration class
* @param rootScope
* @return
* @throws Exception
* @see org.gcube.contentmanager.storageclient.wrapper.Configuration
*
*/
@Deprecated
protected String retrieveEncryptionPhrase() throws Exception {
String currentScope=ScopeProvider.instance.get();
logger.debug("retrieve encryption prhase on scope: "+currentScope);
String encryptedKey=null;
ISClientConnector isclient=new ISClientConnector();
encryptedKey=isclient.retrievePropertyValue("PassPhrase", currentScope);
String decryptString=org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedKey);
return decryptString;
}
}

View File

@ -1,47 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol.smp;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* This is invoked by the platform with a URL of the right protocol.
* @author Fabio Simeoni (University of Strathclyde), @author Roberto Cirillo (ISTI-CNR)
* @deprecated this class will be deleted and will be changed with the factory class invocation: SMPURLConnectionFactory
* @see SMPURLConnectionFactory
*/
@Deprecated
public class SMPURLConnection extends URLConnection {
SMPConnection smp;
Logger logger= LoggerFactory.getLogger(SMPURLConnection.class);
/**
* Constructs a new instance for a given <code>sm</code> URL.
* @deprecated reason this method is deprecated </br>
* {will be removed in next version} </br>
* use {@link #SMPURLConnectionFactory.getSmp(url)}
* @param url the URL.
*/
@Deprecated
public SMPURLConnection(URL url) {
super(url);
this.smp=SMPURLConnectionFactory.getSmp(url);
}
/**{@inheritDoc}*/
@Override
public synchronized void connect() throws IOException {
connected=true;
}
/**{@inheritDoc}*/
@Override
public synchronized InputStream getInputStream() throws IOException {
return smp.getInputStream();
}
}

View File

@ -1,114 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol.smp;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.apache.commons.codec.binary.Base64;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.service.operation.GetHttpUrl;
import org.gcube.contentmanagement.blobstorage.service.operation.GetUrl;
import org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This is invoked by the platform with a URL of the smp protocol with new format (>= 2.2.0 version) .
* @author Roberto Cirillo (ISTI-CNR)
*
* Example: smp://data.gcube.org?uhdnfounhcfnshfnrhbvyaeegytf6dfawiuawgcyg
*/
public class SMPURLConnectionById extends SMPConnection {
private Logger logger= LoggerFactory.getLogger(SMPURLConnectionOld.class);
private String serviceClass="Storage-manager";
private String serviceName="resolver-uri";
private String owner="storage-manager";
/**
* Constructs a new instance for a given <code>sm</code> URL.
* @param url the URL.
*/
public SMPURLConnectionById(URL url) {
super(url);
}
public SMPConnection init(URL url){
return new SMPURLConnectionById(url);
}
/**{@inheritDoc}
* internal handler implementation
* */
@Override
public synchronized InputStream getInputStream() throws IOException {
if (!connected)
this.connect();
try {
return storageClient(this.url.toString());
}
catch(Exception e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
}
}
/**
* Get a StorageManager instance from url
*/
protected InputStream storageClient(String url) throws Exception {
logger.info("url :" + url);
String [] urlParam=url.split(Costants.URL_SEPARATOR);
String protocol=urlParam[0];
protocol=protocol.substring(0, protocol.length()-1);
logger.debug("protocol is "+protocol);
if(ScopeProvider.instance.get() == null){
throw new RuntimeException("Scope not set");
}
String encrypted=retrieveStringEncrypted(urlParam);
MemoryType memory=null;
if(encrypted.contains(Costants.VOLATILE_URL_IDENTIFICATOR)){
memory=MemoryType.VOLATILE;
encrypted=encrypted.replace(Costants.VOLATILE_URL_IDENTIFICATOR, "");
}
logger.debug("String encrypted "+encrypted);
String phrase=retrieveEncryptionPhrase();
String location=null;
if(Base64.isBase64(encrypted) && (protocol.equalsIgnoreCase("http"))){
byte[] valueDecoded= Base64.decodeBase64(encrypted);
String encryptedID = new String(valueDecoded);
location=new StringDecrypter("DES", phrase).decrypt(encryptedID);
}else{
location=new StringDecrypter("DES", phrase).decrypt(encrypted);
}
IClient client=null;
if(memory!=null)
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, memory).getClient();
else
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED).getClient();
InputStream is=null;
is=client.get().RFileAsInputStream(location);
return is;
}
private String retrieveStringEncrypted(String[] urlParam) {
String encrypted=urlParam[3];
int i=4;
while(i < urlParam.length){
encrypted=encrypted+Costants.URL_SEPARATOR+urlParam[i];
i++;
}
return encrypted;
}
}

View File

@ -1,119 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol.smp;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.contentmanagement.blobstorage.service.operation.GetUrl;
import org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants;
import org.gcube.contentmanager.storageclient.protocol.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Factory class used to determine the right smp url protocol: old format(<2.2.0 version), new format (>= 2.2.0-SNAPSHOT)
* @author Roberto Cirillo (ISTI-CNR)
*
*/
public class SMPURLConnectionFactory {
static Logger logger=LoggerFactory.getLogger(SMPURLConnectionFactory.class);
public static SMPConnection getSmp(URL url) {
String urlString=url.toString();
Utils.checkScopeProvider();
if(isNewSmpFormat(urlString)|| isIntermediateType(urlString)){
logger.info("detected new smp format "+url);
SMPConnection connection=load(url);
if (connection!= null)
return connection;
return new SMPURLConnectionById(url);
}else{
logger.info("detected old smp format "+url);
return new SMPURLConnectionOld(url);
}
}
/**
* patch method for a particular smp uri: smp://data.gcube.org/8TFLhJ991DF1M/Ae8rGamC3CgCjAXlnVGmbP5+HKCzc=
* @param urlString
* @return
*/
private static boolean isIntermediateType(String urlString) {
String [] urlParam=urlString.split(Costants.URL_SEPARATOR);
String infraHost=urlParam[2];
if(Utils.isScopeProviderMatch(infraHost))
return true;
String infra=Utils.getInfraFromResolverHost(infraHost);
String rootScope="/"+infra;
ScopeBean scope=new ScopeBean(rootScope);
if(scope.is(Type.INFRASTRUCTURE)){
return Utils.validationScope2(rootScope);
}else{
return false;
}
}
private static boolean isNewSmpFormat(String urlString) {
logger.debug("check format: "+urlString);
String httpString=urlString;
httpString=httpString.replace("smp://", "http://");
logger.debug("httpUrl conversion: "+httpString);
URL httpUrl=null;
try {
httpUrl=new URL(httpString);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
List<ServiceEndpoint> services=Utils.queryServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
String host=null;
if(services != null && services.size()>0){
host=Utils.getResolverHost(services.get(0));
}
logger.debug("uri-resolver host: "+host+" in scope: "+ScopeProvider.instance.get());
if((host!=null) && (host.equals(httpUrl.getHost()))){
return true;
}else{
return false;
}
}
/**
* Load a backend driver from classpath
* @param url
* @return
*/
private static SMPConnection load(URL url){
ServiceLoader<SMPConnection> loader = ServiceLoader.load(SMPConnection.class);
Iterator<SMPConnection> iterator = loader.iterator();
List<SMPConnection> impls = new ArrayList<SMPConnection>();
while(iterator.hasNext())
impls.add(iterator.next());
int implementationCounted=impls.size();
// System.out.println("size: "+implementationCounted);
if(implementationCounted==0){
logger.info(" 0 implementation found. Load default implementation of SMPConnection");
return null;
}else if(implementationCounted>0){
SMPConnection connection = impls.get(0);
logger.info("1 implementation of TransportManager found. ");
connection.init(url);
return connection;
}else{
return null;
}
}
}

View File

@ -1,146 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol.smp;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* This is invoked by the platform with a URL of the right protocol.
* @author Fabio Simeoni (University of Strathclyde), @author Roberto Cirillo (ISTI-CNR)
*
*/
public class SMPURLConnectionOld extends SMPConnection{
Logger logger= LoggerFactory.getLogger(SMPURLConnectionOld.class);
/**
* Constructs a new instance for a given <code>sm</code> URL.
* @param url the URL.
*/
public SMPURLConnectionOld(URL url) {
super(url);
}
public SMPConnection init(URL url){
return new SMPURLConnectionOld(url);
}
/**{@inheritDoc}*/
@Override
public synchronized InputStream getInputStream() throws IOException {
if (!connected)
this.connect();
try {
return storageClient(this.url.toString());
}
catch(Exception e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
}
}
protected InputStream storageClient(String url) throws Exception {
logger.info("url :" + url);
String [] urlParam=url.split("\\?");
logger.info("String encrypted "+urlParam[1]);
String param=new StringDecrypter("DES", retrieveEncryptionPhrase()).decrypt(urlParam[1]);
logger.info("String decrypted: "+param);
String [] getParam=param.split("\\&");
String serviceClass=null;
String serviceName=null;
String owner=null;
String accessType=null;
String memoryType=null;
String scopeType=null;
AccessType type = null;
MemoryType mType = null;
String server= null;
String [] par1;
for(String par : getParam){
if(par.contains("ServiceClass")){
par1=par.split("=");
serviceClass=par1[1];
}else if(par.contains("ServiceName")){
par1=par.split("=");
serviceName=par1[1];
}else if(par.contains("owner")){
par1=par.split("=");
owner=par1[1];
}else if(par.contains("scope")){
par1=par.split("=");
scopeType=par1[1];
}else if(par.contains("server")){
par1=par.split("=");
server=par1[1];
}else if(par.contains("AccessType")){
par1=par.split("=");
accessType=par1[1];
if(accessType.equalsIgnoreCase("public")){
type=AccessType.PUBLIC;
}else if(accessType.equalsIgnoreCase("shared")){
type=AccessType.SHARED;
}
}else if(par.contains("MemoryType")){
par1=par.split("=");
memoryType=par1[1];
if(memoryType.equalsIgnoreCase("VOLATILE")){
mType=MemoryType.VOLATILE;
}else{
mType=MemoryType.PERSISTENT;
}
}
}
// throw an exception if one or more uri parameters are invalid
if((serviceName==null) || (serviceClass==null) || (owner == null) || (scopeType==null) || (type == null)){
logger.error("Bad Parameter in URI");
if (type == null){
logger.error("URI generated from a private file");
throw new MalformedURLException("The uri is generated from a private file. It cannot be accessed");
}
if (serviceName==null) throw new MalformedURLException("The uri generated has an invalid serviceName");
if (serviceClass==null) throw new MalformedURLException("The uri generated has an invalid serviceClass");
if (owner==null) throw new MalformedURLException("The uri generated has an invalid owner");
if (scopeType==null) throw new MalformedURLException("The uri is generated has an invalid scopeType.");
}
String location=extractLocation(urlParam[0]);
logger.info("Parameters from URI "+serviceClass+" "+serviceName+" "+owner+" "+type+" "+mType +" location: "+urlParam[0]+" scope: "+scopeType);
IClient client=null;
String currentScope=ScopeProvider.instance.get();
logger.info("current scope used: "+currentScope+". scope found on url is: "+ scopeType);
// ScopeProvider.instance.set(scopeType);
if(mType != null){
if(server!=null)
client=new StorageClient(serviceClass, serviceName, owner, type, mType, server).getClient();
else
client=new StorageClient(serviceClass, serviceName, owner, type, mType).getClient();
}else{
if (server != null)
client=new StorageClient(serviceClass, serviceName, owner, server, type ).getClient();
else
client=new StorageClient(serviceClass, serviceName, owner, type).getClient();
}
InputStream is=null;
is=client.get().RFileAsInputStream(location);
// ScopeProvider.instance.set(currentScope);
return is;
}
private String extractLocation(String url) {
String [] loc=url.split("//");
logger.info("url extracted: "+loc[1]);
return loc[1];
}
}

View File

@ -1,137 +0,0 @@
package org.gcube.contentmanager.storageclient.model.protocol.smp;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URLConnection;
import org.gcube.contentmanager.storageclient.model.protocol.smp.SMPURLConnectionFactory;
/**
* Allow to the end user to manage a smp url as an url with a configured stream handler
* @author Roberto Cirillo (ISTI-CNR)
*
*/
@Deprecated
public class SMPUrl extends java.net.URLStreamHandler{
private java.net.URL url;
/**
* map a url string as a normal url
* @param u url string
* @throws MalformedURLException
*/
public SMPUrl(String u) throws MalformedURLException{
this.url=new java.net.URL(null, u, this);
}
public URLConnection openConnection() throws IOException{
return this.openConnection(url);
}
@Override
protected URLConnection openConnection(java.net.URL u) throws IOException {
if(u.getProtocol().equalsIgnoreCase("smp")){
return SMPURLConnectionFactory.getSmp(u);
}else{
return new java.net.URL(null, u.toString()).openConnection();
}
}
public String getHost(){
return this.url.getHost();
}
/**
* Gets the path part of this <code>URL</code>.
*
* @return the path part of this <code>URL</code>, or an
* empty string if one does not exist
* @since 1.3
*/
public String getPath() {
return url.getPath();
}
/**
* Gets the userInfo part of this <code>URL</code>.
*
* @return the userInfo part of this <code>URL</code>, or
* <CODE>null</CODE> if one does not exist
* @since 1.3
*/
public String getUserInfo() {
return url.getUserInfo();
}
/**
* Gets the authority part of this <code>URL</code>.
*
* @return the authority part of this <code>URL</code>
* @since 1.3
*/
public String getAuthority() {
return url.getAuthority();
}
/**
* Gets the port number of this <code>URL</code>.
*
* @return the port number, or -1 if the port is not set
*/
public int getPort() {
return url.getPort();
}
/**
* Gets the default port number of the protocol associated
* with this <code>URL</code>. If the URL scheme or the URLStreamHandler
* for the URL do not define a default port number,
* then -1 is returned.
*
* @return the port number
* @since 1.4
*/
public int getDefaultPort() {
return url.getDefaultPort();
}
/**
* Gets the protocol name of this <code>URL</code>.
*
* @return the protocol of this <code>URL</code>.
*/
public String getProtocol() {
return url.getProtocol();
}
/**
* Gets the file name of this <code>URL</code>.
* The returned file portion will be
* the same as <CODE>getPath()</CODE>, plus the concatenation of
* the value of <CODE>getQuery()</CODE>, if any. If there is
* no query portion, this method and <CODE>getPath()</CODE> will
* return identical results.
*
* @return the file name of this <code>URL</code>,
* or an empty string if one does not exist
*/
public String getFile() {
return url.getFile();
}
/**
* Gets the anchor (also known as the "reference") of this
* <code>URL</code>.
*
* @return the anchor (also known as the "reference") of this
* <code>URL</code>, or <CODE>null</CODE> if one does not exist
*/
public String getRef() {
return url.getRef();
}
}

View File

@ -97,7 +97,7 @@ public class StringDecrypter {
{
SecretKey key = keyFactory.generateSecret( keySpec );
cipher.init( Cipher.DECRYPT_MODE, key );
return org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedString, key);
return org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().decrypt(encryptedString, key);
}
catch (Exception e)
{

View File

@ -98,7 +98,7 @@ public class StringEncrypter {
{
SecretKey key = keyFactory.generateSecret( keySpec );
cipher.init( Cipher.ENCRYPT_MODE, key );
return org.gcube.common.encryption.StringEncrypter.getEncrypter().encrypt(unencryptedString, key);
return org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().encrypt(unencryptedString, key);
}
catch (Exception e)
{

View File

@ -9,10 +9,8 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.common.scope.impl.ServiceMapScannerMediator;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
@ -36,47 +34,9 @@ public class Utils {
public static final String URI_RESOLVER_RESOURCE_NAME="HTTP-URI-Resolver";
private static final Logger logger = LoggerFactory.getLogger(Utils.class);
public static boolean validationScope2(String scope){
ScopeBean scopeBean=new ScopeBean(scope);
if((scopeBean.is(Type.VRE)))
scope=scopeBean.enclosingScope().toString();
return ServiceMapScannerMediator.isValid(scope);
}
public static ArrayList<String> getVOScopes(String scope){
ArrayList<String> vos=new ArrayList<String>();
ScopeBean scopeBean=new ScopeBean(scope);
//retrieve INFRA scope
while(!scopeBean.is(Type.INFRASTRUCTURE)){
logger.debug("the scope "+scope+" is not an INFRA scope ");
scopeBean=new ScopeBean(scopeBean.enclosingScope().toString());
}
scope=scopeBean.toString();
if(scopeBean.is(Type.INFRASTRUCTURE)){
Set<String> scopeSet=ServiceMapScannerMediator.getScopeKeySet();
for(String scopeItem : scopeSet){
//retrieve all Vo scopes
logger.debug("scope scanned: "+scopeItem);
if(scopeItem.contains(scope) && (new ScopeBean(scopeItem).is(Type.VO))){
logger.debug("found vo scope: "+scopeItem);
vos.add(scopeItem);
}
}
}
return vos;
}
public static String extractInfrastructureNewVersion(String urlParam){
logger.debug("urlParam: "+urlParam);
String infra= checkVarEnv(INFRASTRUCTURE_ENV_VARIABLE_NAME);
if (infra != null)
return infra;
else
//only for test return the infra from the uri. In prod will be throws a runtime exception
return getInfraFromResolverHost(urlParam);
}
public static String getInfraFromResolverHost(String resolverHost) {
if(resolverHost.equals(GCUBE_RESOLVER_HOST)){
@ -86,48 +46,6 @@ public class Utils {
}else return resolverHost;
}
public static String checkVarEnv(String name){
Map<String, String> env = System.getenv();
TreeSet<String> keys = new TreeSet<String>(env.keySet());
Iterator<String> iter = keys.iterator();
String value=null;
while(iter.hasNext())
{
String key = iter.next();
if(key.equalsIgnoreCase(name)){
value=env.get(key);
break;
}
}
return value;
}
public static boolean isScopeProviderMatch(String infraHost) {
String currentScope=ScopeProvider.instance.get();
if(currentScope != null){
//get vo scope
String voScope=Utils.getVOScope(currentScope);
// get the uri resolver host
List<ServiceEndpoint> services=queryServiceEndpoint(URI_RESOLVER_RESOURCE_CATEGORY, URI_RESOLVER_RESOURCE_NAME);
String host=null;
if(services != null && services.size()>0){
host=getResolverHost(services.get(0));
if(host!=null){
if(infraHost.equalsIgnoreCase(host)){
return true;
}
}
}
}
return false;
}
private static String getVOScope(String currentScope) {
ScopeBean scopeBean=new ScopeBean(currentScope);
if((scopeBean.is(Type.VRE)))
currentScope=scopeBean.enclosingScope().toString();
return currentScope;
}
public static List<ServiceEndpoint> queryServiceEndpoint(String category, String name){
SimpleQuery query = queryFor(ServiceEndpoint.class);
@ -136,25 +54,6 @@ public class Utils {
List<ServiceEndpoint> resources = client.submit(query);
return resources;
}
/**
* if the scope provider is not set then check if the env variable: SCOPE is set and set the scopeProvider
*/
public static void checkScopeProvider(){
String scopeProvided=ScopeProvider.instance.get();
logger.info("check scope: scope found "+scopeProvided);
if ((scopeProvided==null) || (scopeProvided.isEmpty())){
logger.debug("scope not correctly set on ScopeProvider");
logger.info("scope: check variable");
scopeProvided=Utils.checkVarEnv("SCOPE");
if (scopeProvided != null){
ScopeProvider.instance.set(scopeProvided);
}else{
throw new RuntimeException("Scope not set ");
}
}
}
public static String getResolverHost(ServiceEndpoint serviceEndpoint) {
return serviceEndpoint.profile().runtime().hostedOn();

View File

@ -1,5 +1,15 @@
package org.gcube.contentmanager.storageclient.wrapper;
public enum BackendType {
MongoDB, S3
MongoDB, S3;
@Override
public String toString() {
switch(this) {
case MongoDB: return "MongoDB";
case S3: return "S3";
default: throw new IllegalArgumentException();
}
}
}

View File

@ -3,12 +3,11 @@ package org.gcube.contentmanager.storageclient.wrapper;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeSet;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.service.impl.ServiceEngine;
import org.gcube.contentmanager.storageclient.protocol.utils.Utils;
import org.slf4j.Logger;
@ -28,6 +27,7 @@ public class Configuration {
private String sn;
private String user;
private String password;
// if the backend is mongodb, this field is used for crypt/decrypt. If the backend is S3, this field is a token.
private String passPhrase;
private ISClientConnector isclient;
// the scope used for discovering the runtimeResource
@ -36,12 +36,17 @@ public class Configuration {
private String[] volatileHost;
private String[] persistentHosts;
private String resolverHost;
private String region;
private static final Logger logger = LoggerFactory.getLogger(Configuration.class);
private static final String DEFAULT_BACKEND_TYPE="MongoDB";
protected static final String DEFAULT_BACKEND_TYPE="MongoDB";
private static final String WRITE_CONCERN_PROPERTY_NAME="write_concern";
private static final String READ_PREFERENCE_PROPERTY_NAME="read_preference";
private static final String DB_PROPERTY_NAME="collection";
private static final String DB_STRING_SEPARATOR=";";
private static final String PASS_PHRASE_FIELD="PassPhrase";
private static final String TOKEN_FIELD="token";
/**
* home library need a special configuration
*/
@ -85,7 +90,7 @@ public class Configuration {
* @param memory indicates the type of memory used by the storage: Persistent or Volatile
*
*/
public Configuration(String sc, String sn, String scopeString, String owner, String clientID, String accessType, String memory, BackendType backend){
public Configuration(String sc, String sn, String scopeString, String owner, String clientID, String accessType, String memory, String backend){
this.sc=sc;
this.sn=sn;
this.owner=owner;
@ -93,7 +98,7 @@ public class Configuration {
this.typeAccess=accessType;
this.memoryType=memory;
setScopeString(scopeString);
setBackendType(backend.toString());
setBackendType(backend);
}
/**
@ -101,29 +106,19 @@ public class Configuration {
*/
public void getConfiguration(){
String[] newServer=null;
// ISClientConnector isclient=getISClient();
String currentScope=ScopeProvider.instance.get();
String currentScope;
currentScope = SecretManagerProvider.get().getContext();
logger.debug("Scope found on ScopeProvider instance is "+currentScope);
/*COMMENTED THE FOLLOWING LINES 20181214*/
if(RRScope == null){
// if(new ScopeBean(currentScope).is(Type.VRE)){
// logger.debug("If ScopeProvider scope is VRE scope RR scope became VO scope");
// RRScope=new ScopeBean(currentScope).enclosingScope().toString();
// }else{
// logger.debug("If ScopeProvider scope is not a VRE scope RR scope is ScopeProvider scope");
RRScope=currentScope;
// }
}
/*END*/
logger.debug("RuntimeResource scope "+RRScope);
ServiceEndpoint resource=getISClient().getStorageEndpoint(RRScope);
logger.debug("Manually scope was set to"+RRScope+" it doesn't take effect");
//if a specific backend is not passed as input param then take the default one
if (Objects.isNull(getBackendType()))
setBackendType(DEFAULT_BACKEND_TYPE);
ServiceEndpoint resource=getISClient(getBackendType()).getStorageEndpoint();
if(resource ==null )
throw new IllegalStateException("the storage resource is not present on IS in scope: "+RRScope);
List<ServiceEndpoint> resolverResource =getISClient().getServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
List<ServiceEndpoint> resolverResource =getISClient(getBackendType()).getServiceEndpoint(Utils.URI_RESOLVER_RESOURCE_CATEGORY, Utils.URI_RESOLVER_RESOURCE_NAME);
if(resolverResource !=null && resolverResource.size()> 0)
setResolverHost(getISClient().getResolverHost(resolverResource.get(0)));
setResolverHost(getISClient(getBackendType()).getResolverHost(resolverResource.get(0)));
else
throw new IllegalStateException("the uri resolver resource is not present on IS in scope: "+currentScope);
// old method for retrieve hostedOn field in storage ServiceEndpoint resource
@ -131,13 +126,17 @@ public class Configuration {
logger.debug("server not set. Try to query IS in scope: "+scopeString);
String[] serverFound=checkVarEnvMongo();
if(serverFound==null){
serverFound=getISClient().retrieveConnectionInfo(resource);
setUser(getISClient().getUsername());
setPassword(getISClient().password);
setBackendType(getISClient().getBackendType(resource));
serverFound=getISClient(getBackendType()).retrieveConnectionInfo(resource);
setUser(getISClient(getBackendType()).getUsername());
setPassword(getISClient(getBackendType()).password);
setRegion(getISClient(getBackendType()).getRegion());
if (Objects.isNull(getBackendType()))
setBackendType(getISClient(getBackendType()).getBackendType(resource));
}else{
setBackendType(checkVarEnvBackendType());
if(getBackendType() == null) setBackendType(DEFAULT_BACKEND_TYPE);
if (!Objects.isNull(getBackendType()))
setBackendType(checkVarEnvBackendType());
else
setBackendType(DEFAULT_BACKEND_TYPE);
setUser(checkVarEnvUser());
setPassword(checkVarEnvPassword());
}
@ -151,16 +150,33 @@ public class Configuration {
if(newServer==null){
throw new IllegalStateException("Resource not found on Information System");
}else{
setEnvironment(setAreaStorage(getSc(), getSn()));
setServerHosts(newServer, isclient, resource);
try {
setPassPhrase(retrieveEncryptionPhrase());
} catch (Exception e) {
e.printStackTrace();
setEnvironment(setAreaStorage(getSc(), getSn()));
// if the backend is mongodb we should set a separated server for volatile area
if(getBackendType().equals("MongoDB")) {
setServerHosts(newServer, isclient, resource);
try {
setPassPhrase(retrieveEncryptionField(PASS_PHRASE_FIELD));
} catch (Exception e) {
e.printStackTrace();
}
}else {
// if the backend isn't mongodb, the passPhrase field will be filled with a token if it is present on ServiceEndpoint
try {
setPassPhrase(retrieveEncryptionField(TOKEN_FIELD));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setPersistentHosts(newServer);
}
}
logger.debug("Configuration parameters retrieved: host: "+getPersistentHosts()+" user: "+getUser());
}
private void setServerHosts(String[] newServer, ISClientConnector isclient, ServiceEndpoint resource) {
if((getMemoryType() != null) && ((getMemoryType().equals(MemoryType.VOLATILE.toString()) || (getMemoryType().equals(MemoryType.BOTH.toString()))))){
setVolatileHost(isclient.getVolatileHost(resource));
@ -190,7 +206,7 @@ public class Configuration {
private String getHomeLibraryContext(){
String area=null;
String scope=ScopeProvider.instance.get();
String scope= SecretManagerProvider.get().getContext();
String context=null;
if (scope.startsWith("/gcube"))
context= HL_CONTEXT_DEV;
@ -208,18 +224,18 @@ public class Configuration {
}
protected void getOptionalPropertiesFromRR( String currentScope, ServiceEngine engine) {
protected void getOptionalPropertiesFromRR( ServiceEngine engine) {
String write=null;
String read=null;
String [] dbNames=null;
String dbString=null;
// check optional properties only if it is not a volatile storage instance
if((getMemoryType() != null) && (!(getMemoryType().equals(MemoryType.VOLATILE.toString())))){
write=getISClient().retrievePropertyValue(WRITE_CONCERN_PROPERTY_NAME, currentScope);
write=getISClient(getBackendType()).retrievePropertyValue(WRITE_CONCERN_PROPERTY_NAME);
logger.debug("read preference: read from service endpoint");
read=getISClient().retrievePropertyValue(READ_PREFERENCE_PROPERTY_NAME, currentScope);
read=getISClient(getBackendType()).retrievePropertyValue(READ_PREFERENCE_PROPERTY_NAME);
logger.debug(" write preference: read from service endpoint");
dbString=getISClient().retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME);
if((write!=null) && (read!=null)){
engine.setWriteConcern(write);
engine.setReadConcern(read);
@ -233,11 +249,12 @@ public class Configuration {
}
if (dbNames.length > 1)
logger.debug("multiple collection discovered");
engine.setDbNames(dbNames);
if (Objects.isNull(engine.getDbNames()))
engine.setDbNames(dbNames);
}
// added db check also on volatile are
}else if((getMemoryType().equals(MemoryType.VOLATILE.toString()))){
dbString=getISClient().retrievePropertyValue(DB_PROPERTY_NAME, currentScope);
dbString=getISClient(getBackendType()).retrievePropertyValue(DB_PROPERTY_NAME);
if(dbString!=null){
if (dbString.contains(DB_STRING_SEPARATOR)){
logger.debug("more than one collection read from ServiceEnpoint");
@ -349,16 +366,28 @@ public class Configuration {
return null;
}
@Deprecated
public String retrieveEncryptionPhrase() throws Exception {
String currentScope=ScopeProvider.instance.get();
String currentScope=SecretManagerProvider.get().getContext();
logger.debug("retrieve encryption prhase on scope: "+currentScope);
String encryptedKey=null;
// ISClientConnector isclient=getISClient();
logger.info("retrieve encryption phrase from scope "+currentScope);
encryptedKey=getISClient().retrievePropertyValue("PassPhrase", currentScope);
encryptedKey=getISClient(getBackendType()).retrievePropertyValue("PassPhrase");
logger.info("encrypted prhase is "+encryptedKey);
String decryptString=org.gcube.common.encryption.StringEncrypter.getEncrypter().decrypt(encryptedKey);
String decryptString=org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().decrypt(encryptedKey);
return decryptString;
}
public String retrieveEncryptionField(String fieldName) throws Exception {
String currentScope=SecretManagerProvider.get().getContext();
logger.debug("retrieve encryption prhase on scope: "+currentScope);
String encryptedKey=null;
// ISClientConnector isclient=getISClient();
logger.info("retrieve encryption phrase from scope "+currentScope);
encryptedKey=getISClient(getBackendType()).retrievePropertyValue(fieldName);
logger.info("encrypted prhase is "+encryptedKey);
String decryptString=(!Objects.isNull(encryptedKey))?org.gcube.common.encryption.encrypter.StringEncrypter.getEncrypter().decrypt(encryptedKey):null;
return decryptString;
}
@ -483,10 +512,14 @@ public class Configuration {
this.resolverHost = resolverHost;
}
public ISClientConnector getISClient(){
if (isclient == null)
isclient=new ISClientConnector();
return isclient;
private ISClientConnector getISClient(String backendType){
// if ((isclient == null) || (isclient.getBackendType().equals(backendType)))
// isclient=new ISClientConnector(backendType);
//
// return isclient;
return isclient=((isclient == null) || (!isclient.getBackendType().equals(backendType)))?new ISClientConnector(backendType):isclient;
}
public String getSc() {
@ -504,5 +537,13 @@ public class Configuration {
public void setSn(String sn) {
this.sn = sn;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
}

View File

@ -8,11 +8,15 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.gcube.common.encryption.StringEncrypter;
import java.util.Objects;
import org.gcube.common.encryption.encrypter.StringEncrypter;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
@ -34,7 +38,20 @@ public class ISClientConnector {
protected String username;
protected String password;
protected ServiceEndpoint storageResource;
public String region;
private static HashMap<String, Object> isCache;
/**
* identify the ServiceEndpoint Category of the storage-manager backend
*/
public final String CATEGORY="Storage";
/**
* identify the ServiceEndpoint name of the storage-manager backend
*/
public final String NAME="StorageManager";
public ISClientConnector(String backendType){
setBackendType(backendType);
}
public ISClientConnector(){
}
@ -51,31 +68,21 @@ public class ISClientConnector {
return resources;
}
public ServiceEndpoint getStorageEndpoint(String scope) {
public ServiceEndpoint getStorageEndpoint() {
//if the serviceEndpoint has been already discovered and selected, I'm going to use that
// otherwise I'm going to discovered it from IS
if(getStorageResource() == null){
logger.debug("discovering service endpoint");
String savedScope=null;
if(scope!=null){
savedScope=ScopeProvider.instance.get();
logger.debug("set scopeProvider to scope "+scope+" scope provider scope is "+savedScope);
ScopeProvider.instance.set(scope);
}
SimpleQuery query = queryFor(ServiceEndpoint.class);
query.addCondition("$resource/Profile/Category/text() eq '"+Configuration.STORAGE_SERVICEENDPOINT_CATEGORY+"' and $resource/Profile/Name eq '"+Configuration.STORAGE_SERVICEENDPOINT_NAME+"' ");
query.addCondition("$resource/Profile/Category/text() eq '"+CATEGORY+"' and $resource/Profile/Name eq '"+NAME+"' ");
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> resources = client.submit(query);
if(scope!=null){
logger.debug("reset scopeProvider to scope "+scope);
ScopeProvider.instance.set(savedScope);
}
if (resources.size()>0){
ServiceEndpoint storageResource = getPriorityResource(resources);
setStorageResource(storageResource);
return storageResource;
}else
throw new RuntimeException("Storage ServiceEndpoint not found under scope: "+scope);
throw new RuntimeException("Storage ServiceEndpoint not found under scope: "+SecretManagerProvider.get().getContext());
}else{
logger.debug("service endpoint already discovered");
return getStorageResource();
@ -84,43 +91,82 @@ public class ISClientConnector {
private String[] fillConnectionFields(ServiceEndpoint resource) {
logger.debug("fillConnectionsFields method ");
if(resource!=null){
ArrayList<String> srvs=new ArrayList <String>();
// String [] server=new String[resource.profile().accessPoints().size()];
int i=0;
for (AccessPoint ap:resource.profile().accessPoints()) {
if (ap.name().equals("server"+(i+1))) {
// server[i] = ap.address();
srvs.add(ap.address());
// if presents, try to get user and password
setUsername(ap.username());
// set password default value to empty string
setPassword("");
if(getUsername() != null && getUsername().length() > 0){
try {
setPassword(StringEncrypter.getEncrypter().decrypt(ap.password()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
logger.debug("checking resource "+resource.id());
ArrayList<String> server=new ArrayList<String> ();//new String[resource.profile().accessPoints().size()];
if(!(getBackendType(resource).equals(BackendType.MongoDB.name()))) {
logger.info("searching backend: "+getBackendType());
for (AccessPoint ap:resource.profile().accessPoints()) {
if( (ap.name().equals(getBackendType()))){
//in v1.6.0 we are considering only one accessPoint for a backend except for mongodb.
server.add( ap.address());
// if presents, try to get user and password
setUsername(ap.username());
decryptPwd(ap);
setRegion(retrievePropertyValue(ap, "region"));
break;
}
i++;
}
}else {
int i=0;
for (AccessPoint ap:resource.profile().accessPoints()) {
if (ap.name().equals("server"+(i+1))) {
server.add(ap.address());
setUsername(ap.username());
setPassword("");
if(getUsername() != null && getUsername().length() > 0){
try {
setPassword(StringEncrypter.getEncrypter().decrypt(ap.password()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
i++;
}
}
logger.info("credentials Mongodb: "+getUsername()+" "+getPassword());
// setBackendType(retrievePropertyValue(resource, "type"));
}
String [] server=new String[srvs.size()];
server = srvs.toArray(server);
setBackendType(retrievePropertyValue(resource, "type"));
//<<<<<<< HEAD
//
//=======
// String [] server=new String[srvs.size()];
// server = srvs.toArray(server);
// setBackendType(retrievePropertyValue(resource, "type"));
//>>>>>>> master
String [] volatileHost= new String [1];
volatileHost[0]=retrievePropertyValue(resource, "volatile");
setVolatileHost(volatileHost);
logger.info("Type of backend found in RR is "+backendType);
return server;
String [] servers= new String[server.size()];
servers=server.toArray(servers);
return servers;
}else{
throw new IllegalStateException("Runtime Resource found are more than 1 but all without default priority setted");
}
}
private void decryptPwd(AccessPoint ap) {
// set password default value to empty string
setPassword("");
if(getUsername() != null && getUsername().length() > 0){
try {
setPassword(StringEncrypter.getEncrypter().decrypt(ap.password()));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private ServiceEndpoint getPriorityResource(List<ServiceEndpoint> resources) {
ServiceEndpoint defaultResource=null;
logger.info("search RR with priority ");
@ -152,8 +198,8 @@ public class ISClientConnector {
}
public String retrievePropertyValue(String name, String scope) {
ServiceEndpoint res = getStorageEndpoint(scope);
public String retrievePropertyValue(String name) {
ServiceEndpoint res = getStorageEndpoint();
Iterator<AccessPoint> it= res.profile().accessPoints().iterator();
String value=null;
while(it.hasNext()){
@ -168,6 +214,17 @@ public class ISClientConnector {
}
return value;
}
public String retrievePropertyValue(AccessPoint ap, String name) {
String value=null;
Map<String, Property>map= ap.propertyMap();
Property type=map.get(name);
if(type!=null){
value=type.value();
}
return value;
}
private String retrievePropertyValue(ServiceEndpoint res, String name) {
Iterator<AccessPoint> it= res.profile().accessPoints().iterator();
@ -197,7 +254,7 @@ public class ISClientConnector {
return backendType;
}
public void setBackendType(String backendType) {
private void setBackendType(String backendType) {
this.backendType = backendType;
}
@ -233,6 +290,14 @@ public class ISClientConnector {
this.storageResource = storageResource;
}
private void setRegion(String region) {
this.region=region;
}
public String getRegion() {
return region;
}
}
}

View File

@ -1,10 +1,12 @@
package org.gcube.contentmanager.storageclient.wrapper;
package org.gcube.contentmanager.storageclient.wrapper;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
//import org.gcube.contentmanagement.blobstorage.resource.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.common.scope.api.ScopeProvider;
import java.util.Objects;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.service.impl.ServiceEngine;
import org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants;
@ -38,53 +40,20 @@ public class StorageClient {
private static final String DEFAULT_SERVICE_NAME="Default";
private static final MemoryType DEFAULT_MEMORY_TYPE=MemoryType.PERSISTENT;
/**
* Constructor without optional argument created for gcube infrastructure internal use
* @param ServiceClass
* @param ServiceName
* @param owner
* @param typeAccess
* @param scope scope identifier
* @param forceScope if true the scope used is the scope specified in scope parameter, else the scope specified in the parameter scope is used only for discovering the RuntimeResource
*/
@Deprecated
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, String scope, boolean forceScope){
checkScopeProvider();
if(forceScope){
this.currentScope=ScopeProvider.instance.get();
ScopeProvider.instance.set(scope);
this.scopeString=ScopeProvider.instance.get();
}else{
this.RRScope=scope;
this.scopeString=ScopeProvider.instance.get();
}
String id=owner;
this.owner=owner;
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
this.memoryType=MemoryType.BOTH;
this.serviceClass=serviceClass;
this.serviceName=serviceName;
setClientId(serviceClass, serviceName, id);
}
/**
* Constructor without optional argument created for gcube infrastructure internal use
* @param ServiceClass
* @param ServiceName
* @param serviceClass
* @param serviceName
* @param owner
* @param typeAccess
* @param scope
* @param accessType
*/
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
this.scopeString=SecretManagerProvider.get().getContext();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
@ -100,17 +69,15 @@ public class StorageClient {
* New constructor with another optional argument created for gcube infrastructure internal use.
* Available in v1.6.0
* It's possible to specify a specific backend.
* @param ServiceClass
* @param ServiceName
* @param serviceClass
* @param serviceName
* @param owner
* @param typeAccess
* @param scope
* @param accessType
*/
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, BackendType backend){
checkScopeProvider();
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, BackendType backend){;
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
this.scopeString=SecretManagerProvider.get().getContext();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
@ -127,15 +94,13 @@ public class StorageClient {
/**
* Constructor created for external use
* @param owner
* @param typeAccess
* @param accessType
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
* @param scope
*/
public StorageClient(String owner, AccessType accessType, MemoryType memory){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
this.scopeString=SecretManagerProvider.get().getContext();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
@ -150,18 +115,16 @@ public class StorageClient {
/**
* Constructor with optional argument server
* @param ServiceClass
* @param ServiceName
* @param serviceClass
* @param serviceName
* @param owner
* @param typeAccess
* @param scope
* @param accessType
* @param server: define the mongoDBserver
*/
public StorageClient(String serviceClass, String serviceName, String owner, String server, AccessType accessType){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
this.scopeString=SecretManagerProvider.get().getContext();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
@ -176,18 +139,16 @@ public class StorageClient {
/**
* Constructor with optional argument memoryType
* @param ServiceClass
* @param ServiceName
* @param serviceClass
* @param serviceName
* @param owner
* @param typeAccess
* @param accessType
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
* @param scope
*/
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
this.scopeString=SecretManagerProvider.get().getContext();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
@ -203,19 +164,17 @@ public class StorageClient {
/**
* Available in v1.6.0
* It's possible to specify a specific backend.
* @param ServiceClass
* @param ServiceName
* @param serviceClass
* @param serviceName
* @param owner
* @param typeAccess
* @param accessType
* @param backend: specify mongodb (default) or s3
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
* @param scope
*/
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory, BackendType backend){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
this.scopeString=SecretManagerProvider.get().getContext();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
@ -232,19 +191,17 @@ public class StorageClient {
/**
* Constructor with optional arguments server and memory
* @param ServiceClass
* @param ServiceName
* @param serviceClass
* @param serviceName
* @param owner
* @param typeAccess
* @param accessType
* @param memory defines the kind of memory: VOLATILE or PERSISTENT
* @param server: define the mongoDBserver
* @param scope
*/
public StorageClient(String serviceClass, String serviceName, String owner, AccessType accessType, MemoryType memory, String server){
checkScopeProvider();
String id=owner;
this.owner=owner;
this.scopeString=ScopeProvider.instance.get();
this.scopeString=SecretManagerProvider.get().getContext();
if(accessType!=null)
this.typeAccess=accessType;
else throw new RuntimeException("AccessType parameter must be not null");
@ -264,7 +221,11 @@ public class StorageClient {
* @throws IllegalStateException if the resource is not found on the IS
*/
public IClient getClient(){
Configuration cfg= new Configuration(serviceClass, serviceName, scopeString, owner, clientID, typeAccess.toString(), memoryType.toString());
Configuration cfg=null;
if(Objects.isNull(getBackendType()))
cfg= new Configuration(serviceClass, serviceName, scopeString, owner, clientID, typeAccess.toString(), memoryType.toString());
else
cfg= new Configuration(serviceClass, serviceName, scopeString, owner, clientID, typeAccess.toString(), memoryType.toString(), getBackendType());
cfg.getConfiguration();
ServiceEngine engine= new ServiceEngine(cfg.getPersistentHosts(), cfg.getVolatileHost(), cfg.getEnvironment(), cfg.getTypeAccess(), cfg.getOwner(), cfg.getMemoryType());
// set additional fields for the new engine object
@ -275,15 +236,20 @@ public class StorageClient {
engine.setBackendUser(cfg.getUser());
engine.setBackendPassword(cfg.getPassword());
engine.setResolverHost(cfg.getResolverHost());
if(cfg.getPassPhrase()!=null)
engine.setRegion(cfg.getRegion());
if(cfg.getPassPhrase()!=null) {
engine.setPassPhrase(cfg.getPassPhrase());
engine.setToken(cfg.getPassPhrase());
}
if(getMemoryType() !=null)
engine.setGcubeMemoryType(getMemoryType().toString());
engine.setGcubeScope(ScopeProvider.instance.get());
engine.setGcubeScope(SecretManagerProvider.get().getContext());
engine.setOwnerGcube(owner);
cfg.getOptionalPropertiesFromRR( getCurrentScope(), engine);
if(getCurrentScope()!=null)
ScopeProvider.instance.set(getCurrentScope());
cfg.getOptionalPropertiesFromRR(engine);
if(getCurrentScope()!=null){
if(!getCurrentScope().equals(SecretManagerProvider.get().getContext()))
logger.warn("scope force to "+getCurrentScope()+"doesn't take effect. The current scope is set to"+SecretManagerProvider.get().getContext());
}
return engine;
}
@ -300,23 +266,6 @@ public class StorageClient {
}
}
/**
* if the scope provider is not set then check if the env variable: SCOPE is set and set the scopeProvider
*/
private void checkScopeProvider(){
String scopeProvided=ScopeProvider.instance.get();
if (scopeProvided==null){
scopeProvided=Utils.checkVarEnv("SCOPE");
if (scopeProvided != null){
ScopeProvider.instance.set(scopeProvided);
}else{
throw new RuntimeException("Scope not set ");
}
}else setCurrentScope(scopeProvided);
}
public String getClientID() {
return clientID;
@ -427,6 +376,8 @@ public class StorageClient {
public String getBackendType() {
if(Objects.isNull(backendType))
backendType=Configuration.DEFAULT_BACKEND_TYPE;
logger.debug("backend type returned is "+backendType);
return backendType;
}

View File

@ -3,41 +3,41 @@ package org.gcube.contentmanager.storageclient.test;
import static org.junit.Assert.*;
import java.io.File;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.junit.After;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class CopyDirTest {
private String owner="rcirillo";
private static String owner="rcirillo";
// local file
private String localPath="src/test/resources/CostaRica1.jpg";
private static String localPath="src/test/resources/CostaRica1.jpg";
//remote files
private String remoteOriginalFilePath="/test/img/original.jpg";
private String remoteOriginalFilePath2="/test/img/original2.jpg";
private String remoteCopyFilePath="/test/copyImg/img/original.jpg";
private String remoteCopyFilePath2="/test/copyImg/img/original2.jpg";
private static String remoteOriginalFilePath="/test/img/original.jpg";
private static String remoteOriginalFilePath2="/test/img/original2.jpg";
private static String remoteCopyFilePath="/test/copyImg/img/original.jpg";
private static String remoteCopyFilePath2="/test/copyImg/img/original2.jpg";
//remote directories
private String remoteOriginalDirPath="/test/img/";
private String remoteCopyDirPath="/test/copyImg";
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
private static String remoteOriginalDirPath="/test/img/";
private static String remoteCopyDirPath="/test/copyImg";
private static String absoluteLocalPath;
private static String newFilePath="src/test/resources";
private static IClient client;
// private String scope="/gcube/devsec";//"/d4science.research-infrastructures.eu/FARM";//"/CNR.it/ISTI";//"/gcube"; // "/d4science.research-infrastructures.eu/FARM/VTI";//
private String serviceClass="JUnitTest-CopyDir";
private String serviceName="StorageManager";
private static String serviceClass="JUnitTest-CopyDir";
private static String serviceName="StorageManager";
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
@BeforeClass
public static void getClient() throws RemoteBackendException{
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
@ -124,15 +124,15 @@ public class CopyDirTest {
}
private void setLocalResources() {
private static void setLocalResources() {
absoluteLocalPath=new File(localPath).getAbsolutePath();
String dir=new File(absoluteLocalPath).getParent();
newFilePath=dir+"/testJunitLink.jpg";
absoluteLocalPath=new File(localPath).getAbsolutePath();
}
@After
public void deleteRemoteDir(){
@AfterClass
public static void deleteRemoteDir(){
client.removeDir().RDir(remoteCopyDirPath);
client.removeDir().RDir(remoteOriginalDirPath);
}

View File

@ -1,18 +1,19 @@
package org.gcube.contentmanager.storageclient.test;
import static org.gcube.contentmanager.storageclient.test.utils.Costants.*;
import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -38,19 +39,15 @@ public class CopyTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setLocalResources();
// String id=client.put(true).LFile(absoluteLocalFrog).RFile(remoteOriginalFilePath);
// System.out.println("id of the following path "+remoteOriginalFilePath+" is: "+id );
// assertNotNull(id);
}
@ -60,7 +57,7 @@ public class CopyTest {
*/
@Test
public void removeCopiedFileTest() throws RemoteBackendException {
// put orignal file
// put orignal file
String id=client.put(true).LFile(absoluteLocalFrog).RFile(remoteOriginalFilePath);
System.out.println("id of the following path "+remoteOriginalFilePath+" is: "+id );
//first copy
@ -69,6 +66,7 @@ public class CopyTest {
File f =new File(newFilePath);
System.out.println("path new File downloaded: "+f.getAbsolutePath());
assertTrue(f.exists());
// removing local and copied file
removeLocalFile();
removeCopiedFile(remoteCopyPath, "test/copyDir/");
checkOriginalFileIsAlive();
@ -150,6 +148,7 @@ public class CopyTest {
File f =new File(newFilePath2);
System.out.println("path new File downloaded: "+f.getAbsolutePath());
assertTrue(f.exists());
// check if the remote file is a dog
assertEquals(dogSize, f.length());
// removeCopiedFile(remoteCopyPath, "test/copyDir/");

View File

@ -1,8 +1,9 @@
package org.gcube.contentmanager.storageclient.test;
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
import static org.junit.Assert.*;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
@ -25,7 +26,7 @@ public class CountingTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
@ -62,6 +63,7 @@ public class CountingTest {
System.out.println(owner+" volume: "+userVolume);
}
// @After
// public void sleep(){
// try {

View File

@ -9,7 +9,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.bson.types.ObjectId;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -17,32 +17,35 @@ import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class DownloadsTest {
private String owner="rcirillo";
private String localPath="src/test/resources/CostaRica1.jpg";
private String remotePath="/test/img/CostaRica1.jpg";
private String remotePath1="/test/img/CostaRica2.jpg";
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
private static String owner="rcirillo";
private static String localPath="src/test/resources/CostaRica1.jpg";
private static String remotePath="/test/img/CostaRica1.jpg";
private static String remotePath1="/test/img/CostaRica2.jpg";
private static String absoluteLocalPath;
private static String newFilePath="src/test/resources";
private static IClient client;
// private String scope="/d4science.research-infrastructures.eu"; //"/gcube";//"/gcube";//"/d4science.research-infrastructures.eu"; //"/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";// //"/CNR.it";// ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String serviceClass="JUnitTest";
private String serviceName="StorageManager";
private static String serviceClass="JUnitTest";
private static String serviceName="StorageManager";
private String NotExistingId="5a5c7d1d1b9b060285bbe2bd";
private String id;
private String id1;
private static String id;
private static String id1;
private String encryptedId="OE5tOCtuTUt5eXVNd3JkRDlnRFpDY1h1MVVWaTg0cUtHbWJQNStIS0N6Yz0";//"SG1EN2JFNXIELzZ1czdsSkRIa0Evd3VzcGFHU3J6L2RHbWJQNStIS0N6Yz0";//"OE5tOCtuTUt5eXVNd3JkRDlnRFpDY1h1MVVWaTg0cUtHbWJQNStIS0N6Yz0";//"SThtL0xRU281M2UzY29ldE44SkhkbzVkMlBWVmM4aEJHbWJQNStIS0N6Yz0";//"dExaYzNKelNyQVZMemxpcXplVXYzZGN4OGZTQ2w4aU5HbWJQNStIS0N6Yz0";//"Mm9nc0tZbXR1TVI2cVRxL3pVUElrRXJkbk9vVDY2eEJHbWJQNStIS0N6Yz0";//"FemRmUEFtRGVZMnozcEdBekVHU3E4Skt5dkh2OXJObHFHbWJQNStIS0N6Yz0";//"L0p3OGJjUHhFaEJoTmppdjlsK0l0Z0h1b3VpVlloUzVHbWJQNStIS0N6Yz0";//"NWJTRFdxQkQxclJHV05FbExrRDJjL0g4QTBwSnV1TVdHbWJQNStIS0N6Yz0";//"M2JIM2hqNUNyRkxBdG00cnRaWDBpUGxRTmtVQmtEdXBHbWJQNStIS0N6Yz0";//"lfV6BqnBWUbN5dUiQ6xpkMgI69wEwcm6Ygh60bFzaL3h2Run5e9uZMoTix+ykL5H";//"huivj74/QCHnj376YGe/FicgYHSHcwph7SoMty7FBmAh+80AzGQtOdanne6zJBd5";//"lfV6BqnBWUbN5dUiQ6xpkMgI69wEwcm6Ygh60bFzaL3h2Run5e9uZMoTix+ykL5H";//"bksxMGVWTlZ3WjM5Z1ZXYXlUOUtMZzVSNlBhZXFGb05HbWJQNStIS0N6Yz0";//"bEVydmtsOHhCclZMZGd4cEtnTVQzZXQ5UVNxWHZURGJHbWJQNStIS0N6Yz0";//"bEVydmtsOHhCclZMZGd4cEtnTVQz";//"cHEvek1sbjdBaWJkc0s4SzZpSUJpU0c2ZEgyOEVyUGJHbWJQNStIS0N6Yz0";//"RnpoMy9ZaVRoRkZjbk8ybGx0QnlRR";//"L1pWTlV3ZWxPbHRyMloxZ0JnWUVHdHYvUnZDVHJiMTBHbWJQNStIS0N6Yz0";
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
@BeforeClass
public static void getClient() throws RemoteBackendException{
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
// ScopeProvider.instance.set(scope);
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE, Costants.BACKEND_TYPE).getClient();
assertNotNull(client);
} catch (Exception e) {
// TODO Auto-generated catch block
@ -50,10 +53,11 @@ public class DownloadsTest {
}
setLocalResources();
id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
System.out.println("upload done ");
System.out.println("upload done. Returned id "+id);
id1=client.put(true).LFile(absoluteLocalPath).RFile(remotePath1);
System.out.println("upload done ");
System.out.println("upload done. Returned id1: "+id1);
assertNotNull(id);
assertNotNull(id1);
}
@ -97,8 +101,8 @@ public class DownloadsTest {
@Test
public void downloadByInputStream() throws IOException, InterruptedException {
downloadByIS(id);
downloadByIS(id1);
downloadByIS(id);
}
@ -164,8 +168,8 @@ public class DownloadsTest {
}
@After
public void removeRemoteFile() throws RemoteBackendException{
@AfterClass
public static void removeRemoteFile() throws RemoteBackendException{
String id=client.remove().RFile(remotePath);
System.out.println("removeRemotePath id: "+id);
String id1=client.remove().RFile(remotePath1);
@ -181,7 +185,7 @@ public class DownloadsTest {
}
private void setLocalResources() {
private static void setLocalResources() {
absoluteLocalPath=new File(localPath).getAbsolutePath();
String dir=new File(absoluteLocalPath).getParent();
newFilePath=dir+"/Junit.jpg";

View File

@ -9,7 +9,7 @@ import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -43,7 +43,7 @@ public class DuplicateTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();

View File

@ -3,7 +3,8 @@ package org.gcube.contentmanager.storageclient.test;
import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -36,7 +37,7 @@ public class ForceCloseTest {
@Before
public void getClient(){
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
@ -53,12 +54,6 @@ public class ForceCloseTest {
@Test
public void forceCloseTest(){
// try {
// Thread.sleep(10000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
client.forceClose();
//download
try {
@ -66,23 +61,9 @@ public class ForceCloseTest {
}catch(Exception e ) {
assertNotNull(e);
}
// try {
// client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
// assertNotNull(client);
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// delete
removeRemoteFile();
client.forceClose();
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@After

View File

@ -1,13 +1,17 @@
package org.gcube.contentmanager.storageclient.test;
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import static org.junit.Assert.assertNotNull;
import static org.gcube.resources.discovery.icclient.ICFactory.*;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.ISClientConnector;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
@ -19,12 +23,11 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class FwsQueryTest {
String scope="/gcube/devsec";
@Before
public void setscope(){
ScopeProvider.instance.set(scope);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));;
}
// @Test
@ -91,7 +94,8 @@ public class FwsQueryTest {
public void getRR() throws Exception{
System.out.println("retrieve server from RuntimeResource");
ISClientConnector isConnector= new ISClientConnector();
ServiceEndpoint resource = isConnector.getStorageEndpoint(scope);
ServiceEndpoint resource = isConnector.getStorageEndpoint();
assertNotNull(resource);
String[] server=isConnector.retrieveConnectionInfo(resource);
for(int j=0; j<server.length; j++){
System.out.println("s" +j+" = "+server[j]);

View File

@ -5,8 +5,8 @@ import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanagement.blobstorage.resource.MyFile;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -14,27 +14,29 @@ import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class GetMetaFileTest {
private String owner="rcirillo";
private String localPath="src/test/resources/CostaRica1.jpg";
private String remotePath="/test/img2/CostaRica1.jpg";
private String remotePath2="/test/img2/CostaRica2.jpg";
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
private static String owner="rcirillo";
private static String localPath="src/test/resources/CostaRica1.jpg";
private static String remotePath="/test/img2/CostaRica1.jpg";
private static String remotePath2="/test/img2/CostaRica2.jpg";
private static String absoluteLocalPath;
private static String newFilePath="src/test/resources";
private static IClient client;
// private String scope="/gcube/devsec"; //"/d4science.research-infrastructures.eu"; ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String serviceClass="JUnitTest";
private String serviceName="StorageManager";
private String id;
private String id2;
private static String serviceClass="JUnitTest";
private static String serviceName="StorageManager";
private static String id;
private static String id2;
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
@BeforeClass
public static void getClient() throws RemoteBackendException{
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
@ -53,7 +55,7 @@ public class GetMetaFileTest {
@Test
public void getMetaFileByPath() throws RemoteBackendException {
MyFile f= client.getMetaFile().RFile(remotePath);
RequestObject f= client.getMetaFile().RFile(remotePath);
// System.out.println("mime is: "+f.getMimeType());
client.put(true, "image/png").LFile("src/test/resources/dog.jpg").RFile(remotePath);
f= client.getMetaFile().RFile(remotePath);
@ -70,7 +72,7 @@ public class GetMetaFileTest {
@Test
public void getMetaFileById() throws RemoteBackendException {
MyFile f= client.getMetaFile().RFile(id);
RequestObject f= client.getMetaFile().RFile(id);
assertNotNull(f);
assertEquals(id, f.getId());
print(f);
@ -81,15 +83,15 @@ public class GetMetaFileTest {
}
@After
public void removeRemoteFile() throws RemoteBackendException{
String id=client.remove().RFile(remotePath);
String id2=client.remove().RFile(remotePath2);
@AfterClass
public static void removeRemoteFile() throws RemoteBackendException{
client.remove().RFile(remotePath);
client.remove().RFile(remotePath2);
List<StorageObject> list=client.showDir().RDir("test/img2");
assertTrue(list.isEmpty());
}
private void print(MyFile f) {
private void print(RequestObject f) {
System.out.println("\t name "+f.getName());
System.out.println("\t size "+f.getSize());
System.out.println("\t owner "+f.getOwner());
@ -107,7 +109,7 @@ public class GetMetaFileTest {
}
private void setLocalResources() {
private static void setLocalResources() {
absoluteLocalPath=new File(localPath).getAbsolutePath();
String dir=new File(absoluteLocalPath).getParent();
newFilePath=dir+"/testJunit.jpg";

View File

@ -8,18 +8,17 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class HLcheckTest {
@ -30,7 +29,7 @@ public class HLcheckTest {
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
// private String scope="/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//Costants.DEFAULT_SCOPE_STRING;//"/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";// //"/CNR.it";// ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String scope="/d4science.research-infrastructures.eu";//"/gcube";//"/d4science.research-infrastructures.eu";//Costants.DEFAULT_SCOPE_STRING;//"/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";//"/d4science.research-infrastructures.eu";// //"/CNR.it";// ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String serviceClass="org.gcube.portlets.user";//"JUnitTest";
private String serviceName="home-library";//"test-home-library";//"StorageManager";
private String id;
@ -38,10 +37,10 @@ public class HLcheckTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
// ScopeProvider.instance.set(scope);
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_SCOPE_STRING, false).getClient();
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED).getClient();
assertNotNull(client);
} catch (Exception e) {
// TODO Auto-generated catch block
@ -56,7 +55,7 @@ public class HLcheckTest {
}
@Test
// @Test
public void downloadByPath() throws RemoteBackendException {
String idFound=client.get().LFile(newFilePath).RFile(remotePath);
System.out.println("downloadByPath id: "+idFound+" id orig "+id );
@ -66,14 +65,14 @@ public class HLcheckTest {
removeLocalFile();
}
@Test
// @Test
public void downloadByInputStream() throws IOException, InterruptedException {
downloadByIS(id);
downloadByIS(id1);
}
@Test
// @Test
public void downloadById() throws RemoteBackendException{
// String idReturned=client.get().LFile(newFilePath).RFileById(id);
String idReturned=client.get().LFile(newFilePath).RFile(id);
@ -87,6 +86,9 @@ public class HLcheckTest {
@Test
public void downloadBySpecificIdOnlyForTest() throws RemoteBackendException{
//// String file="/home/rcirillo-pc/Downloads/ce1159aa-a87f-4074-a3f9-36fe26d62f87-d4science.research-infrastructures.eu-gCubeApps-DESCRAMBLE.zip";
// String file="/Users/roberto/VivianaOtero/detailed_simulation_4327.csv";
// String idReturned=client.get().LFile(file).RFile("60830489d56b08199c3407c6");
String idReturned=client.get().LFile(newFilePath).RFileById(id);
// String file="/home/rcirillo-pc/Downloads/ce1159aa-a87f-4074-a3f9-36fe26d62f87-d4science.research-infrastructures.eu-gCubeApps-DESCRAMBLE.zip";
// String idReturned=client.get().LFile(absoluteLocalPath).RFile("5f6a1f405b0bde3544cbd3be");
@ -101,7 +103,7 @@ public class HLcheckTest {
@After
// @After
public void removeRemoteFile() throws RemoteBackendException{
String id=client.remove().RFile(remotePath);
System.out.println("removeRemotePath id: "+id);

View File

@ -0,0 +1,41 @@
package org.gcube.contentmanager.storageclient.test;
import org.gcube.common.security.Owner;
import org.gcube.common.security.secrets.Secret;
import java.util.Collections;
import java.util.Map;
public class ICSecret extends Secret{
private String context;
protected ICSecret(String context) {
this.context = context;
}
@Override
public Owner getOwner() {
return null;
}
@Override
public String getContext() {
return context;
}
@Override
public Map<String, String> getHTTPAuthorizationHeaders() {
return Collections.emptyMap();
}
@Override
public boolean isExpired() {
return false;
}
@Override
public boolean isValid(){ return true; }
}

View File

@ -5,7 +5,7 @@ import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -32,7 +32,7 @@ public class LinkTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();

View File

@ -1,5 +1,6 @@
package org.gcube.contentmanager.storageclient.test;
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@ -7,7 +8,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -37,7 +38,7 @@ public class LockTest {
@Before
public void getClient(){
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);

View File

@ -4,37 +4,37 @@ import static org.junit.Assert.*;
import java.io.File;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class MoveDirTest {
private String owner="rcirillo";
private String localPath="src/test/resources/CostaRica1.jpg";
private String remoteOriginalFilePath="/test/move/img/original.jpg";
private String remoteOriginalFilePath2="/test/move/img/original2.jpg";
private String remoteMovePath="/test/move/";
private String remoteMovePath2="/test/trash/";
private String remoteMoveFilePath="/test/trash/move/img/original.jpg";
private String remoteMoveFilePath2="/test/trash/move/img/original2.jpg";
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
private static String owner="rcirillo";
private static String localPath="src/test/resources/CostaRica1.jpg";
private static String remoteOriginalFilePath="/test/move/img/original.jpg";
private static String remoteOriginalFilePath2="/test/move/img/original2.jpg";
private static String remoteMovePath="/test/move/";
private static String remoteMovePath2="/test/trash/";
private static String remoteMoveFilePath="/test/trash/move/img/original.jpg";
private static String remoteMoveFilePath2="/test/trash/move/img/original2.jpg";
private static String absoluteLocalPath;
private static String newFilePath="src/test/resources";
private static IClient client;
// private String scope="/gcube/devsec";//"/d4science.research-infrastructures.eu";//"/CNR.it/ISTI";//"/gcube"; // "/d4science.research-infrastructures.eu/FARM/VTI";//
private String serviceClass="JUnitTest-MoveDir";
private String serviceName="StorageManager";
private static String serviceClass="JUnitTest-MoveDir";
private static String serviceName="StorageManager";
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
@BeforeClass
public static void getClient() throws RemoteBackendException{
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
@ -82,20 +82,20 @@ public class MoveDirTest {
}
private void setLocalResources() {
private static void setLocalResources() {
absoluteLocalPath=new File(localPath).getAbsolutePath();
String dir=new File(absoluteLocalPath).getParent();
newFilePath=dir+"/testJunitMoveOp.jpg";
absoluteLocalPath=new File(localPath).getAbsolutePath();
}
private void removeLocalFile(){
private static void removeLocalFile(){
File f=new File(newFilePath);
f.delete();
assertFalse(f.exists());
}
private void checkOriginalFileIsAlive(String remoteOriginalFilePath) {
private static void checkOriginalFileIsAlive(String remoteOriginalFilePath) {
String id=null;
try{
id=client.get().LFile(newFilePath).RFile(remoteOriginalFilePath);
@ -103,15 +103,15 @@ public class MoveDirTest {
assertNull(id);
}
private void checkMoveFileIsAlive() {
private static void checkMoveFileIsAlive() {
String id=client.get().LFile(newFilePath).RFile(remoteMovePath);
System.out.println("id link is alive: "+id);
assertNotNull(id);
removeLocalFile();
}
@After
public void removeRemoteDirs(){
@AfterClass
public static void removeRemoteDirs(){
client.removeDir().RDir(remoteMovePath2);
}

View File

@ -3,7 +3,8 @@ package org.gcube.contentmanager.storageclient.test;
import static org.junit.Assert.*;
import java.io.File;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
@ -29,7 +30,7 @@ public class MoveTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();

View File

@ -1,41 +1,41 @@
package org.gcube.contentmanager.storageclient.test;
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanagement.blobstorage.resource.MyFile;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.RequestObject;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class PropertiesTest {
private String owner="rcirillo";
private String localPath="src/test/resources/CostaRica1.jpg";
private String remotePath="/test/mimeTest/CostaRica1.jpg";
private String absoluteLocalPath;
private String newFilePath="src/test/resources";
private IClient client;
// private String scope="/gcube/devsec"; //"/d4science.research-infrastructures.eu"; ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private String serviceClass="JUnitTest";
private String serviceName="StorageManager";
private String id;
private String field="mimetype";
private String value="image/png";
private static String owner="rcirillo";
private static String localPath="src/test/resources/CostaRica1.jpg";
private static String remotePath="/test/mimeTest/CostaRica1.jpg";
private static String absoluteLocalPath;
private static String newFilePath="src/test/resources";
private static IClient client;
private static String scope="/gcube/devsec"; //"/d4science.research-infrastructures.eu"; ///gcube/devsec/devVRE"; //"/CNR.it/ISTI";//"/gcube/devsec/devVRE"; // /d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/CNR.it/ISTI";//
private static String serviceClass="JUnitTest";
private static String serviceName="StorageManager";
private static String id;
private static String field="mimetype";
private static String value="image/png";
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
@BeforeClass
public static void getClient() throws RemoteBackendException{
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.PUBLIC, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
@ -46,6 +46,8 @@ public class PropertiesTest {
setLocalResources();
id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
assertNotNull(id);
String result= client.setMetaInfo(field, value).RFile(id);
}
@ -53,12 +55,12 @@ public class PropertiesTest {
public void getPropertyByPath() throws RemoteBackendException {
String valueFound= client.getMetaInfo(field).RFile(remotePath);
System.out.println("value found for property: "+field+" is "+valueFound);
MyFile f= client.getMetaFile().RFile(remotePath);
RequestObject f= client.getMetaFile().RFile(remotePath);
assertNotNull(f);
print(f);
String result= client.setMetaInfo(field, value).RFile(remotePath);
System.out.println("new property set ");
MyFile f1= client.getMetaFile().RFile(remotePath);
RequestObject f1= client.getMetaFile().RFile(remotePath);
print(f1);
assertNotNull(f1);
assertEquals(f1.getMimeType(), value);
@ -70,36 +72,35 @@ public class PropertiesTest {
public void getPropertyById() throws RemoteBackendException {
String valueFound= client.getMetaInfo(field).RFile(id);
System.out.println("value found for property: "+field+" is "+valueFound);
MyFile f= client.getMetaFile().RFile(id);
RequestObject f= client.getMetaFile().RFile(id);
assertNotNull(f);
print(f);
String result= client.setMetaInfo(field, value).RFile(id);
System.out.println("new property set ");
MyFile f1= client.getMetaFile().RFile(id);
RequestObject f1= client.getMetaFile().RFile(id);
print(f1);
assertNotNull(f1);
assertEquals(f1.getMimeType(), value);
}
// @Test
@Test
public void setProperty() throws RemoteBackendException {
String result= client.setMetaInfo(field, value).RFile(id);
MyFile f= client.getMetaFile().RFile(remotePath);
RequestObject f= client.getMetaFile().RFile(remotePath);
assertNotNull(f);
print(f);
}
@After
public void removeRemoteFile() throws RemoteBackendException{
@AfterClass
public static void removeRemoteFile() throws RemoteBackendException{
String id=client.remove().RFile(remotePath);
List<StorageObject> list=client.showDir().RDir("test/mimeTest");
assertTrue(list.isEmpty());
removeLocalFile();
}
private void print(MyFile f) {
private void print(RequestObject f) {
System.out.println("\t name "+f.getName());
System.out.println("\t size "+f.getSize());
System.out.println("\t owner "+f.getOwner());
@ -111,14 +112,14 @@ public class PropertiesTest {
}
private void removeLocalFile(){
private static void removeLocalFile(){
File f=new File(newFilePath);
f.delete();
assertFalse(f.exists());
}
private void setLocalResources() {
private static void setLocalResources() {
absoluteLocalPath=new File(localPath).getAbsolutePath();
String dir=new File(absoluteLocalPath).getParent();
newFilePath=dir+"/testJunit.jpg";

View File

@ -5,7 +5,7 @@ import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -33,7 +33,7 @@ public class RemoveTest {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);

View File

@ -7,7 +7,7 @@ import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -33,7 +33,7 @@ public class RemoveVolatileArea {
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
@ -47,7 +47,7 @@ public class RemoveVolatileArea {
}
@Test
// @Test
public void removeVolatile(){
client.removeDir().RDir("/Home/roberto.cirillo/Workspace/Trash/");
}

View File

@ -3,12 +3,14 @@
*/
package org.gcube.contentmanager.storageclient.test;
import static org.gcube.contentmanager.storageclient.test.utils.Costants.DEFAULT_SCOPE_STRING;
import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -42,7 +44,7 @@ public class ReplaceFileTest {
@Before
public void getClient(){
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);

View File

@ -8,7 +8,7 @@ import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -16,6 +16,7 @@ import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
/**
@ -24,29 +25,29 @@ import org.junit.Test;
*/
public class SoftCopyTest {
private String owner="rcirillo";
private String localFrog="src/test/resources/CostaRica1.jpg";//"src/test/resources/testFile.txt";//"src/test/resources/CostaRica1.jpg";
private String localDog="src/test/resources/dog.jpg";
private static String owner="rcirillo";
private static String localFrog="src/test/resources/CostaRica1.jpg";//"src/test/resources/testFile.txt";//"src/test/resources/CostaRica1.jpg";
private static String localDog="src/test/resources/dog.jpg";
private String remoteOriginalFilePath="/test/frog.jpg";
private String remoteCopyPath="/test/SoftCopy1/frog1.jpg";
private String remoteCopyPath2="/test/SoftCopy2/frog2.jpg";
private String remoteCopyPath3="/test/SoftCopy3/frog3.jpg";
private String remoteCopyPath3="/test/SoftCopy3/frog3.jpg";
private String remoteCopyDir="/test/copyDir/";
private String absoluteLocalFrog;
private String absoluteLocalDog;
private String newFilePath="src/test/resources";
private IClient client;
private String serviceClass="CopyTest";
private String serviceName="StorageManager";
private String newFilePath2;
private long frogSize;
private long dogSize;
private static String absoluteLocalFrog;
private static String absoluteLocalDog;
private static String newFilePath="src/test/resources";
private static IClient client;
private static String serviceClass="CopyTest";
private static String serviceName="StorageManager";
private static String newFilePath2;
private static long frogSize;
private static long dogSize;
@Before
public void getClient() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
@BeforeClass
public static void getClient() throws RemoteBackendException{
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
@ -272,7 +273,7 @@ public class SoftCopyTest {
}
private void setLocalResources() {
private static void setLocalResources() {
File f1=new File(localFrog);
absoluteLocalFrog=f1.getAbsolutePath();
frogSize=f1.length();

View File

@ -10,7 +10,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
@ -20,25 +20,26 @@ import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class UploadsTest {
private String owner="rcirillo";
private String localPath="src/test/resources/CostaRica.jpg";//"src/test/resources/empty.txt";//"src/test/resources/CostaRica1.jpg";
private String localPath1="src/test/resources/CostaRica1.jpg";
private static String owner="rcirillo";
private static String localPath="src/test/resources/CostaRica.jpg";//"src/test/resources/empty.txt";//"src/test/resources/CostaRica1.jpg";
private static String localPath1="src/test/resources/CostaRica1.jpg";
private String remotePath="/tests/img/tabulardatadump.tar.gz";//"/tests/img/CostaRica1.jpg";//"/tests/img/empty.txt";//
private String absoluteLocalPath;
private String absoluteLocalPath1;
private static String absoluteLocalPath;
private static String absoluteLocalPath1;
// private String newFilePath="src/test/resources";
private IClient client;
private static IClient client;
// private String scope="/gcube";//"/d4science.research-infrastructures.eu"; //"/d4science.research-infrastructures.eu"; //"/gcube/devsec";//"/d4science.research-infrastructures.eu"; //"/CNR.it";////"/gcube/devsec";//""/CNR.it/ISTI";//"/gcube";//"/gcube/devNext/NextNext";//
private String serviceClass="JUnitTest";
private String serviceName="StorageManager";
private static String serviceClass="JUnitTest";
private static String serviceName="StorageManager";
@Before
public void getClient(){
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
@BeforeClass
public static void getClient(){
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client=new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
assertNotNull(client);
@ -136,10 +137,12 @@ public class UploadsTest {
private void setLocalResources() {
private static void setLocalResources() {
absoluteLocalPath=new File(localPath).getAbsolutePath();
String dir=new File(absoluteLocalPath).getParent();
absoluteLocalPath1=new File(localPath1).getAbsolutePath();
String dir1=new File(absoluteLocalPath1).getParent();
}
}

View File

@ -10,14 +10,12 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.model.protocol.smp.Handler;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
@ -45,7 +43,7 @@ public class UrlResolverByIdTest {
@Before
public void init() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client = new StorageClient(serviceClass, serviceName, owner , AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
} catch (Exception e) {
@ -58,116 +56,48 @@ public class UrlResolverByIdTest {
}
// @Test
public void getUrlbyIdNotPaylloadCheck() throws RemoteBackendException {
String url=client.getUrl(true).RFile(remotePath);
System.out.println("url generated: "+url);
assertNotNull(url);
id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
System.out.println("id retrieved: "+id);
client.moveFile().from(remotePath).to(newPath);
verifyUrl(url);
}
@Test
public void getUrlbyId() throws RemoteBackendException {
public void getHttpsbyId() throws RemoteBackendException {
// id="5aa16dfe02cadc50bff0eaf1";//"5aa16dfe02cadc50bff0eaf7";//"5a0c1cddf1d47d0c2fea0c1c";//"5a0c1cddf1d47d0c2fea0c1c";//"5a056737f1d47d0c2fe1ccb8";//"5a048c4cf1d47d0c2fe10537";//client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
String url=client.getHttpUrl(true).RFile(id);
// String url=client.getUrl().RFileById(id);
System.out.println("httpUrl generated: "+url);
String url=client.getHttpsUrl(true).RFile(id);
System.out.println("httpsUrl generated: "+url);
assertNotNull(url);
// id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
// System.out.println("id retrieved: "+id);
// client.moveFile().from(remotePath).to(newPath);
// verifyUrl(url);
}
// @Test
// public void getUrlbyId() throws RemoteBackendException {
//// id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
// String url=client.getHttpUrl().RFileById("5aa16dfe02cadc50bff0eaf7");
// System.out.println("url generated: "+url);
// assertNotNull(url);
//// url=url+"-VLT";
// System.out.println("id retrieved: "+id);
// client.moveFile().from(remotePath).to(newPath);
// verifyUrl(url);
// }
@Test
public void getUrlbyPath() throws RemoteBackendException {
id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
String url=client.getUrl(true).RFile(remotePath);
String url=client.getHttpsUrl(true).RFile(remotePath);
System.out.println("url generated: "+url);
assertNotNull(url);
System.out.println("id retrieved: "+id);
client.moveFile().from(remotePath).to(newPath);
verifyUrl(url);
client.moveFile().from(newPath).to(remotePath);
}
@Test
public void getFilebyEncryptedId() throws RemoteBackendException {
id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
String url=client.getUrl(true).RFile(remotePath);
String url=client.getHttpsUrl(true).RFile(remotePath);
System.out.println("url generated: "+url);
assertNotNull(url);
String idEncrypted=url.substring(url.lastIndexOf(".org/")+5);
System.out.println("id encrypted: "+id);
client.get().RFileAsInputStream(remotePath);
client.moveFile().from(remotePath).to(newPath);
verifyUrl(url);
client.moveFile().from(newPath).to(remotePath);
}
/**
* download the file and verify if the file exist
* @param url
*/
private void verifyUrl(String url) {
Handler.activateProtocol();
URL smsHome = null;
try {
smsHome = new URL(url);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
URLConnection uc = null;
File f=null;
try {
uc = ( URLConnection ) smsHome.openConnection ( );
InputStream is=uc.getInputStream();
f=new File(localNewPath);
FileOutputStream out=new FileOutputStream(f);
byte buf[]=new byte[1024];
int len=0;
System.out.println("InputStream "+is);
while((len=is.read(buf))>0){
out.write(buf,0,len);
}
out.close();
is.close();
}catch(Exception e ){
e.printStackTrace();
assertTrue(false);
}
assertTrue(f.exists());
}
@After
public void removeRemoteFile() throws RemoteBackendException{
String id=client.remove().RFile(remotePath);
List<StorageObject> list=client.showDir().RDir("Uritest/img");
assertTrue(list.isEmpty());
// String id2=client.remove().RFile(newPath);
// List<StorageObject> list2=client.showDir().RDir("Uritest/img5");
// assertTrue(list.isEmpty());
removeLocalFiles();
}

View File

@ -1,19 +1,14 @@
package org.gcube.contentmanager.storageclient.test;
import static org.junit.Assert.*;
import java.io.File;
import java.util.List;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.contentmanagement.blobstorage.resource.StorageObject;
import org.gcube.common.security.providers.SecretManagerProvider;
import org.gcube.contentmanagement.blobstorage.service.IClient;
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@ -31,7 +26,7 @@ public class UrlResolverTest {
@Before
public void init() throws RemoteBackendException{
ScopeProvider.instance.set(Costants.DEFAULT_SCOPE_STRING);
SecretManagerProvider.set(new ICSecret(Costants.DEFAULT_SCOPE_STRING));
try {
client = new StorageClient(serviceClass, serviceName, owner , AccessType.SHARED, Costants.DEFAULT_MEMORY_TYPE).getClient();
} catch (Exception e) {
@ -41,17 +36,11 @@ public class UrlResolverTest {
setLocalResources();
String id=client.put(true).LFile(absoluteLocalPath).RFile(remotePath);
}
@Test
public void getUrl() throws RemoteBackendException {
String url=client.getUrl().RFile(remotePath);
System.out.println("url generated: "+url);
}
@Test
public void getHttpUrl() throws RemoteBackendException {
String url=client.getHttpUrl().RFile(remotePath);
public void getHttpsUrl() throws RemoteBackendException {
String url=client.getHttpsUrl().RFile(remotePath);
System.out.println("HttpUrl generated: "+url);
}

View File

@ -1,26 +0,0 @@
package org.gcube.contentmanager.storageclient.test;
import static org.junit.Assert.*;
import org.gcube.common.scope.impl.ServiceMapScannerMediator;
import org.gcube.contentmanager.storageclient.test.utils.Costants;
import org.junit.BeforeClass;
import org.junit.Test;
public class scopeValidationTest {
static ServiceMapScannerMediator scanner;
// String scope="/gcube";
@BeforeClass
public static void init(){
scanner=new ServiceMapScannerMediator();
}
@Test
public void test() {
assertTrue(scanner.isValid(Costants.DEFAULT_SCOPE_STRING));
}
}

View File

@ -4,6 +4,7 @@
package org.gcube.contentmanager.storageclient.test.utils;
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
@ -14,7 +15,8 @@ import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
public final class Costants {
public static final MemoryType DEFAULT_MEMORY_TYPE = MemoryType.PERSISTENT;
public static final String DEFAULT_SCOPE_STRING="/gcube";
public static final String DEFAULT_SCOPE_STRING="/gcube/devsec/devVRE";//"/gcube/devNext/NextNext";//"/gcube/devsec/devVRE";
public static final String DEFAULT_PASS_PHRASE="this is a phrasethis is a phrase";
public static final BackendType BACKEND_TYPE=BackendType.MongoDB;
}