Skip to content

Commit c079fb6

Browse files
Remove Dead Code from Azure Repo Plugin (#42178) (#42569)
* None of this stuff is used
1 parent 2077f9f commit c079fb6

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
@@ -115,20 +115,16 @@ public AzureRepository(RepositoryMetaData metadata, Environment environment, Nam
115115
}
116116
}
117117

118-
// only use for testing
119118
@Override
120119
protected BlobStore getBlobStore() {
121120
return super.getBlobStore();
122121
}
123122

124-
/**
125-
* {@inheritDoc}
126-
*/
127123
@Override
128-
protected AzureBlobStore createBlobStore() throws URISyntaxException, StorageException {
124+
protected AzureBlobStore createBlobStore() {
129125
final AzureBlobStore blobStore = new AzureBlobStore(metadata, storageService);
130126

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

142-
/**
143-
* {@inheritDoc}
144-
*/
145138
@Override
146139
protected ByteSizeValue chunkSize() {
147140
return chunkSize;

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

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

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

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

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

150-
public void deleteFiles(String account, String container, String path) throws URISyntaxException, StorageException {
151-
final Tuple<CloudBlobClient, Supplier<OperationContext>> client = client(account);
152-
// container name must be lower case.
153-
logger.trace(() -> new ParameterizedMessage("delete files container [{}], path [{}]", container, path));
154-
SocketAccess.doPrivilegedVoidException(() -> {
155-
// list the blobs using a flat blob listing mode
156-
final CloudBlobContainer blobContainer = client.v1().getContainerReference(container);
157-
for (final ListBlobItem blobItem : blobContainer.listBlobs(path, true, EnumSet.noneOf(BlobListingDetails.class), null,
158-
client.v2().get())) {
159-
final String blobName = blobNameFromUri(blobItem.getUri());
160-
logger.trace(() -> new ParameterizedMessage("removing blob [{}] full URI was [{}]", blobName, blobItem.getUri()));
161-
// don't call {@code #deleteBlob}, use the same client
162-
final CloudBlockBlob azureBlob = blobContainer.getBlockBlobReference(blobName);
163-
azureBlob.delete(DeleteSnapshotsOption.NONE, null, null, client.v2().get());
164-
}
165-
});
166-
}
167-
168150
/**
169151
* Extract the blob name from a URI like https://myservice.azure.net/container/path/to/myfile
170152
* 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
@@ -34,7 +34,6 @@
3434
import java.io.IOException;
3535
import java.io.InputStream;
3636
import java.net.SocketPermission;
37-
import java.net.URISyntaxException;
3837
import java.nio.file.FileAlreadyExistsException;
3938
import java.nio.file.NoSuchFileException;
4039
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)