Skip to content

Commit 0fc278f

Browse files
original-brownbearGurkan Kaymak
authored and
Gurkan Kaymak
committed
Remove Dead Code from Azure Repo Plugin (elastic#42178)
* None of this stuff is used
1 parent a21c448 commit 0fc278f

File tree

8 files changed

+19
-82
lines changed

8 files changed

+19
-82
lines changed

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureBlobStore.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public class AzureBlobStore implements BlobStore {
4545
private final String container;
4646
private final LocationMode locationMode;
4747

48-
public AzureBlobStore(RepositoryMetaData metadata, AzureStorageService service)
49-
throws URISyntaxException, StorageException {
48+
public AzureBlobStore(RepositoryMetaData metadata, AzureStorageService service) {
5049
this.container = Repository.CONTAINER_SETTING.get(metadata.settings());
5150
this.clientName = Repository.CLIENT_NAME.get(metadata.settings());
5251
this.service = service;
@@ -69,10 +68,6 @@ public LocationMode getLocationMode() {
6968
return locationMode;
7069
}
7170

72-
public String getClientName() {
73-
return clientName;
74-
}
75-
7671
@Override
7772
public BlobContainer blobContainer(BlobPath path) {
7873
return new AzureBlobContainer(path, this);

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureRepository.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,16 @@ public AzureRepository(RepositoryMetaData metadata, Environment environment, Nam
112112
}
113113
}
114114

115-
// only use for testing
116115
@Override
117116
protected BlobStore getBlobStore() {
118117
return super.getBlobStore();
119118
}
120119

121-
/**
122-
* {@inheritDoc}
123-
*/
124120
@Override
125-
protected AzureBlobStore createBlobStore() throws URISyntaxException, StorageException {
121+
protected AzureBlobStore createBlobStore() {
126122
final AzureBlobStore blobStore = new AzureBlobStore(metadata, storageService);
127123

128-
logger.debug((org.apache.logging.log4j.util.Supplier<?>) () -> new ParameterizedMessage(
124+
logger.debug(() -> new ParameterizedMessage(
129125
"using container [{}], chunk_size [{}], compress [{}], base_path [{}]",
130126
blobStore, chunkSize, isCompress(), basePath));
131127
return blobStore;
@@ -136,9 +132,6 @@ protected BlobPath basePath() {
136132
return basePath;
137133
}
138134

139-
/**
140-
* {@inheritDoc}
141-
*/
142135
@Override
143136
protected ByteSizeValue chunkSize() {
144137
return chunkSize;

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureStorageService.java

+3-21
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public Tuple<CloudBlobClient, Supplier<OperationContext>> client(String clientNa
9797
}
9898
}
9999

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

118-
protected CloudBlobClient createClient(AzureStorageSettings azureStorageSettings) throws InvalidKeyException, URISyntaxException {
118+
private static CloudBlobClient createClient(AzureStorageSettings azureStorageSettings) throws InvalidKeyException, URISyntaxException {
119119
final String connectionString = azureStorageSettings.buildConnectionString();
120120
return CloudStorageAccount.parse(connectionString).createCloudBlobClient();
121121
}
122122

123-
protected OperationContext buildOperationContext(AzureStorageSettings azureStorageSettings) {
123+
private static OperationContext buildOperationContext(AzureStorageSettings azureStorageSettings) {
124124
final OperationContext context = new OperationContext();
125125
context.setProxy(azureStorageSettings.getProxy());
126126
return context;
@@ -146,24 +146,6 @@ public boolean doesContainerExist(String account, String container) throws URISy
146146
return SocketAccess.doPrivilegedException(() -> blobContainer.exists(null, null, client.v2().get()));
147147
}
148148

149-
public void deleteFiles(String account, String container, String path) throws URISyntaxException, StorageException {
150-
final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client(account);
151-
// container name must be lower case.
152-
logger.trace(() -> new ParameterizedMessage("delete files container [{}], path [{}]", container, path));
153-
SocketAccess.doPrivilegedVoidException(() -> {
154-
// list the blobs using a flat blob listing mode
155-
final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
156-
for (final ListBlobItem blobItem : blobContainer.listBlobs(path, true, EnumSet.noneOf(BlobListingDetails.class), null,
157-
client.v2().get())) {
158-
final String blobName = blobNameFromUri(blobItem.getUri());
159-
logger.trace(() -> new ParameterizedMessage("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri()));
160-
// don't call {@code #deleteBlob}, use the same client
161-
final CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blobName);
162-
azureBlob.delete(DeleteSnapshotsOption.NONE, null, null, client.v2().get());
163-
}
164-
});
165-
}
166-
167149
/**
168150
* Extract the blob name from a URI like https://myservice.azure.net/container/path/to/myfile
169151
* It should remove the container part (first part of the path) and gives path/to/myfile

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/AzureStorageSettings.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ private AzureStorageSettings(String account, String key, String endpointSuffix,
129129
this.locationMode = LocationMode.PRIMARY_ONLY;
130130
}
131131

132-
public String getKey() {
133-
return key;
134-
}
135-
136-
public String getAccount() {
137-
return account;
138-
}
139-
140132
public String getEndpointSuffix() {
141133
return endpointSuffix;
142134
}
@@ -207,7 +199,7 @@ public static Map<String, AzureStorageSettings> load(Settings settings) {
207199

208200
// pkg private for tests
209201
/** Parse settings for a single client. */
210-
static AzureStorageSettings getClientSettings(Settings settings, String clientName) {
202+
private static AzureStorageSettings getClientSettings(Settings settings, String clientName) {
211203
try (SecureString account = getConfigValue(settings, clientName, ACCOUNT_SETTING);
212204
SecureString key = getConfigValue(settings, clientName, KEY_SETTING)) {
213205
return new AzureStorageSettings(account.toString(), key.toString(),
@@ -226,7 +218,7 @@ private static <T> T getConfigValue(Settings settings, String clientName,
226218
return concreteSetting.get(settings);
227219
}
228220

229-
public static <T> T getValue(Settings settings, String groupName, Setting<T> setting) {
221+
private static <T> T getValue(Settings settings, String groupName, Setting<T> setting) {
230222
final Setting.AffixKey k = (Setting.AffixKey) setting.getRawKey();
231223
final String fullKey = k.toConcreteKey(groupName).toString();
232224
return setting.getConcreteSetting(fullKey).get(settings);

plugins/repository-azure/src/main/java/org/elasticsearch/repositories/azure/SocketAccess.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static <T> T doPrivilegedIOException(PrivilegedExceptionAction<T> operati
4848
}
4949
}
5050

51-
public static <T> T doPrivilegedException(PrivilegedExceptionAction<T> operation) throws StorageException, URISyntaxException {
51+
public static <T> T doPrivilegedException(PrivilegedExceptionAction<T> operation) throws StorageException {
5252
SpecialPermission.check();
5353
try {
5454
return AccessController.doPrivileged(operation);

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureBlobStoreContainerTests.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,17 @@
1919

2020
package org.elasticsearch.repositories.azure;
2121

22-
import com.microsoft.azure.storage.StorageException;
2322
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
2423
import org.elasticsearch.common.blobstore.BlobStore;
2524
import org.elasticsearch.common.settings.Settings;
2625
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;
2726

28-
import java.io.IOException;
29-
import java.net.URISyntaxException;
3027

3128
public class AzureBlobStoreContainerTests extends ESBlobStoreContainerTestCase {
3229
@Override
33-
protected BlobStore newBlobStore() throws IOException {
34-
try {
35-
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
36-
AzureStorageServiceMock client = new AzureStorageServiceMock();
37-
return new AzureBlobStore(repositoryMetaData, client);
38-
} catch (URISyntaxException | StorageException e) {
39-
throw new IOException(e);
40-
}
30+
protected BlobStore newBlobStore() {
31+
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
32+
AzureStorageServiceMock client = new AzureStorageServiceMock();
33+
return new AzureBlobStore(repositoryMetaData, client);
4134
}
4235
}

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureBlobStoreTests.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,17 @@
1818
*/
1919
package org.elasticsearch.repositories.azure;
2020

21-
import com.microsoft.azure.storage.StorageException;
2221
import org.elasticsearch.cluster.metadata.RepositoryMetaData;
2322
import org.elasticsearch.common.blobstore.BlobStore;
2423
import org.elasticsearch.common.settings.Settings;
2524
import org.elasticsearch.repositories.ESBlobStoreTestCase;
2625

27-
import java.io.IOException;
28-
import java.net.URISyntaxException;
29-
3026
public class AzureBlobStoreTests extends ESBlobStoreTestCase {
3127

3228
@Override
33-
protected BlobStore newBlobStore() throws IOException {
34-
try {
35-
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
36-
AzureStorageServiceMock client = new AzureStorageServiceMock();
37-
return new AzureBlobStore(repositoryMetaData, client);
38-
} catch (URISyntaxException | StorageException e) {
39-
throw new IOException(e);
40-
}
29+
protected BlobStore newBlobStore() {
30+
RepositoryMetaData repositoryMetaData = new RepositoryMetaData("azure", "ittest", Settings.EMPTY);
31+
AzureStorageServiceMock client = new AzureStorageServiceMock();
32+
return new AzureBlobStore(repositoryMetaData, client);
4133
}
4234
}

plugins/repository-azure/src/test/java/org/elasticsearch/repositories/azure/AzureStorageServiceMock.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.io.IOException;
3434
import java.io.InputStream;
3535
import java.net.SocketPermission;
36-
import java.net.URISyntaxException;
3736
import java.nio.file.FileAlreadyExistsException;
3837
import java.nio.file.NoSuchFileException;
3938
import java.security.AccessController;
@@ -61,21 +60,13 @@ public boolean doesContainerExist(String account, String container) {
6160
return true;
6261
}
6362

64-
@Override
65-
public void deleteFiles(String account, String container, String path) throws URISyntaxException, StorageException {
66-
final Map<String, BlobMetaData> blobs = listBlobsByPrefix(account, container, path, null);
67-
for (String key : blobs.keySet()) {
68-
deleteBlob(account, container, key);
69-
}
70-
}
71-
7263
@Override
7364
public boolean blobExists(String account, String container, String blob) {
7465
return blobs.containsKey(blob);
7566
}
7667

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

110101
@Override
111102
public void writeBlob(String account, String container, String blobName, InputStream inputStream, long blobSize,
112-
boolean failIfAlreadyExists)
113-
throws URISyntaxException, StorageException, FileAlreadyExistsException {
103+
boolean failIfAlreadyExists) throws StorageException, FileAlreadyExistsException {
114104
if (failIfAlreadyExists && blobs.containsKey(blobName)) {
115105
throw new FileAlreadyExistsException(blobName);
116106
}

0 commit comments

Comments
 (0)