Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Add support for shared configuration via Azure #250

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1.5.5 - xxxxxxxxxxxxxxxxx
=========================
1.5.5 - March 4, 2015
=====================

* Issue 231: Possible NPE due to not checking for null from usState.getUs()

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ There is an Exhibitor mailing list. Join here: http://groups.google.com/group/ex

## AUTHOR

Jordan Zimmerman (jzimmerman@netflix.com)
Jordan Zimmerman (jordan@jordanzimmerman.com)

## LICENSE

Expand Down
1 change: 1 addition & 0 deletions exhibitor-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
compile 'org.codehaus.jsr166-mirror:jsr166y:1.7.0'

compile "com.amazonaws:aws-java-sdk:${awsVersion}"
compile "com.microsoft.azure:azure-storage:${azureVersion}"
compile "com.sun.jersey:jersey-core:${jerseyVersion}"
compile "com.sun.jersey:jersey-server:${jerseyVersion}"
compile "com.sun.jersey:jersey-json:${jerseyVersion}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.netflix.exhibitor.core.azure;

import com.microsoft.azure.storage.blob.BlobProperties;
import com.microsoft.azure.storage.blob.CloudBlob;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.ListBlobItem;

import java.io.Closeable;

public interface AzureClient extends Closeable {
public CloudBlobClient getClient() throws Exception;

public CloudBlob getBlob(String containerName, String uri) throws Exception;

public BlobProperties getBlobProperties(String containerName, String uri) throws Exception;

public Iterable<ListBlobItem> listBlobs(String containerName, String prefix) throws Exception;

public void putBlob(byte[] bytes, String containerName, String uri) throws Exception;

public void deleteBlob(String containerName, String uri) throws Exception;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.netflix.exhibitor.core.azure;

public interface AzureClientFactory {
/**
* Create a client with the given credentials
*
* @param credentials credentials
* @return client
* @throws Exception errors
*/
public AzureClient makeNewClient(AzureCredential credentials) throws Exception;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.netflix.exhibitor.core.azure;


public class AzureClientFactoryImpl implements AzureClientFactory {
@Override
public AzureClient makeNewClient(AzureCredential credentials) throws Exception {
return new AzureClientImpl(credentials);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.netflix.exhibitor.core.azure;

import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.blob.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;

public class AzureClientImpl implements AzureClient {
private final Logger log = LoggerFactory.getLogger(getClass());
private final String storageConnectionString;

public AzureClientImpl(AzureCredential credentials) {
this.storageConnectionString =
"DefaultEndpointsProtocol=http" +
";AccountName=" + credentials.getAccountName() +
";AccountKey=" + credentials.getAccountKey();
}

@Override
public CloudBlobClient getClient() throws Exception {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(this.storageConnectionString);
return storageAccount.createCloudBlobClient();
}

@Override
public CloudBlob getBlob(String containerName, String uri) throws Exception {
CloudBlobContainer container = getClient().getContainerReference(containerName);
return container.getBlockBlobReference(uri);
}

@Override
public BlobProperties getBlobProperties(String containerName, String uri) throws Exception {
CloudBlob blob = getBlob(containerName, uri);
blob.downloadAttributes();
return blob.getProperties();
}

@Override
public Iterable<ListBlobItem> listBlobs(String containerName, String prefix) throws Exception {
CloudBlobContainer container = getClient().getContainerReference(containerName);
return container.listBlobs(prefix);
}

@Override
public void putBlob(byte[] bytes, String containerName, String uri) throws Exception {
CloudBlob blob = getBlob(containerName, uri);
blob.getContainer().createIfNotExists();
blob.upload(new ByteArrayInputStream(bytes), bytes.length);
}

@Override
public void deleteBlob(String containerName, String uri) throws Exception {
getBlob(containerName, uri).deleteIfExists();
}

@Override
public void close() throws IOException {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.netflix.exhibitor.core.azure;

public interface AzureCredential {
public String getAccountName();
public String getAccountKey();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.netflix.exhibitor.core.azure;

import org.apache.curator.utils.CloseableUtils;

import java.io.*;
import java.util.Properties;

public class PropertyBasedAzureCredential implements AzureCredential {
private final String accountName;
private final String accountKey;

public static final String PROPERTY_AZURE_ACCOUNT_NAME = "com.netflix.exhibitor.azure.account-name";
public static final String PROPERTY_AZURE_ACCOUNT_KEY = "com.netflix.exhibitor.azure.account-key";

public PropertyBasedAzureCredential(File propertiesFile) throws IOException
{
this(loadProperties(propertiesFile));
}

public PropertyBasedAzureCredential(Properties properties)
{
accountName = properties.getProperty(PROPERTY_AZURE_ACCOUNT_NAME);
accountKey = properties.getProperty(PROPERTY_AZURE_ACCOUNT_KEY);
}

@Override
public String getAccountName()
{
return accountName;
}

public String getAccountKey()
{
return accountKey;
}

private static Properties loadProperties(File propertiesFile) throws IOException
{
Properties properties = new Properties();
InputStream in = new BufferedInputStream(new FileInputStream(propertiesFile));
try
{
properties.load(in);
}
finally
{
CloseableUtils.closeQuietly(in);
}
return properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public abstract class PseudoLockBase implements PseudoLock
/**
* @param lockPrefix key prefix
* @param timeoutMs max age for locks
* @param pollingMs how often to poll S3
* @param pollingMs how often to poll storage service
*/
public PseudoLockBase(String lockPrefix, int timeoutMs, int pollingMs)
{
Expand All @@ -65,8 +65,8 @@ public PseudoLockBase(String lockPrefix, int timeoutMs, int pollingMs)
/**
* @param lockPrefix key prefix
* @param timeoutMs max age for locks
* @param pollingMs how often to poll S3
* @param settlingMs how long to wait for S3 to reach consistency
* @param pollingMs how often to poll storage service
* @param settlingMs how long to wait for storage service to reach consistency
*/
public PseudoLockBase(String lockPrefix, int timeoutMs, int pollingMs, int settlingMs)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.netflix.exhibitor.core.config.azure;

public class AzureConfigArguments {
private final String container;
private final String blobName;
private final AzureConfigAutoManageLockArguments lockArguments;

public AzureConfigArguments(String container, String blobName, AzureConfigAutoManageLockArguments lockArguments)
{
this.container = container;
this.blobName = blobName;
this.lockArguments = lockArguments;
}

public String getContainer()
{
return container;
}

public String getBlobName()
{
return blobName;
}

public AzureConfigAutoManageLockArguments getLockArguments()
{
return lockArguments;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.netflix.exhibitor.core.config.azure;

import com.netflix.exhibitor.core.config.AutoManageLockArguments;
import java.util.concurrent.TimeUnit;

public class AzureConfigAutoManageLockArguments extends AutoManageLockArguments
{
private final int settlingMs;

public AzureConfigAutoManageLockArguments(String prefix)
{
super(prefix);
settlingMs = (int)TimeUnit.SECONDS.toMillis(5); // TODO - get this right
}

public AzureConfigAutoManageLockArguments(String prefix, int timeoutMs, int pollingMs, int settlingMs)
{
super(prefix, timeoutMs, pollingMs);
this.settlingMs = settlingMs;
}

public int getSettlingMs()
{
return settlingMs;
}
}
Loading