Search in sources :

Example 91 with Instance

use of com.google.cloud.compute.v1.Instance in project java-redis by googleapis.

the class ITSystemTest method cleanUpOldInstances.

public static void cleanUpOldInstances() throws ParseException {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    Timestamp cutoff = Timestamp.of(calendar.getTime());
    List<Instance> instances = Lists.newArrayList(client.listInstances(PARENT).iterateAll());
    for (Instance old_instance : instances) {
        Timestamp createdAt = Timestamp.ofTimeSecondsAndNanos(old_instance.getCreateTime().getSeconds(), old_instance.getCreateTime().getNanos());
        if (createdAt.compareTo(cutoff) < 0) {
            client.deleteInstanceAsync(old_instance.getName());
            LOG.info("redis instance " + old_instance.getName() + " deleted successfully.");
        }
    }
}
Also used : Instance(com.google.cloud.redis.v1.Instance) Calendar(java.util.Calendar) Timestamp(com.google.cloud.Timestamp)

Example 92 with Instance

use of com.google.cloud.compute.v1.Instance in project java-redis by googleapis.

the class ITSystemTest method testListInstances.

@Test
public void testListInstances() {
    List<Instance> instances = Lists.newArrayList(client.listInstances(PARENT).iterateAll());
    for (Instance instance : instances) {
        if (INSTANCE_NAME.toString().equals(instance.getName())) {
            assertEquals(TIER, instance.getTier());
            assertEquals(INSTANCE_NAME.toString(), instance.getName());
        }
    }
}
Also used : Instance(com.google.cloud.redis.v1beta1.Instance) Test(org.junit.Test)

Example 93 with Instance

use of com.google.cloud.compute.v1.Instance in project java-notebooks by googleapis.

the class ITNotebookServiceClientTest method setUp.

@BeforeClass
public static void setUp() throws IOException, ExecutionException, InterruptedException {
    // Create Test Notebook Instance
    client = NotebookServiceClient.create();
    ContainerImage containerImage = ContainerImage.newBuilder().setRepository(FieldBehavior.OPTIONAL.name()).build();
    Environment environment = Environment.newBuilder().setName(ENVIRONMENT_NAME).setContainerImage(containerImage).build();
    CreateEnvironmentRequest environmentRequest = CreateEnvironmentRequest.newBuilder().setParent(PARENT).setEnvironmentId(ENVIRONMENT_ID).setEnvironment(environment).build();
    expectedEnvironmentResponse = client.createEnvironmentAsync(environmentRequest).get();
    Instance notebookInstance = Instance.newBuilder().setContainerImage(containerImage).setMachineType(MACHINE_TYPE_A).build();
    CreateInstanceRequest instanceRequest = CreateInstanceRequest.newBuilder().setParent(PARENT).setInstanceId(NOTEBOOK_INSTANCE_ID).setInstance(notebookInstance).build();
    expectedNotebookInstance = client.createInstanceAsync(instanceRequest).get();
}
Also used : CreateEnvironmentRequest(com.google.cloud.notebooks.v1beta1.CreateEnvironmentRequest) Instance(com.google.cloud.notebooks.v1beta1.Instance) ContainerImage(com.google.cloud.notebooks.v1beta1.ContainerImage) Environment(com.google.cloud.notebooks.v1beta1.Environment) CreateInstanceRequest(com.google.cloud.notebooks.v1beta1.CreateInstanceRequest) BeforeClass(org.junit.BeforeClass)

Example 94 with Instance

use of com.google.cloud.compute.v1.Instance in project java-notebooks by googleapis.

the class ITNotebookServiceClientTest method testGetInstance.

@Test
public void testGetInstance() {
    GetInstanceRequest request = GetInstanceRequest.newBuilder().setName(INSTANCE_NAME).build();
    Instance actualNotebookInstance = client.getInstance(request);
    assertEquals(expectedNotebookInstance.getContainerImage(), actualNotebookInstance.getContainerImage());
    assertEquals(expectedNotebookInstance.getName(), actualNotebookInstance.getName());
    assertEquals(expectedNotebookInstance.getNetwork(), actualNotebookInstance.getNetwork());
    assertEquals(expectedNotebookInstance.getSubnet(), actualNotebookInstance.getSubnet());
}
Also used : GetInstanceRequest(com.google.cloud.notebooks.v1beta1.GetInstanceRequest) Instance(com.google.cloud.notebooks.v1beta1.Instance) Test(org.junit.Test)

Example 95 with Instance

use of com.google.cloud.compute.v1.Instance in project java-notebooks by googleapis.

the class ITNotebookServiceClientTest method stopInstance.

private String stopInstance() throws ExecutionException, InterruptedException {
    StopInstanceRequest request = StopInstanceRequest.newBuilder().setName(INSTANCE_NAME).build();
    Instance response = client.stopInstanceAsync(request).get();
    return response.getState().name();
}
Also used : Instance(com.google.cloud.notebooks.v1beta1.Instance) StopInstanceRequest(com.google.cloud.notebooks.v1beta1.StopInstanceRequest)

Aggregations

Test (org.junit.Test)41 Instance (com.google.cloud.redis.v1beta1.Instance)34 CloudRedisClient (com.google.cloud.redis.v1beta1.CloudRedisClient)30 InstancesClient (com.google.cloud.compute.v1.InstancesClient)29 Operation (com.google.cloud.compute.v1.Operation)29 Instance (com.google.cloud.compute.v1.Instance)25 ByteString (com.google.protobuf.ByteString)17 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)16 AbstractMessage (com.google.protobuf.AbstractMessage)13 InsertInstanceRequest (com.google.cloud.compute.v1.InsertInstanceRequest)11 Instance (com.google.spanner.admin.instance.v1.Instance)11 Instance (com.google.bigtable.admin.v2.Instance)10 InstanceTemplatesClient (com.google.cloud.compute.v1.InstanceTemplatesClient)9 Instance (com.google.cloud.notebooks.v1beta1.Instance)9 ArrayList (java.util.ArrayList)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 InstanceTemplate (com.google.cloud.compute.v1.InstanceTemplate)7 NetworkInterface (com.google.cloud.compute.v1.NetworkInterface)7 Any (com.google.protobuf.Any)7 FieldMask (com.google.protobuf.FieldMask)7