Reference documentation and code samples for the Google Cloud Datastore Admin V1 Client class DatastoreAdminClient.
Service Description: Google Cloud Datastore Admin API
The Datastore Admin API provides several admin services for Cloud Datastore.
Concepts: Project, namespace, kind, and entity as defined in the Google Cloud Datastore API.
Operation: An Operation represents work being performed in the background.
EntityFilter: Allows specifying a subset of entities in a project. This is specified as a combination of kinds and namespaces (either or both of which may be all).
Export/Import Service:
- The Export/Import service provides the ability to copy all or a subset of entities to/from Google Cloud Storage.
- Exported data may be imported into Cloud Datastore for any Google Cloud Platform project. It is not restricted to the export source project. It is possible to export from one project and then import into another.
- Exported data can also be loaded into Google BigQuery for analysis.
- Exports and imports are performed asynchronously. An Operation resource is created for each export/import. The state (including any errors encountered) of the export/import may be queried via the Operation resource.
Index Service:
- The index service manages Cloud Datastore composite indexes.
- Index creation and deletion are performed asynchronously. An Operation resource is created for each such asynchronous operation. The state of the operation (including any errors encountered) may be queried via the Operation resource.
Operation Service:
- The Operations collection provides a record of actions performed for the specified project (including any operations in progress). Operations are not created directly but through calls on other collections or resources.
- An operation that is not yet done may be cancelled. The request to cancel is asynchronous and the operation may continue to run for some time after the request to cancel is made.
- An operation that is done may be deleted so that it is no longer listed as part of the Operation collection.
- ListOperations returns all pending operations, but not completed operations.
- Operations are created by service DatastoreAdmin, but are accessed via service google.longrunning.Operations.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods.
Namespace
Google \ Cloud \ Datastore \ Admin \ V1 \ ClientMethods
__construct
Constructor.
Parameters | |
---|---|
Name | Description |
options |
array
Optional. Options for configuring the service API wrapper. |
↳ apiEndpoint |
string
The address of the API remote host. May optionally include the port, formatted as "
|
↳ credentials |
string|array|FetchAuthTokenInterface|CredentialsWrapper
The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. |
↳ credentialsConfig |
array
Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() . |
↳ disableRetries |
bool
Determines whether or not retries defined by the client configuration should be disabled. Defaults to |
↳ clientConfig |
string|array
Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder. |
↳ transport |
string|TransportInterface
The transport used for executing network requests. May be either the string |
↳ transportConfig |
array
Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options. |
↳ clientCertSource |
callable
A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS. |
createIndex
Creates the specified index.
A newly created index's initial state is CREATING
. On completion of the
returned google.longrunning.Operation, the
state will be READY
. If the index already exists, the call will return an
ALREADY_EXISTS
status.
During index creation, the process could result in an error, in which
case the index will move to the ERROR
state. The process can be recovered
by fixing the data that caused the error, removing the index with
delete, then
re-creating the index with create.
Indexes with a single property cannot be created.
The async variant is Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient::createIndexAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\CreateIndexRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient;
use Google\Cloud\Datastore\Admin\V1\CreateIndexRequest;
use Google\Cloud\Datastore\Admin\V1\Index;
use Google\Rpc\Status;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function create_index_sample(): void
{
// Create a client.
$datastoreAdminClient = new DatastoreAdminClient();
// Prepare the request message.
$request = new CreateIndexRequest();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $datastoreAdminClient->createIndex($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Index $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
deleteIndex
Deletes an existing index.
An index can only be deleted if it is in a READY
or ERROR
state. On
successful execution of the request, the index will be in a DELETING
state. And on completion of the
returned google.longrunning.Operation, the
index will be removed.
During index deletion, the process could result in an error, in which
case the index will move to the ERROR
state. The process can be recovered
by fixing the data that caused the error, followed by calling
delete again.
The async variant is Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient::deleteIndexAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\DeleteIndexRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient;
use Google\Cloud\Datastore\Admin\V1\DeleteIndexRequest;
use Google\Cloud\Datastore\Admin\V1\Index;
use Google\Rpc\Status;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function delete_index_sample(): void
{
// Create a client.
$datastoreAdminClient = new DatastoreAdminClient();
// Prepare the request message.
$request = new DeleteIndexRequest();
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $datastoreAdminClient->deleteIndex($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var Index $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
exportEntities
Exports a copy of all or a subset of entities from Google Cloud Datastore to another storage system, such as Google Cloud Storage. Recent updates to entities may not be reflected in the export. The export occurs in the background and its progress can be monitored and managed via the Operation resource that is created. The output of an export may only be used once the associated operation is done. If an export operation is cancelled before completion it may leave partial data behind in Google Cloud Storage.
The async variant is Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient::exportEntitiesAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\ExportEntitiesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient;
use Google\Cloud\Datastore\Admin\V1\ExportEntitiesRequest;
use Google\Cloud\Datastore\Admin\V1\ExportEntitiesResponse;
use Google\Rpc\Status;
/**
* @param string $projectId Project ID against which to make the request.
* @param string $outputUrlPrefix Location for the export metadata and data files.
*
* The full resource URL of the external storage location. Currently, only
* Google Cloud Storage is supported. So output_url_prefix should be of the
* form: `gs://BUCKET_NAME[/NAMESPACE_PATH]`, where `BUCKET_NAME` is the
* name of the Cloud Storage bucket and `NAMESPACE_PATH` is an optional Cloud
* Storage namespace path (this is not a Cloud Datastore namespace). For more
* information about Cloud Storage namespace paths, see
* [Object name
* considerations](https://cloud.google.com/storage/docs/naming#object-considerations).
*
* The resulting files will be nested deeper than the specified URL prefix.
* The final output URL will be provided in the
* [google.datastore.admin.v1.ExportEntitiesResponse.output_url][google.datastore.admin.v1.ExportEntitiesResponse.output_url]
* field. That value should be used for subsequent ImportEntities operations.
*
* By nesting the data files deeper, the same Cloud Storage bucket can be used
* in multiple ExportEntities operations without conflict.
*/
function export_entities_sample(string $projectId, string $outputUrlPrefix): void
{
// Create a client.
$datastoreAdminClient = new DatastoreAdminClient();
// Prepare the request message.
$request = (new ExportEntitiesRequest())
->setProjectId($projectId)
->setOutputUrlPrefix($outputUrlPrefix);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $datastoreAdminClient->exportEntities($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var ExportEntitiesResponse $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$projectId = '[PROJECT_ID]';
$outputUrlPrefix = '[OUTPUT_URL_PREFIX]';
export_entities_sample($projectId, $outputUrlPrefix);
}
getIndex
Gets an index.
The async variant is Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient::getIndexAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\GetIndexRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\Cloud\Datastore\Admin\V1\Index |
use Google\ApiCore\ApiException;
use Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient;
use Google\Cloud\Datastore\Admin\V1\GetIndexRequest;
use Google\Cloud\Datastore\Admin\V1\Index;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function get_index_sample(): void
{
// Create a client.
$datastoreAdminClient = new DatastoreAdminClient();
// Prepare the request message.
$request = new GetIndexRequest();
// Call the API and handle any network failures.
try {
/** @var Index $response */
$response = $datastoreAdminClient->getIndex($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
importEntities
Imports entities into Google Cloud Datastore. Existing entities with the same key are overwritten. The import occurs in the background and its progress can be monitored and managed via the Operation resource that is created. If an ImportEntities operation is cancelled, it is possible that a subset of the data has already been imported to Cloud Datastore.
The async variant is Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient::importEntitiesAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\ImportEntitiesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient;
use Google\Cloud\Datastore\Admin\V1\ImportEntitiesRequest;
use Google\Rpc\Status;
/**
* @param string $projectId Project ID against which to make the request.
* @param string $inputUrl The full resource URL of the external storage location.
* Currently, only Google Cloud Storage is supported. So input_url should be
* of the form:
* `gs://BUCKET_NAME[/NAMESPACE_PATH]/OVERALL_EXPORT_METADATA_FILE`, where
* `BUCKET_NAME` is the name of the Cloud Storage bucket, `NAMESPACE_PATH` is
* an optional Cloud Storage namespace path (this is not a Cloud Datastore
* namespace), and `OVERALL_EXPORT_METADATA_FILE` is the metadata file written
* by the ExportEntities operation. For more information about Cloud Storage
* namespace paths, see
* [Object name
* considerations](https://cloud.google.com/storage/docs/naming#object-considerations).
*
* For more information, see
* [google.datastore.admin.v1.ExportEntitiesResponse.output_url][google.datastore.admin.v1.ExportEntitiesResponse.output_url].
*/
function import_entities_sample(string $projectId, string $inputUrl): void
{
// Create a client.
$datastoreAdminClient = new DatastoreAdminClient();
// Prepare the request message.
$request = (new ImportEntitiesRequest())
->setProjectId($projectId)
->setInputUrl($inputUrl);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $datastoreAdminClient->importEntities($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
printf('Operation completed successfully.' . PHP_EOL);
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$projectId = '[PROJECT_ID]';
$inputUrl = '[INPUT_URL]';
import_entities_sample($projectId, $inputUrl);
}
listIndexes
Lists the indexes that match the specified filters. Datastore uses an eventually consistent query to fetch the list of indexes and may occasionally return stale results.
The async variant is Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient::listIndexesAsync() .
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\ListIndexesRequest
A request to house fields associated with the call. |
callOptions |
array
Optional. |
↳ retrySettings |
RetrySettings|array
Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage. |
Returns | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Datastore\Admin\V1\Client\DatastoreAdminClient;
use Google\Cloud\Datastore\Admin\V1\Index;
use Google\Cloud\Datastore\Admin\V1\ListIndexesRequest;
/**
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function list_indexes_sample(): void
{
// Create a client.
$datastoreAdminClient = new DatastoreAdminClient();
// Prepare the request message.
$request = new ListIndexesRequest();
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $datastoreAdminClient->listIndexes($request);
/** @var Index $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
createIndexAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\CreateIndexRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
deleteIndexAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\DeleteIndexRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
exportEntitiesAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\ExportEntitiesRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getIndexAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\GetIndexRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
importEntitiesAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\ImportEntitiesRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
listIndexesAsync
Parameters | |
---|---|
Name | Description |
request |
Google\Cloud\Datastore\Admin\V1\ListIndexesRequest
|
optionalArgs = [] |
array
|
Returns | |
---|---|
Type | Description |
GuzzleHttp\Promise\PromiseInterface |
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
Returns | |
---|---|
Type | Description |
Google\ApiCore\LongRunning\OperationsClient |
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
Parameters | |
---|---|
Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |