/** Constructs an instance of CloudRedisClient with default settings. */ public static final CloudRedisClient create() throws IOException { return create(CloudRedisSettings.newBuilder().build()); }
/** * Gets the details of a specific Redis instance. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * Instance response = cloudRedisClient.getInstance(name.toString()); * } * </code></pre> * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Instance getInstance(String name) { GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name).build(); return getInstance(request); }
/** * Lists all Redis instances owned by a project in either the specified location (region) or all * locations. * * <p>The location should have the following format: * * `projects/{project_id}/locations/{location_id}` * * <p>If `location_id` is specified as `-` (wildcard), then all regions available to the project * are queried, and the results are aggregated. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); * for (Instance element : cloudRedisClient.listInstances(parent.toString()).iterateAll()) { * // doThingsWith(element); * } * } * </code></pre> * * @param parent Required. The resource name of the instance location using the form: * `projects/{project_id}/locations/{location_id}` where `location_id` refers to a GCP region * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final ListInstancesPagedResponse listInstances(String parent) { ListInstancesRequest request = ListInstancesRequest.newBuilder().setParent(parent).build(); return listInstances(request); }
/** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * Empty response = cloudRedisClient.deleteInstanceAsync(name.toString()).get(); * } * </code></pre> * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty, OperationMetadata> deleteInstanceAsync(String name) { DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name).build(); return deleteInstanceAsync(request); }
.setInstance(instance) .build(); return createInstanceAsync(request);
return updateInstanceAsync(request);
/** * Constructs an instance of CloudRedisClient, using the given settings. The channels are created * based on the settings passed in, or defaults for any settings that are not set. */ public static final CloudRedisClient create(CloudRedisSettings settings) throws IOException { return new CloudRedisClient(settings); }
/** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder() * .setName(name.toString()) * .build(); * Empty response = cloudRedisClient.deleteInstanceAsync(request).get(); * } * </code></pre> * * @param request The request object containing all of the parameters for the API call. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty, OperationMetadata> deleteInstanceAsync( DeleteInstanceRequest request) { return deleteInstanceOperationCallable().futureCall(request); }
@After public void tearDown() throws Exception { client.close(); }
public final OperationFuture<Instance, OperationMetadata> createInstanceAsync( CreateInstanceRequest request) { return createInstanceOperationCallable().futureCall(request);
/** * Deletes a specific Redis instance. Instance stops serving and data is deleted. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * Empty response = cloudRedisClient.deleteInstanceAsync(name).get(); * } * </code></pre> * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ @BetaApi( "The surface for long-running operations is not stable yet and may change in the future.") public final OperationFuture<Empty, OperationMetadata> deleteInstanceAsync(InstanceName name) { DeleteInstanceRequest request = DeleteInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return deleteInstanceAsync(request); }
.setInstance(instance) .build(); return createInstanceAsync(request);
@Test @SuppressWarnings("all") public void updateInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { String pathsElement = "display_name"; String pathsElement2 = "memory_size_gb"; List<String> paths = Arrays.asList(pathsElement, pathsElement2); FieldMask updateMask = FieldMask.newBuilder().addAllPaths(paths).build(); String displayName = "UpdatedDisplayName"; int memorySizeGb = 4; Instance instance = Instance.newBuilder().setDisplayName(displayName).setMemorySizeGb(memorySizeGb).build(); client.updateInstanceAsync(updateMask, instance).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
/** * Constructs an instance of CloudRedisClient, using the given stub for making calls. This is for * advanced usage - prefer to use CloudRedisSettings}. */ @BetaApi("A restructuring of stub classes is planned, so this may break in the future") public static final CloudRedisClient create(CloudRedisStub stub) { return new CloudRedisClient(stub); }
.setParent(parent == null ? null : parent.toString()) .build(); return listInstances(request);
/** * Gets the details of a specific Redis instance. * * <p>Sample code: * * <pre><code> * try (CloudRedisClient cloudRedisClient = CloudRedisClient.create()) { * InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); * Instance response = cloudRedisClient.getInstance(name); * } * </code></pre> * * @param name Required. Redis instance resource name using the form: * `projects/{project_id}/locations/{location_id}/instances/{instance_id}` where `location_id` * refers to a GCP region * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Instance getInstance(InstanceName name) { GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(name == null ? null : name.toString()).build(); return getInstance(request); }
@Test @SuppressWarnings("all") public void deleteInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { InstanceName name = InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]"); client.deleteInstanceAsync(name).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } } }
@Test @SuppressWarnings("all") public void createInstanceExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockCloudRedis.addException(exception); try { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); String instanceId = "test_instance"; Instance.Tier tier = Instance.Tier.BASIC; int memorySizeGb = 1; Instance instance = Instance.newBuilder().setTier(tier).setMemorySizeGb(memorySizeGb).build(); client.createInstanceAsync(parent, instanceId, instance).get(); Assert.fail("No exception raised"); } catch (ExecutionException e) { Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass()); InvalidArgumentException apiException = (InvalidArgumentException) e.getCause(); Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode()); } }
Instance.newBuilder().setDisplayName(displayName).setMemorySizeGb(memorySizeGb).build(); Instance actualResponse = client.updateInstanceAsync(updateMask, instance).get(); Assert.assertEquals(expectedResponse, actualResponse);
@Before public void setUp() throws IOException { serviceHelper.reset(); channelProvider = serviceHelper.createChannelProvider(); CloudRedisSettings settings = CloudRedisSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(NoCredentialsProvider.create()) .build(); client = CloudRedisClient.create(settings); }