fix cloud-azure to not use shaded APIs
This commit is contained in:
parent
6e9080f41a
commit
43ce650755
|
@ -24,7 +24,6 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.repositories.RepositoryException;
|
||||
|
@ -35,6 +34,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -109,7 +109,7 @@ public class AzureBlobContainer extends AbstractBlobContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(@Nullable String prefix) throws IOException {
|
||||
public Map<String, BlobMetaData> listBlobsByPrefix(@Nullable String prefix) throws IOException {
|
||||
|
||||
try {
|
||||
return blobStore.client().listBlobsByPrefix(blobStore.container(), keyPath, prefix);
|
||||
|
@ -138,7 +138,7 @@ public class AzureBlobContainer extends AbstractBlobContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, BlobMetaData> listBlobs() throws IOException {
|
||||
public Map<String, BlobMetaData> listBlobs() throws IOException {
|
||||
return listBlobsByPrefix(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@ package org.elasticsearch.cloud.azure.storage;
|
|||
|
||||
import com.microsoft.azure.storage.StorageException;
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Azure Storage Service interface
|
||||
|
@ -58,7 +58,7 @@ public interface AzureStorageService {
|
|||
|
||||
OutputStream getOutputStream(String container, String blob) throws URISyntaxException, StorageException;
|
||||
|
||||
ImmutableMap<String,BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) throws URISyntaxException, StorageException;
|
||||
Map<String,BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) throws URISyntaxException, StorageException;
|
||||
|
||||
void moveBlob(String container, String sourceBlob, String targetBlob) throws URISyntaxException, StorageException;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ import com.microsoft.azure.storage.blob.*;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -35,6 +35,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage.*;
|
||||
|
||||
|
@ -168,9 +169,9 @@ public class AzureStorageServiceImpl extends AbstractLifecycleComponent<AzureSto
|
|||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) throws URISyntaxException, StorageException {
|
||||
public Map<String, BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) throws URISyntaxException, StorageException {
|
||||
logger.debug("listing container [{}], keyPath [{}], prefix [{}]", container, keyPath, prefix);
|
||||
ImmutableMap.Builder<String, BlobMetaData> blobsBuilder = ImmutableMap.builder();
|
||||
MapBuilder<String, BlobMetaData> blobsBuilder = MapBuilder.newMapBuilder();
|
||||
|
||||
CloudBlobContainer blob_container = client.getContainerReference(container);
|
||||
if (blob_container.exists()) {
|
||||
|
@ -185,7 +186,7 @@ public class AzureStorageServiceImpl extends AbstractLifecycleComponent<AzureSto
|
|||
}
|
||||
}
|
||||
|
||||
return blobsBuilder.build();
|
||||
return blobsBuilder.immutableMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.cloud.azure.AzureServiceRemoteException;
|
|||
import org.elasticsearch.cloud.azure.management.AzureComputeService;
|
||||
import org.elasticsearch.cloud.azure.management.AzureComputeService.Discovery;
|
||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||
import org.elasticsearch.common.collect.Lists;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.network.NetworkService;
|
||||
|
@ -38,6 +37,7 @@ import org.elasticsearch.transport.TransportService;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -157,7 +157,7 @@ public class AzureUnicastHostsProvider extends AbstractComponent implements Unic
|
|||
}
|
||||
logger.debug("start building nodes list using Azure API");
|
||||
|
||||
cachedDiscoNodes = Lists.newArrayList();
|
||||
cachedDiscoNodes = new ArrayList<>();
|
||||
|
||||
HostedServiceGetDetailedResponse detailed;
|
||||
try {
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.plugin.cloud.azure;
|
||||
|
||||
import org.elasticsearch.cloud.azure.AzureModule;
|
||||
import org.elasticsearch.common.collect.Lists;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
|
@ -30,6 +29,7 @@ import org.elasticsearch.repositories.RepositoriesModule;
|
|||
import org.elasticsearch.repositories.azure.AzureRepository;
|
||||
import org.elasticsearch.repositories.azure.AzureRepositoryModule;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.elasticsearch.cloud.azure.AzureModule.isSnapshotReady;
|
||||
|
@ -59,7 +59,7 @@ public class CloudAzurePlugin extends AbstractPlugin {
|
|||
|
||||
@Override
|
||||
public Collection<Class<? extends Module>> modules() {
|
||||
Collection<Class<? extends Module>> modules = Lists.newArrayList();
|
||||
Collection<Class<? extends Module>> modules = new ArrayList<>();
|
||||
if (AzureModule.isCloudReady(settings)) {
|
||||
modules.add(AzureModule.class);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.cluster.metadata.SnapshotId;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
|
@ -40,6 +39,7 @@ import org.elasticsearch.snapshots.SnapshotCreationException;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Azure file system implementation of the BlobStoreRepository
|
||||
|
@ -139,7 +139,7 @@ public class AzureRepository extends BlobStoreRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initializeSnapshot(SnapshotId snapshotId, ImmutableList<String> indices, MetaData metaData) {
|
||||
public void initializeSnapshot(SnapshotId snapshotId, List<String> indices, MetaData metaData) {
|
||||
try {
|
||||
if (!blobStore.client().doesContainerExist(blobStore.container())) {
|
||||
logger.debug("container [{}] does not exist. Creating...", blobStore.container());
|
||||
|
|
|
@ -20,9 +20,9 @@
|
|||
package org.elasticsearch.cloud.azure.management;
|
||||
|
||||
import com.microsoft.windowsazure.management.compute.models.*;
|
||||
import org.elasticsearch.common.collect.Lists;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
|
@ -58,10 +58,10 @@ public class AzureComputeServiceSimpleMock extends AzureComputeServiceAbstractMo
|
|||
endpoint.setName("elasticsearch");
|
||||
endpoint.setVirtualIPAddress(InetAddress.getLoopbackAddress());
|
||||
endpoint.setPort(9400);
|
||||
instance.setInstanceEndpoints(Lists.newArrayList(endpoint));
|
||||
instance.setInstanceEndpoints(CollectionUtils.newArrayList(endpoint));
|
||||
|
||||
deployment.setRoleInstances(Lists.newArrayList(instance));
|
||||
response.setDeployments(Lists.newArrayList(deployment));
|
||||
deployment.setRoleInstances(CollectionUtils.newArrayList(instance));
|
||||
response.setDeployments(CollectionUtils.newArrayList(deployment));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -20,13 +20,14 @@
|
|||
package org.elasticsearch.cloud.azure.management;
|
||||
|
||||
import com.microsoft.windowsazure.management.compute.models.*;
|
||||
import org.elasticsearch.common.collect.Lists;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.network.NetworkService;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
|
||||
/**
|
||||
* Mock Azure API with two started nodes
|
||||
*/
|
||||
|
@ -62,7 +63,7 @@ public class AzureComputeServiceTwoNodesMock extends AzureComputeServiceAbstract
|
|||
endpoint1.setName("elasticsearch");
|
||||
endpoint1.setVirtualIPAddress(InetAddress.getLoopbackAddress());
|
||||
endpoint1.setPort(9400);
|
||||
instance1.setInstanceEndpoints(Lists.newArrayList(endpoint1));
|
||||
instance1.setInstanceEndpoints(CollectionUtils.newArrayList(endpoint1));
|
||||
|
||||
// Fake a first instance
|
||||
RoleInstance instance2 = new RoleInstance();
|
||||
|
@ -76,11 +77,11 @@ public class AzureComputeServiceTwoNodesMock extends AzureComputeServiceAbstract
|
|||
endpoint2.setName("elasticsearch");
|
||||
endpoint2.setVirtualIPAddress(InetAddress.getLoopbackAddress());
|
||||
endpoint2.setPort(9401);
|
||||
instance2.setInstanceEndpoints(Lists.newArrayList(endpoint2));
|
||||
instance2.setInstanceEndpoints(CollectionUtils.newArrayList(endpoint2));
|
||||
|
||||
deployment.setRoleInstances(Lists.newArrayList(instance1, instance2));
|
||||
deployment.setRoleInstances(CollectionUtils.newArrayList(instance1, instance2));
|
||||
|
||||
response.setDeployments(Lists.newArrayList(deployment));
|
||||
response.setDeployments(CollectionUtils.newArrayList(deployment));
|
||||
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import com.microsoft.azure.storage.StorageException;
|
|||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -90,15 +90,14 @@ public class AzureStorageServiceMock extends AbstractLifecycleComponent<AzureSto
|
|||
}
|
||||
|
||||
@Override
|
||||
public ImmutableMap<String, BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) {
|
||||
ImmutableMap.Builder<String, BlobMetaData> blobsBuilder = ImmutableMap.builder();
|
||||
public Map<String, BlobMetaData> listBlobsByPrefix(String container, String keyPath, String prefix) {
|
||||
MapBuilder<String, BlobMetaData> blobsBuilder = MapBuilder.newMapBuilder();
|
||||
for (String blobName : blobs.keySet()) {
|
||||
if (startsWithIgnoreCase(blobName, prefix)) {
|
||||
blobsBuilder.put(blobName, new PlainBlobMetaData(blobName, blobs.get(blobName).size()));
|
||||
}
|
||||
}
|
||||
ImmutableMap<String, BlobMetaData> map = blobsBuilder.build();
|
||||
return map;
|
||||
return blobsBuilder.immutableMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.elasticsearch.cloud.azure.storage.AzureStorageService.Storage;
|
|||
import org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.base.Predicate;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.repositories.RepositoryMissingException;
|
||||
import org.elasticsearch.repositories.RepositoryVerificationException;
|
||||
|
@ -45,6 +44,7 @@ import org.elasticsearch.test.store.MockFSDirectoryService;
|
|||
import org.junit.*;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -329,7 +329,7 @@ public class AzureSnapshotRestoreITest extends AbstractAzureTest {
|
|||
* For issue #21: https://github.com/elasticsearch/elasticsearch-cloud-azure/issues/21
|
||||
*/
|
||||
@Test
|
||||
public void testForbiddenContainerName() throws URISyntaxException, StorageException, InterruptedException {
|
||||
public void testForbiddenContainerName() throws Exception {
|
||||
checkContainerName("", false);
|
||||
checkContainerName("es", false);
|
||||
checkContainerName("-elasticsearch", false);
|
||||
|
@ -347,12 +347,13 @@ public class AzureSnapshotRestoreITest extends AbstractAzureTest {
|
|||
* @param container Container name we want to create
|
||||
* @param correct Is this container name correct
|
||||
*/
|
||||
private void checkContainerName(final String container, final boolean correct) throws URISyntaxException, StorageException, InterruptedException {
|
||||
private void checkContainerName(final String container, final boolean correct) throws Exception {
|
||||
logger.info("--> creating azure repository with container name [{}]", container);
|
||||
// It could happen that we just removed from a previous test the same container so
|
||||
// we can not create it yet.
|
||||
assertThat(awaitBusy(new Predicate<Object>() {
|
||||
public boolean apply(Object obj) {
|
||||
assertBusy(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
PutRepositoryResponse putRepositoryResponse = client().admin().cluster().preparePutRepository("test-repo")
|
||||
.setType("azure").setSettings(Settings.settingsBuilder()
|
||||
|
@ -367,16 +368,15 @@ public class AzureSnapshotRestoreITest extends AbstractAzureTest {
|
|||
} catch (StorageException | URISyntaxException e) {
|
||||
// We can ignore that as we just try to clean after the test
|
||||
}
|
||||
return (putRepositoryResponse.isAcknowledged() == correct);
|
||||
assertTrue(putRepositoryResponse.isAcknowledged() == correct);
|
||||
} catch (RepositoryVerificationException e) {
|
||||
if (!correct) {
|
||||
return true;
|
||||
}
|
||||
if (correct) {
|
||||
logger.debug(" -> container is being removed. Let's wait a bit...");
|
||||
return false;
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}, 5, TimeUnit.MINUTES), equalTo(true));
|
||||
}
|
||||
}, 5, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -407,28 +407,28 @@ public class AzureSnapshotRestoreITest extends AbstractAzureTest {
|
|||
* When a user remove a container you can not immediately create it again.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveAndCreateContainer() throws URISyntaxException, StorageException, InterruptedException {
|
||||
public void testRemoveAndCreateContainer() throws Exception {
|
||||
final String container = getContainerName().concat("-testremove");
|
||||
final AzureStorageService storageService = internalCluster().getInstance(AzureStorageService.class);
|
||||
|
||||
// It could happen that we run this test really close to a previous one
|
||||
// so we might need some time to be able to create the container
|
||||
assertThat(awaitBusy(new Predicate<Object>() {
|
||||
public boolean apply(Object obj) {
|
||||
assertBusy(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
storageService.createContainer(container);
|
||||
logger.debug(" -> container created...");
|
||||
return true;
|
||||
} catch (URISyntaxException e) {
|
||||
// Incorrect URL. This should never happen.
|
||||
return false;
|
||||
fail();
|
||||
} catch (StorageException e) {
|
||||
// It could happen. Let's wait for a while.
|
||||
logger.debug(" -> container is being removed. Let's wait a bit...");
|
||||
return false;
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}, 30, TimeUnit.SECONDS), equalTo(true));
|
||||
}, 30, TimeUnit.SECONDS);
|
||||
storageService.removeContainer(container);
|
||||
|
||||
ClusterAdminClient client = client().admin().cluster();
|
||||
|
|
Loading…
Reference in New Issue