parent
e2691d7e5c
commit
35d3bdab84
|
@ -126,6 +126,7 @@ class InstallPluginCommand extends Command {
|
|||
"mapper-murmur3",
|
||||
"mapper-size",
|
||||
"repository-azure",
|
||||
"repository-gcs",
|
||||
"repository-hdfs",
|
||||
"repository-s3",
|
||||
"store-smb",
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.elasticsearch.common.blobstore.fs.FsBlobStore;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.test.ESBlobStoreContainerTestCase;
|
||||
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.elasticsearch.common.blobstore.fs.FsBlobStore;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.test.ESBlobStoreTestCase;
|
||||
import org.elasticsearch.repositories.ESBlobStoreTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
|
|
@ -20,7 +20,7 @@ package org.elasticsearch.snapshots;
|
|||
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.test.ESBlobStoreRepositoryIntegTestCase;
|
||||
import org.elasticsearch.repositories.ESBlobStoreRepositoryIntegTestCase;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
|
||||
|
|
|
@ -75,6 +75,7 @@ DEFAULT_PLUGINS = ["analysis-icu",
|
|||
"mapper-murmur3",
|
||||
"mapper-size",
|
||||
"repository-azure",
|
||||
"repository-gcs",
|
||||
"repository-hdfs",
|
||||
"repository-s3",
|
||||
"store-smb"]
|
||||
|
|
|
@ -0,0 +1,216 @@
|
|||
[[repository-gcs]]
|
||||
=== Google Cloud Storage Repository Plugin
|
||||
|
||||
The GCS repository plugin adds support for using the https://cloud.google.com/storage/[Google Cloud Storage]
|
||||
service as a repository for {ref}/modules-snapshots.html[Snapshot/Restore].
|
||||
|
||||
[[repository-gcs-install]]
|
||||
[float]
|
||||
==== Installation
|
||||
|
||||
This plugin can be installed using the plugin manager:
|
||||
|
||||
[source,sh]
|
||||
----------------------------------------------------------------
|
||||
sudo bin/elasticsearch-plugin install repository-gcs
|
||||
----------------------------------------------------------------
|
||||
|
||||
NOTE: The plugin requires new permission to be installed in order to work
|
||||
|
||||
The plugin must be installed on every node in the cluster, and each node must
|
||||
be restarted after installation.
|
||||
|
||||
[[repository-gcs-remove]]
|
||||
[float]
|
||||
==== Removal
|
||||
|
||||
The plugin can be removed with the following command:
|
||||
|
||||
[source,sh]
|
||||
----------------------------------------------------------------
|
||||
sudo bin/elasticsearch-plugin remove repository-gcs
|
||||
----------------------------------------------------------------
|
||||
|
||||
The node must be stopped before removing the plugin.
|
||||
|
||||
[[repository-gcs-usage]]
|
||||
==== Getting started
|
||||
|
||||
The plugin uses the https://cloud.google.com/storage/docs/json_api/[Google Cloud Storage JSON API] (v1)
|
||||
to connect to the Storage service. If this is the first time you use Google Cloud Storage, you first
|
||||
need to connect to the https://console.cloud.google.com/[Google Cloud Platform Console] and create a new
|
||||
project. Once your project is created, you must enable the Cloud Storage Service for your project.
|
||||
|
||||
[[repository-gcs-creating-bucket]]
|
||||
===== Creating a Bucket
|
||||
|
||||
Google Cloud Storage service uses the concept of https://cloud.google.com/storage/docs/key-terms[Bucket]
|
||||
as a container for all the data. Buckets are usually created using the
|
||||
https://console.cloud.google.com/[Google Cloud Platform Console]. The plugin will not automatically
|
||||
create buckets.
|
||||
|
||||
To create a new bucket:
|
||||
|
||||
1. Connect to the https://console.cloud.google.com/[Google Cloud Platform Console]
|
||||
2. Select your project
|
||||
3. Got to the https://console.cloud.google.com/storage/browser[Storage Browser]
|
||||
4. Click the "Create Bucket" button
|
||||
5. Enter a the name of the new bucket
|
||||
6. Select a storage class
|
||||
7. Select a location
|
||||
8. Click the "Create" button
|
||||
|
||||
The bucket should now be created.
|
||||
|
||||
[[repository-gcs-service-authentication]]
|
||||
===== Service Authentication
|
||||
|
||||
The plugin supports two authentication modes:
|
||||
|
||||
* the built-in <<repository-gcs-using-compute-engine, Compute Engine authentication>>. This mode is
|
||||
recommended if your elasticsearch node is running on a Compute Engine virtual machine.
|
||||
|
||||
* the <<repository-gcs-using-service-account, Service Account>> authentication mode.
|
||||
|
||||
[[repository-gcs-using-compute-engine]]
|
||||
===== Using Compute Engine
|
||||
When running on Compute Engine, the plugin use the Google's built-in authentication mechanism to
|
||||
authenticate on the Storage service. Compute Engine virtual machines are usually associated to a
|
||||
default service account. This service account can be found in the VM instance details in the
|
||||
https://console.cloud.google.com/compute/[Compute Engine console].
|
||||
|
||||
To indicate that a repository should use the built-in authentication,
|
||||
the repository `service_account` setting must be set to `_default_`:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
PUT _snapshot/my_gcs_repository_on_compute_engine
|
||||
{
|
||||
"type": "gcs",
|
||||
"settings": {
|
||||
"bucket": "my_bucket",
|
||||
"service_account": "_default_"
|
||||
}
|
||||
}
|
||||
----
|
||||
// CONSOLE
|
||||
|
||||
NOTE: The Compute Engine VM must be allowed to use the Storage service. This can be done only at VM
|
||||
creation time, when "Storage" access can be configured to "Read/Write" permission. Check your
|
||||
instance details at the section "Cloud API access scopes".
|
||||
|
||||
[[repository-gcs-using-service-account]]
|
||||
===== Using a Service Account
|
||||
If your elasticsearch node is not running on Compute Engine, or if you don't want to use Google
|
||||
built-in authentication mechanism, you can authenticate on the Storage service using a
|
||||
https://cloud.google.com/iam/docs/overview#service_account[Service Account] file.
|
||||
|
||||
To create a service account file:
|
||||
1. Connect to the https://console.cloud.google.com/[Google Cloud Platform Console]
|
||||
2. Select your project
|
||||
3. Got to the https://console.cloud.google.com/permissions[Permission] tab
|
||||
4. Select the https://console.cloud.google.com/permissions/serviceaccounts[Service Accounts] tab
|
||||
5. Click on "Create service account"
|
||||
6. Once created, select the new service account and download a JSON key file
|
||||
|
||||
A service account file looks like this:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "your-project-id",
|
||||
"private_key_id": "...",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "service-account-for-your-repository@your-project-id.iam.gserviceaccount.com",
|
||||
"client_id": "...",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://accounts.google.com/o/oauth2/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "..."
|
||||
}
|
||||
----
|
||||
|
||||
This file must be copied in the `config` directory of the elasticsearch installation and on
|
||||
every node of the cluster.
|
||||
|
||||
To indicate that a repository should use a service account file:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
PUT _snapshot/my_gcs_repository
|
||||
{
|
||||
"type": "gcs",
|
||||
"settings": {
|
||||
"bucket": "my_bucket",
|
||||
"service_account": "service_account.json"
|
||||
}
|
||||
}
|
||||
----
|
||||
// CONSOLE
|
||||
|
||||
|
||||
[[repository-gcs-bucket-permission]]
|
||||
===== Set Bucket Permission
|
||||
|
||||
The service account used to access the bucket must have the "Writer" access to the bucket:
|
||||
|
||||
1. Connect to the https://console.cloud.google.com/[Google Cloud Platform Console]
|
||||
2. Select your project
|
||||
3. Got to the [https://console.cloud.google.com/storage/browser]Storage Browser
|
||||
4. Select the bucket and "Edit bucket permission"
|
||||
5. The service account must be configured as a "User" with "Writer" access
|
||||
|
||||
|
||||
[[repository-gcs-repository]]
|
||||
==== Create a Repository
|
||||
|
||||
Once everything is installed and every node is started, you can create a new repository that
|
||||
uses Google Cloud Storage to store snapshots:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
PUT _snapshot/my_gcs_repository
|
||||
{
|
||||
"type": "gcs",
|
||||
"settings": {
|
||||
"bucket": "my_bucket",
|
||||
"service_account": "service_account.json"
|
||||
}
|
||||
}
|
||||
----
|
||||
// CONSOLE
|
||||
|
||||
The following settings are supported:
|
||||
|
||||
`bucket`::
|
||||
|
||||
The name of the bucket to be used for snapshots. (Mandatory)
|
||||
|
||||
`service_account`::
|
||||
|
||||
The service account to use. It can be a relative path to a service account JSON file
|
||||
or the value `_default_` that indicate to use built-in Compute Engine service account.
|
||||
|
||||
`base_path`::
|
||||
|
||||
Specifies the path within bucket to repository data. Defaults to
|
||||
the root of the bucket.
|
||||
|
||||
`chunk_size`::
|
||||
|
||||
Big files can be broken down into chunks during snapshotting if needed.
|
||||
The chunk size can be specified in bytes or by using size value notation,
|
||||
i.e. `1g`, `10m`, `5k`. Defaults to `100m`.
|
||||
|
||||
`compress`::
|
||||
|
||||
When set to `true` metadata files are stored in compressed format. This
|
||||
setting doesn't affect index files that are already compressed by default.
|
||||
Defaults to `false`.
|
||||
|
||||
`application_name`::
|
||||
|
||||
Name used by the plugin when it uses the Google Cloud JSON API. Setting
|
||||
a custom name can be useful to authenticate your cluster when requests
|
||||
statistics are logged in the Google Cloud Platform. Default to `repository-gcs`
|
|
@ -22,6 +22,10 @@ The Azure repository plugin adds support for using Azure as a repository.
|
|||
|
||||
The Hadoop HDFS Repository plugin adds support for using HDFS as a repository.
|
||||
|
||||
<<repository-gcs,Google Cloud Storage Repository>>::
|
||||
|
||||
The GCS repository plugin adds support for using Google Cloud Storage service as a repository.
|
||||
|
||||
|
||||
[float]
|
||||
=== Community contributed repository plugins
|
||||
|
@ -37,3 +41,4 @@ include::repository-s3.asciidoc[]
|
|||
|
||||
include::repository-hdfs.asciidoc[]
|
||||
|
||||
include::repository-gcs.asciidoc[]
|
||||
|
|
|
@ -162,6 +162,7 @@ Other repository backends are available in these official plugins:
|
|||
* {plugins}/repository-s3.html[repository-s3] for S3 repository support
|
||||
* {plugins}/repository-hdfs.html[repository-hdfs] for HDFS repository support in Hadoop environments
|
||||
* {plugins}/repository-azure.html[repository-azure] for Azure storage repositories
|
||||
* {plugins}/repository-gcs.html[repository-gcs] for Google Cloud Storage repositories
|
||||
|
||||
[float]
|
||||
===== Repository Verification
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
esplugin {
|
||||
description 'The GCS repository plugin adds Google Cloud Storage support for repositories.'
|
||||
classname 'org.elasticsearch.plugin.repository.gcs.GoogleCloudStoragePlugin'
|
||||
}
|
||||
|
||||
versions << [
|
||||
'google': '1.21.0',
|
||||
]
|
||||
|
||||
dependencies {
|
||||
compile "com.google.apis:google-api-services-storage:v1-rev66-${versions.google}"
|
||||
compile "com.google.api-client:google-api-client:${versions.google}"
|
||||
compile "com.google.oauth-client:google-oauth-client:${versions.google}"
|
||||
compile "org.apache.httpcomponents:httpclient:${versions.httpclient}"
|
||||
compile "org.apache.httpcomponents:httpcore:${versions.httpcore}"
|
||||
compile "commons-logging:commons-logging:${versions.commonslogging}"
|
||||
compile "commons-codec:commons-codec:${versions.commonscodec}"
|
||||
compile "com.google.http-client:google-http-client:${versions.google}"
|
||||
compile "com.google.http-client:google-http-client-jackson2:${versions.google}"
|
||||
}
|
||||
|
||||
dependencyLicenses {
|
||||
mapping from: /google-.*/, to: 'google'
|
||||
}
|
||||
|
||||
thirdPartyAudit.excludes = [
|
||||
// classes are missing
|
||||
'com.google.common.base.Splitter',
|
||||
'com.google.common.collect.Lists',
|
||||
'javax.servlet.ServletContextEvent',
|
||||
'javax.servlet.ServletContextListener',
|
||||
'org.apache.avalon.framework.logger.Logger',
|
||||
'org.apache.log.Hierarchy',
|
||||
'org.apache.log.Logger',
|
||||
]
|
|
@ -0,0 +1 @@
|
|||
4b95f4897fa13f2cd904aee711aeafc0c5295cd8
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,17 @@
|
|||
Apache Commons Codec
|
||||
Copyright 2002-2015 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
||||
|
||||
src/test/org/apache/commons/codec/language/DoubleMetaphoneTest.java
|
||||
contains test data from http://aspell.net/test/orig/batch0.tab.
|
||||
Copyright (C) 2002 Kevin Atkinson (kevina@gnu.org)
|
||||
|
||||
===============================================================================
|
||||
|
||||
The content of package org.apache.commons.codec.language.bm has been translated
|
||||
from the original php source code available at http://stevemorse.org/phoneticinfo.htm
|
||||
with permission from the original authors.
|
||||
Original source copyright:
|
||||
Copyright (c) 2008 Alexander Beider & Stephen P. Morse.
|
|
@ -0,0 +1 @@
|
|||
f6f66e966c70a83ffbdb6f17a0919eaf7c8aca7f
|
|
@ -0,0 +1,202 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
Apache Commons CLI
|
||||
Copyright 2001-2009 The Apache Software Foundation
|
||||
|
||||
This product includes software developed by
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1 @@
|
|||
16a6b3c680f3bf7b81bb42790ff5c1b72c5bbedc
|
|
@ -0,0 +1 @@
|
|||
eb753d716e4f8dec203deb0f8fdca86913a79029
|
|
@ -0,0 +1 @@
|
|||
42631630fe1276d4d6d6397bb07d53a4e4fec278
|
|
@ -0,0 +1 @@
|
|||
8ce17bdd15fff0fd8cf359757f29e778fc7191ad
|
|
@ -0,0 +1 @@
|
|||
61ec42bbfc51aafde5eb8b4923c602c5b5965bc2
|
|
@ -0,0 +1 @@
|
|||
4c47155e3e6c9a41a28db36680b828ced53b8af4
|
|
@ -0,0 +1,558 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
=========================================================================
|
||||
|
||||
This project includes Public Suffix List copied from
|
||||
<https://publicsuffix.org/list/effective_tld_names.dat>
|
||||
licensed under the terms of the Mozilla Public License, v. 2.0
|
||||
|
||||
Full license text: <http://mozilla.org/MPL/2.0/>
|
||||
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
|
@ -0,0 +1,5 @@
|
|||
Apache HttpComponents Client
|
||||
Copyright 1999-2015 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
|
@ -0,0 +1 @@
|
|||
f91b7a4aadc5cf486df6e4634748d7dd7a73f06d
|
|
@ -0,0 +1,241 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
=========================================================================
|
||||
|
||||
This project contains annotations in the package org.apache.http.annotation
|
||||
which are derived from JCIP-ANNOTATIONS
|
||||
Copyright (c) 2005 Brian Goetz and Tim Peierls.
|
||||
See http://www.jcip.net and the Creative Commons Attribution License
|
||||
(http://creativecommons.org/licenses/by/2.5)
|
||||
Full text: http://creativecommons.org/licenses/by/2.5/legalcode
|
||||
|
||||
License
|
||||
|
||||
THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
|
||||
|
||||
BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
|
||||
|
||||
1. Definitions
|
||||
|
||||
"Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
|
||||
"Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
|
||||
"Licensor" means the individual or entity that offers the Work under the terms of this License.
|
||||
"Original Author" means the individual or entity who created the Work.
|
||||
"Work" means the copyrightable work of authorship offered under the terms of this License.
|
||||
"You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
|
||||
|
||||
2. Fair Use Rights. Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.
|
||||
|
||||
3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
|
||||
|
||||
to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
|
||||
to create and reproduce Derivative Works;
|
||||
to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
|
||||
to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
|
||||
|
||||
For the avoidance of doubt, where the work is a musical composition:
|
||||
Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
|
||||
Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights agency or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
|
||||
Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).
|
||||
|
||||
The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.
|
||||
|
||||
4. Restrictions.The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
|
||||
|
||||
You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(b), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(b), as requested.
|
||||
If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.
|
||||
|
||||
5. Representations, Warranties and Disclaimer
|
||||
|
||||
UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
|
||||
|
||||
6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
7. Termination
|
||||
|
||||
This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
|
||||
Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
|
||||
|
||||
8. Miscellaneous
|
||||
|
||||
Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
|
||||
Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
|
||||
If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
|
||||
No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
|
||||
This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
|
|
@ -0,0 +1,8 @@
|
|||
Apache HttpComponents Core
|
||||
Copyright 2005-2014 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
||||
|
||||
This project contains annotations derived from JCIP-ANNOTATIONS
|
||||
Copyright (c) 2005 Brian Goetz and Tim Peierls. See http://www.jcip.net
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.blobstore.gcs;
|
||||
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.blobstore.BlobStoreException;
|
||||
import org.elasticsearch.common.blobstore.support.AbstractBlobContainer;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class GoogleCloudStorageBlobContainer extends AbstractBlobContainer {
|
||||
|
||||
private final GoogleCloudStorageBlobStore blobStore;
|
||||
private final String path;
|
||||
|
||||
GoogleCloudStorageBlobContainer(BlobPath path, GoogleCloudStorageBlobStore blobStore) {
|
||||
super(path);
|
||||
this.blobStore = blobStore;
|
||||
|
||||
String keyPath = path.buildAsString("/");
|
||||
// TODO Move this keyPath logic to the buildAsString() method
|
||||
if (!keyPath.isEmpty()) {
|
||||
keyPath = keyPath + "/";
|
||||
}
|
||||
this.path = keyPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean blobExists(String blobName) {
|
||||
try {
|
||||
return blobStore.blobExists(buildKey(blobName));
|
||||
} catch (Exception e) {
|
||||
throw new BlobStoreException("Failed to check if blob [" + blobName + "] exists", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, BlobMetaData> listBlobs() throws IOException {
|
||||
return blobStore.listBlobs(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, BlobMetaData> listBlobsByPrefix(String prefix) throws IOException {
|
||||
return blobStore.listBlobsByPrefix(path, prefix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream readBlob(String blobName) throws IOException {
|
||||
return blobStore.readBlob(buildKey(blobName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
|
||||
blobStore.writeBlob(buildKey(blobName), inputStream, blobSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeBlob(String blobName, BytesReference bytes) throws IOException {
|
||||
writeBlob(blobName, bytes.streamInput(), bytes.length());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBlob(String blobName) throws IOException {
|
||||
blobStore.deleteBlob(buildKey(blobName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBlobsByPrefix(String prefix) throws IOException {
|
||||
blobStore.deleteBlobsByPrefix(buildKey(prefix));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBlobs(Collection<String> blobNames) throws IOException {
|
||||
blobStore.deleteBlobs(buildKeys(blobNames));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(String sourceBlobName, String targetBlobName) throws IOException {
|
||||
blobStore.moveBlob(buildKey(sourceBlobName), buildKey(targetBlobName));
|
||||
}
|
||||
|
||||
protected String buildKey(String blobName) {
|
||||
assert blobName != null;
|
||||
return path + blobName;
|
||||
}
|
||||
|
||||
protected Set<String> buildKeys(Collection<String> blobNames) {
|
||||
Set<String> keys = new HashSet<>();
|
||||
if (blobNames != null) {
|
||||
keys.addAll(blobNames.stream().map(this::buildKey).collect(Collectors.toList()));
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,432 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.blobstore.gcs;
|
||||
|
||||
import com.google.api.client.googleapis.batch.BatchRequest;
|
||||
import com.google.api.client.googleapis.batch.json.JsonBatchCallback;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
|
||||
import com.google.api.client.http.HttpHeaders;
|
||||
import com.google.api.client.http.InputStreamContent;
|
||||
import com.google.api.services.storage.Storage;
|
||||
import com.google.api.services.storage.model.Bucket;
|
||||
import com.google.api.services.storage.model.Objects;
|
||||
import com.google.api.services.storage.model.StorageObject;
|
||||
import org.elasticsearch.SpecialPermission;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.blobstore.BlobContainer;
|
||||
import org.elasticsearch.common.blobstore.BlobMetaData;
|
||||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.blobstore.BlobStoreException;
|
||||
import org.elasticsearch.common.blobstore.support.PlainBlobMetaData;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.CountDown;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Spliterator;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
|
||||
|
||||
public class GoogleCloudStorageBlobStore extends AbstractComponent implements BlobStore {
|
||||
|
||||
/**
|
||||
* Google Cloud Storage batch requests are limited to 1000 operations
|
||||
**/
|
||||
private static final int MAX_BATCHING_REQUESTS = 999;
|
||||
|
||||
private final Storage client;
|
||||
private final String bucket;
|
||||
|
||||
public GoogleCloudStorageBlobStore(Settings settings, String bucket, Storage storageClient) {
|
||||
super(settings);
|
||||
this.bucket = bucket;
|
||||
this.client = storageClient;
|
||||
|
||||
if (doesBucketExist(bucket) == false) {
|
||||
throw new BlobStoreException("Bucket [" + bucket + "] does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlobContainer blobContainer(BlobPath path) {
|
||||
return new GoogleCloudStorageBlobContainer(path, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(BlobPath path) throws IOException {
|
||||
String keyPath = path.buildAsString("/");
|
||||
// TODO Move this keyPath logic to the buildAsString() method
|
||||
if (!keyPath.isEmpty()) {
|
||||
keyPath = keyPath + "/";
|
||||
}
|
||||
deleteBlobsByPrefix(keyPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the given bucket exists
|
||||
*
|
||||
* @param bucketName name of the bucket
|
||||
* @return true if the bucket exists, false otherwise
|
||||
*/
|
||||
boolean doesBucketExist(String bucketName) {
|
||||
try {
|
||||
return doPrivileged(() -> {
|
||||
try {
|
||||
Bucket bucket = client.buckets().get(bucketName).execute();
|
||||
if (bucket != null) {
|
||||
return Strings.hasText(bucket.getId());
|
||||
}
|
||||
} catch (GoogleJsonResponseException e) {
|
||||
GoogleJsonError error = e.getDetails();
|
||||
if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
|
||||
return false;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
} catch (IOException e) {
|
||||
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<String, BlobMetaData> listBlobs(String path) throws IOException {
|
||||
return doPrivileged(() -> listBlobsByPath(bucket, path, 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<String, BlobMetaData> listBlobsByPrefix(String path, String prefix) throws IOException {
|
||||
return doPrivileged(() -> listBlobsByPath(bucket, buildKey(path, prefix), path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all blobs in a given bucket
|
||||
*
|
||||
* @param bucketName name of the bucket
|
||||
* @param path base path of the blobs to list
|
||||
* @param pathToRemove if true, this path part is removed from blob name
|
||||
* @return a map of blob names and their metadata
|
||||
*/
|
||||
private Map<String, BlobMetaData> listBlobsByPath(String bucketName, String path, String pathToRemove) throws IOException {
|
||||
return blobsStream(client, bucketName, path, MAX_BATCHING_REQUESTS)
|
||||
.map(new BlobMetaDataConverter(pathToRemove))
|
||||
.collect(Collectors.toMap(PlainBlobMetaData::name, Function.identity()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the blob exists in the bucket
|
||||
*
|
||||
* @param blobName name of the blob
|
||||
* @return true if the blob exists, false otherwise
|
||||
*/
|
||||
boolean blobExists(String blobName) throws IOException {
|
||||
return doPrivileged(() -> {
|
||||
try {
|
||||
StorageObject blob = client.objects().get(bucket, blobName).execute();
|
||||
if (blob != null) {
|
||||
return Strings.hasText(blob.getId());
|
||||
}
|
||||
} catch (GoogleJsonResponseException e) {
|
||||
GoogleJsonError error = e.getDetails();
|
||||
if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
|
||||
return false;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an {@link java.io.InputStream} for a given blob
|
||||
*
|
||||
* @param blobName name of the blob
|
||||
* @return an InputStream
|
||||
*/
|
||||
InputStream readBlob(String blobName) throws IOException {
|
||||
return doPrivileged(() -> {
|
||||
try {
|
||||
Storage.Objects.Get object = client.objects().get(bucket, blobName);
|
||||
return object.executeMediaAsInputStream();
|
||||
} catch (GoogleJsonResponseException e) {
|
||||
GoogleJsonError error = e.getDetails();
|
||||
if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
|
||||
throw new FileNotFoundException(e.getMessage());
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a blob in the bucket.
|
||||
*
|
||||
* @param inputStream content of the blob to be written
|
||||
* @param blobSize expected size of the blob to be written
|
||||
*/
|
||||
void writeBlob(String blobName, InputStream inputStream, long blobSize) throws IOException {
|
||||
doPrivileged(() -> {
|
||||
InputStreamContent stream = new InputStreamContent(null, inputStream);
|
||||
stream.setLength(blobSize);
|
||||
|
||||
Storage.Objects.Insert insert = client.objects().insert(bucket, null, stream);
|
||||
insert.setName(blobName);
|
||||
insert.execute();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a blob in the bucket
|
||||
*
|
||||
* @param blobName name of the blob
|
||||
*/
|
||||
void deleteBlob(String blobName) throws IOException {
|
||||
doPrivileged(() -> client.objects().delete(bucket, blobName).execute());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple blobs in the bucket that have a given prefix
|
||||
*
|
||||
* @param prefix prefix of the buckets to delete
|
||||
*/
|
||||
void deleteBlobsByPrefix(String prefix) throws IOException {
|
||||
doPrivileged(() -> {
|
||||
deleteBlobs(listBlobsByPath(bucket, prefix, null).keySet());
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes multiple blobs in the given bucket (uses a batch request to perform this)
|
||||
*
|
||||
* @param blobNames names of the bucket to delete
|
||||
*/
|
||||
void deleteBlobs(Collection<String> blobNames) throws IOException {
|
||||
if (blobNames == null || blobNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (blobNames.size() == 1) {
|
||||
deleteBlob(blobNames.iterator().next());
|
||||
return;
|
||||
}
|
||||
|
||||
doPrivileged(() -> {
|
||||
final List<Storage.Objects.Delete> deletions = new ArrayList<>();
|
||||
final Iterator<String> blobs = blobNames.iterator();
|
||||
|
||||
while (blobs.hasNext()) {
|
||||
// Create a delete request for each blob to delete
|
||||
deletions.add(client.objects().delete(bucket, blobs.next()));
|
||||
|
||||
if (blobs.hasNext() == false || deletions.size() == MAX_BATCHING_REQUESTS) {
|
||||
try {
|
||||
// Deletions are executed using a batch request
|
||||
BatchRequest batch = client.batch();
|
||||
|
||||
// Used to track successful deletions
|
||||
CountDown countDown = new CountDown(deletions.size());
|
||||
|
||||
for (Storage.Objects.Delete delete : deletions) {
|
||||
// Queue the delete request in batch
|
||||
delete.queue(batch, new JsonBatchCallback<Void>() {
|
||||
@Override
|
||||
public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) throws IOException {
|
||||
logger.error("failed to delete blob [{}] in bucket [{}]: {}", delete.getObject(), delete.getBucket(), e
|
||||
.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Void aVoid, HttpHeaders responseHeaders) throws IOException {
|
||||
countDown.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
batch.execute();
|
||||
|
||||
if (countDown.isCountedDown() == false) {
|
||||
throw new IOException("Failed to delete all [" + deletions.size() + "] blobs");
|
||||
}
|
||||
} finally {
|
||||
deletions.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a blob within the same bucket
|
||||
*
|
||||
* @param sourceBlob name of the blob to move
|
||||
* @param targetBlob new name of the blob in the target bucket
|
||||
*/
|
||||
void moveBlob(String sourceBlob, String targetBlob) throws IOException {
|
||||
doPrivileged(() -> {
|
||||
// There's no atomic "move" in GCS so we need to copy and delete
|
||||
client.objects().copy(bucket, sourceBlob, bucket, targetBlob, null).execute();
|
||||
client.objects().delete(bucket, sourceBlob).execute();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a {@link PrivilegedExceptionAction} with privileges enabled.
|
||||
*/
|
||||
<T> T doPrivileged(PrivilegedExceptionAction<T> operation) throws IOException {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new SpecialPermission());
|
||||
}
|
||||
try {
|
||||
return AccessController.doPrivileged((PrivilegedExceptionAction<T>) operation::run);
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (IOException) e.getException();
|
||||
}
|
||||
}
|
||||
|
||||
private String buildKey(String keyPath, String s) {
|
||||
assert s != null;
|
||||
return keyPath + s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link StorageObject} to a {@link PlainBlobMetaData}
|
||||
*/
|
||||
class BlobMetaDataConverter implements Function<StorageObject, PlainBlobMetaData> {
|
||||
|
||||
private final String pathToRemove;
|
||||
|
||||
BlobMetaDataConverter(String pathToRemove) {
|
||||
this.pathToRemove = pathToRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlainBlobMetaData apply(StorageObject storageObject) {
|
||||
String blobName = storageObject.getName();
|
||||
if (Strings.hasLength(pathToRemove)) {
|
||||
blobName = blobName.substring(pathToRemove.length());
|
||||
}
|
||||
return new PlainBlobMetaData(blobName, storageObject.getSize().longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spliterator can be used to list storage objects stored in a bucket.
|
||||
*/
|
||||
static class StorageObjectsSpliterator implements Spliterator<StorageObject> {
|
||||
|
||||
private final Storage.Objects.List list;
|
||||
|
||||
StorageObjectsSpliterator(Storage client, String bucketName, String prefix, long pageSize) throws IOException {
|
||||
list = client.objects().list(bucketName);
|
||||
list.setMaxResults(pageSize);
|
||||
if (prefix != null) {
|
||||
list.setPrefix(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryAdvance(Consumer<? super StorageObject> action) {
|
||||
try {
|
||||
// Retrieves the next page of items
|
||||
Objects objects = list.execute();
|
||||
|
||||
if ((objects == null) || (objects.getItems() == null) || (objects.getItems().isEmpty())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Consumes all the items
|
||||
objects.getItems().forEach(action::accept);
|
||||
|
||||
// Sets the page token of the next page,
|
||||
// null indicates that all items have been consumed
|
||||
String next = objects.getNextPageToken();
|
||||
if (next != null) {
|
||||
list.setPageToken(next);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
throw new BlobStoreException("Exception while listing objects", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Spliterator<StorageObject> trySplit() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long estimateSize() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int characteristics() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Stream} of {@link StorageObject}s that are stored in a given bucket.
|
||||
*/
|
||||
static Stream<StorageObject> blobsStream(Storage client, String bucketName, String prefix, long pageSize) throws IOException {
|
||||
return StreamSupport.stream(new StorageObjectsSpliterator(client, bucketName, prefix, pageSize), false);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.plugin.repository.gcs;
|
||||
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.repositories.gcs.GoogleCloudStorageService;
|
||||
|
||||
public class GoogleCloudStorageModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GoogleCloudStorageService.class).to(GoogleCloudStorageService.InternalGoogleCloudStorageService.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.plugin.repository.gcs;
|
||||
|
||||
import com.google.api.client.auth.oauth2.TokenRequest;
|
||||
import com.google.api.client.auth.oauth2.TokenResponse;
|
||||
import com.google.api.client.googleapis.json.GoogleJsonError;
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.http.HttpHeaders;
|
||||
import com.google.api.client.json.GenericJson;
|
||||
import com.google.api.client.json.webtoken.JsonWebSignature;
|
||||
import com.google.api.client.json.webtoken.JsonWebToken;
|
||||
import com.google.api.client.util.ClassInfo;
|
||||
import com.google.api.client.util.Data;
|
||||
import com.google.api.services.storage.Storage;
|
||||
import com.google.api.services.storage.model.Bucket;
|
||||
import com.google.api.services.storage.model.Objects;
|
||||
import com.google.api.services.storage.model.StorageObject;
|
||||
import org.elasticsearch.SpecialPermission;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardRepository;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.repositories.RepositoriesModule;
|
||||
import org.elasticsearch.repositories.gcs.GoogleCloudStorageRepository;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class GoogleCloudStoragePlugin extends Plugin {
|
||||
|
||||
public static final String NAME = "repository-gcs";
|
||||
|
||||
static {
|
||||
/*
|
||||
* Google HTTP client changes access levels because its silly and we
|
||||
* can't allow that on any old stack stack so we pull it here, up front,
|
||||
* so we can cleanly check the permissions for it. Without this changing
|
||||
* the permission can fail if any part of core is on the stack because
|
||||
* our plugin permissions don't allow core to "reach through" plugins to
|
||||
* change the permission. Because that'd be silly.
|
||||
*/
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPermission(new SpecialPermission());
|
||||
}
|
||||
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||
// ClassInfo put in cache all the fields of a given class
|
||||
// that are annoted with @Key; at the same time it changes
|
||||
// the field access level using setAccessible(). Calling
|
||||
// them here put the ClassInfo in cache (they are never evicted)
|
||||
// before the SecurityManager is installed.
|
||||
ClassInfo.of(HttpHeaders.class, true);
|
||||
|
||||
ClassInfo.of(JsonWebSignature.Header.class, false);
|
||||
ClassInfo.of(JsonWebToken.Payload.class, false);
|
||||
|
||||
ClassInfo.of(TokenRequest.class, false);
|
||||
ClassInfo.of(TokenResponse.class, false);
|
||||
|
||||
ClassInfo.of(GenericJson.class, false);
|
||||
ClassInfo.of(GenericUrl.class, false);
|
||||
|
||||
Data.nullOf(GoogleJsonError.ErrorInfo.class);
|
||||
ClassInfo.of(GoogleJsonError.class, false);
|
||||
|
||||
Data.nullOf(Bucket.Cors.class);
|
||||
ClassInfo.of(Bucket.class, false);
|
||||
ClassInfo.of(Bucket.Cors.class, false);
|
||||
ClassInfo.of(Bucket.Lifecycle.class, false);
|
||||
ClassInfo.of(Bucket.Logging.class, false);
|
||||
ClassInfo.of(Bucket.Owner.class, false);
|
||||
ClassInfo.of(Bucket.Versioning.class, false);
|
||||
ClassInfo.of(Bucket.Website.class, false);
|
||||
|
||||
ClassInfo.of(StorageObject.class, false);
|
||||
ClassInfo.of(StorageObject.Owner.class, false);
|
||||
|
||||
ClassInfo.of(Objects.class, false);
|
||||
|
||||
ClassInfo.of(Storage.Buckets.Get.class, false);
|
||||
ClassInfo.of(Storage.Buckets.Insert.class, false);
|
||||
|
||||
ClassInfo.of(Storage.Objects.Get.class, false);
|
||||
ClassInfo.of(Storage.Objects.Insert.class, false);
|
||||
ClassInfo.of(Storage.Objects.Delete.class, false);
|
||||
ClassInfo.of(Storage.Objects.Copy.class, false);
|
||||
ClassInfo.of(Storage.Objects.List.class, false);
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Google Cloud Storage Repository Plugin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Module> nodeModules() {
|
||||
return Collections.singletonList(new GoogleCloudStorageModule());
|
||||
}
|
||||
|
||||
public void onModule(RepositoriesModule repositoriesModule) {
|
||||
repositoriesModule.registerRepository(GoogleCloudStorageRepository.TYPE,
|
||||
GoogleCloudStorageRepository.class, BlobStoreIndexShardRepository.class);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.repositories.gcs;
|
||||
|
||||
import com.google.api.services.storage.Storage;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.blobstore.gcs.GoogleCloudStorageBlobStore;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Setting;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.snapshots.IndexShardRepository;
|
||||
import org.elasticsearch.plugin.repository.gcs.GoogleCloudStoragePlugin;
|
||||
import org.elasticsearch.repositories.RepositoryException;
|
||||
import org.elasticsearch.repositories.RepositoryName;
|
||||
import org.elasticsearch.repositories.RepositorySettings;
|
||||
import org.elasticsearch.repositories.blobstore.BlobStoreRepository;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.elasticsearch.common.settings.Setting.Property;
|
||||
import static org.elasticsearch.common.settings.Setting.boolSetting;
|
||||
import static org.elasticsearch.common.settings.Setting.byteSizeSetting;
|
||||
import static org.elasticsearch.common.settings.Setting.simpleString;
|
||||
import static org.elasticsearch.common.settings.Setting.timeSetting;
|
||||
import static org.elasticsearch.common.unit.TimeValue.timeValueMillis;
|
||||
|
||||
public class GoogleCloudStorageRepository extends BlobStoreRepository {
|
||||
|
||||
public static final String TYPE = "gcs";
|
||||
|
||||
public static final TimeValue NO_TIMEOUT = timeValueMillis(-1);
|
||||
|
||||
public static final Setting<String> BUCKET =
|
||||
simpleString("bucket", Property.NodeScope, Property.Dynamic);
|
||||
public static final Setting<String> BASE_PATH =
|
||||
simpleString("base_path", Property.NodeScope, Property.Dynamic);
|
||||
public static final Setting<Boolean> COMPRESS =
|
||||
boolSetting("compress", false, Property.NodeScope, Property.Dynamic);
|
||||
public static final Setting<ByteSizeValue> CHUNK_SIZE =
|
||||
byteSizeSetting("chunk_size", new ByteSizeValue(100, ByteSizeUnit.MB), Property.NodeScope, Property.Dynamic);
|
||||
public static final Setting<String> APPLICATION_NAME =
|
||||
new Setting<>("application_name", GoogleCloudStoragePlugin.NAME, Function.identity(), Property.NodeScope, Property.Dynamic);
|
||||
public static final Setting<String> SERVICE_ACCOUNT =
|
||||
simpleString("service_account", Property.NodeScope, Property.Dynamic, Property.Filtered);
|
||||
public static final Setting<TimeValue> HTTP_READ_TIMEOUT =
|
||||
timeSetting("http.read_timeout", NO_TIMEOUT, Property.NodeScope, Property.Dynamic);
|
||||
public static final Setting<TimeValue> HTTP_CONNECT_TIMEOUT =
|
||||
timeSetting("http.connect_timeout", NO_TIMEOUT, Property.NodeScope, Property.Dynamic);
|
||||
|
||||
private final ByteSizeValue chunkSize;
|
||||
private final boolean compress;
|
||||
private final BlobPath basePath;
|
||||
private final GoogleCloudStorageBlobStore blobStore;
|
||||
|
||||
@Inject
|
||||
public GoogleCloudStorageRepository(RepositoryName repositoryName, RepositorySettings repositorySettings,
|
||||
IndexShardRepository indexShardRepository,
|
||||
GoogleCloudStorageService storageService) throws Exception {
|
||||
super(repositoryName.getName(), repositorySettings, indexShardRepository);
|
||||
|
||||
String bucket = get(BUCKET, repositoryName, repositorySettings);
|
||||
String application = get(APPLICATION_NAME, repositoryName, repositorySettings);
|
||||
String serviceAccount = get(SERVICE_ACCOUNT, repositoryName, repositorySettings);
|
||||
|
||||
String basePath = BASE_PATH.get(repositorySettings.settings());
|
||||
if (Strings.hasLength(basePath)) {
|
||||
BlobPath path = new BlobPath();
|
||||
for (String elem : basePath.split("/")) {
|
||||
path = path.add(elem);
|
||||
}
|
||||
this.basePath = path;
|
||||
} else {
|
||||
this.basePath = BlobPath.cleanPath();
|
||||
}
|
||||
|
||||
TimeValue connectTimeout = null;
|
||||
TimeValue readTimeout = null;
|
||||
|
||||
TimeValue timeout = HTTP_CONNECT_TIMEOUT.get(repositorySettings.settings());
|
||||
if ((timeout != null) && (timeout.millis() != NO_TIMEOUT.millis())) {
|
||||
connectTimeout = timeout;
|
||||
}
|
||||
|
||||
timeout = HTTP_READ_TIMEOUT.get(repositorySettings.settings());
|
||||
if ((timeout != null) && (timeout.millis() != NO_TIMEOUT.millis())) {
|
||||
readTimeout = timeout;
|
||||
}
|
||||
|
||||
this.compress = get(COMPRESS, repositoryName, repositorySettings);
|
||||
this.chunkSize = get(CHUNK_SIZE, repositoryName, repositorySettings);
|
||||
|
||||
logger.debug("using bucket [{}], base_path [{}], chunk_size [{}], compress [{}], application [{}]",
|
||||
bucket, basePath, chunkSize, compress, application);
|
||||
|
||||
Storage client = storageService.createClient(serviceAccount, application, connectTimeout, readTimeout);
|
||||
this.blobStore = new GoogleCloudStorageBlobStore(settings, bucket, client);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected BlobStore blobStore() {
|
||||
return blobStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BlobPath basePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCompress() {
|
||||
return compress;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ByteSizeValue chunkSize() {
|
||||
return chunkSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a given setting from the repository settings, throwing a {@link RepositoryException} if the setting does not exist or is empty.
|
||||
*/
|
||||
static <T> T get(Setting<T> setting, RepositoryName name, RepositorySettings repositorySettings) {
|
||||
T value = setting.get(repositorySettings.settings());
|
||||
if (value == null) {
|
||||
throw new RepositoryException(name.getName(), "Setting [" + setting.getKey() + "] is not defined for repository");
|
||||
}
|
||||
if ((value instanceof String) && (Strings.hasText((String) value)) == false) {
|
||||
throw new RepositoryException(name.getName(), "Setting [" + setting.getKey() + "] is empty for repository");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.repositories.gcs;
|
||||
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||
import com.google.api.client.http.HttpBackOffIOExceptionHandler;
|
||||
import com.google.api.client.http.HttpBackOffUnsuccessfulResponseHandler;
|
||||
import com.google.api.client.http.HttpIOExceptionHandler;
|
||||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpRequestInitializer;
|
||||
import com.google.api.client.http.HttpUnsuccessfulResponseHandler;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.util.ExponentialBackOff;
|
||||
import com.google.api.services.storage.Storage;
|
||||
import com.google.api.services.storage.StorageScopes;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.env.Environment;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
|
||||
public interface GoogleCloudStorageService {
|
||||
|
||||
/**
|
||||
* Creates a client that can be used to manage Google Cloud Storage objects.
|
||||
*
|
||||
* @param serviceAccount path to service account file
|
||||
* @param application name of the application
|
||||
* @param connectTimeout connection timeout for HTTP requests
|
||||
* @param readTimeout read timeout for HTTP requests
|
||||
* @return a Client instance that can be used to manage objects
|
||||
*/
|
||||
Storage createClient(String serviceAccount, String application, TimeValue connectTimeout, TimeValue readTimeout) throws Exception;
|
||||
|
||||
/**
|
||||
* Default implementation
|
||||
*/
|
||||
class InternalGoogleCloudStorageService extends AbstractComponent implements GoogleCloudStorageService {
|
||||
|
||||
private static final String DEFAULT = "_default_";
|
||||
|
||||
private final Environment environment;
|
||||
|
||||
@Inject
|
||||
public InternalGoogleCloudStorageService(Settings settings, Environment environment) {
|
||||
super(settings);
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Storage createClient(String serviceAccount, String application, TimeValue connectTimeout, TimeValue readTimeout)
|
||||
throws Exception {
|
||||
try {
|
||||
GoogleCredential credentials = (DEFAULT.equalsIgnoreCase(serviceAccount)) ? loadDefault() : loadCredentials(serviceAccount);
|
||||
NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||
|
||||
Storage.Builder storage = new Storage.Builder(httpTransport, JacksonFactory.getDefaultInstance(),
|
||||
new DefaultHttpRequestInitializer(credentials, connectTimeout, readTimeout));
|
||||
storage.setApplicationName(application);
|
||||
|
||||
logger.debug("initializing client with service account [{}/{}]",
|
||||
credentials.getServiceAccountId(), credentials.getServiceAccountUser());
|
||||
return storage.build();
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("Error when loading Google Cloud Storage credentials file", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request initializer that loads credentials from the service account file
|
||||
* and manages authentication for HTTP requests
|
||||
*/
|
||||
private GoogleCredential 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 = environment.configFile().resolve(serviceAccount);
|
||||
if (Files.exists(account) == false) {
|
||||
throw new ElasticsearchException("Unable to find service account file [" + serviceAccount
|
||||
+ "] defined for repository");
|
||||
}
|
||||
|
||||
try (InputStream is = Files.newInputStream(account)) {
|
||||
GoogleCredential credential = GoogleCredential.fromStream(is);
|
||||
if (credential.createScopedRequired()) {
|
||||
credential = credential.createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL));
|
||||
}
|
||||
return credential;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request initializer that loads default credentials when running on Compute Engine
|
||||
*/
|
||||
private GoogleCredential loadDefault() throws IOException {
|
||||
return GoogleCredential.getApplicationDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request initializer that set timeouts and backoff handler while deferring authentication to GoogleCredential.
|
||||
* See https://cloud.google.com/storage/transfer/create-client#retry
|
||||
*/
|
||||
class DefaultHttpRequestInitializer implements HttpRequestInitializer {
|
||||
|
||||
private final TimeValue connectTimeout;
|
||||
private final TimeValue readTimeout;
|
||||
private final GoogleCredential credential;
|
||||
private final HttpUnsuccessfulResponseHandler handler;
|
||||
private final HttpIOExceptionHandler ioHandler;
|
||||
|
||||
DefaultHttpRequestInitializer(GoogleCredential credential, TimeValue connectTimeout, TimeValue readTimeout) {
|
||||
this.credential = credential;
|
||||
this.connectTimeout = connectTimeout;
|
||||
this.readTimeout = readTimeout;
|
||||
this.handler = new HttpBackOffUnsuccessfulResponseHandler(newBackOff());
|
||||
this.ioHandler = new HttpBackOffIOExceptionHandler(newBackOff());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(HttpRequest request) throws IOException {
|
||||
if (connectTimeout != null) {
|
||||
request.setConnectTimeout((int) connectTimeout.millis());
|
||||
}
|
||||
if (readTimeout != null) {
|
||||
request.setReadTimeout((int) readTimeout.millis());
|
||||
}
|
||||
|
||||
request.setIOExceptionHandler(ioHandler);
|
||||
request.setInterceptor(credential);
|
||||
|
||||
request.setUnsuccessfulResponseHandler((req, resp, supportsRetry) -> {
|
||||
// Let the credential handle the response. If it failed, we rely on our backoff handler
|
||||
return credential.handleResponse(req, resp, supportsRetry) || handler.handleResponse(req, resp, supportsRetry);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private ExponentialBackOff newBackOff() {
|
||||
return new ExponentialBackOff.Builder()
|
||||
.setInitialIntervalMillis(100)
|
||||
.setMaxIntervalMillis(6000)
|
||||
.setMaxElapsedTimeMillis(900000)
|
||||
.setMultiplier(1.5)
|
||||
.setRandomizationFactor(0.5)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
grant {
|
||||
permission java.lang.RuntimePermission "accessDeclaredMembers";
|
||||
permission java.lang.RuntimePermission "setFactory";
|
||||
permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
|
||||
permission java.net.URLPermission "http://www.googleapis.com/*", "*";
|
||||
permission java.net.URLPermission "https://www.googleapis.com/*", "*";
|
||||
};
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.blobstore.gcs;
|
||||
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.repositories.ESBlobStoreContainerTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class GoogleCloudStorageBlobStoreContainerTests extends ESBlobStoreContainerTestCase {
|
||||
|
||||
@Override
|
||||
protected BlobStore newBlobStore() throws IOException {
|
||||
String bucket = randomAsciiOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
|
||||
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockHttpTransport.newStorage(bucket, getTestName()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.blobstore.gcs;
|
||||
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.repositories.ESBlobStoreTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
public class GoogleCloudStorageBlobStoreTests extends ESBlobStoreTestCase {
|
||||
|
||||
@Override
|
||||
protected BlobStore newBlobStore() throws IOException {
|
||||
String bucket = randomAsciiOfLength(randomIntBetween(1, 10)).toLowerCase(Locale.ROOT);
|
||||
return new GoogleCloudStorageBlobStore(Settings.EMPTY, bucket, MockHttpTransport.newStorage(bucket, getTestName()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,432 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.common.blobstore.gcs;
|
||||
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.LowLevelHttpRequest;
|
||||
import com.google.api.client.http.LowLevelHttpResponse;
|
||||
import com.google.api.client.json.Json;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
|
||||
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
|
||||
import com.google.api.services.storage.Storage;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.path.PathTrie;
|
||||
import org.elasticsearch.common.util.Callback;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.rest.support.RestUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
||||
/**
|
||||
* Mock for {@link HttpTransport} to test Google Cloud Storage service.
|
||||
* <p>
|
||||
* This basically handles each type of request used by the {@link GoogleCloudStorageBlobStore} and provides appropriate responses like
|
||||
* the Google Cloud Storage service would do. It is largely based on official documentation available at https://cloud.google
|
||||
* .com/storage/docs/json_api/v1/.
|
||||
*/
|
||||
public class MockHttpTransport extends com.google.api.client.testing.http.MockHttpTransport {
|
||||
|
||||
private final AtomicInteger objectsCount = new AtomicInteger(0);
|
||||
private final Map<String, String> objectsNames = ConcurrentCollections.newConcurrentMap();
|
||||
private final Map<String, byte[]> objectsContent = ConcurrentCollections.newConcurrentMap();
|
||||
|
||||
private final PathTrie<Handler> handlers = new PathTrie<>(RestUtils.REST_DECODER);
|
||||
|
||||
public MockHttpTransport(String bucket) {
|
||||
|
||||
// GET Bucket
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/buckets/get
|
||||
handlers.insert("GET https://www.googleapis.com/storage/v1/b/{bucket}", (url, params, req) -> {
|
||||
String name = params.get("bucket");
|
||||
if (Strings.hasText(name) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "bucket name is missing");
|
||||
}
|
||||
|
||||
if (name.equals(bucket)) {
|
||||
return newMockResponse().setContent(buildBucketResource(bucket));
|
||||
} else {
|
||||
return newMockError(RestStatus.NOT_FOUND, "bucket not found");
|
||||
}
|
||||
});
|
||||
|
||||
// GET Object
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/objects/get
|
||||
handlers.insert("GET https://www.googleapis.com/storage/v1/b/{bucket}/o/{object}", (url, params, req) -> {
|
||||
String name = params.get("object");
|
||||
if (Strings.hasText(name) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "object name is missing");
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> object : objectsNames.entrySet()) {
|
||||
if (object.getValue().equals(name)) {
|
||||
byte[] content = objectsContent.get(object.getKey());
|
||||
if (content != null) {
|
||||
return newMockResponse().setContent(buildObjectResource(bucket, name, object.getKey(), content.length));
|
||||
}
|
||||
}
|
||||
}
|
||||
return newMockError(RestStatus.NOT_FOUND, "object not found");
|
||||
});
|
||||
|
||||
// Download Object
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/request-endpoints
|
||||
handlers.insert("GET https://www.googleapis.com/download/storage/v1/b/{bucket}/o/{object}", (url, params, req) -> {
|
||||
String name = params.get("object");
|
||||
if (Strings.hasText(name) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "object name is missing");
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> object : objectsNames.entrySet()) {
|
||||
if (object.getValue().equals(name)) {
|
||||
byte[] content = objectsContent.get(object.getKey());
|
||||
if (content == null) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "object content is missing");
|
||||
}
|
||||
return newMockResponse().setContent(new ByteArrayInputStream(content));
|
||||
}
|
||||
}
|
||||
return newMockError(RestStatus.NOT_FOUND, "object not found");
|
||||
});
|
||||
|
||||
// Insert Object (initialization)
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/objects/insert
|
||||
handlers.insert("POST https://www.googleapis.com/upload/storage/v1/b/{bucket}/o", (url, params, req) -> {
|
||||
if ("resumable".equals(params.get("uploadType")) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "upload type must be resumable");
|
||||
}
|
||||
|
||||
String name = params.get("name");
|
||||
if (Strings.hasText(name) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "object name is missing");
|
||||
}
|
||||
|
||||
String objectId = String.valueOf(objectsCount.getAndIncrement());
|
||||
objectsNames.put(objectId, name);
|
||||
|
||||
return newMockResponse()
|
||||
.setStatusCode(RestStatus.CREATED.getStatus())
|
||||
.addHeader("Location", "https://www.googleapis.com/upload/storage/v1/b/" + bucket +
|
||||
"/o?uploadType=resumable&upload_id=" + objectId);
|
||||
});
|
||||
|
||||
// Insert Object (upload)
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload
|
||||
handlers.insert("PUT https://www.googleapis.com/upload/storage/v1/b/{bucket}/o", (url, params, req) -> {
|
||||
String objectId = params.get("upload_id");
|
||||
if (Strings.hasText(objectId) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "upload id is missing");
|
||||
}
|
||||
|
||||
String name = objectsNames.get(objectId);
|
||||
if (Strings.hasText(name) == false) {
|
||||
return newMockError(RestStatus.NOT_FOUND, "object name not found");
|
||||
}
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream((int) req.getContentLength());
|
||||
try {
|
||||
req.getStreamingContent().writeTo(os);
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
byte[] content = os.toByteArray();
|
||||
objectsContent.put(objectId, content);
|
||||
return newMockResponse().setContent(buildObjectResource(bucket, name, objectId, content.length));
|
||||
});
|
||||
|
||||
// List Objects
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/objects/list
|
||||
handlers.insert("GET https://www.googleapis.com/storage/v1/b/{bucket}/o", (url, params, req) -> {
|
||||
String prefix = params.get("prefix");
|
||||
|
||||
try (XContentBuilder builder = jsonBuilder()) {
|
||||
builder.startObject();
|
||||
builder.field("kind", "storage#objects");
|
||||
builder.startArray("items");
|
||||
for (Map.Entry<String, String> o : objectsNames.entrySet()) {
|
||||
if (prefix != null && o.getValue().startsWith(prefix) == false) {
|
||||
continue;
|
||||
}
|
||||
buildObjectResource(builder, bucket, o.getValue(), o.getKey(), objectsContent.get(o.getKey()).length);
|
||||
}
|
||||
builder.endArray();
|
||||
builder.endObject();
|
||||
return newMockResponse().setContent(builder.string());
|
||||
} catch (IOException e) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
// Delete Object
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/objects/delete
|
||||
handlers.insert("DELETE https://www.googleapis.com/storage/v1/b/{bucket}/o/{object}", (url, params, req) -> {
|
||||
String name = params.get("object");
|
||||
if (Strings.hasText(name) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "object name is missing");
|
||||
}
|
||||
|
||||
String objectId = null;
|
||||
for (Map.Entry<String, String> object : objectsNames.entrySet()) {
|
||||
if (object.getValue().equals(name)) {
|
||||
objectId = object.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (objectId != null) {
|
||||
objectsNames.remove(objectId);
|
||||
objectsContent.remove(objectId);
|
||||
return newMockResponse().setStatusCode(RestStatus.NO_CONTENT.getStatus());
|
||||
}
|
||||
return newMockError(RestStatus.NOT_FOUND, "object not found");
|
||||
});
|
||||
|
||||
// Copy Object
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/objects/copy
|
||||
handlers.insert("POST https://www.googleapis.com/storage/v1/b/{srcBucket}/o/{srcObject}/copyTo/b/{destBucket}/o/{destObject}",
|
||||
(url, params, req) -> {
|
||||
String source = params.get("srcObject");
|
||||
if (Strings.hasText(source) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "source object name is missing");
|
||||
}
|
||||
|
||||
String dest = params.get("destObject");
|
||||
if (Strings.hasText(dest) == false) {
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "destination object name is missing");
|
||||
}
|
||||
|
||||
String srcObjectId = null;
|
||||
for (Map.Entry<String, String> object : objectsNames.entrySet()) {
|
||||
if (object.getValue().equals(source)) {
|
||||
srcObjectId = object.getKey();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (srcObjectId == null) {
|
||||
return newMockError(RestStatus.NOT_FOUND, "source object not found");
|
||||
}
|
||||
|
||||
byte[] content = objectsContent.get(srcObjectId);
|
||||
if (content == null) {
|
||||
return newMockError(RestStatus.NOT_FOUND, "source content can not be found");
|
||||
}
|
||||
|
||||
String destObjectId = String.valueOf(objectsCount.getAndIncrement());
|
||||
objectsNames.put(destObjectId, dest);
|
||||
objectsContent.put(destObjectId, content);
|
||||
|
||||
return newMockResponse().setContent(buildObjectResource(bucket, dest, destObjectId, content.length));
|
||||
});
|
||||
|
||||
// Batch
|
||||
//
|
||||
// https://cloud.google.com/storage/docs/json_api/v1/how-tos/batch
|
||||
handlers.insert("POST https://www.googleapis.com/batch", (url, params, req) -> {
|
||||
List<MockLowLevelHttpResponse> responses = new ArrayList<>();
|
||||
|
||||
// A batch request body looks like this:
|
||||
//
|
||||
// --__END_OF_PART__
|
||||
// Content-Length: 71
|
||||
// Content-Type: application/http
|
||||
// content-id: 1
|
||||
// content-transfer-encoding: binary
|
||||
//
|
||||
// DELETE https://www.googleapis.com/storage/v1/b/ohifkgu/o/foo%2Ftest
|
||||
//
|
||||
//
|
||||
// --__END_OF_PART__
|
||||
// Content-Length: 71
|
||||
// Content-Type: application/http
|
||||
// content-id: 2
|
||||
// content-transfer-encoding: binary
|
||||
//
|
||||
// DELETE https://www.googleapis.com/storage/v1/b/ohifkgu/o/bar%2Ftest
|
||||
//
|
||||
//
|
||||
// --__END_OF_PART__--
|
||||
|
||||
// Here we simply process the request body line by line and delegate to other handlers
|
||||
// if possible.
|
||||
try (ByteArrayOutputStream os = new ByteArrayOutputStream((int) req.getContentLength())) {
|
||||
req.getStreamingContent().writeTo(os);
|
||||
|
||||
Streams.readAllLines(new ByteArrayInputStream(os.toByteArray()), new Callback<String>() {
|
||||
@Override
|
||||
public void handle(String line) {
|
||||
Handler handler = handlers.retrieve(line, params);
|
||||
if (handler != null) {
|
||||
try {
|
||||
responses.add(handler.execute(line, params, req));
|
||||
} catch (IOException e) {
|
||||
responses.add(newMockError(RestStatus.INTERNAL_SERVER_ERROR, e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Now we can build the response
|
||||
String boundary = "__END_OF_PART__";
|
||||
String sep = "--";
|
||||
String line = "\r\n";
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (MockLowLevelHttpResponse resp : responses) {
|
||||
builder.append(sep).append(boundary).append(line);
|
||||
builder.append(line);
|
||||
builder.append("HTTP/1.1 ").append(resp.getStatusCode()).append(' ').append(resp.getReasonPhrase()).append(line);
|
||||
builder.append("Content-Length: ").append(resp.getContentLength()).append(line);
|
||||
builder.append(line);
|
||||
}
|
||||
builder.append(line);
|
||||
builder.append(sep).append(boundary).append(sep);
|
||||
|
||||
return newMockResponse().setContentType("multipart/mixed; boundary=" + boundary).setContent(builder.toString());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
|
||||
return new MockLowLevelHttpRequest() {
|
||||
@Override
|
||||
public LowLevelHttpResponse execute() throws IOException {
|
||||
String rawPath = url;
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
int pathEndPos = url.indexOf('?');
|
||||
if (pathEndPos != -1) {
|
||||
rawPath = url.substring(0, pathEndPos);
|
||||
RestUtils.decodeQueryString(url, pathEndPos + 1, params);
|
||||
}
|
||||
|
||||
Handler handler = handlers.retrieve(method + " " + rawPath, params);
|
||||
if (handler != null) {
|
||||
return handler.execute(rawPath, params, this);
|
||||
}
|
||||
return newMockError(RestStatus.INTERNAL_SERVER_ERROR, "Unable to handle request [method=" + method + ", url=" + url + "]");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static MockLowLevelHttpResponse newMockResponse() {
|
||||
return new MockLowLevelHttpResponse()
|
||||
.setContentType(Json.MEDIA_TYPE)
|
||||
.setStatusCode(RestStatus.OK.getStatus())
|
||||
.setReasonPhrase(RestStatus.OK.name());
|
||||
}
|
||||
|
||||
private static MockLowLevelHttpResponse newMockError(RestStatus status, String message) {
|
||||
MockLowLevelHttpResponse response = newMockResponse().setStatusCode(status.getStatus()).setReasonPhrase(status.name());
|
||||
try {
|
||||
response.setContent(buildErrorResource(status, message));
|
||||
} catch (IOException e) {
|
||||
response.setContent("Failed to build error resource [" + message + "] because of: " + e.getMessage());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage Error JSON representation
|
||||
*/
|
||||
private static String buildErrorResource(RestStatus status, String message) throws IOException {
|
||||
return jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("error")
|
||||
.field("code", status.getStatus())
|
||||
.field("message", message)
|
||||
.startArray("errors")
|
||||
.startObject()
|
||||
.field("domain", "global")
|
||||
.field("reason", status.toString())
|
||||
.field("message", message)
|
||||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.string();
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage Bucket JSON representation as defined in
|
||||
* https://cloud.google.com/storage/docs/json_api/v1/bucket#resource
|
||||
*/
|
||||
private static String buildBucketResource(String name) throws IOException {
|
||||
return jsonBuilder().startObject()
|
||||
.field("kind", "storage#bucket")
|
||||
.field("id", name)
|
||||
.endObject()
|
||||
.string();
|
||||
}
|
||||
|
||||
/**
|
||||
* Storage Object JSON representation as defined in
|
||||
* https://cloud.google.com/storage/docs/json_api/v1/objects#resource
|
||||
*/
|
||||
private static XContentBuilder buildObjectResource(XContentBuilder builder, String bucket, String name, String id, int size)
|
||||
throws IOException {
|
||||
return builder.startObject()
|
||||
.field("kind", "storage#object")
|
||||
.field("id", String.join("/", bucket, name, id))
|
||||
.field("name", name)
|
||||
.field("size", String.valueOf(size))
|
||||
.endObject();
|
||||
}
|
||||
|
||||
private static String buildObjectResource(String bucket, String name, String id, int size) throws IOException {
|
||||
return buildObjectResource(jsonBuilder(), bucket, name, id, size).string();
|
||||
}
|
||||
|
||||
interface Handler {
|
||||
MockLowLevelHttpResponse execute(String url, Map<String, String> params, MockLowLevelHttpRequest request) throws IOException;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instanciates a mocked Storage client for tests.
|
||||
*/
|
||||
public static Storage newStorage(String bucket, String applicationName) {
|
||||
return new Storage.Builder(new MockHttpTransport(bucket), new JacksonFactory(), null)
|
||||
.setApplicationName(applicationName)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.repositories.gcs;
|
||||
|
||||
import com.google.api.services.storage.Storage;
|
||||
import org.elasticsearch.common.blobstore.gcs.MockHttpTransport;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.plugin.repository.gcs.GoogleCloudStorageModule;
|
||||
import org.elasticsearch.plugin.repository.gcs.GoogleCloudStoragePlugin;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.repositories.ESBlobStoreRepositoryIntegTestCase;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
|
||||
public class GoogleCloudStorageBlobStoreRepositoryTests extends ESBlobStoreRepositoryIntegTestCase {
|
||||
|
||||
private static final String BUCKET = "gcs-repository-test";
|
||||
|
||||
// Static storage client shared among all nodes in order to act like a remote repository service:
|
||||
// all nodes must see the same content
|
||||
private static final AtomicReference<Storage> storage = new AtomicReference<>();
|
||||
|
||||
@Override
|
||||
protected Collection<Class<? extends Plugin>> nodePlugins() {
|
||||
return pluginList(MockGoogleCloudStoragePlugin.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createTestRepository(String name) {
|
||||
assertAcked(client().admin().cluster().preparePutRepository(name)
|
||||
.setType(GoogleCloudStorageRepository.TYPE)
|
||||
.setSettings(Settings.builder()
|
||||
.put("bucket", BUCKET)
|
||||
.put("base_path", GoogleCloudStorageBlobStoreRepositoryTests.class.getSimpleName())
|
||||
.put("service_account", "_default_")
|
||||
.put("compress", randomBoolean())
|
||||
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpStorage() {
|
||||
storage.set(MockHttpTransport.newStorage(BUCKET, GoogleCloudStorageBlobStoreRepositoryTests.class.getName()));
|
||||
}
|
||||
|
||||
public static class MockGoogleCloudStoragePlugin extends GoogleCloudStoragePlugin {
|
||||
|
||||
public MockGoogleCloudStoragePlugin() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Module> nodeModules() {
|
||||
return Collections.singletonList(new MockGoogleCloudStorageModule());
|
||||
}
|
||||
}
|
||||
|
||||
public static class MockGoogleCloudStorageModule extends GoogleCloudStorageModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GoogleCloudStorageService.class).to(MockGoogleCloudStorageService.class).asEagerSingleton();
|
||||
}
|
||||
}
|
||||
|
||||
public static class MockGoogleCloudStorageService implements GoogleCloudStorageService {
|
||||
|
||||
@Override
|
||||
public Storage createClient(String serviceAccount, String application, TimeValue connectTimeout, TimeValue readTimeout) throws
|
||||
Exception {
|
||||
return storage.get();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.repositories.gcs;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.annotations.Name;
|
||||
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
|
||||
import org.elasticsearch.test.rest.ESRestTestCase;
|
||||
import org.elasticsearch.test.rest.RestTestCandidate;
|
||||
import org.elasticsearch.test.rest.parser.RestTestParseException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GoogleCloudStorageRepositoryRestIT extends ESRestTestCase {
|
||||
|
||||
public GoogleCloudStorageRepositoryRestIT(@Name("yaml") RestTestCandidate testCandidate) {
|
||||
super(testCandidate);
|
||||
}
|
||||
|
||||
@ParametersFactory
|
||||
public static Iterable<Object[]> parameters() throws IOException, RestTestParseException {
|
||||
return createParameters(0, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Integration tests for Repository GCS component
|
||||
#
|
||||
"Repository GCS loaded":
|
||||
- do:
|
||||
cluster.state: {}
|
||||
|
||||
# Get master node id
|
||||
- set: { master_node: master }
|
||||
|
||||
- do:
|
||||
nodes.info: {}
|
||||
|
||||
- match: { nodes.$master.plugins.0.name: repository-gcs }
|
|
@ -289,6 +289,10 @@ fi
|
|||
install_and_check_plugin repository azure azure-storage-*.jar
|
||||
}
|
||||
|
||||
@test "[$GROUP] install repository-gcs plugin" {
|
||||
install_and_check_plugin repository gcs google-api-services-storage-*.jar
|
||||
}
|
||||
|
||||
@test "[$GROUP] install repository-s3 plugin" {
|
||||
install_and_check_plugin repository s3 aws-java-sdk-core-*.jar
|
||||
}
|
||||
|
@ -387,6 +391,10 @@ fi
|
|||
remove_plugin repository-azure
|
||||
}
|
||||
|
||||
@test "[$GROUP] remove repository-gcs plugin" {
|
||||
remove_plugin repository-gcs
|
||||
}
|
||||
|
||||
@test "[$GROUP] remove repository-hdfs plugin" {
|
||||
remove_plugin repository-hdfs
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ List projects = [
|
|||
'plugins:mapper-murmur3',
|
||||
'plugins:mapper-size',
|
||||
'plugins:repository-azure',
|
||||
'plugins:repository-gcs',
|
||||
'plugins:repository-hdfs',
|
||||
'plugins:repository-s3',
|
||||
'plugins:jvm-example',
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.test;
|
||||
package org.elasticsearch.repositories;
|
||||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.apache.lucene.util.BytesRefBuilder;
|
||||
|
@ -25,6 +25,7 @@ import org.elasticsearch.common.blobstore.BlobMetaData;
|
|||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -32,9 +33,9 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.test.ESBlobStoreTestCase.writeRandomBlob;
|
||||
import static org.elasticsearch.test.ESBlobStoreTestCase.randomBytes;
|
||||
import static org.elasticsearch.test.ESBlobStoreTestCase.readBlobFully;
|
||||
import static org.elasticsearch.repositories.ESBlobStoreTestCase.writeRandomBlob;
|
||||
import static org.elasticsearch.repositories.ESBlobStoreTestCase.randomBytes;
|
||||
import static org.elasticsearch.repositories.ESBlobStoreTestCase.readBlobFully;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
|
|
@ -16,13 +16,14 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.test;
|
||||
package org.elasticsearch.repositories;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
@ -59,7 +60,8 @@ public abstract class ESBlobStoreRepositoryIntegTestCase extends ESIntegTestCase
|
|||
|
||||
String snapshotName = randomAsciiName();
|
||||
logger.info("--> create snapshot {}:{}", repoName, snapshotName);
|
||||
assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName).setWaitForCompletion(true).setIndices(indexNames));
|
||||
assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName)
|
||||
.setWaitForCompletion(true).setIndices(indexNames));
|
||||
|
||||
List<String> deleteIndices = randomSubsetOf(randomIntBetween(0, indexCount), indexNames);
|
||||
if (deleteIndices.size() > 0) {
|
||||
|
@ -99,6 +101,9 @@ public abstract class ESBlobStoreRepositoryIntegTestCase extends ESIntegTestCase
|
|||
for (int i = 0; i < indexCount; i++) {
|
||||
assertHitCount(client().prepareSearch(indexNames[i]).setSize(0).get(), docCounts[i]);
|
||||
}
|
||||
|
||||
logger.info("--> delete snapshot {}:{}", repoName, snapshotName);
|
||||
assertAcked(client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotName).get());
|
||||
}
|
||||
|
||||
public void testMultipleSnapshotAndRollback() throws Exception {
|
||||
|
@ -130,7 +135,8 @@ public abstract class ESBlobStoreRepositoryIntegTestCase extends ESIntegTestCase
|
|||
// Check number of documents in this iteration
|
||||
docCounts[i] = (int) client().prepareSearch(indexName).setSize(0).get().getHits().totalHits();
|
||||
logger.info("--> create snapshot {}:{} with {} documents", repoName, snapshotName + "-" + i, docCounts[i]);
|
||||
assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName + "-" + i).setWaitForCompletion(true).setIndices(indexName));
|
||||
assertSuccessfulSnapshot(client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName + "-" + i)
|
||||
.setWaitForCompletion(true).setIndices(indexName));
|
||||
}
|
||||
|
||||
int restoreOperations = randomIntBetween(1, 3);
|
||||
|
@ -142,10 +148,17 @@ public abstract class ESBlobStoreRepositoryIntegTestCase extends ESIntegTestCase
|
|||
assertAcked(client().admin().indices().prepareClose(indexName));
|
||||
|
||||
logger.info("--> restore index from the snapshot");
|
||||
assertSuccessfulRestore(client().admin().cluster().prepareRestoreSnapshot(repoName, snapshotName + "-" + iterationToRestore).setWaitForCompletion(true));
|
||||
assertSuccessfulRestore(client().admin().cluster().prepareRestoreSnapshot(repoName, snapshotName + "-" + iterationToRestore)
|
||||
.setWaitForCompletion(true));
|
||||
|
||||
ensureGreen();
|
||||
assertHitCount(client().prepareSearch(indexName).setSize(0).get(), docCounts[iterationToRestore]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < iterationCount; i++) {
|
||||
logger.info("--> delete snapshot {}:{}", repoName, snapshotName + "-" + i);
|
||||
assertAcked(client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotName + "-" + i).get());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addRandomDocuments(String name, int numDocs) throws ExecutionException, InterruptedException {
|
|
@ -16,12 +16,13 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.test;
|
||||
package org.elasticsearch.repositories;
|
||||
|
||||
import org.elasticsearch.common.blobstore.BlobContainer;
|
||||
import org.elasticsearch.common.blobstore.BlobPath;
|
||||
import org.elasticsearch.common.blobstore.BlobStore;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
Loading…
Reference in New Issue