introduce new filestorage.common bundle, so that filestorage bundle can be upgraded to java 1.8

This commit is contained in:
Fredrik Teschke
2015-01-29 16:50:40 +01:00
parent 45e907b9e7
commit 02972d1bea
38 changed files with 189 additions and 96 deletions
+1 -1
View File
@@ -2,6 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+12 -12
View File
@@ -1,12 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -4,7 +4,7 @@ Bundle-Name: Sse File storage
Bundle-SymbolicName: com.sap.sse.filestorage
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: SAP
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: com.sap.sse.filestorage,
com.sap.sse.filestorage.impl,
com.sap.sse.filestorage.testsupport
@@ -19,4 +19,6 @@ Require-Bundle: org.apache.servicemix.bundles.aws-java-sdk;bundle-version="1.9.8
org.apache.commons.logging;bundle-version="1.1.3",
com.sap.sse.common,
com.sap.sse.mongodb;bundle-version="1.0.0",
com.mongodb.driver;bundle-version="2.6.2"
com.mongodb.driver;bundle-version="2.6.2",
com.sap.sse.replication;bundle-version="1.0.0",
com.sap.sse.filestorage.common;bundle-version="1.0.0"
@@ -1,35 +0,0 @@
package com.sap.sse.filestorage;
import com.sap.sse.common.NoCorrespondingServiceRegisteredException;
/**
* OSGi service for managing {@link FileStorageService FileStorageServices}.
*
* @author Fredrik Teschke
*
*/
public interface FileStorageManagementService {
FileStorageService[] getAvailableFileStorageServices();
FileStorageService getFileStorageService(String name);
/**
* Sets the property of the service, and also stores the property value so that it can be restored after a server
* restart.
*
* @throws NoCorrespondingServiceRegisteredException
* service may have disappeared from registry in the meantime
* @throws IllegalArgumentException
* if the property with name {@code propertyName} doesn't exist for the service
*/
void setFileStorageServiceProperty(String serviceName, String propertyName, String propertyValue)
throws NoCorrespondingServiceRegisteredException, IllegalArgumentException;
/**
* @throws NoCorrespondingServiceRegisteredException
* if no service has been selected so far.
*/
FileStorageService getActiveFileStorageService() throws NoCorrespondingServiceRegisteredException;
void setActiveFileStorageService(FileStorageService service);
}
@@ -1,57 +0,0 @@
package com.sap.sse.filestorage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import com.sap.sse.common.TypeBasedServiceFinder;
/**
* Service for storing files. The interface is intentionally agnostic of the underlying implementation, which may be
* provided e.g. by using Amazon's S3 or simply saving the files to a statically reachable directory on one of our
* servers. Implementations of this service are announced via the OSGi service registry. They should provide their name
* as the OSGi property {@link TypeBasedServiceFinder#TYPE type};
*
* TODO The storage service to use should be configured via the AdminConsole. Upon auto-discovering the available
* services, the AdminConsole should allow to edit properties for each service (e.g. access credentials for AWS S3). We
* probably need a generic property discovery mechanism (key-value based?), and to survive server restarts these
* properties should be saved to the MongoDB.
*
* @author Fredrik Teschke
*
*/
public interface FileStorageService {
/**
* @param originalFileExtension
* may be {@code null}
*/
URI storeFile(InputStream is, String fileExtension, long lengthInBytes) throws IOException,
OperationFailedException, InvalidPropertiesException;
/**
* From the given {@code uri} it should be possible to determine the file to remove.
*/
void removeFile(URI uri) throws OperationFailedException, InvalidPropertiesException;
Property[] getProperties();
/**
* Should not be called directly, but through {@link FileStorageManagementService#setFileStorageServiceProperty}
* as this deals with storing the new values.
* @throws IllegalArgumentException
* if {@code name} is not a valid property name
*/
void internalSetProperty(String name, String value) throws IllegalArgumentException;
String getName();
/**
* Description text that explains the storage service.
*/
String getDescription();
/**
* Test whether properties are valid, e.g. by trying to log in using access credentials provided as properties.
*/
void testProperties() throws InvalidPropertiesException;
}
@@ -1,46 +0,0 @@
package com.sap.sse.filestorage;
import java.util.HashMap;
import java.util.Map;
import com.sap.sse.common.Util.Pair;
public class InvalidPropertiesException extends Exception {
private static final long serialVersionUID = -7328897153875728802L;
private final Map<Property, String> perPropertyMessages = new HashMap<>();
public InvalidPropertiesException(String message) {
super(message);
}
public InvalidPropertiesException(String message, Throwable cause) {
super(message, cause);
}
@SafeVarargs
public InvalidPropertiesException(String message,
Pair<Property, String>... perPropertyMessages) {
this(message, null, perPropertyMessages);
}
@SafeVarargs
public InvalidPropertiesException(String message, Throwable cause,
Pair<Property, String>... perPropertyMessages) {
super(message, cause);
for (Pair<Property, String> pair : perPropertyMessages) {
this.perPropertyMessages.put(pair.getA(), pair.getB());
}
}
@Override
/**
* Returns the overall error message (always exists).
*/
public String getMessage() {
return super.getMessage();
}
public Map<Property, String> getPerPropertyMessage() {
return perPropertyMessages;
}
}
@@ -1,9 +0,0 @@
package com.sap.sse.filestorage;
public class OperationFailedException extends Exception {
private static final long serialVersionUID = 3361800673687196602L;
public OperationFailedException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -1,17 +0,0 @@
package com.sap.sse.filestorage;
/**
* Property of a file storage service.
* @author Fredrik Teschke
*
*/
public interface Property {
boolean isRequired();
String getName();
/**
* @return {@code null} if not yet initialized
*/
String getValue();
String getDescription();
}
@@ -8,9 +8,9 @@ import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import com.sap.sse.common.TypeBasedServiceFinder;
import com.sap.sse.filestorage.FileStorageManagementService;
import com.sap.sse.filestorage.FileStorageService;
import com.sap.sse.filestorage.FileStorageServicePropertyStore;
import com.sap.sse.filestorage.common.FileStorageManagementService;
import com.sap.sse.filestorage.common.FileStorageService;
import com.sap.sse.mongodb.MongoDBConfiguration;
public class Activator implements BundleActivator {
@@ -19,10 +19,10 @@ import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.filestorage.FileStorageService;
import com.sap.sse.filestorage.InvalidPropertiesException;
import com.sap.sse.filestorage.OperationFailedException;
import com.sap.sse.filestorage.Property;
import com.sap.sse.filestorage.common.FileStorageService;
import com.sap.sse.filestorage.common.FileStorageServiceProperty;
import com.sap.sse.filestorage.common.InvalidPropertiesException;
import com.sap.sse.filestorage.common.OperationFailedException;
/**
* For testing purposes configure the access credentials as follows: To link this service to an AWS account, create the
@@ -42,20 +42,20 @@ public class AmazonS3FileStorageServiceImpl implements FileStorageService {
private static final String retrievalProtocol = "http";
// private static final String bucketName = "ftes-sap-sailing";
private final PropertyImpl accessId = new PropertyImpl("accessId", false,
private final FileStorageServicePropertyImpl accessId = new FileStorageServicePropertyImpl("accessId", false,
"Access ID (leave blank to use ~/.aws/credentials instead)");
private final PropertyImpl accessKey = new PropertyImpl("accessKey", false,
private final FileStorageServicePropertyImpl accessKey = new FileStorageServicePropertyImpl("accessKey", false,
"Secret Access Key (leave blank to use ~/.aws/credentials instead)");
private final PropertyImpl bucketName = new PropertyImpl("bucketName", true,
private final FileStorageServicePropertyImpl bucketName = new FileStorageServicePropertyImpl("bucketName", true,
"Name of Bucket to use (has to already exist, and user needs sufficient permissions)");
private final Map<String, PropertyImpl> properties = new HashMap<>();
private final Map<String, FileStorageServicePropertyImpl> properties = new HashMap<>();
public AmazonS3FileStorageServiceImpl() {
addProperties(accessId, accessKey, bucketName);
}
private void addProperties(PropertyImpl... properties) {
for (PropertyImpl p : properties) {
private void addProperties(FileStorageServicePropertyImpl... properties) {
for (FileStorageServicePropertyImpl p : properties) {
this.properties.put(p.getName(), p);
}
}
@@ -107,15 +107,15 @@ public class AmazonS3FileStorageServiceImpl implements FileStorageService {
.withCannedAcl(CannedAccessControlList.PublicRead);
final AmazonS3Client s3Client = createS3Client();
new Thread() {
public void run() {
try {
s3Client.putObject(request);
} catch (AmazonClientException e) {
logger.log(Level.WARNING, "Could not store file", e);
}
};
}.run();
new Thread() {
public void run() {
try {
s3Client.putObject(request);
} catch (AmazonClientException e) {
logger.log(Level.WARNING, "Could not store file", e);
}
};
}.run();
URI uri = getUri(key);
logger.info("Stored file " + uri);
return uri;
@@ -134,8 +134,8 @@ public class AmazonS3FileStorageServiceImpl implements FileStorageService {
}
@Override
public Property[] getProperties() {
return new Property[] { accessId, accessKey, bucketName };
public FileStorageServiceProperty[] getProperties() {
return new FileStorageServiceProperty[] { accessId, accessKey, bucketName };
}
@Override
@@ -166,14 +166,12 @@ public class AmazonS3FileStorageServiceImpl implements FileStorageService {
s3.doesBucketExist(bucketName.getValue());
} catch (Exception e) {
throw new InvalidPropertiesException("invalid credentials or not enough access rights for the bucket", e,
new Pair<Property, String>(accessId, "seems to be invalid"), new Pair<Property, String>(accessKey,
"seems to be invalid"));
new Pair<>(accessId, "seems to be invalid"), new Pair<>(accessKey, "seems to be invalid"));
}
// test if bucket exists
if (!s3.doesBucketExist(bucketName.getValue())) {
throw new InvalidPropertiesException("invalid bucket", new Pair<Property, String>(bucketName,
"bucket does not exist"));
throw new InvalidPropertiesException("invalid bucket", new Pair<>(bucketName, "bucket does not exist"));
}
}
}
@@ -11,9 +11,9 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer;
import com.sap.sse.common.NoCorrespondingServiceRegisteredException;
import com.sap.sse.common.TypeBasedServiceFinder;
import com.sap.sse.filestorage.FileStorageManagementService;
import com.sap.sse.filestorage.FileStorageService;
import com.sap.sse.filestorage.FileStorageServicePropertyStore;
import com.sap.sse.filestorage.common.FileStorageManagementService;
import com.sap.sse.filestorage.common.FileStorageService;
import com.sap.sse.osgi.CachedOsgiTypeBasedServiceFinderFactory;
/**
@@ -1,18 +1,19 @@
package com.sap.sse.filestorage.impl;
import com.sap.sse.filestorage.Property;
import com.sap.sse.filestorage.common.FileStorageServiceProperty;
public class PropertyImpl implements Property {
public class FileStorageServicePropertyImpl implements FileStorageServiceProperty {
private final boolean isRequired;
private final String name;
private final String description;
private String value;
public PropertyImpl(String name, boolean isRequired, String description) {
public FileStorageServicePropertyImpl(String name, boolean isRequired, String description) {
this(name, isRequired, description, null);
}
public PropertyImpl(String name, boolean isRequired, String description, String value) {
public FileStorageServicePropertyImpl(String name, boolean isRequired, String description, String value) {
this.name = name;
this.description = description;
this.value = value;
@@ -11,9 +11,9 @@ import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sap.sse.filestorage.FileStorageService;
import com.sap.sse.filestorage.InvalidPropertiesException;
import com.sap.sse.filestorage.Property;
import com.sap.sse.filestorage.common.FileStorageService;
import com.sap.sse.filestorage.common.FileStorageServiceProperty;
import com.sap.sse.filestorage.common.InvalidPropertiesException;
public class LocalFileStorageServiceImpl implements FileStorageService {
private static final Logger logger = Logger.getLogger(LocalFileStorageServiceImpl.class.getName());
@@ -76,7 +76,7 @@ public class LocalFileStorageServiceImpl implements FileStorageService {
}
@Override
public Property[] getProperties() {
public FileStorageServiceProperty[] getProperties() {
// TODO Auto-generated method stub
return null;
}
@@ -0,0 +1,15 @@
package com.sap.sse.filestorage.impl;
import com.sap.sse.common.NoCorrespondingServiceRegisteredException;
import com.sap.sse.filestorage.common.FileStorageService;
/**
* Defines internal operations that do are called only by
* @author Fredrik Teschke
*
*/
public interface ReplicableFileStorageManagementService {
void internalSetFileStorageServiceProperty(String serviceName, String propertyName, String propertyValue)
throws NoCorrespondingServiceRegisteredException, IllegalArgumentException;
void internalSetActiveFileStorageService(FileStorageService service);
}
@@ -1,6 +1,6 @@
package com.sap.sse.filestorage.testsupport;
import com.sap.sse.filestorage.InvalidPropertiesException;
import com.sap.sse.filestorage.common.InvalidPropertiesException;
import com.sap.sse.filestorage.impl.AmazonS3FileStorageServiceImpl;
public class AmazonS3TestSupport {