diff --git a/core/platform-common/pom.xml b/core/platform-common/pom.xml index 90d7add271c4e8e96285eac0619b7500cdb37a4d..92ff7f9491ac0e92eb3d88072fab51717725941b 100644 --- a/core/platform-common/pom.xml +++ b/core/platform-common/pom.xml @@ -193,4 +193,4 @@ <version>20200518</version> </dependency> </dependencies> -</project> \ No newline at end of file +</project> diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/CloudService.java b/core/platform-common/src/main/java/org/sunbird/cloud/CloudService.java deleted file mode 100644 index c6a83da6fe1f2e35b0fff52d233cc6853e9ff8b6..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/CloudService.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sunbird.cloud; - -import java.io.File; -import java.util.List; -import org.sunbird.request.RequestContext; - -/** Created by arvind on 24/8/17. */ -public interface CloudService { - - String uploadFile( - String containerName, String filName, String fileLocation, RequestContext context); - - boolean downLoadFile( - String containerName, String fileName, String downloadFolder, RequestContext context); - - String uploadFile(String containerName, File file, RequestContext context); - - boolean deleteFile(String containerName, String fileName, RequestContext context); - - List<String> listAllFiles(String containerName, RequestContext context); - - boolean deleteContainer(String containerName, RequestContext context); -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/CloudServiceFactory.java b/core/platform-common/src/main/java/org/sunbird/cloud/CloudServiceFactory.java deleted file mode 100644 index 6fb8677870c90d51a52bcee1ee40c8c3566027a3..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/CloudServiceFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.sunbird.cloud; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.sunbird.cloud.aws.AwsCloudService; -import org.sunbird.cloud.azure.AzureCloudService; -import org.sunbird.cloud.gcp.GcpCloudService; - -/** - * Factory class to store the various upload download services like Azure , Amazon S3 etc... Created - * by arvind on 24/8/17. - */ -public class CloudServiceFactory { - - private static final Map<String, CloudService> factory = new HashMap<>(); - private static final List<String> allowedServiceNames = Arrays.asList("azure", "aws", "gcloud"); - - private CloudServiceFactory() {} - - /** - * @param serviceName - * @return - */ - public static Object get(String serviceName) { - - if (null != (factory.get(serviceName))) { - return factory.get(serviceName); - } else { - // create the service with the given name - return createService(serviceName); - } - } - - /** - * @param serviceName - * @return - */ - private static CloudService createService(String serviceName) { - - if (!(allowedServiceNames.contains(serviceName))) { - return null; - } - - synchronized (CloudServiceFactory.class) { - if (null == (factory.get(serviceName)) && "azure".equalsIgnoreCase(serviceName)) { - CloudService service = new AzureCloudService(); - factory.put("azure", service); - } else if (null == (factory.get(serviceName)) && "aws".equalsIgnoreCase(serviceName)) { - CloudService service = new AwsCloudService(); - factory.put("aws", service); - } else if (null == (factory.get(serviceName)) && "gcloud".equalsIgnoreCase(serviceName)) { - CloudService service = new GcpCloudService(); - factory.put("gcloud", service); - } - } - return factory.get(serviceName); - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsCloudService.java b/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsCloudService.java deleted file mode 100644 index 1c9a4ea6571a43b6a8dcbe5c7415c509e08d4937..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsCloudService.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.sunbird.cloud.aws; - -import java.io.File; -import java.util.List; -import org.sunbird.cloud.CloudService; -import org.sunbird.request.RequestContext; - -/** Created by arvind on 24/8/17. */ -public class AwsCloudService implements CloudService { - - @Override - public String uploadFile( - String containerName, String filName, String fileLocation, RequestContext context) { - return null; - } - - @Override - public boolean downLoadFile( - String containerName, String fileName, String downloadFolder, RequestContext context) { - return false; - } - - @Override - public String uploadFile(String containerName, File file, RequestContext context) { - return AwsFileUtility.uploadFile(containerName, file, context); - } - - @Override - public boolean deleteFile(String containerName, String fileName, RequestContext context) { - return false; - } - - @Override - public List<String> listAllFiles(String containerName, RequestContext context) { - return null; - } - - @Override - public boolean deleteContainer(String containerName, RequestContext context) { - return false; - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsConnectionManager.java b/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsConnectionManager.java deleted file mode 100644 index 765dd7dc507e668bb3cce71223ad07b49180a47b..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsConnectionManager.java +++ /dev/null @@ -1,34 +0,0 @@ -/** */ -package org.sunbird.cloud.aws; - -import org.sunbird.cloud.storage.BaseStorageService; -import org.sunbird.cloud.storage.factory.StorageConfig; -import org.sunbird.cloud.storage.factory.StorageServiceFactory; -import org.sunbird.keys.JsonKey; -import org.sunbird.logging.LoggerUtil; - -/** - * This class will manage azure connection. - * - * @author Manzarul - */ -public class AwsConnectionManager { - - private static final LoggerUtil logger = new LoggerUtil(AwsConnectionManager.class); - - private static BaseStorageService storageService = null; - - private AwsConnectionManager() {} - - public static BaseStorageService getStorageService() { - if (null == storageService) { - String accountName = System.getenv(JsonKey.ACCOUNT_NAME); - String accountKey = System.getenv(JsonKey.ACCOUNT_KEY); - - StorageConfig storageConfig = new StorageConfig("aws", accountName, accountKey); - logger.info("StorageParams:init:all storage params initialized for aws block"); - storageService = StorageServiceFactory.getStorageService(storageConfig); - } - return storageService; - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsFileUtility.java b/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsFileUtility.java deleted file mode 100644 index c17c23678bd4e2e915d6326a8b028727221be030..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/aws/AwsFileUtility.java +++ /dev/null @@ -1,48 +0,0 @@ -/** */ -package org.sunbird.cloud.aws; - -import java.io.*; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.logging.LoggerUtil; -import org.sunbird.request.RequestContext; -import scala.Option; - -/** @author Manzarul */ -public class AwsFileUtility { - - private static final LoggerUtil logger = new LoggerUtil(AwsFileUtility.class); - - private static final String DEFAULT_CONTAINER = "default"; - - public static String uploadFile(String containerName, File source, RequestContext context) { - - String containerPath = ""; - String contrName = ""; - - if (StringUtils.isBlank(containerName)) { - contrName = DEFAULT_CONTAINER; - } else { - contrName = containerName.toLowerCase(); - } - if (contrName.startsWith("/")) { - contrName = containerName.substring(1); - } - if (contrName.contains("/")) { - String[] arr = contrName.split("/", 2); - containerPath = arr[0]; - } else { - containerPath = contrName; - } - - String objectKey = containerPath + source.getName(); - return AwsConnectionManager.getStorageService() - .upload( - contrName, - source.getAbsolutePath(), - objectKey, - Option.apply(false), - Option.apply(1), - Option.apply(3), - Option.empty()); - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureCloudService.java b/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureCloudService.java deleted file mode 100644 index a91441308b8513a3bb1052e821719cb5750cc89c..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureCloudService.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.sunbird.cloud.azure; - -import java.io.File; -import java.util.List; -import org.sunbird.cloud.CloudService; -import org.sunbird.request.RequestContext; - -/** Created by arvind on 24/8/17. */ -public class AzureCloudService implements CloudService { - - @Override - public String uploadFile( - String containerName, String fileName, String fileLocation, RequestContext context) { - return AzureFileUtility.uploadFile(containerName, fileName, fileLocation, context); - } - - @Override - public boolean downLoadFile( - String containerName, String fileName, String downloadFolder, RequestContext context) { - return AzureFileUtility.downloadFile(containerName, fileName, downloadFolder, context); - } - - @Override - public String uploadFile(String containerName, File file, RequestContext context) { - return AzureFileUtility.uploadFile(containerName, file, context); - } - - @Override - public boolean deleteFile(String containerName, String fileName, RequestContext context) { - return AzureFileUtility.deleteFile(containerName, fileName, context); - } - - @Override - public List<String> listAllFiles(String containerName, RequestContext context) { - return AzureFileUtility.listAllBlobbs(containerName, context); - } - - @Override - public boolean deleteContainer(String containerName, RequestContext context) { - return AzureFileUtility.deleteContainer(containerName, context); - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureConnectionManager.java b/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureConnectionManager.java deleted file mode 100644 index f4cb3ec3bd0afc7503e2905aa49193538a5e6849..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureConnectionManager.java +++ /dev/null @@ -1,131 +0,0 @@ -/** */ -package org.sunbird.cloud.azure; - -import com.microsoft.azure.storage.CloudStorageAccount; -import com.microsoft.azure.storage.StorageException; -import com.microsoft.azure.storage.blob.BlobContainerPermissions; -import com.microsoft.azure.storage.blob.BlobContainerPublicAccessType; -import com.microsoft.azure.storage.blob.CloudBlobClient; -import com.microsoft.azure.storage.blob.CloudBlobContainer; -import java.net.URISyntaxException; -import java.security.InvalidKeyException; -import java.util.Locale; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.keys.JsonKey; -import org.sunbird.logging.LoggerUtil; -import org.sunbird.util.ProjectUtil; - -/** - * This class will manage azure connection. - * - * @author Manzarul - */ -public class AzureConnectionManager { - - private static final LoggerUtil logger = new LoggerUtil(AzureConnectionManager.class); - private static String accountName = ""; - private static String accountKey = ""; - private static String storageAccountString; - private static AzureConnectionManager connectionManager; - - static { - String name = System.getenv(JsonKey.ACCOUNT_NAME); - String key = System.getenv(JsonKey.ACCOUNT_KEY); - if (StringUtils.isBlank(name) || StringUtils.isBlank(key)) { - logger.info( - "Azure account name and key is not provided by environment variable." + name + " " + key); - accountName = ProjectUtil.getConfigValue(JsonKey.ACCOUNT_NAME); - accountKey = ProjectUtil.getConfigValue(JsonKey.ACCOUNT_KEY); - storageAccountString = - "DefaultEndpointsProtocol=https;AccountName=" - + accountName - + ";AccountKey=" - + accountKey - + ";EndpointSuffix=core.windows.net"; - } else { - accountName = name; - accountKey = key; - logger.info( - "Azure account name and key is provided by environment variable." + name + " " + key); - storageAccountString = - "DefaultEndpointsProtocol=https;AccountName=" - + accountName - + ";AccountKey=" - + accountKey - + ";EndpointSuffix=core.windows.net"; - } - } - - private AzureConnectionManager() throws CloneNotSupportedException { - if (connectionManager != null) throw new CloneNotSupportedException(); - } - - /** - * This method will provide Azure CloudBlobContainer object or in case of error it will provide - * null; - * - * @param containerName String - * @return CloudBlobContainer or null - */ - public static CloudBlobContainer getContainer(String containerName, boolean isPublicAccess) { - - try { - CloudBlobClient cloudBlobClient = getBlobClient(); - // Get a reference to a container , The container name must be lower case - CloudBlobContainer container = - cloudBlobClient.getContainerReference(containerName.toLowerCase(Locale.ENGLISH)); - // Create the container if it does not exist. - boolean response = container.createIfNotExists(); - logger.info("container creation done if not exist==" + response); - // Create a permissions object. - if (isPublicAccess) { - BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); - // Include public access in the permissions object. - containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); - // Set the permissions on the container. - container.uploadPermissions(containerPermissions); - } - return container; - } catch (Exception e) { - logger.error("Exception occurred while fetching container" + e.getMessage(), e); - } - return null; - } - - public static CloudBlobContainer getContainerReference(String containerName) { - - CloudBlobContainer container = null; - try { - // Create the blob client. - CloudBlobClient blobClient = getBlobClient(); - // Retrieve reference to a previously created container. - container = blobClient.getContainerReference(containerName.toLowerCase(Locale.ENGLISH)); - if (container.exists()) { - return container; - } - } catch (URISyntaxException e) { - logger.error("CloudBlobContainer:getContainerReference" + e.getMessage(), e); - } catch (StorageException e) { - logger.error("CloudBlobContainer:getContainerReference" + e.getMessage(), e); - } - logger.info("Container does not exist ==" + containerName); - return null; - } - - private static CloudBlobClient getBlobClient() { - - // Retrieve storage account from connection-string. - CloudStorageAccount storageAccount = null; - CloudBlobClient blobClient = null; - try { - storageAccount = CloudStorageAccount.parse(storageAccountString); - // Create the blob client. - blobClient = storageAccount.createCloudBlobClient(); - } catch (URISyntaxException e) { - logger.error("CloudBlobClient:getBlobClient" + e.getMessage(), e); - } catch (InvalidKeyException e) { - logger.error("CloudBlobClient:getBlobClient" + e.getMessage(), e); - } - return blobClient; - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureFileUtility.java b/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureFileUtility.java deleted file mode 100644 index cc43c3d8fa720633123c58467561ff65842c6ce9..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/azure/AzureFileUtility.java +++ /dev/null @@ -1,239 +0,0 @@ -/** */ -package org.sunbird.cloud.azure; - -import com.microsoft.azure.storage.StorageException; -import com.microsoft.azure.storage.blob.CloudBlobContainer; -import com.microsoft.azure.storage.blob.CloudBlockBlob; -import com.microsoft.azure.storage.blob.ListBlobItem; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.apache.tika.Tika; -import org.sunbird.logging.LoggerUtil; -import org.sunbird.request.RequestContext; - -/** @author Manzarul */ -public class AzureFileUtility { - - private static final LoggerUtil logger = new LoggerUtil(AzureFileUtility.class); - - private static final String DEFAULT_CONTAINER = "default"; - - /** - * This method will remove the file from Azure Storage. - * - * @param containerName - * @param fileName - * @param context - * @return boolean - */ - public static boolean deleteFile(String containerName, String fileName, RequestContext context) { - if (fileName == null) { - logger.info(context, "File name can not be null"); - return false; - } - if (StringUtils.isBlank(containerName)) { - logger.info(context, "Container name can't be null or empty"); - return false; - } - CloudBlobContainer container = AzureConnectionManager.getContainer(containerName, true); - if (container == null) { - logger.info(context, "Unable to get Azure contains object"); - return false; - } - try { - // Retrieve reference to a blob named "myimage.jpg". - CloudBlockBlob blob = container.getBlockBlobReference(fileName); - // Delete the blob. - boolean response = blob.deleteIfExists(); - if (!response) { - logger.info(context, "Provided file not found to delete."); - } - return true; - } catch (Exception e) { - logger.error(context, e.getMessage(), e); - } - return false; - } - - /** - * This method will remove the container from Azure Storage. - * - * @param containerName - * @param context - * @return boolean - */ - public static boolean deleteContainer(String containerName, RequestContext context) { - if (StringUtils.isBlank(containerName)) { - logger.info(context, "Container name can't be null or empty"); - return false; - } - CloudBlobContainer container = AzureConnectionManager.getContainer(containerName, true); - if (container == null) { - logger.info(context, "Unable to get Azure contains object"); - return false; - } - try { - boolean response = container.deleteIfExists(); - if (!response) { - logger.info(context, "Container not found.."); - } else { - logger.info(context, "Container is deleted==="); - } - return true; - } catch (Exception e) { - logger.error(context, e.getMessage(), e); - } - return false; - } - - public static String uploadFile( - String containerName, String blobName, String fileName, RequestContext context) { - - CloudBlobContainer container = AzureConnectionManager.getContainer(containerName, true); - // Create or overwrite the "myimage.jpg" blob with contents from a local file. - CloudBlockBlob blob = null; - String fileUrl = null; - FileInputStream fis = null; - Tika tika = new Tika(); - try { - blob = container.getBlockBlobReference(blobName); - File source = new File(fileName); - fis = new FileInputStream(source); - String mimeType = tika.detect(source); - logger.info(context, "File - " + source.getName() + " mimeType " + mimeType); - blob.getProperties().setContentType(mimeType); - blob.upload(fis, source.length()); - // fileUrl = blob.getStorageUri().getPrimaryUri().getPath(); - fileUrl = blob.getUri().toString(); - } catch (URISyntaxException | IOException e) { - logger.error(context, "Unable to upload file :" + fileName, e); - } catch (Exception e) { - logger.error(context, "Unable to upload file :" + e.getMessage(), e); - } finally { - if (null != fis) { - try { - fis.close(); - } catch (IOException e) { - logger.error(context, e.getMessage(), e); - } - } - } - - return fileUrl; - } - - public static String uploadFile(String containerName, File source, RequestContext context) { - - String containerPath = ""; - String filePath = ""; - Tika tika = new Tika(); - String contrName = containerName; - - if (StringUtils.isBlank(containerName)) { - contrName = DEFAULT_CONTAINER; - } else { - contrName = containerName.toLowerCase(); - } - if (contrName.startsWith("/")) { - contrName = containerName.substring(1); - } - if (contrName.contains("/")) { - String[] arr = contrName.split("/", 2); - containerPath = arr[0]; - if (arr[1].length() > 0 && arr[1].endsWith("/")) { - filePath = arr[1]; - } else if (arr[1].length() > 0) { - filePath = arr[1] + "/"; - } - } else { - containerPath = contrName; - } - - CloudBlobContainer container = AzureConnectionManager.getContainer(containerPath, true); - // Create or overwrite the "myimage.jpg" blob with contents from a local file. - CloudBlockBlob blob = null; - String fileUrl = null; - FileInputStream fis = null; - try { - blob = container.getBlockBlobReference(filePath + source.getName()); - // File source = new File(fileName); - fis = new FileInputStream(source); - String mimeType = tika.detect(source); - logger.info(context, "File - " + source.getName() + " mimeType " + mimeType); - blob.getProperties().setContentType(mimeType); - blob.upload(fis, source.length()); - // fileUrl = blob.getStorageUri().getPrimaryUri().getPath(); - fileUrl = blob.getUri().toString(); - } catch (URISyntaxException | IOException e) { - logger.error(context, "Unable to upload file :" + source.getName(), e); - } catch (Exception e) { - logger.error(context, e.getMessage(), e); - } finally { - if (null != fis) { - try { - fis.close(); - } catch (IOException e) { - logger.error(context, e.getMessage(), e); - } - } - } - return fileUrl; - } - - public static boolean downloadFile( - String containerName, String blobName, String downloadFolder, RequestContext context) { - - String dwnldFolder = ""; - boolean flag = false; - CloudBlobContainer container = AzureConnectionManager.getContainer(containerName, true); - // Create or overwrite blob with contents . - CloudBlockBlob blob = null; - FileOutputStream fos = null; - - try { - blob = container.getBlockBlobReference(blobName); - if (blob.exists()) { - if (!(downloadFolder.endsWith(("/")))) { - dwnldFolder = downloadFolder + "/"; - } - File file = new File(dwnldFolder + blobName); - fos = new FileOutputStream(file); - blob.download(fos); - } - } catch (URISyntaxException | StorageException | FileNotFoundException e) { - logger.error(context, "Unable to upload blobfile :" + blobName, e); - } catch (Exception e) { - logger.error(context, e.getMessage(), e); - } finally { - if (null != fos) { - try { - fos.close(); - } catch (IOException e) { - logger.error(context, e.getMessage(), e); - } - } - } - return flag; - } - - public static List<String> listAllBlobbs(String containerName, RequestContext context) { - - List<String> blobsList = new ArrayList<>(); - CloudBlobContainer container = AzureConnectionManager.getContainer(containerName, true); - // Loop over blobs within the container and output the URI to each of them. - logger.info(context, "get all blobs details"); - if (container != null) { - for (ListBlobItem blobItem : container.listBlobs()) { - blobsList.add(blobItem.getUri().toString()); - } - } - return blobsList; - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpCloudService.java b/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpCloudService.java deleted file mode 100644 index 41b449154601a0964e3922307a42e25d2af59516..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpCloudService.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.sunbird.cloud.gcp; - -import java.io.File; -import java.util.List; -import org.sunbird.cloud.CloudService; -import org.sunbird.request.RequestContext; - -/** Created by arvind on 24/8/17. */ -public class GcpCloudService implements CloudService { - - @Override - public String uploadFile( - String containerName, String filName, String fileLocation, RequestContext context) { - return null; - } - - @Override - public boolean downLoadFile( - String containerName, String fileName, String downloadFolder, RequestContext context) { - return false; - } - - @Override - public String uploadFile(String containerName, File file, RequestContext context) { - return GcpFileUtility.uploadFile(containerName, file, context); - } - - @Override - public boolean deleteFile(String containerName, String fileName, RequestContext context) { - return false; - } - - @Override - public List<String> listAllFiles(String containerName, RequestContext context) { - return null; - } - - @Override - public boolean deleteContainer(String containerName, RequestContext context) { - return false; - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpConnectionManager.java b/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpConnectionManager.java deleted file mode 100644 index ee8621025f3e3515a848d4606b3498deb1164930..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpConnectionManager.java +++ /dev/null @@ -1,33 +0,0 @@ -/** */ -package org.sunbird.cloud.gcp; - -import org.sunbird.cloud.storage.BaseStorageService; -import org.sunbird.cloud.storage.factory.StorageConfig; -import org.sunbird.cloud.storage.factory.StorageServiceFactory; -import org.sunbird.keys.JsonKey; -import org.sunbird.logging.LoggerUtil; - -/** - * This class will manage azure connection. - * - * @author Manzarul - */ -public class GcpConnectionManager { - - private static final LoggerUtil logger = new LoggerUtil(GcpConnectionManager.class); - - private static BaseStorageService storageService = null; - - private GcpConnectionManager() {} - - public static BaseStorageService getStorageService() { - if (null == storageService) { - String accountName = System.getenv(JsonKey.ACCOUNT_NAME); - String accountKey = System.getenv(JsonKey.ACCOUNT_KEY); - StorageConfig storageConfig = new StorageConfig("gcloud", accountName, accountKey); - logger.info("StorageParams:init:all storage params initialized for gcp block"); - storageService = StorageServiceFactory.getStorageService(storageConfig); - } - return storageService; - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpFileUtility.java b/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpFileUtility.java deleted file mode 100644 index 71c89290bafee100db7545221bf7302ea656cab6..0000000000000000000000000000000000000000 --- a/core/platform-common/src/main/java/org/sunbird/cloud/gcp/GcpFileUtility.java +++ /dev/null @@ -1,50 +0,0 @@ -/** */ -package org.sunbird.cloud.gcp; - -import java.io.File; -import org.apache.commons.lang3.StringUtils; -import org.sunbird.logging.LoggerUtil; -import org.sunbird.request.RequestContext; -import scala.Option; - -/** @author Manzarul */ -public class GcpFileUtility { - - private static final LoggerUtil logger = new LoggerUtil(GcpFileUtility.class); - - private static final String DEFAULT_CONTAINER = "default"; - - public static String uploadFile(String containerName, File source, RequestContext context) { - - String containerPath = ""; - String contrName = ""; - - if (StringUtils.isBlank(containerName)) { - contrName = DEFAULT_CONTAINER; - } else { - contrName = containerName.toLowerCase(); - } - if (contrName.startsWith("/")) { - contrName = containerName.substring(1); - } - if (contrName.contains("/")) { - String[] arr = contrName.split("/", 2); - containerPath = arr[0]; - } else { - containerPath = contrName; - } - - String objectKey = containerPath + source.getName(); - // upload(container, file, objectKey, isDirectory , attempt , retryCount , ttl ) - - return GcpConnectionManager.getStorageService() - .upload( - contrName, - source.getAbsolutePath(), - objectKey, - Option.apply(false), - Option.apply(1), - Option.apply(3), - Option.empty()); - } -} diff --git a/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java b/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java index a197c7f4cd650ba3bed510185268866fa10282f9..c9b7fa84f083f28a6866f791321afb960b261090 100644 --- a/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java +++ b/core/platform-common/src/main/java/org/sunbird/keys/JsonKey.java @@ -635,8 +635,6 @@ public final class JsonKey { public static final String DISABLE_MULTIPLE_ORG_ROLE = "sunbird_disable_multiple_org_role"; public static final String PASSWORD_RESET_LOGIN_PAGE_URL = "sunbird_password_reset_login_page_url"; - public static final String CLOUD_SERVICE_PROVIDER = "sunbird_cloud_service_provider"; - private JsonKey() {} } diff --git a/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java b/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java index a3dd1a82173af716ddd17a1099c0b376df8040eb..dceb38ff75bc73513b2daa058b3328728ee31aee 100644 --- a/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java +++ b/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java @@ -5,44 +5,15 @@ import java.util.Map; import org.sunbird.cloud.storage.IStorageService; import org.sunbird.cloud.storage.factory.StorageConfig; import org.sunbird.cloud.storage.factory.StorageServiceFactory; -import org.sunbird.exception.ProjectCommonException; -import org.sunbird.exception.ResponseCode; import org.sunbird.keys.JsonKey; import scala.Option; import scala.Some; public class CloudStorageUtil { private static final int STORAGE_SERVICE_API_RETRY_COUNT = 3; - private static final Map<String, IStorageService> storageServiceMap = new HashMap<>(); - - public enum CloudStorageType { - AZURE("azure"); - private String type; - - private CloudStorageType(String type) { - this.type = type; - } - - public String getType() { - return this.type; - } - - public static CloudStorageType getByName(String type) { - if (AZURE.type.equals(type)) { - return CloudStorageType.AZURE; - } else { - ProjectCommonException.throwClientErrorException( - ResponseCode.errorUnsupportedCloudStorage, - ProjectUtil.formatMessage( - ResponseCode.errorUnsupportedCloudStorage.getErrorMessage(), type)); - return null; - } - } - } - public static String upload( - CloudStorageType storageType, String container, String objectKey, String filePath) { + String storageType, String container, String objectKey, String filePath) { IStorageService storageService = getStorageService(storageType); @@ -57,20 +28,13 @@ public class CloudStorageUtil { } public static String getSignedUrl( - CloudStorageType storageType, String container, String objectKey) { + String storageType, String container, String objectKey) { IStorageService storageService = getStorageService(storageType); - return getSignedUrl(storageService, storageType, container, objectKey); - } - - public static String getAnalyticsSignedUrl( - CloudStorageType storageType, String container, String objectKey) { - IStorageService analyticsStorageService = getAnalyticsStorageService(storageType); - return getSignedUrl(analyticsStorageService, storageType, container, objectKey); + return getSignedUrl(storageService, container, objectKey); } public static String getSignedUrl( IStorageService storageService, - CloudStorageType storageType, String container, String objectKey) { int timeoutInSeconds = getTimeoutInSeconds(); @@ -78,27 +42,21 @@ public class CloudStorageUtil { container, objectKey, Some.apply(timeoutInSeconds), Some.apply("r")); } - private static IStorageService getStorageService(CloudStorageType storageType) { + private static IStorageService getStorageService(String storageType) { String storageKey = PropertiesCache.getInstance().getProperty(JsonKey.ACCOUNT_NAME); String storageSecret = PropertiesCache.getInstance().getProperty(JsonKey.ACCOUNT_KEY); return getStorageService(storageType, storageKey, storageSecret); } - private static IStorageService getAnalyticsStorageService(CloudStorageType storageType) { - String storageKey = PropertiesCache.getInstance().getProperty(JsonKey.ANALYTICS_ACCOUNT_NAME); - String storageSecret = PropertiesCache.getInstance().getProperty(JsonKey.ANALYTICS_ACCOUNT_KEY); - return getStorageService(storageType, storageKey, storageSecret); - } - private static IStorageService getStorageService( - CloudStorageType storageType, String storageKey, String storageSecret) { - String compositeKey = storageType.getType() + "-" + storageKey; + String storageType, String storageKey, String storageSecret) { + String compositeKey = storageType + "-" + storageKey; if (storageServiceMap.containsKey(compositeKey)) { return storageServiceMap.get(compositeKey); } synchronized (CloudStorageUtil.class) { StorageConfig storageConfig = - new StorageConfig(storageType.getType(), storageKey, storageSecret); + new StorageConfig(storageType, storageKey, storageSecret); IStorageService storageService = StorageServiceFactory.getStorageService(storageConfig); storageServiceMap.put(compositeKey, storageService); } @@ -109,10 +67,4 @@ public class CloudStorageUtil { String timeoutInSecondsStr = ProjectUtil.getConfigValue(JsonKey.DOWNLOAD_LINK_EXPIRY_TIMEOUT); return Integer.parseInt(timeoutInSecondsStr); } - - public static String getUri( - CloudStorageType storageType, String container, String prefix, boolean isDirectory) { - IStorageService storageService = getStorageService(storageType); - return storageService.getUri(container, prefix, Option.apply(isDirectory)); - } -} +} \ No newline at end of file diff --git a/core/platform-common/src/main/resources/externalresource.properties b/core/platform-common/src/main/resources/externalresource.properties index 44614cc95a78a61f63f279b8a30211d8b88b4348..6acaf6cba11564f2776217efe1620b798f3a335e 100644 --- a/core/platform-common/src/main/resources/externalresource.properties +++ b/core/platform-common/src/main/resources/externalresource.properties @@ -104,4 +104,4 @@ notification_service_v1_delete_url=/private/v1/notification/feed/delete channel_registration_disabled=false #Login Page URL used as redirect URL in Password set / reset action. This will be suffixed with sunbird_web_url value. sunbird_password_reset_login_page_url=/resources -sunbird_cloud_service_provider= \ No newline at end of file +sunbird_cloud_service_provider= diff --git a/core/platform-common/src/test/java/org/sunbird/azure/AzureServiceFactoryTest.java b/core/platform-common/src/test/java/org/sunbird/azure/AzureServiceFactoryTest.java deleted file mode 100644 index a41c67b8005aa60ac0d3534d2b0cef405dfd4e9e..0000000000000000000000000000000000000000 --- a/core/platform-common/src/test/java/org/sunbird/azure/AzureServiceFactoryTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/** */ -package org.sunbird.azure; - -import static org.powermock.api.mockito.PowerMockito.doReturn; -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -import com.microsoft.azure.storage.CloudStorageAccount; -import com.microsoft.azure.storage.blob.CloudBlobClient; -import com.microsoft.azure.storage.blob.CloudBlobContainer; -import com.microsoft.azure.storage.blob.ListBlobItem; -import java.io.File; -import java.net.URI; -import java.util.ArrayList; -import java.util.List; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.sunbird.cloud.CloudService; -import org.sunbird.cloud.CloudServiceFactory; -import org.sunbird.cloud.azure.AzureConnectionManager; -import org.sunbird.util.PropertiesCache; - -/** @author Manzarul */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@RunWith(PowerMockRunner.class) -@PrepareForTest({ - CloudStorageAccount.class, - CloudBlobClient.class, - CloudBlobContainer.class, - ListBlobItem.class, - PropertiesCache.class -}) -@PowerMockIgnore({ - "javax.management.*", - "javax.net.ssl.*", - "javax.security.*", - "com.microsoft.azure.storage.*", - "jdk.internal.reflect.*", - "javax.crypto.*", - "javax.script.*", - "javax.xml.*", - "com.sun.org.apache.xerces.*", - "org.xml.*" -}) -public class AzureServiceFactoryTest { - - private static Object obj = null; - private static CloudBlobContainer container = null; - private static CloudBlobContainer container1 = null; - private static String containerName = "testcontainerxyz"; - - @BeforeClass - public static void getObject() { - - PowerMockito.mockStatic(PropertiesCache.class); - PropertiesCache propertiesCache = mock(PropertiesCache.class); - when(PropertiesCache.getInstance()).thenReturn(propertiesCache); - PowerMockito.when(propertiesCache.getProperty(Mockito.anyString())).thenReturn("anyString"); - - obj = CloudServiceFactory.get("azure"); - } - - @Before - public void addMockRules() { - - CloudStorageAccount cloudStorageAccount = mock(CloudStorageAccount.class); - CloudBlobClient cloudBlobClient = mock(CloudBlobClient.class); - CloudBlobContainer cloudBlobContainer = mock(CloudBlobContainer.class); - - ListBlobItem listBlobItem = mock(ListBlobItem.class); - List<ListBlobItem> lst = new ArrayList<>(); - lst.add(listBlobItem); - PowerMockito.mockStatic(CloudStorageAccount.class); - try { - doReturn(cloudStorageAccount).when(CloudStorageAccount.class, "parse", Mockito.anyString()); - doReturn(cloudBlobClient).when(cloudStorageAccount).createCloudBlobClient(); - doReturn(cloudBlobContainer).when(cloudBlobClient).getContainerReference(Mockito.anyString()); - doReturn(true).when(cloudBlobContainer).exists(); - when(cloudBlobContainer.listBlobs()).thenReturn(lst); - when(listBlobItem.getUri()).thenReturn(new URI("http://www.google.com")); - - } catch (Exception e) { - Assert.fail("Could not initalize mocks, underlying reason " + e.getLocalizedMessage()); - } - } - - @Test - public void testGetFailureWithWrongType() { - Object obj = CloudServiceFactory.get("Azure12"); - Assert.assertNull(obj); - } - - @Test - public void testGetSuccess() { - Object obj1 = CloudServiceFactory.get("azure"); - Assert.assertNotNull(obj1); - Assert.assertTrue(obj.equals(obj1)); - } - - @Test - public void testGetContainerSuccessWithAccessPublic() { - container = AzureConnectionManager.getContainer(containerName, true); - Assert.assertNotNull(container); - } - - @Test - public void testGetContainerReferenceSuccess() { - container1 = AzureConnectionManager.getContainerReference(containerName); - Assert.assertNotNull(container1); - } - - @Test - public void testUploadFileSuccess() { - CloudService service = (CloudService) obj; - String url = service.uploadFile(containerName, new File("test.txt"), null); - Assert.assertEquals(null, url); - } - - @Test - public void testUploadFileFailureWithoutContainerName() { - CloudService service = (CloudService) obj; - String url = service.uploadFile("", new File("test.txt"), null); - Assert.assertEquals(null, url); - } - - @Test - public void testUploadFileSuccessWithMultiplePath() { - CloudService service = (CloudService) obj; - String url = service.uploadFile("/tez/po/" + containerName, new File("test.txt"), null); - Assert.assertEquals(null, url); - } - - @Test - public void testUploadFileSuccessWithFileLocation() { - CloudService service = (CloudService) obj; - String url = service.uploadFile(containerName, "test.txt", "", null); - Assert.assertEquals(null, url); - } - - @Test - public void testListAllFilesSuccess() { - CloudService service = (CloudService) obj; - List<String> filesList = service.listAllFiles(containerName, null); - Assert.assertEquals(1, filesList.size()); - } - - @Test - public void testDownloadFileSuccess() { - CloudService service = (CloudService) obj; - Boolean isFileDeleted = service.downLoadFile(containerName, "test1.txt", "", null); - Assert.assertFalse(isFileDeleted); - } - - @Test - public void testDeleteFileSuccess() { - CloudService service = (CloudService) obj; - Boolean isFileDeleted = service.deleteFile(containerName, "test1.txt", null); - Assert.assertFalse(isFileDeleted); - } - - @Test - public void testDeleteFileSuccessWithoutContainerName() { - CloudService service = (CloudService) obj; - Boolean isFileDeleted = service.deleteFile("", "test.abc", null); - Assert.assertFalse(isFileDeleted); - } - - @Test - public void testDeleteContainerSuccess() { - CloudService service = (CloudService) obj; - boolean response = service.deleteContainer(containerName, null); - Assert.assertTrue(response); - } - - @AfterClass - public static void shutDown() { - container1 = null; - container = null; - obj = null; - } -} diff --git a/core/platform-common/src/test/java/org/sunbird/cloud/aws/AwsServiceTest.java b/core/platform-common/src/test/java/org/sunbird/cloud/aws/AwsServiceTest.java deleted file mode 100644 index 5f7e6cdc3d9d1d596469413bcf557bf52c8ec7a6..0000000000000000000000000000000000000000 --- a/core/platform-common/src/test/java/org/sunbird/cloud/aws/AwsServiceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.sunbird.cloud.aws; - -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -import java.io.File; -import java.util.List; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.sunbird.cloud.CloudService; -import org.sunbird.cloud.CloudServiceFactory; -import org.sunbird.util.PropertiesCache; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({PropertiesCache.class}) -@PowerMockIgnore({ - "javax.management.*", - "javax.net.ssl.*", - "javax.security.*", - "com.microsoft.azure.storage.*", - "jdk.internal.reflect.*", - "javax.crypto.*", - "javax.script.*", - "javax.xml.*", - "com.sun.org.apache.xerces.*", - "org.xml.*" -}) -public class AwsServiceTest { - - private static Object obj = null; - - @BeforeClass - public static void getObject() { - - PowerMockito.mockStatic(PropertiesCache.class); - PropertiesCache propertiesCache = mock(PropertiesCache.class); - when(PropertiesCache.getInstance()).thenReturn(propertiesCache); - PowerMockito.when(propertiesCache.getProperty(Mockito.anyString())).thenReturn("anyString"); - - obj = CloudServiceFactory.get("aws"); - } - - @Test - public void testGetSuccess() { - Object obj1 = CloudServiceFactory.get("aws"); - Assert.assertNotNull(obj1); - Assert.assertTrue(obj.equals(obj1)); - } - - @Test - public void testUploadFileFailure() { - try { - CloudService service = (CloudService) obj; - service.uploadFile("/container/sub/", new File("test.txt"), null); - } catch (Exception ex) { - Assert.assertNotNull(ex); - } - } - - @Test - public void testUploadFileSuccess() { - CloudService service = (CloudService) obj; - String url = service.uploadFile("containerName", "fileName", "/conf", null); - Assert.assertEquals(null, url); - } - - @Test - public void testDownloadFileSuccess() { - CloudService service = (CloudService) obj; - boolean url = service.downLoadFile("containerName", "fileName", "/conf", null); - Assert.assertFalse(url); - } - - @Test - public void testDeleteFileSuccess() { - CloudService service = (CloudService) obj; - boolean url = service.deleteFile("containerName", "fileName", null); - Assert.assertFalse(url); - } - - @Test - public void testListAllFileSuccess() { - CloudService service = (CloudService) obj; - List url = service.listAllFiles("containerName", null); - Assert.assertNull(url); - } - - @Test - public void testDeleteContainerSuccess() { - CloudService service = (CloudService) obj; - boolean url = service.deleteContainer("containerName", null); - Assert.assertFalse(url); - } - - @Test - public void testUploadFileFailure2() { - try { - CloudService service = (CloudService) obj; - service.uploadFile("", new File("test.txt"), null); - } catch (Exception ex) { - Assert.assertNotNull(ex); - } - } -} diff --git a/core/platform-common/src/test/java/org/sunbird/cloud/gcp/GcpServiceTest.java b/core/platform-common/src/test/java/org/sunbird/cloud/gcp/GcpServiceTest.java deleted file mode 100644 index c094b833723852ce6b8e069d7ca9e7e5711c26c2..0000000000000000000000000000000000000000 --- a/core/platform-common/src/test/java/org/sunbird/cloud/gcp/GcpServiceTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.sunbird.cloud.gcp; - -import static org.powermock.api.mockito.PowerMockito.mock; -import static org.powermock.api.mockito.PowerMockito.when; - -import java.io.File; -import java.util.List; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.sunbird.cloud.CloudService; -import org.sunbird.cloud.CloudServiceFactory; -import org.sunbird.util.PropertiesCache; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({PropertiesCache.class}) -@PowerMockIgnore({ - "javax.management.*", - "javax.net.ssl.*", - "javax.security.*", - "com.microsoft.azure.storage.*", - "jdk.internal.reflect.*", - "javax.crypto.*", - "javax.script.*", - "javax.xml.*", - "com.sun.org.apache.xerces.*", - "org.xml.*" -}) -public class GcpServiceTest { - private static Object obj = null; - - @BeforeClass - public static void getObject() { - - PowerMockito.mockStatic(PropertiesCache.class); - PropertiesCache propertiesCache = mock(PropertiesCache.class); - when(PropertiesCache.getInstance()).thenReturn(propertiesCache); - PowerMockito.when(propertiesCache.getProperty(Mockito.anyString())).thenReturn("anyString"); - - obj = CloudServiceFactory.get("gcloud"); - } - - @Test - public void testGetSuccess() { - Object obj1 = CloudServiceFactory.get("gcloud"); - Assert.assertNotNull(obj1); - Assert.assertTrue(obj.equals(obj1)); - } - - @Test - public void testUploadFileSuccess() { - CloudService service = (CloudService) obj; - String url = service.uploadFile("containerName", "fileName", "/conf", null); - Assert.assertEquals(null, url); - } - - @Test - public void testDownloadFileSuccess() { - CloudService service = (CloudService) obj; - boolean url = service.downLoadFile("containerName", "fileName", "/conf", null); - Assert.assertFalse(url); - } - - @Test - public void testUploadFileFailure2() { - try { - CloudService service = (CloudService) obj; - String url = service.uploadFile("", new File("test.txt"), null); - } catch (Exception ex) { - Assert.assertNotNull(ex); - } - } - - @Test - public void testDeleteFileSuccess() { - CloudService service = (CloudService) obj; - boolean url = service.deleteFile("containerName", "fileName", null); - Assert.assertFalse(url); - } - - @Test - public void testListAllFileSuccess() { - CloudService service = (CloudService) obj; - List url = service.listAllFiles("containerName", null); - Assert.assertNull(url); - } - - @Test - public void testDeleteContainerSuccess() { - CloudService service = (CloudService) obj; - boolean url = service.deleteContainer("containerName", null); - Assert.assertFalse(url); - } - - @Test - public void testUploadFileFailure() { - try { - CloudService service = (CloudService) obj; - service.uploadFile("/container/sub/", new File("test.txt"), null); - } catch (Exception ex) { - Assert.assertNotNull(ex); - } - } -} diff --git a/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java b/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java index 30ac072b904068b67a529c5546d03f8a8791c108..18fce8442ee954a4778de691e5a9604466207c46 100644 --- a/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java +++ b/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertTrue; import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.powermock.api.mockito.PowerMockito.when; - import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; @@ -17,8 +16,6 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.sunbird.cloud.storage.BaseStorageService; import org.sunbird.cloud.storage.factory.StorageServiceFactory; -import org.sunbird.exception.ProjectCommonException; -import org.sunbird.util.CloudStorageUtil.CloudStorageType; import scala.Option; @RunWith(PowerMockRunner.class) @@ -69,29 +66,18 @@ public class CloudStorageUtilTest { } } - @Test - public void testGetStorageTypeSuccess() { - CloudStorageType storageType = CloudStorageType.getByName("azure"); - assertTrue(CloudStorageType.AZURE.equals(storageType)); - } - - @Test(expected = ProjectCommonException.class) - public void testGetStorageTypeFailureWithWrongType() { - CloudStorageType.getByName("wrongstorage"); - } - @Test // @Ignore public void testUploadSuccess() { String result = - CloudStorageUtil.upload(CloudStorageType.AZURE, "container", "key", "/file/path"); + CloudStorageUtil.upload("azure", "container", "key", "/file/path"); assertTrue(UPLOAD_URL.equals(result)); } @Test @Ignore public void testGetSignedUrlSuccess() { - String signedUrl = CloudStorageUtil.getSignedUrl(CloudStorageType.AZURE, "container", "key"); + String signedUrl = CloudStorageUtil.getSignedUrl("azure", "container", "key"); assertTrue(SIGNED_URL.equals(signedUrl)); } } diff --git a/service/src/main/java/org/sunbird/actor/fileuploadservice/FileUploadServiceActor.java b/service/src/main/java/org/sunbird/actor/fileuploadservice/FileUploadServiceActor.java index 132148e342b76b44ab6de2d512cec77f645044b9..6e0662d98d6d98fc8c05faef68cf2248fc7c4b55 100644 --- a/service/src/main/java/org/sunbird/actor/fileuploadservice/FileUploadServiceActor.java +++ b/service/src/main/java/org/sunbird/actor/fileuploadservice/FileUploadServiceActor.java @@ -6,8 +6,6 @@ import java.io.IOException; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.sunbird.actor.core.BaseActor; -import org.sunbird.cloud.CloudService; -import org.sunbird.cloud.CloudServiceFactory; import org.sunbird.exception.ProjectCommonException; import org.sunbird.exception.ResponseCode; import org.sunbird.keys.JsonKey; @@ -15,6 +13,7 @@ import org.sunbird.operations.ActorOperations; import org.sunbird.request.Request; import org.sunbird.request.RequestContext; import org.sunbird.response.Response; +import org.sunbird.util.CloudStorageUtil; import org.sunbird.util.ProjectUtil; public class FileUploadServiceActor extends BaseActor { @@ -55,8 +54,7 @@ public class FileUploadServiceActor extends BaseActor { fos = new FileOutputStream(file); fos.write((byte[]) req.get(JsonKey.FILE)); String cspProvider = ProjectUtil.getConfigValue(JsonKey.CLOUD_SERVICE_PROVIDER); - CloudService service = (CloudService) CloudServiceFactory.get(cspProvider); - if (null == service) { + if (null == cspProvider) { logger.info(context, "The cloud service is not available"); ProjectCommonException exception = new ProjectCommonException( @@ -66,7 +64,7 @@ public class FileUploadServiceActor extends BaseActor { sender().tell(exception, self()); } String container = (String) req.get(JsonKey.CONTAINER); - avatarUrl = service.uploadFile(container, file, context); + avatarUrl= CloudStorageUtil.upload(cspProvider,container,fileName,fName); } catch (IOException e) { logger.error(context, "Exception Occurred while reading file in FileUploadServiceActor", e); throw e;