Search in sources :

Example 6 with InstanceGroupManager

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

the class RegionInstanceGroupManagersClientTest method listManagedInstancesTest.

@Test
public void listManagedInstancesTest() throws Exception {
    ManagedInstance responsesElement = ManagedInstance.newBuilder().build();
    RegionInstanceGroupManagersListInstancesResponse expectedResponse = RegionInstanceGroupManagersListInstancesResponse.newBuilder().setNextPageToken("").addAllManagedInstances(Arrays.asList(responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    String region = "region-9622";
    String instanceGroupManager = "instanceGroupManager-7543";
    ListManagedInstancesPagedResponse pagedListResponse = client.listManagedInstances(project, region, instanceGroupManager);
    List<ManagedInstance> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getManagedInstancesList().get(0), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : ListManagedInstancesPagedResponse(com.google.cloud.compute.v1.RegionInstanceGroupManagersClient.ListManagedInstancesPagedResponse) Test(org.junit.Test)

Example 7 with InstanceGroupManager

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

the class InstanceGroupManagersClientTest method listPerInstanceConfigsTest.

@Test
public void listPerInstanceConfigsTest() throws Exception {
    PerInstanceConfig responsesElement = PerInstanceConfig.newBuilder().build();
    InstanceGroupManagersListPerInstanceConfigsResp expectedResponse = InstanceGroupManagersListPerInstanceConfigsResp.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    String zone = "zone-5246";
    String instanceGroupManager = "instanceGroupManager-7543";
    ListPerInstanceConfigsPagedResponse pagedListResponse = client.listPerInstanceConfigs(project, zone, instanceGroupManager);
    List<PerInstanceConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsList().get(0), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : ListPerInstanceConfigsPagedResponse(com.google.cloud.compute.v1.InstanceGroupManagersClient.ListPerInstanceConfigsPagedResponse) Test(org.junit.Test)

Example 8 with InstanceGroupManager

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

the class RegionInstanceGroupManagersClientTest method listTest.

@Test
public void listTest() throws Exception {
    InstanceGroupManager responsesElement = InstanceGroupManager.newBuilder().build();
    RegionInstanceGroupManagerList expectedResponse = RegionInstanceGroupManagerList.newBuilder().setNextPageToken("").addAllItems(Arrays.asList(responsesElement)).build();
    mockService.addResponse(expectedResponse);
    String project = "project-6911";
    String region = "region-9622";
    ListPagedResponse pagedListResponse = client.list(project, region);
    List<InstanceGroupManager> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getItemsList().get(0), resources.get(0));
    List<String> actualRequests = mockService.getRequestPaths();
    Assert.assertEquals(1, actualRequests.size());
    String apiClientHeaderKey = mockService.getRequestHeaders().get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey()).iterator().next();
    Assert.assertTrue(GaxHttpJsonProperties.getDefaultApiClientHeaderPattern().matcher(apiClientHeaderKey).matches());
}
Also used : ListPagedResponse(com.google.cloud.compute.v1.RegionInstanceGroupManagersClient.ListPagedResponse) Test(org.junit.Test)

Example 9 with InstanceGroupManager

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

the class ITSmokeInstancesTest method testResizeGroupToZero.

@Test
public void testResizeGroupToZero() throws IOException, ExecutionException, InterruptedException {
    // We test here: 1)set body field to zero
    // 2)set query param to zero
    List<String> instanceGroupManagersToClean = new ArrayList<>();
    List<String> instanceTemplatesToClean = new ArrayList<>();
    InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create();
    InstanceGroupManagersClient instanceGroupManagersClient = InstanceGroupManagersClient.create();
    String templateName = generateRandomName("template");
    String instanceGroupManagerName = generateRandomName("igm");
    Instance instance = insertInstance();
    InstanceTemplate instanceTemplate = InstanceTemplate.newBuilder().setSourceInstance(instance.getSelfLink()).setName(templateName).build();
    Operation insertOperation = instanceTemplatesClient.insertAsync(DEFAULT_PROJECT, instanceTemplate).get();
    instanceTemplatesToClean.add(templateName);
    try {
        InstanceGroupManager instanceGroupManager = InstanceGroupManager.newBuilder().setName(instanceGroupManagerName).setBaseInstanceName("java-gapic").setInstanceTemplate(insertOperation.getTargetLink()).setTargetSize(0).build();
        instanceGroupManagersClient.insertAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManager).get();
        instanceGroupManagersToClean.add(instanceGroupManagerName);
        InstanceGroupManager fetched = instanceGroupManagersClient.get(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName);
        Assert.assertEquals(0, fetched.getTargetSize());
        instanceGroupManagersClient.resizeAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName, 1).get();
        InstanceGroupManager resizedIGM = instanceGroupManagersClient.get(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName);
        Assert.assertEquals(1, resizedIGM.getTargetSize());
        instanceGroupManagersClient.resizeAsync(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName, 0).get();
        InstanceGroupManager instanceGroupManagerResized = instanceGroupManagersClient.get(DEFAULT_PROJECT, DEFAULT_ZONE, instanceGroupManagerName);
        Assert.assertEquals(0, instanceGroupManagerResized.getTargetSize());
    } finally {
        for (String name : instanceGroupManagersToClean) {
            instanceGroupManagersClient.deleteAsync(DEFAULT_PROJECT, DEFAULT_ZONE, name).get();
        }
        for (String name : instanceTemplatesToClean) {
            instanceTemplatesClient.deleteAsync(DEFAULT_PROJECT, name).get();
        }
    }
}
Also used : InstanceGroupManager(com.google.cloud.compute.v1.InstanceGroupManager) InstanceGroupManagersClient(com.google.cloud.compute.v1.InstanceGroupManagersClient) Instance(com.google.cloud.compute.v1.Instance) ArrayList(java.util.ArrayList) Operation(com.google.cloud.compute.v1.Operation) InstanceTemplatesClient(com.google.cloud.compute.v1.InstanceTemplatesClient) InstanceTemplate(com.google.cloud.compute.v1.InstanceTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 Instance (com.google.cloud.compute.v1.Instance)1 InstanceGroupManager (com.google.cloud.compute.v1.InstanceGroupManager)1 InstanceGroupManagersClient (com.google.cloud.compute.v1.InstanceGroupManagersClient)1 AggregatedListPagedResponse (com.google.cloud.compute.v1.InstanceGroupManagersClient.AggregatedListPagedResponse)1 ListErrorsPagedResponse (com.google.cloud.compute.v1.InstanceGroupManagersClient.ListErrorsPagedResponse)1 ListManagedInstancesPagedResponse (com.google.cloud.compute.v1.InstanceGroupManagersClient.ListManagedInstancesPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.InstanceGroupManagersClient.ListPagedResponse)1 ListPerInstanceConfigsPagedResponse (com.google.cloud.compute.v1.InstanceGroupManagersClient.ListPerInstanceConfigsPagedResponse)1 InstanceTemplate (com.google.cloud.compute.v1.InstanceTemplate)1 InstanceTemplatesClient (com.google.cloud.compute.v1.InstanceTemplatesClient)1 Operation (com.google.cloud.compute.v1.Operation)1 ListErrorsPagedResponse (com.google.cloud.compute.v1.RegionInstanceGroupManagersClient.ListErrorsPagedResponse)1 ListManagedInstancesPagedResponse (com.google.cloud.compute.v1.RegionInstanceGroupManagersClient.ListManagedInstancesPagedResponse)1 ListPagedResponse (com.google.cloud.compute.v1.RegionInstanceGroupManagersClient.ListPagedResponse)1 ListPerInstanceConfigsPagedResponse (com.google.cloud.compute.v1.RegionInstanceGroupManagersClient.ListPerInstanceConfigsPagedResponse)1 ArrayList (java.util.ArrayList)1