moved sotorage constant names

This commit is contained in:
lucio 2024-08-16 15:50:42 +02:00
parent 4955cdcad6
commit e36f4eb776
8 changed files with 50 additions and 44 deletions

View File

@ -40,4 +40,5 @@ public class Constants {
public static final String ADMIN_USER ="admin"; public static final String ADMIN_USER ="admin";
public static final SimpleCredentials JCR_CREDENTIALS = new SimpleCredentials(ADMIN_USER,"admin".toCharArray()); public static final SimpleCredentials JCR_CREDENTIALS = new SimpleCredentials(ADMIN_USER,"admin".toCharArray());
} }

View File

@ -8,17 +8,12 @@ import java.util.Map;
import java.util.zip.Deflater; import java.util.zip.Deflater;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import javax.jcr.Node; import javax.jcr.Node;
import javax.jcr.RepositoryException; import javax.jcr.RepositoryException;
import javax.jcr.Session; import javax.jcr.Session;
import javax.jcr.version.Version; import javax.jcr.version.Version;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.StreamingOutput;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.gcube.common.storagehub.model.Constants;
import org.gcube.common.storagehub.model.Excludes; import org.gcube.common.storagehub.model.Excludes;
import org.gcube.common.storagehub.model.Paths; import org.gcube.common.storagehub.model.Paths;
import org.gcube.common.storagehub.model.exceptions.InvalidItemException; import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
@ -33,6 +28,7 @@ import org.gcube.common.storagehub.model.items.nodes.Content;
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend; import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
import org.gcube.common.storagehub.model.storages.StorageBackend; import org.gcube.common.storagehub.model.storages.StorageBackend;
import org.gcube.common.storagehub.model.storages.StorageBackendFactory; import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
import org.gcube.common.storagehub.model.storages.StorageNames;
import org.gcube.data.access.storagehub.SingleFileStreamingOutput; import org.gcube.data.access.storagehub.SingleFileStreamingOutput;
import org.gcube.data.access.storagehub.accounting.AccountingHandler; import org.gcube.data.access.storagehub.accounting.AccountingHandler;
import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter; import org.gcube.data.access.storagehub.handlers.items.Node2ItemConverter;
@ -40,6 +36,11 @@ import org.gcube.data.access.storagehub.handlers.plugins.StorageBackendHandler;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.StreamingOutput;
@Singleton @Singleton
public class DownloadHandler { public class DownloadHandler {
@ -147,9 +148,9 @@ public class DownloadHandler {
streamToWrite = sb.download(content); streamToWrite = sb.download(content);
}catch (StorageIdNotFoundException e) { }catch (StorageIdNotFoundException e) {
//TODO: temporary code, it will last until the MINIO porting will not finish //TODO: temporary code, it will last until the MINIO porting will not finish
if (sbf.getName().equals(Constants.MONGO_STORAGE)) { if (sbf.getName().equals(StorageNames.MONGO_STORAGE)) {
sbf = storageBackendHandler.get(Constants.DEFAULT_S3_STORAGE); sbf = storageBackendHandler.get(StorageNames.DEFAULT_S3_STORAGE);
sbf.create(new PayloadBackend(Constants.DEFAULT_S3_STORAGE, null)); sbf.create(new PayloadBackend(StorageNames.DEFAULT_S3_STORAGE, null));
} else } else
throw e; throw e;
} }

View File

@ -4,35 +4,35 @@ import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.gcube.common.storagehub.model.exceptions.PluginNotFoundException;
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
import org.gcube.common.storagehub.model.storages.StorageNames;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import jakarta.enterprise.inject.Instance; import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.inject.Singleton; import jakarta.inject.Singleton;
import org.gcube.common.storagehub.model.Constants;
import org.gcube.common.storagehub.model.exceptions.PluginNotFoundException;
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Singleton @Singleton
public class StorageBackendHandler { public class StorageBackendHandler {
private static Logger log = LoggerFactory.getLogger(StorageBackendHandler.class); private static Logger log = LoggerFactory.getLogger(StorageBackendHandler.class);
public static PayloadBackend getDefaultPayloadForFolder() { public static PayloadBackend getDefaultPayloadForFolder() {
return new PayloadBackend(Constants.DEFAULT_S3_STORAGE, null); return new PayloadBackend(StorageNames.DEFAULT_S3_STORAGE, null);
} }
@Inject @Inject
Instance<StorageBackendFactory> factories; Instance<StorageBackendFactory> factories;
Map<String, StorageBackendFactory> storagebackendMap= new HashMap<String, StorageBackendFactory>(); Map<String, StorageBackendFactory> storagebackendMap = new HashMap<String, StorageBackendFactory>();
@PostConstruct @PostConstruct
void init(){ void init() {
if (factories !=null) if (factories != null)
for (StorageBackendFactory connector : factories) { for (StorageBackendFactory connector : factories) {
if (storagebackendMap.containsKey(connector.getName())) { if (storagebackendMap.containsKey(connector.getName())) {
log.error("multiple storage backend with the same name"); log.error("multiple storage backend with the same name");
@ -46,7 +46,8 @@ public class StorageBackendHandler {
public StorageBackendFactory get(PayloadBackend payload) throws PluginNotFoundException { public StorageBackendFactory get(PayloadBackend payload) throws PluginNotFoundException {
if (payload == null || !storagebackendMap.containsKey(payload.getStorageName())) if (payload == null || !storagebackendMap.containsKey(payload.getStorageName()))
throw new PluginNotFoundException(String.format("implementation for storage %s not found", payload.getStorageName())); throw new PluginNotFoundException(
String.format("implementation for storage %s not found", payload.getStorageName()));
return storagebackendMap.get(payload.getStorageName()); return storagebackendMap.get(payload.getStorageName());
} }

View File

@ -34,6 +34,7 @@ import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
import org.gcube.common.storagehub.model.exceptions.NotFoundException; import org.gcube.common.storagehub.model.exceptions.NotFoundException;
import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.exceptions.StorageHubException;
import org.gcube.common.storagehub.model.items.Item; import org.gcube.common.storagehub.model.items.Item;
import org.gcube.common.storagehub.model.storages.StorageNames;
import org.gcube.common.storagehub.model.types.NodeProperty; import org.gcube.common.storagehub.model.types.NodeProperty;
import org.gcube.common.storagehub.model.types.PrimaryNodeType; import org.gcube.common.storagehub.model.types.PrimaryNodeType;
import org.gcube.data.access.storagehub.Constants; import org.gcube.data.access.storagehub.Constants;
@ -327,8 +328,8 @@ public class GroupManagerDelegate {
FolderCreationParameters folderParameters; FolderCreationParameters folderParameters;
if (!useDefaultStorage) if (!useDefaultStorage)
folderParameters = FolderCreationParameters.builder().onRepository("gcube-minio") folderParameters = FolderCreationParameters.builder().onRepository(StorageNames.GCUBE_STORAGE)
.withParameters(Collections.singletonMap("bucketName", name + "-gcube-vre")).name(name) .withParameters(Collections.singletonMap("bucketName", name.toLowerCase() + "-gcube-vre")).name(name)
.description("VREFolder for " + groupId).author(owner).on(sharedRootNode.getIdentifier()) .description("VREFolder for " + groupId).author(owner).on(sharedRootNode.getIdentifier())
.with(session).build(); .with(session).build();
else else

View File

@ -1,19 +1,19 @@
package org.gcube.data.access.storagehub.storage.backend.impl; package org.gcube.data.access.storagehub.storage.backend.impl;
import jakarta.inject.Singleton;
import org.gcube.common.storagehub.model.Constants;
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters; import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend; import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
import org.gcube.common.storagehub.model.storages.StorageBackend; import org.gcube.common.storagehub.model.storages.StorageBackend;
import org.gcube.common.storagehub.model.storages.StorageBackendFactory; import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
import org.gcube.common.storagehub.model.storages.StorageNames;
import jakarta.inject.Singleton;
@Singleton @Singleton
public class GCubeMongoStorageBackendFactory implements StorageBackendFactory { public class GCubeMongoStorageBackendFactory implements StorageBackendFactory {
@Override @Override
public String getName() { public String getName() {
return Constants.MONGO_STORAGE; return StorageNames.MONGO_STORAGE;
} }
@Override @Override

View File

@ -9,18 +9,18 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.UUID; import java.util.UUID;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;
import org.gcube.common.storagehub.model.Constants;
import org.gcube.common.storagehub.model.Metadata; import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters; import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend; import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
import org.gcube.common.storagehub.model.storages.StorageBackend; import org.gcube.common.storagehub.model.storages.StorageBackend;
import org.gcube.common.storagehub.model.storages.StorageBackendFactory; import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
import org.gcube.common.storagehub.model.storages.StorageNames;
import org.gcube.smartgears.ContextProvider; import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.application.ApplicationContext;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;
@Singleton @Singleton
public class GcubeDefaultS3StorageBackendFactory implements StorageBackendFactory { public class GcubeDefaultS3StorageBackendFactory implements StorageBackendFactory {
@ -37,7 +37,7 @@ public class GcubeDefaultS3StorageBackendFactory implements StorageBackendFactor
@Override @Override
public String getName() { public String getName() {
return Constants.DEFAULT_S3_STORAGE; return StorageNames.DEFAULT_S3_STORAGE;
} }
@Override @Override

View File

@ -9,17 +9,18 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.UUID; import java.util.UUID;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;
import org.gcube.common.storagehub.model.Metadata; import org.gcube.common.storagehub.model.Metadata;
import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters; import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters;
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend; import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
import org.gcube.common.storagehub.model.storages.StorageBackend; import org.gcube.common.storagehub.model.storages.StorageBackend;
import org.gcube.common.storagehub.model.storages.StorageBackendFactory; import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
import org.gcube.common.storagehub.model.storages.StorageNames;
import org.gcube.smartgears.ContextProvider; import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.application.ApplicationContext;
import jakarta.annotation.PostConstruct;
import jakarta.inject.Singleton;
@Singleton @Singleton
public class GcubeS3StorageBackendFactory implements StorageBackendFactory { public class GcubeS3StorageBackendFactory implements StorageBackendFactory {
@ -34,7 +35,7 @@ public class GcubeS3StorageBackendFactory implements StorageBackendFactory {
@Override @Override
public String getName() { public String getName() {
return "gcube-s3"; return StorageNames.GCUBE_STORAGE;
} }
@Override @Override

View File

@ -21,6 +21,7 @@ import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration; import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.transfer.TransferManager; import com.amazonaws.services.s3.transfer.TransferManager;
import com.amazonaws.services.s3.transfer.TransferManagerBuilder; import com.amazonaws.services.s3.transfer.TransferManagerBuilder;
@ -70,7 +71,7 @@ public class S3Backend extends StorageBackend{
log.debug("creating {} bucket",this.bucketName); log.debug("creating {} bucket",this.bucketName);
client.createBucket(bucketName); client.createBucket(bucketName);
log.debug("bucket {} created",this.bucketName); log.debug("bucket {} created",this.bucketName);
} } else log.debug("bucket not created");
} catch (Exception e) { } catch (Exception e) {
log.error("error initializing s3",e); log.error("error initializing s3",e);