1<?php
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy of
7 * the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18namespace Google\Service\Spanner\Resource;
19
20use Google\Service\Spanner\CreateInstanceRequest;
21use Google\Service\Spanner\GetIamPolicyRequest;
22use Google\Service\Spanner\Instance;
23use Google\Service\Spanner\ListInstancesResponse;
24use Google\Service\Spanner\Operation;
25use Google\Service\Spanner\Policy;
26use Google\Service\Spanner\SetIamPolicyRequest;
27use Google\Service\Spanner\SpannerEmpty;
28use Google\Service\Spanner\TestIamPermissionsRequest;
29use Google\Service\Spanner\TestIamPermissionsResponse;
30use Google\Service\Spanner\UpdateInstanceRequest;
31
32/**
33 * The "instances" collection of methods.
34 * Typical usage is:
35 *  <code>
36 *   $spannerService = new Google\Service\Spanner(...);
37 *   $instances = $spannerService->instances;
38 *  </code>
39 */
40class ProjectsInstances extends \Google\Service\Resource
41{
42  /**
43   * Creates an instance and begins preparing it to begin serving. The returned
44   * long-running operation can be used to track the progress of preparing the new
45   * instance. The instance name is assigned by the caller. If the named instance
46   * already exists, `CreateInstance` returns `ALREADY_EXISTS`. Immediately upon
47   * completion of this request: * The instance is readable via the API, with all
48   * requested attributes but no allocated resources. Its state is `CREATING`.
49   * Until completion of the returned operation: * Cancelling the operation
50   * renders the instance immediately unreadable via the API. * The instance can
51   * be deleted. * All other attempts to modify the instance are rejected. Upon
52   * completion of the returned operation: * Billing for all successfully-
53   * allocated resources begins (some types may have lower than the requested
54   * levels). * Databases can be created in the instance. * The instance's
55   * allocated resource levels are readable via the API. * The instance's state
56   * becomes `READY`. The returned long-running operation will have a name of the
57   * format `/operations/` and can be used to track creation of the instance. The
58   * metadata field type is CreateInstanceMetadata. The response field type is
59   * Instance, if successful. (instances.create)
60   *
61   * @param string $parent Required. The name of the project in which to create
62   * the instance. Values are of the form `projects/`.
63   * @param CreateInstanceRequest $postBody
64   * @param array $optParams Optional parameters.
65   * @return Operation
66   */
67  public function create($parent, CreateInstanceRequest $postBody, $optParams = [])
68  {
69    $params = ['parent' => $parent, 'postBody' => $postBody];
70    $params = array_merge($params, $optParams);
71    return $this->call('create', [$params], Operation::class);
72  }
73  /**
74   * Deletes an instance. Immediately upon completion of the request: * Billing
75   * ceases for all of the instance's reserved resources. Soon afterward: * The
76   * instance and *all of its databases* immediately and irrevocably disappear
77   * from the API. All data in the databases is permanently deleted.
78   * (instances.delete)
79   *
80   * @param string $name Required. The name of the instance to be deleted. Values
81   * are of the form `projects//instances/`
82   * @param array $optParams Optional parameters.
83   * @return SpannerEmpty
84   */
85  public function delete($name, $optParams = [])
86  {
87    $params = ['name' => $name];
88    $params = array_merge($params, $optParams);
89    return $this->call('delete', [$params], SpannerEmpty::class);
90  }
91  /**
92   * Gets information about a particular instance. (instances.get)
93   *
94   * @param string $name Required. The name of the requested instance. Values are
95   * of the form `projects//instances/`.
96   * @param array $optParams Optional parameters.
97   *
98   * @opt_param string fieldMask If field_mask is present, specifies the subset of
99   * Instance fields that should be returned. If absent, all Instance fields are
100   * returned.
101   * @return Instance
102   */
103  public function get($name, $optParams = [])
104  {
105    $params = ['name' => $name];
106    $params = array_merge($params, $optParams);
107    return $this->call('get', [$params], Instance::class);
108  }
109  /**
110   * Gets the access control policy for an instance resource. Returns an empty
111   * policy if an instance exists but does not have a policy set. Authorization
112   * requires `spanner.instances.getIamPolicy` on resource.
113   * (instances.getIamPolicy)
114   *
115   * @param string $resource REQUIRED: The Cloud Spanner resource for which the
116   * policy is being retrieved. The format is `projects//instances/` for instance
117   * resources and `projects//instances//databases/` for database resources.
118   * @param GetIamPolicyRequest $postBody
119   * @param array $optParams Optional parameters.
120   * @return Policy
121   */
122  public function getIamPolicy($resource, GetIamPolicyRequest $postBody, $optParams = [])
123  {
124    $params = ['resource' => $resource, 'postBody' => $postBody];
125    $params = array_merge($params, $optParams);
126    return $this->call('getIamPolicy', [$params], Policy::class);
127  }
128  /**
129   * Lists all instances in the given project. (instances.listProjectsInstances)
130   *
131   * @param string $parent Required. The name of the project for which a list of
132   * instances is requested. Values are of the form `projects/`.
133   * @param array $optParams Optional parameters.
134   *
135   * @opt_param string filter An expression for filtering the results of the
136   * request. Filter rules are case insensitive. The fields eligible for filtering
137   * are: * `name` * `display_name` * `labels.key` where key is the name of a
138   * label Some examples of using filters are: * `name:*` --> The instance has a
139   * name. * `name:Howl` --> The instance's name contains the string "howl". *
140   * `name:HOWL` --> Equivalent to above. * `NAME:howl` --> Equivalent to above. *
141   * `labels.env:*` --> The instance has the label "env". * `labels.env:dev` -->
142   * The instance has the label "env" and the value of the label contains the
143   * string "dev". * `name:howl labels.env:dev` --> The instance's name contains
144   * "howl" and it has the label "env" with its value containing "dev".
145   * @opt_param string instanceDeadline Deadline used while retrieving metadata
146   * for instances. Instances whose metadata cannot be retrieved within this
147   * deadline will be added to unreachable in ListInstancesResponse.
148   * @opt_param int pageSize Number of instances to be returned in the response.
149   * If 0 or less, defaults to the server's maximum allowed page size.
150   * @opt_param string pageToken If non-empty, `page_token` should contain a
151   * next_page_token from a previous ListInstancesResponse.
152   * @return ListInstancesResponse
153   */
154  public function listProjectsInstances($parent, $optParams = [])
155  {
156    $params = ['parent' => $parent];
157    $params = array_merge($params, $optParams);
158    return $this->call('list', [$params], ListInstancesResponse::class);
159  }
160  /**
161   * Updates an instance, and begins allocating or releasing resources as
162   * requested. The returned long-running operation can be used to track the
163   * progress of updating the instance. If the named instance does not exist,
164   * returns `NOT_FOUND`. Immediately upon completion of this request: * For
165   * resource types for which a decrease in the instance's allocation has been
166   * requested, billing is based on the newly-requested level. Until completion of
167   * the returned operation: * Cancelling the operation sets its metadata's
168   * cancel_time, and begins restoring resources to their pre-request values. The
169   * operation is guaranteed to succeed at undoing all resource changes, after
170   * which point it terminates with a `CANCELLED` status. * All other attempts to
171   * modify the instance are rejected. * Reading the instance via the API
172   * continues to give the pre-request resource levels. Upon completion of the
173   * returned operation: * Billing begins for all successfully-allocated resources
174   * (some types may have lower than the requested levels). * All newly-reserved
175   * resources are available for serving the instance's tables. * The instance's
176   * new resource levels are readable via the API. The returned long-running
177   * operation will have a name of the format `/operations/` and can be used to
178   * track the instance modification. The metadata field type is
179   * UpdateInstanceMetadata. The response field type is Instance, if successful.
180   * Authorization requires `spanner.instances.update` permission on the resource
181   * name. (instances.patch)
182   *
183   * @param string $name Required. A unique identifier for the instance, which
184   * cannot be changed after the instance is created. Values are of the form
185   * `projects//instances/a-z*[a-z0-9]`. The final segment of the name must be
186   * between 2 and 64 characters in length.
187   * @param UpdateInstanceRequest $postBody
188   * @param array $optParams Optional parameters.
189   * @return Operation
190   */
191  public function patch($name, UpdateInstanceRequest $postBody, $optParams = [])
192  {
193    $params = ['name' => $name, 'postBody' => $postBody];
194    $params = array_merge($params, $optParams);
195    return $this->call('patch', [$params], Operation::class);
196  }
197  /**
198   * Sets the access control policy on an instance resource. Replaces any existing
199   * policy. Authorization requires `spanner.instances.setIamPolicy` on resource.
200   * (instances.setIamPolicy)
201   *
202   * @param string $resource REQUIRED: The Cloud Spanner resource for which the
203   * policy is being set. The format is `projects//instances/` for instance
204   * resources and `projects//instances//databases/` for databases resources.
205   * @param SetIamPolicyRequest $postBody
206   * @param array $optParams Optional parameters.
207   * @return Policy
208   */
209  public function setIamPolicy($resource, SetIamPolicyRequest $postBody, $optParams = [])
210  {
211    $params = ['resource' => $resource, 'postBody' => $postBody];
212    $params = array_merge($params, $optParams);
213    return $this->call('setIamPolicy', [$params], Policy::class);
214  }
215  /**
216   * Returns permissions that the caller has on the specified instance resource.
217   * Attempting this RPC on a non-existent Cloud Spanner instance resource will
218   * result in a NOT_FOUND error if the user has `spanner.instances.list`
219   * permission on the containing Google Cloud Project. Otherwise returns an empty
220   * set of permissions. (instances.testIamPermissions)
221   *
222   * @param string $resource REQUIRED: The Cloud Spanner resource for which
223   * permissions are being tested. The format is `projects//instances/` for
224   * instance resources and `projects//instances//databases/` for database
225   * resources.
226   * @param TestIamPermissionsRequest $postBody
227   * @param array $optParams Optional parameters.
228   * @return TestIamPermissionsResponse
229   */
230  public function testIamPermissions($resource, TestIamPermissionsRequest $postBody, $optParams = [])
231  {
232    $params = ['resource' => $resource, 'postBody' => $postBody];
233    $params = array_merge($params, $optParams);
234    return $this->call('testIamPermissions', [$params], TestIamPermissionsResponse::class);
235  }
236}
237
238// Adding a class alias for backwards compatibility with the previous class name.
239class_alias(ProjectsInstances::class, 'Google_Service_Spanner_Resource_ProjectsInstances');
240