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 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.ZipOutputStream;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
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.gcube.common.storagehub.model.Constants;
import org.gcube.common.storagehub.model.Excludes;
import org.gcube.common.storagehub.model.Paths;
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.storages.StorageBackend;
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.accounting.AccountingHandler;
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.LoggerFactory;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.StreamingOutput;
@Singleton
public class DownloadHandler {
@ -147,9 +148,9 @@ public class DownloadHandler {
streamToWrite = sb.download(content);
}catch (StorageIdNotFoundException e) {
//TODO: temporary code, it will last until the MINIO porting will not finish
if (sbf.getName().equals(Constants.MONGO_STORAGE)) {
sbf = storageBackendHandler.get(Constants.DEFAULT_S3_STORAGE);
sbf.create(new PayloadBackend(Constants.DEFAULT_S3_STORAGE, null));
if (sbf.getName().equals(StorageNames.MONGO_STORAGE)) {
sbf = storageBackendHandler.get(StorageNames.DEFAULT_S3_STORAGE);
sbf.create(new PayloadBackend(StorageNames.DEFAULT_S3_STORAGE, null));
} else
throw e;
}

View File

@ -4,35 +4,35 @@ import java.util.Collection;
import java.util.HashMap;
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.enterprise.inject.Instance;
import jakarta.inject.Inject;
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
public class StorageBackendHandler {
private static Logger log = LoggerFactory.getLogger(StorageBackendHandler.class);
public static PayloadBackend getDefaultPayloadForFolder() {
return new PayloadBackend(Constants.DEFAULT_S3_STORAGE, null);
return new PayloadBackend(StorageNames.DEFAULT_S3_STORAGE, null);
}
@Inject
Instance<StorageBackendFactory> factories;
Map<String, StorageBackendFactory> storagebackendMap= new HashMap<String, StorageBackendFactory>();
Map<String, StorageBackendFactory> storagebackendMap = new HashMap<String, StorageBackendFactory>();
@PostConstruct
void init(){
if (factories !=null)
void init() {
if (factories != null)
for (StorageBackendFactory connector : factories) {
if (storagebackendMap.containsKey(connector.getName())) {
log.error("multiple storage backend with the same name");
@ -46,7 +46,8 @@ public class StorageBackendHandler {
public StorageBackendFactory get(PayloadBackend payload) throws PluginNotFoundException {
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());
}

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.StorageHubException;
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.PrimaryNodeType;
import org.gcube.data.access.storagehub.Constants;
@ -327,8 +328,8 @@ public class GroupManagerDelegate {
FolderCreationParameters folderParameters;
if (!useDefaultStorage)
folderParameters = FolderCreationParameters.builder().onRepository("gcube-minio")
.withParameters(Collections.singletonMap("bucketName", name + "-gcube-vre")).name(name)
folderParameters = FolderCreationParameters.builder().onRepository(StorageNames.GCUBE_STORAGE)
.withParameters(Collections.singletonMap("bucketName", name.toLowerCase() + "-gcube-vre")).name(name)
.description("VREFolder for " + groupId).author(owner).on(sharedRootNode.getIdentifier())
.with(session).build();
else

View File

@ -1,19 +1,19 @@
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.items.nodes.PayloadBackend;
import org.gcube.common.storagehub.model.storages.StorageBackend;
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
import org.gcube.common.storagehub.model.storages.StorageNames;
import jakarta.inject.Singleton;
@Singleton
public class GCubeMongoStorageBackendFactory implements StorageBackendFactory {
@Override
public String getName() {
return Constants.MONGO_STORAGE;
return StorageNames.MONGO_STORAGE;
}
@Override

View File

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

View File

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

View File

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