diff --git a/plugins/cloud-gce/pom.xml b/plugins/cloud-gce/pom.xml
index 7ad404d05292f..45d4e49b5724e 100644
--- a/plugins/cloud-gce/pom.xml
+++ b/plugins/cloud-gce/pom.xml
@@ -23,12 +23,15 @@ governing permissions and limitations under the License. -->
cloud-gce
Plugin: Cloud: Google Compute Engine
- The Google Compute Engine (GCE) Cloud plugin allows to use GCE API for the unicast discovery mechanism.
+ The Google Compute Engine (GCE) Cloud plugin allows to use GCE API for the unicast discovery
+ mechanism.
+
- org.elasticsearch.plugin.cloud.gce.CloudGcePlugin
+ org.elasticsearch.plugin.cloud.gce.CloudGcePlugin
+
v1-rev144-1.21.0
- 1.0.0
+ 1.0.0
cloud_gce
false
@@ -39,21 +42,21 @@ governing permissions and limitations under the License. -->
- com.google.apis
- google-api-services-compute
- ${google.gce.version}
-
-
- com.google.guava
- guava-jdk5
-
-
+ com.google.apis
+ google-api-services-compute
+ ${google.gce.version}
+
+
+ com.google.guava
+ guava-jdk5
+
+
+
+
+ com.google.cloud
+ google-cloud-storage
+ ${google.gcs.version}
-
- com.google.cloud
- google-cloud-storage
- ${google.gcs.version}
-
@@ -65,7 +68,7 @@ governing permissions and limitations under the License. -->
-
+
de.thetaphi
forbiddenapis
@@ -117,8 +120,8 @@ governing permissions and limitations under the License. -->
-
-
+
+
true
@@ -133,8 +136,8 @@ governing permissions and limitations under the License. -->
-
-
+
+
true
@@ -165,28 +168,29 @@ governing permissions and limitations under the License. -->
maven-assembly-plugin
- org.apache.maven.plugins
- maven-antrun-plugin
-
-
-
- certificate-setup
- generate-test-resources
-
- run
-
-
-
-
-
-
-
-
-
- ${skip.unit.tests}
-
-
-
+ org.apache.maven.plugins
+ maven-antrun-plugin
+
+
+
+ certificate-setup
+ generate-test-resources
+
+ run
+
+
+
+
+
+
+
+
+
+ ${skip.unit.tests}
+
+
+
+
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeService.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeService.java
index 3ba69fe496685..f1c57ae8c7c88 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeService.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeService.java
@@ -42,6 +42,7 @@ final class Fields {
/**
* Return a collection of running instances within the same GCE project
+ *
* @return a collection of running instances within the same GCE project
*/
Collection instances();
@@ -54,10 +55,11 @@ final class Fields {
* `hostname` when we need to resolve the host name
* `network-interfaces/0/ip` when we need to resolve private IP
*
- * @see org.elasticsearch.cloud.gce.network.GceNameResolver for bindings
+ *
* @param metadataPath path to metadata information
* @return extracted information (for example a hostname or an IP address)
* @throws IOException in case metadata URL is not accessible
+ * @see org.elasticsearch.cloud.gce.network.GceNameResolver for bindings
*/
String metadata(String metadataPath) throws IOException;
}
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeServiceImpl.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeServiceImpl.java
index 0615c013b4709..e76f78f4efda9 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeServiceImpl.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/GceComputeServiceImpl.java
@@ -55,6 +55,7 @@
import java.util.List;
import static org.elasticsearch.common.util.CollectionUtils.eagerTransform;
+
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.*;
@@ -83,47 +84,47 @@ public class GceComputeServiceImpl extends AbstractLifecycleComponent instances() {
- logger.debug("get instances for project [{}], zones [{}]", project, zones);
-
- List> instanceListByZone = eagerTransform(zones, new Function>() {
- @Override
- public List apply(final String zoneId) {
- try {
- // hack around code messiness in GCE code
- // TODO: get this fixed
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(new SpecialPermission());
- }
- InstanceList instanceList = AccessController.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public InstanceList run() throws Exception {
- Compute.Instances.List list = client().instances().list(project, zoneId);
- return list.execute();
- }
- });
- if (instanceList.isEmpty() || instanceList.getItems() == null) {
- return Collections.EMPTY_LIST;
+ logger.debug("get instances for project [{}], zones [{}]", project, zones);
+
+ List> instanceListByZone = eagerTransform(zones, new Function>() {
+ @Override
+ public List apply(final String zoneId) {
+ try {
+ // hack around code messiness in GCE code
+ // TODO: get this fixed
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(new SpecialPermission());
+ }
+ InstanceList instanceList = AccessController.doPrivileged(new PrivilegedExceptionAction() {
+ @Override
+ public InstanceList run() throws Exception {
+ Compute.Instances.List list = client().instances().list(project, zoneId);
+ return list.execute();
}
-
- return instanceList.getItems();
- } catch (PrivilegedActionException e) {
- logger.warn("Problem fetching instance list for zone {}", zoneId);
- logger.debug("Full exception:", e);
-
+ });
+ if (instanceList.isEmpty() || instanceList.getItems() == null) {
return Collections.EMPTY_LIST;
}
- }
- });
- // Collapse instances from all zones into one neat list
- List instanceList = CollectionUtils.iterableAsArrayList(Iterables.concat(instanceListByZone));
+ return instanceList.getItems();
+ } catch (PrivilegedActionException e) {
+ logger.warn("Problem fetching instance list for zone {}", zoneId);
+ logger.debug("Full exception:", e);
- if (instanceList.size() == 0) {
- logger.warn("disabling GCE discovery. Can not get list of nodes");
+ return Collections.EMPTY_LIST;
+ }
}
+ });
+
+ // Collapse instances from all zones into one neat list
+ List instanceList = CollectionUtils.iterableAsArrayList(Iterables.concat(instanceListByZone));
+
+ if (instanceList.size() == 0) {
+ logger.warn("disabling GCE discovery. Can not get list of nodes");
+ }
- return instanceList;
+ return instanceList;
}
@Override
@@ -146,9 +147,9 @@ public HttpHeaders run() throws IOException {
headers.put("Metadata-Flavor", "Google");
HttpResponse response;
response = getGceHttpTransport().createRequestFactory()
- .buildGetRequest(new GenericUrl(url))
- .setHeaders(headers)
- .execute();
+ .buildGetRequest(new GenericUrl(url))
+ .setHeaders(headers)
+ .execute();
String metadata = response.parseAsString();
logger.debug("metadata found [{}]", metadata);
return metadata;
@@ -161,10 +162,14 @@ public HttpHeaders run() throws IOException {
private TimeValue refreshInterval = null;
private long lastRefresh;
- /** Global instance of the HTTP transport. */
+ /**
+ * Global instance of the HTTP transport.
+ */
private HttpTransport gceHttpTransport;
- /** Global instance of the JSON factory. */
+ /**
+ * Global instance of the JSON factory.
+ */
private JsonFactory gceJsonFactory;
@Inject
@@ -176,7 +181,7 @@ public GceComputeServiceImpl(Settings settings, NetworkService networkService) {
networkService.addCustomNameResolver(new GceNameResolver(settings, this));
this.gceHost = settings.get("cloud.gce.host", DEFAULT_GCE_HOST);
- this.metaDataUrl = gceHost + "/computeMetadata/v1/instance";
+ this.metaDataUrl = gceHost + "/computeMetadata/v1/instance";
this.gceRootUrl = settings.get("cloud.gce.root_url", DEFAULT_GCE_ROOT_URL);
this.tokenServerEncodedUrl = metaDataUrl + "/service-accounts/default/token";
this.validateCerts = settings.getAsBoolean("cloud.gce.validate_certificates", true);
@@ -197,7 +202,7 @@ protected synchronized HttpTransport getGceHttpTransport() throws GeneralSecurit
public synchronized Compute client() {
if (refreshInterval != null && refreshInterval.millis() != 0) {
if (client != null &&
- (refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
+ (refreshInterval.millis() < 0 || (System.currentTimeMillis() - lastRefresh) < refreshInterval.millis())) {
if (logger.isTraceEnabled()) logger.trace("using cache to retrieve client");
return client;
}
@@ -209,8 +214,8 @@ public synchronized Compute client() {
logger.info("starting GCE discovery service");
final ComputeCredential credential = new ComputeCredential.Builder(getGceHttpTransport(), gceJsonFactory)
- .setTokenServerEncodedUrl(this.tokenServerEncodedUrl)
- .build();
+ .setTokenServerEncodedUrl(this.tokenServerEncodedUrl)
+ .build();
// hack around code messiness in GCE code
// TODO: get this fixed
@@ -228,12 +233,13 @@ public Void run() throws IOException {
logger.debug("token [{}] will expire in [{}] s", credential.getAccessToken(), credential.getExpiresInSeconds());
if (credential.getExpiresInSeconds() != null) {
- refreshInterval = TimeValue.timeValueSeconds(credential.getExpiresInSeconds()-1);
+ refreshInterval = TimeValue.timeValueSeconds(credential.getExpiresInSeconds() - 1);
}
final boolean ifRetry = settings.getAsBoolean(Fields.RETRY, true);
final Compute.Builder builder = new Compute.Builder(getGceHttpTransport(), gceJsonFactory, null)
- .setApplicationName(Fields.VERSION).setRootUrl(gceRootUrl);;
+ .setApplicationName(Fields.VERSION).setRootUrl(gceRootUrl);
+ ;
if (ifRetry) {
int maxWait = settings.getAsInt(Fields.MAXWAIT, -1);
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java
index 22d79fb1614ae..a0cfa1d9d79fe 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gce/network/GceNameResolver.java
@@ -101,7 +101,7 @@ private InetAddress[] resolve(String value) throws IOException {
gceMetadataPath = Strings.replace(GceAddressResolverType.PRIVATE_IP.gceName, "{{network}}", network);
} else {
throw new IllegalArgumentException("[" + value + "] is not one of the supported GCE network.host setting. " +
- "Expecting _gce_, _gce:privateIp:X_, _gce:hostname_");
+ "Expecting _gce_, _gce:privateIp:X_, _gce:hostname_");
}
try {
@@ -110,7 +110,7 @@ private InetAddress[] resolve(String value) throws IOException {
throw new IOException("no gce metadata returned from [" + gceMetadataPath + "] for [" + value + "]");
}
// only one address: because we explicitly ask for only one via the GceHostnameType
- return new InetAddress[] { InetAddress.getByName(metadataResult) };
+ return new InetAddress[]{InetAddress.getByName(metadataResult)};
} catch (IOException e) {
throw new IOException("IOException caught when fetching InetAddress from [" + gceMetadataPath + "]", e);
}
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSModule.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSModule.java
index ad51e2fcf8799..6cead5b49cf88 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSModule.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSModule.java
@@ -22,16 +22,16 @@
import org.elasticsearch.common.inject.AbstractModule;
public class GCSModule extends AbstractModule {
-
- static Class extends GCSService> storageServiceImpl = GCSServiceImpl.class;
- public static Class extends GCSService> getStorageServiceImpl() {
- return storageServiceImpl;
+ static Class extends GCSService> storageServiceImpl = GCSServiceImpl.class;
+
+ public static Class extends GCSService> getStorageServiceImpl() {
+ return storageServiceImpl;
}
- @Override
- protected void configure() {
- bind(GCSService.class).to(storageServiceImpl).asEagerSingleton();
- }
+ @Override
+ protected void configure() {
+ bind(GCSService.class).to(storageServiceImpl).asEagerSingleton();
+ }
-}
\ No newline at end of file
+}
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSService.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSService.java
index 2f88a8c7d0264..4773d6e66535e 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSService.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSService.java
@@ -29,17 +29,19 @@
public interface GCSService extends LifecycleComponent {
- final class RepositoryGCS {
- private RepositoryGCS() {}
- public static final String BUCKET = "repositories.gcs.bucket";
- public static final String BASE_PATH = "repositories.gcs.base_path";
- public static final String APPLICATION_NAME = "repositories.gcs.application_name";
- public static final String SERVICE_ACCOUNT = "repositories.gcs.service_account";
- public static final String HTTP_READ_TIMEOUT = "repositories.gcs.http.read_timeout";
- public static final String HTTP_CONNECT_TIMEOUT = "repositories.gcs.http.connect_timeout";
+ final class RepositoryGCS {
+ private RepositoryGCS() {
+ }
+
+ public static final String BUCKET = "repositories.gcs.bucket";
+ public static final String BASE_PATH = "repositories.gcs.base_path";
+ public static final String APPLICATION_NAME = "repositories.gcs.application_name";
+ public static final String SERVICE_ACCOUNT = "repositories.gcs.service_account";
+ public static final String HTTP_READ_TIMEOUT = "repositories.gcs.http.read_timeout";
+ public static final String HTTP_CONNECT_TIMEOUT = "repositories.gcs.http.connect_timeout";
public static final String CHUNK_SIZE = "repositories.gcs.chunk_size";
- public static final String COMPRESS = "repositories.gcs.compress";
- }
-
- Storage createClient(String serviceAccount,String application,TimeValue connectTimeout, TimeValue readTimeout) throws IOException, GeneralSecurityException;
+ public static final String COMPRESS = "repositories.gcs.compress";
+ }
+
+ Storage createClient(String serviceAccount, String application, TimeValue connectTimeout, TimeValue readTimeout) throws IOException, GeneralSecurityException;
}
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSServiceImpl.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSServiceImpl.java
index b8f627eeebb86..c5c259b3416c7 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSServiceImpl.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/GCSServiceImpl.java
@@ -46,108 +46,108 @@
public class GCSServiceImpl extends AbstractLifecycleComponent implements GCSService {
- private Environment env;
-
- @Inject
- public GCSServiceImpl(Environment env) {
- super(env.settings());
- this.env = env;
- }
-
- @Override
- public Storage createClient(final String serviceAccount, final String application, final TimeValue connectTimeout,
- final TimeValue readTimeout) throws IOException, GeneralSecurityException {
-
- final NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
- builder.trustCertificates(GoogleUtils.getCertificateTrustStore());
- final HttpTransport httpTransport = builder.build();
-
- final HttpTransportOptions httpTransportOptions = HttpTransportOptions.newBuilder()
- .setConnectTimeout(RepoUtil.toTimeout(connectTimeout))
- .setReadTimeout(RepoUtil.toTimeout(readTimeout))
- .setHttpTransportFactory(new HttpTransportFactory() {
- @Override
- public HttpTransport create() {
- return httpTransport;
- }
- })
- .build();
-
- final ServiceAccountCredentials serviceAccountCredentials = loadCredentials(serviceAccount);
-
-
- final String projectId = getProjectId(serviceAccountCredentials);
-
- logger.debug("Project ID: [{}]", projectId);
- logger.debug("initializing client with service account [{}]", serviceAccountCredentials.toString());
-
- return StorageOptions.newBuilder()
- .setCredentials(serviceAccountCredentials)
- .setTransportOptions(httpTransportOptions)
- .setProjectId(projectId)
- .build()
- .getService();
- }
-
- /**
- * Retrieve the cloud project Id from the service account
- * @param serviceAccountCredentials
- * @return Project Id
- */
- private String getProjectId(ServiceAccountCredentials serviceAccountCredentials) {
-
- //Assuming that the client email is from the same cloud project
-
- String[] emailParts = serviceAccountCredentials.getClientEmail().split("@");
- String[] domainPart = emailParts[1].split("\\.");
- return domainPart[0];
- }
-
- /**
- * HTTP request initializer that loads credentials from the service account file
- * and manages authentication for HTTP requests
- */
- private ServiceAccountCredentials loadCredentials(String serviceAccount) throws IOException {
- if (serviceAccount == null) {
- throw new ElasticsearchException("Cannot load Google Cloud Storage service account file from a null path");
- }
-
- Path account = env.configFile().resolve(serviceAccount);
- if (!Files.exists(account)) {
- throw new ElasticsearchException(
- "Unable to find service account file [" + serviceAccount + "] defined for repository");
- }
- else {
- logger.info("Found service account: [{}]", account.toAbsolutePath());
- }
-
- try (InputStream is = Files.newInputStream(account)) {
- return RepoUtil.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public ServiceAccountCredentials run() throws Exception {
- final Collection scopes = Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL);
- final ServiceAccountCredentials credentials = ServiceAccountCredentials.fromStream(is);
- if (credentials.createScopedRequired()) {
- return (ServiceAccountCredentials) credentials.createScoped(scopes);
- }
- return credentials;
- }
- });
- }
- }
-
- @Override
- protected void doStart() {
- logger.debug("Started Component GCSServiceImpl");
- }
-
- @Override
- protected void doStop() {
- logger.debug("Stopped Component GCSServiceImpl");
- }
-
- @Override
- protected void doClose() {
- logger.debug("Closed Component GCSServiceImpl");
- }
+ private Environment env;
+
+ @Inject
+ public GCSServiceImpl(Environment env) {
+ super(env.settings());
+ this.env = env;
+ }
+
+ @Override
+ public Storage createClient(final String serviceAccount, final String application, final TimeValue connectTimeout,
+ final TimeValue readTimeout) throws IOException, GeneralSecurityException {
+
+ final NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
+ builder.trustCertificates(GoogleUtils.getCertificateTrustStore());
+ final HttpTransport httpTransport = builder.build();
+
+ final HttpTransportOptions httpTransportOptions = HttpTransportOptions.newBuilder()
+ .setConnectTimeout(RepoUtil.toTimeout(connectTimeout))
+ .setReadTimeout(RepoUtil.toTimeout(readTimeout))
+ .setHttpTransportFactory(new HttpTransportFactory() {
+ @Override
+ public HttpTransport create() {
+ return httpTransport;
+ }
+ })
+ .build();
+
+ final ServiceAccountCredentials serviceAccountCredentials = loadCredentials(serviceAccount);
+
+
+ final String projectId = getProjectId(serviceAccountCredentials);
+
+ logger.debug("Project ID: [{}]", projectId);
+ logger.debug("initializing client with service account [{}]", serviceAccountCredentials.toString());
+
+ return StorageOptions.newBuilder()
+ .setCredentials(serviceAccountCredentials)
+ .setTransportOptions(httpTransportOptions)
+ .setProjectId(projectId)
+ .build()
+ .getService();
+ }
+
+ /**
+ * Retrieve the cloud project Id from the service account
+ *
+ * @param serviceAccountCredentials
+ * @return Project Id
+ */
+ private String getProjectId(ServiceAccountCredentials serviceAccountCredentials) {
+
+ //Assuming that the client email is from the same cloud project
+
+ String[] emailParts = serviceAccountCredentials.getClientEmail().split("@");
+ String[] domainPart = emailParts[1].split("\\.");
+ return domainPart[0];
+ }
+
+ /**
+ * HTTP request initializer that loads credentials from the service account file
+ * and manages authentication for HTTP requests
+ */
+ private ServiceAccountCredentials loadCredentials(String serviceAccount) throws IOException {
+ if (serviceAccount == null) {
+ throw new ElasticsearchException("Cannot load Google Cloud Storage service account file from a null path");
+ }
+
+ Path account = env.configFile().resolve(serviceAccount);
+ if (!Files.exists(account)) {
+ throw new ElasticsearchException(
+ "Unable to find service account file [" + serviceAccount + "] defined for repository");
+ } else {
+ logger.info("Found service account: [{}]", account.toAbsolutePath());
+ }
+
+ try (InputStream is = Files.newInputStream(account)) {
+ return RepoUtil.doPrivileged(new PrivilegedExceptionAction() {
+ @Override
+ public ServiceAccountCredentials run() throws Exception {
+ final Collection scopes = Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL);
+ final ServiceAccountCredentials credentials = ServiceAccountCredentials.fromStream(is);
+ if (credentials.createScopedRequired()) {
+ return (ServiceAccountCredentials) credentials.createScoped(scopes);
+ }
+ return credentials;
+ }
+ });
+ }
+ }
+
+ @Override
+ protected void doStart() {
+ logger.debug("Started Component GCSServiceImpl");
+ }
+
+ @Override
+ protected void doStop() {
+ logger.debug("Stopped Component GCSServiceImpl");
+ }
+
+ @Override
+ protected void doClose() {
+ logger.debug("Closed Component GCSServiceImpl");
+ }
}
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobContainer.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobContainer.java
index 59979bb6a851a..4dc7ff418ef39 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobContainer.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobContainer.java
@@ -34,84 +34,84 @@
public class GCSBlobContainer extends AbstractBlobContainer {
- private final ESLogger logger = Loggers.getLogger(getClass());
- private final GCSBlobStore blobStore;
- private final String path;
-
- protected GCSBlobContainer(BlobPath path, GCSBlobStore blobStore) {
- super(path);
- this.blobStore = blobStore;
- String keyPath = path.buildAsString("/");
- if (!keyPath.isEmpty()) {
+ private final ESLogger logger = Loggers.getLogger(getClass());
+ private final GCSBlobStore blobStore;
+ private final String path;
+
+ protected GCSBlobContainer(BlobPath path, GCSBlobStore blobStore) {
+ super(path);
+ this.blobStore = blobStore;
+ String keyPath = path.buildAsString("/");
+ if (!keyPath.isEmpty()) {
keyPath = keyPath + "/";
}
this.path = keyPath;
-
+
logger.debug("Path: {}", this.path);
- }
-
- @Override
- public boolean blobExists(String blobName) {
- logger.debug("Check if blob {} exists", blobName);
- try {
- return blobStore.blobExists(buildKey(blobName));
- } catch (Exception e) {
- throw new BlobStoreException("Failed to check if blob [" + blobName + "] exists", e);
- }
- }
-
- @Override
- public Map listBlobs() throws IOException {
- logger.debug("List all blobs");
- return blobStore.listBlobs(path);
- }
-
- @Override
- public Map listBlobsByPrefix(String prefix) throws IOException {
- logger.debug("List all blobs by prefix: {}", prefix);
- return blobStore.listBlobsByPrefix(path, prefix);
- }
-
- @Override
- public InputStream readBlob(String blobName) throws IOException {
- logger.debug("Read blob {}", blobName);
- return blobStore.readBlob(buildKey(blobName));
- }
-
- @Override
- public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
- logger.debug("InputStream - Write to blob {}", blobName);
-
- if (blobExists(blobName)) {
- throw new FileAlreadyExistsException("blob [" + blobName + "] already exists, cannot overwrite");
- }
- blobStore.writeBlob(buildKey(blobName), inputStream, blobSize);
- }
-
- @Override
- public void writeBlob(String blobName, BytesReference bytes) throws IOException {
- logger.debug("BytesReference - Write to blob {}", blobName);
-
- if (blobExists(blobName)) {
- throw new FileAlreadyExistsException("blob [" + blobName + "] already exists, cannot overwrite");
- }
- blobStore.writeBlob(buildKey(blobName), bytes);
- }
-
- @Override
- public void deleteBlob(String blobName) throws IOException {
- logger.debug("Delete to blob {}", blobName);
- blobStore.deleteBlob(buildKey(blobName));
- }
-
- @Override
- public void move(String sourceBlobName, String targetBlobName) throws IOException {
- logger.debug("Move blob from {} to {}", sourceBlobName,targetBlobName);
- blobStore.moveBlob(buildKey(sourceBlobName), buildKey(targetBlobName));
- }
-
- protected String buildKey(String blobName) {
- assert blobName != null;
- return path + blobName;
- }
+ }
+
+ @Override
+ public boolean blobExists(String blobName) {
+ logger.debug("Check if blob {} exists", blobName);
+ try {
+ return blobStore.blobExists(buildKey(blobName));
+ } catch (Exception e) {
+ throw new BlobStoreException("Failed to check if blob [" + blobName + "] exists", e);
+ }
+ }
+
+ @Override
+ public Map listBlobs() throws IOException {
+ logger.debug("List all blobs");
+ return blobStore.listBlobs(path);
+ }
+
+ @Override
+ public Map listBlobsByPrefix(String prefix) throws IOException {
+ logger.debug("List all blobs by prefix: {}", prefix);
+ return blobStore.listBlobsByPrefix(path, prefix);
+ }
+
+ @Override
+ public InputStream readBlob(String blobName) throws IOException {
+ logger.debug("Read blob {}", blobName);
+ return blobStore.readBlob(buildKey(blobName));
+ }
+
+ @Override
+ public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
+ logger.debug("InputStream - Write to blob {}", blobName);
+
+ if (blobExists(blobName)) {
+ throw new FileAlreadyExistsException("blob [" + blobName + "] already exists, cannot overwrite");
+ }
+ blobStore.writeBlob(buildKey(blobName), inputStream, blobSize);
+ }
+
+ @Override
+ public void writeBlob(String blobName, BytesReference bytes) throws IOException {
+ logger.debug("BytesReference - Write to blob {}", blobName);
+
+ if (blobExists(blobName)) {
+ throw new FileAlreadyExistsException("blob [" + blobName + "] already exists, cannot overwrite");
+ }
+ blobStore.writeBlob(buildKey(blobName), bytes);
+ }
+
+ @Override
+ public void deleteBlob(String blobName) throws IOException {
+ logger.debug("Delete to blob {}", blobName);
+ blobStore.deleteBlob(buildKey(blobName));
+ }
+
+ @Override
+ public void move(String sourceBlobName, String targetBlobName) throws IOException {
+ logger.debug("Move blob from {} to {}", sourceBlobName, targetBlobName);
+ blobStore.moveBlob(buildKey(sourceBlobName), buildKey(targetBlobName));
+ }
+
+ protected String buildKey(String blobName) {
+ assert blobName != null;
+ return path + blobName;
+ }
}
diff --git a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobStore.java b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobStore.java
index 8e09d2d5e8106..7ffbbb0d8fafb 100644
--- a/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobStore.java
+++ b/plugins/cloud-gce/src/main/java/org/elasticsearch/cloud/gcs/blobstore/GCSBlobStore.java
@@ -19,6 +19,23 @@
package org.elasticsearch.cloud.gcs.blobstore;
+import com.google.api.gax.paging.Page;
+import com.google.cloud.ReadChannel;
+import com.google.cloud.WriteChannel;
+import com.google.cloud.storage.*;
+import com.google.cloud.storage.Storage.BlobListOption;
+import com.google.cloud.storage.Storage.CopyRequest;
+import org.elasticsearch.common.SuppressForbidden;
+import org.elasticsearch.common.blobstore.*;
+import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
+import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.collect.MapBuilder;
+import org.elasticsearch.common.component.AbstractComponent;
+import org.elasticsearch.common.io.Streams;
+import org.elasticsearch.common.io.stream.StreamInput;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.repositories.gcs.RepoUtil;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -28,433 +45,432 @@
import java.nio.channels.WritableByteChannel;
import java.nio.file.NoSuchFileException;
import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.elasticsearch.common.blobstore.BlobContainer;
-import org.elasticsearch.common.blobstore.BlobPath;
-import org.elasticsearch.common.blobstore.BlobStore;
-import org.elasticsearch.common.blobstore.BlobMetaData;
-import org.elasticsearch.common.blobstore.BlobStoreException;
-import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
-import org.elasticsearch.common.bytes.BytesReference;
-import org.elasticsearch.common.collect.MapBuilder;
-import org.elasticsearch.common.component.AbstractComponent;
-import org.elasticsearch.common.io.stream.StreamInput;
-import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.repositories.gcs.RepoUtil;
-import org.elasticsearch.common.SuppressForbidden;
-import org.elasticsearch.common.io.Streams;
-
-import com.google.cloud.ReadChannel;
-import com.google.cloud.WriteChannel;
-import com.google.cloud.storage.Blob;
-import com.google.cloud.storage.BlobId;
-import com.google.cloud.storage.BlobInfo;
-import com.google.cloud.storage.Storage;
-import com.google.cloud.storage.Storage.BlobListOption;
-import com.google.cloud.storage.Storage.CopyRequest;
-import com.google.cloud.storage.StorageException;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicLong;
public class GCSBlobStore extends AbstractComponent implements BlobStore {
-
- // The recommended maximum size of a blob that should be uploaded in a single
- // request. Larger files should be uploaded over multiple requests (this is
- // called "resumable upload")
- // https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload
- private static final int LARGE_BLOB_THRESHOLD_BYTE_SIZE = 5 * 1024 * 1024;
-
- private final Storage storage;
- private final String bucket;
-
- public GCSBlobStore(Settings settings, String bucket, Storage storage) {
- super(settings);
- this.bucket = bucket;
- this.storage = storage;
-
- if (!doesBucketExist(bucket)) {
- throw new BlobStoreException("Bucket [" + bucket + "] does not exist");
- }
- }
-
- @Override
- public BlobContainer blobContainer(BlobPath path) {
- logger.info("Set blob container with path: {}", path);
- return new GCSBlobContainer(path, this);
- }
-
- @Override
- public void delete(BlobPath path) throws IOException {
- logger.debug("Delete path: {}", path.toString());
- String keyPath = path.buildAsString("/");
- if (!keyPath.isEmpty()) {
- keyPath = keyPath + "/";
- }
- logger.debug("Delete path: {}", keyPath);
- deleteBlobsByPrefix(keyPath);
- }
-
- @Override
- public void close() {
- logger.debug("Closed GCSBlobStore");
- }
-
- /**
- * Return true if the given bucket exists
- *
- * @param bucketName name of the bucket
- * @return true if the bucket exists, false otherwise
- */
- boolean doesBucketExist(final String bucketName) {
- logger.debug("Checking if bucekt exists: {}", bucketName);
- try {
- return RepoUtil.doPrivileged(new PrivilegedExceptionAction() {
- @Override
- public Boolean run() throws Exception {
- return storage.get(bucketName) != null;
- }
- });
- } catch (IOException e) {
- logger.error("Error checking if bucket exists: {}", e, bucketName);
- throw new BlobStoreException("Unable to check if bucket [" + bucketName + "] exists", e);
- }
- }
-
- /**
- * List all blobs in the bucket
- *
- * @param path base path of the blobs to list
- * @return a map of blob names and their metadata
- */
- Map listBlobs(final String path) throws IOException {
- return listBlobsByPrefix(path, "");
- }
-
- /**
- * List all blobs in the bucket which have a prefix
- *
- * @param path base path of the blobs to list
- * @param prefix prefix of the blobs to list
- * @return a map of blob names and their metadata
- */
- Map listBlobsByPrefix(final String path, final String prefix) throws IOException {
- logger.debug("List blobs for path: {}, prefix: {}", path, prefix);
- final String pathPrefix = buildKey(path, prefix);
- logger.debug("Path prefix: {}", pathPrefix);
- final MapBuilder mapBuilder = MapBuilder.newMapBuilder();
-
- return RepoUtil.doPrivileged(new PrivilegedExceptionAction