Skip to content

Commit

Permalink
Remove Dead Code from Azure Repo Plugin (#42178) (#42569)
Browse files Browse the repository at this point in the history
* None of this stuff is used
  • Loading branch information
original-brownbear authored May 28, 2019
1 parent 2077f9f commit c079fb6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public class AzureBlobStore implements BlobStore {
private final String container;
private final LocationMode locationMode;

public AzureBlobStore(RepositoryMetaData metadata, AzureStorageService service)
throws URISyntaxException, StorageException {
public AzureBlobStore(RepositoryMetaData metadata, AzureStorageService service) {
this.container = Repository.CONTAINER_SETTING.get(metadata.settings());
this.clientName = Repository.CLIENT_NAME.get(metadata.settings());
this.service = service;
Expand All @@ -69,10 +68,6 @@ public LocationMode getLocationMode() {
return locationMode;
}

public String getClientName() {
return clientName;
}

@Override
public BlobContainer blobContainer(BlobPath path) {
return new AzureBlobContainer(path, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,16 @@ public AzureRepository(RepositoryMetaData metadata, Environment environment, Nam
}
}

// only use for testing
@Override
protected BlobStore getBlobStore() {
return super.getBlobStore();
}

/**
* {@inheritDoc}
*/
@Override
protected AzureBlobStore createBlobStore() throws URISyntaxException, StorageException {
protected AzureBlobStore createBlobStore() {
final AzureBlobStore blobStore = new AzureBlobStore(metadata, storageService);

logger.debug((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage(
logger.debug(() -> new ParameterizedMessage(
"using container [{}], chunk_size [{}], compress [{}], base_path [{}]",
blobStore, chunkSize, isCompress(), basePath));
return blobStore;
Expand All @@ -139,9 +135,6 @@ protected BlobPath basePath() {
return basePath;
}

/**
* {@inheritDoc}
*/
@Override
protected ByteSizeValue chunkSize() {
return chunkSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Tuple<CloudBlobClient, Supplier<OperationContext>> client(String clientNa
}
}

protected CloudBlobClient buildClient(AzureStorageSettings azureStorageSettings) throws InvalidKeyException, URISyntaxException {
private static CloudBlobClient buildClient(AzureStorageSettings azureStorageSettings) throws InvalidKeyException, URISyntaxException {
final CloudBlobClient client = createClient(azureStorageSettings);
// Set timeout option if the user sets cloud.azure.storage.timeout or
// cloud.azure.storage.xxx.timeout (it's negative by default)
Expand All @@ -116,12 +116,12 @@ protected CloudBlobClient buildClient(AzureStorageSettings azureStorageSettings)
return client;
}

protected CloudBlobClient createClient(AzureStorageSettings azureStorageSettings) throws InvalidKeyException, URISyntaxException {
private static CloudBlobClient createClient(AzureStorageSettings azureStorageSettings) throws InvalidKeyException, URISyntaxException {
final String connectionString = azureStorageSettings.buildConnectionString();
return CloudStorageAccount.parse(connectionString).createCloudBlobClient();
}

protected OperationContext buildOperationContext(AzureStorageSettings azureStorageSettings) {
private static OperationContext buildOperationContext(AzureStorageSettings azureStorageSettings) {
final OperationContext context = new OperationContext();
context.setProxy(azureStorageSettings.getProxy());
return context;
Expand All @@ -147,24 +147,6 @@ public boolean doesContainerExist(String account, String container) throws URISy
return SocketAccess.doPrivilegedException(() -> blobContainer.exists(null, null, client.v2().get()));
}

public void deleteFiles(String account, String container, String path) throws URISyntaxException, StorageException {
final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client(account);
// container name must be lower case.
logger.trace(() -> new ParameterizedMessage("delete files container [{}], path [{}]", container, path));
SocketAccess.doPrivilegedVoidException(() -> {
// list the blobs using a flat blob listing mode
final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
for (final ListBlobItem blobItem : blobContainer.listBlobs(path, true, EnumSet.noneOf(BlobListingDetails.class), null,
client.v2().get())) {
final String blobName = blobNameFromUri(blobItem.getUri());
logger.trace(() -> new ParameterizedMessage("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri()));
// don't call {@code #deleteBlob}, use the same client
final CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blobName);
azureBlob.delete(DeleteSnapshotsOption.NONE, null, null, client.v2().get());
}
});
}

/**
* Extract the blob name from a URI like https://myservice.azure.net/container/path/to/myfile
* It should remove the container part (first part of the path) and gives path/to/myfile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,6 @@ private AzureStorageSettings(String account, String key, String endpointSuffix,
this.locationMode = LocationMode.PRIMARY_ONLY;
}

public String getKey() {
return key;
}

public String getAccount() {
return account;
}

public String getEndpointSuffix() {
return endpointSuffix;
}
Expand Down Expand Up @@ -207,7 +199,7 @@ public static Map<String, AzureStorageSettings> load(Settings settings) {

// pkg private for tests
/** Parse settings for a single client. */
static AzureStorageSettings getClientSettings(Settings settings, String clientName) {
private static AzureStorageSettings getClientSettings(Settings settings, String clientName) {
try (SecureString account = getConfigValue(settings, clientName, ACCOUNT_SETTING);
SecureString key = getConfigValue(settings, clientName, KEY_SETTING)) {
return new AzureStorageSettings(account.toString(), key.toString(),
Expand All @@ -226,7 +218,7 @@ private static <T> T getConfigValue(Settings settings, String clientName,
return concreteSetting.get(settings);
}

public static <T> T getValue(Settings settings, String groupName, Setting<T> setting) {
private static <T> T getValue(Settings settings, String groupName, Setting<T> setting) {
final Setting.AffixKey k = (Setting.AffixKey) setting.getRawKey();
final String fullKey = k.toConcreteKey(groupName).toString();
return setting.getConcreteSetting(fullKey).get(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static <T> T doPrivilegedIOException(PrivilegedExceptionAction<T> operati
}
}

public static <T> T doPrivilegedException(PrivilegedExceptionAction<T> operation) throws StorageException, URISyntaxException {
public static <T> T doPrivilegedException(PrivilegedExceptionAction<T> operation) throws StorageException {
SpecialPermission.check();
try {
return AccessController.doPrivileged(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,17 @@

package org.elasticsearch.repositories.azure;

import com.microsoft.azure.storage.StorageException;
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
import org.elasticsearch.common.blobstore.BlobStore;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;

import java.io.IOException;
import java.net.URISyntaxException;

public class AzureBlobStoreContainerTests extends ESBlobStoreContainerTestCase {
@Override
protected BlobStore newBlobStore() throws IOException {
try {
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
AzureStorageServiceMock client = new AzureStorageServiceMock();
return new AzureBlobStore(repositoryMetaData, client);
} catch (URISyntaxException | StorageException e) {
throw new IOException(e);
}
protected BlobStore newBlobStore() {
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
AzureStorageServiceMock client = new AzureStorageServiceMock();
return new AzureBlobStore(repositoryMetaData, client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,17 @@
*/
package org.elasticsearch.repositories.azure;

import com.microsoft.azure.storage.StorageException;
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
import org.elasticsearch.common.blobstore.BlobStore;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.repositories.ESBlobStoreTestCase;

import java.io.IOException;
import java.net.URISyntaxException;

public class AzureBlobStoreTests extends ESBlobStoreTestCase {

@Override
protected BlobStore newBlobStore() throws IOException {
try {
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
AzureStorageServiceMock client = new AzureStorageServiceMock();
return new AzureBlobStore(repositoryMetaData, client);
} catch (URISyntaxException | StorageException e) {
throw new IOException(e);
}
protected BlobStore newBlobStore() {
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
AzureStorageServiceMock client = new AzureStorageServiceMock();
return new AzureBlobStore(repositoryMetaData, client);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketPermission;
import java.net.URISyntaxException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.NoSuchFileException;
import java.security.AccessController;
Expand All @@ -61,21 +60,13 @@ public boolean doesContainerExist(String account, String container) {
return true;
}

@Override
public void deleteFiles(String account, String container, String path) throws URISyntaxException, StorageException {
final Map<String, BlobMetaData> blobs = listBlobsByPrefix(account, container, path, null);
for (String key : blobs.keySet()) {
deleteBlob(account, container, key);
}
}

@Override
public boolean blobExists(String account, String container, String blob) {
return blobs.containsKey(blob);
}

@Override
public void deleteBlob(String account, String container, String blob) throws URISyntaxException, StorageException {
public void deleteBlob(String account, String container, String blob) throws StorageException {
if (blobs.remove(blob) == null) {
throw new StorageException("BlobNotFound", "[" + blob + "] does not exist.", 404, null, null);
}
Expand Down Expand Up @@ -109,8 +100,7 @@ public Map<String, BlobMetaData> listBlobsByPrefix(String account, String contai

@Override
public void writeBlob(String account, String container, String blobName, InputStream inputStream, long blobSize,
boolean failIfAlreadyExists)
throws URISyntaxException, StorageException, FileAlreadyExistsException {
boolean failIfAlreadyExists) throws StorageException, FileAlreadyExistsException {
if (failIfAlreadyExists && blobs.containsKey(blobName)) {
throw new FileAlreadyExistsException(blobName);
}
Expand Down

0 comments on commit c079fb6

Please sign in to comment.