Search in sources :

Example 1 with RegionBackendServices

use of com.google.api.services.compute.Compute.RegionBackendServices in project cloudbreak by hortonworks.

the class GcpBackendServiceResourceBuilderTest method testBuildWithSeperateHCPort.

@Test
public void testBuildWithSeperateHCPort() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("hcport", 8080);
    parameters.put("trafficport", 80);
    CloudResource hcResource = new CloudResource.Builder().type(ResourceType.GCP_HEALTH_CHECK).status(CommonStatus.CREATED).group("master").name("hcsuper").params(parameters).persistent(true).build();
    CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_BACKEND_SERVICE).status(CommonStatus.CREATED).group("master").name("super").params(parameters).persistent(true).build();
    when(group.getName()).thenReturn("master");
    Compute.RegionBackendServices.Insert insert = mock(Compute.RegionBackendServices.Insert.class);
    Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
    targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(80, 8080), Set.of(group));
    when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
    when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
    when(gcpContext.getCompute()).thenReturn(compute);
    when(gcpContext.getProjectId()).thenReturn("id");
    when(gcpContext.getLoadBalancerResources(any())).thenReturn(List.of(hcResource));
    when(gcpContext.getLocation()).thenReturn(location);
    when(location.getAvailabilityZone()).thenReturn(availabilityZone);
    when(availabilityZone.value()).thenReturn("us-west2");
    when(location.getRegion()).thenReturn(region);
    when(region.getRegionName()).thenReturn("us-west2");
    when(compute.regionBackendServices()).thenReturn(regionBackendServices);
    when(regionBackendServices.insert(anyString(), anyString(), any())).thenReturn(insert);
    when(insert.execute()).thenReturn(operation);
    when(operation.getName()).thenReturn("name");
    when(operation.getHttpErrorStatusCode()).thenReturn(null);
    when(gcpLoadBalancerTypeConverter.getScheme(any(CloudLoadBalancer.class))).thenCallRealMethod();
    List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
    Assert.assertEquals("super", cloudResources.get(0).getName());
    Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
    Assertions.assertEquals(80, cloudResources.get(0).getParameter("trafficport", Integer.class));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) RegionBackendServices(com.google.api.services.compute.Compute.RegionBackendServices) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test)

Example 2 with RegionBackendServices

use of com.google.api.services.compute.Compute.RegionBackendServices in project cloudbreak by hortonworks.

the class GcpBackendServiceResourceBuilderTest method testBuildWithMultipleTrafficPorts.

@Test
public void testBuildWithMultipleTrafficPorts() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("hcport", 8443);
    parameters.put("trafficports", List.of(443, 11443));
    CloudResource hcResource = new CloudResource.Builder().type(ResourceType.GCP_HEALTH_CHECK).status(CommonStatus.CREATED).group("master").name("hcsuper").params(parameters).persistent(true).build();
    CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_BACKEND_SERVICE).status(CommonStatus.CREATED).group("master").name("super").params(parameters).persistent(true).build();
    when(group.getName()).thenReturn("master");
    Compute.RegionBackendServices.Insert insert = mock(Compute.RegionBackendServices.Insert.class);
    Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
    targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(443, 8443), Set.of(group));
    targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(11443, 8443), Set.of(group));
    when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
    when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
    when(gcpContext.getCompute()).thenReturn(compute);
    when(gcpContext.getProjectId()).thenReturn("id");
    when(gcpContext.getLoadBalancerResources(any())).thenReturn(List.of(hcResource));
    when(gcpContext.getLocation()).thenReturn(location);
    when(location.getAvailabilityZone()).thenReturn(availabilityZone);
    when(availabilityZone.value()).thenReturn("us-west2");
    when(location.getRegion()).thenReturn(region);
    when(region.getRegionName()).thenReturn("us-west2");
    when(compute.regionBackendServices()).thenReturn(regionBackendServices);
    when(regionBackendServices.insert(anyString(), anyString(), any())).thenReturn(insert);
    when(insert.execute()).thenReturn(operation);
    when(operation.getName()).thenReturn("name");
    when(operation.getHttpErrorStatusCode()).thenReturn(null);
    when(gcpLoadBalancerTypeConverter.getScheme(any(CloudLoadBalancer.class))).thenCallRealMethod();
    List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
    Assert.assertEquals("super", cloudResources.get(0).getName());
    Assertions.assertEquals(8443, cloudResources.get(0).getParameter("hcport", Integer.class));
    List<Integer> ports = (List<Integer>) cloudResources.get(0).getParameters().get("trafficports");
    Assertions.assertTrue(ports.contains(443));
    Assertions.assertTrue(ports.contains(11443));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) RegionBackendServices(com.google.api.services.compute.Compute.RegionBackendServices) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test)

Example 3 with RegionBackendServices

use of com.google.api.services.compute.Compute.RegionBackendServices in project cloudbreak by hortonworks.

the class GcpBackendServiceResourceBuilderTest method testDelete.

@Test
public void testDelete() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("hcport", 8080);
    parameters.put("trafficport", 80);
    CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_BACKEND_SERVICE).status(CommonStatus.CREATED).group("master").name("super").params(parameters).persistent(true).build();
    Compute.RegionBackendServices.Delete delete = mock(Compute.RegionBackendServices.Delete.class);
    when(gcpContext.getCompute()).thenReturn(compute);
    when(gcpContext.getProjectId()).thenReturn("id");
    when(gcpContext.getLocation()).thenReturn(location);
    when(location.getRegion()).thenReturn(region);
    when(region.getRegionName()).thenReturn("us-west2");
    when(compute.regionBackendServices()).thenReturn(regionBackendServices);
    when(regionBackendServices.delete(anyString(), anyString(), any())).thenReturn(delete);
    when(delete.execute()).thenReturn(operation);
    when(operation.getName()).thenReturn("name");
    CloudResource cloudResource = underTest.delete(gcpContext, authenticatedContext, resource);
    Assert.assertEquals("super", cloudResource.getName());
    Assertions.assertEquals(8080, cloudResource.getParameter("hcport", Integer.class));
    Assertions.assertEquals(80, cloudResource.getParameter("trafficport", Integer.class));
    Assert.assertEquals(ResourceType.GCP_BACKEND_SERVICE, cloudResource.getType());
    Assert.assertEquals(CommonStatus.CREATED, cloudResource.getStatus());
}
Also used : RegionBackendServices(com.google.api.services.compute.Compute.RegionBackendServices) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Aggregations

RegionBackendServices (com.google.api.services.compute.Compute.RegionBackendServices)3 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)3 HashMap (java.util.HashMap)3 Test (org.junit.jupiter.api.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)2 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)2 Set (java.util.Set)2 List (java.util.List)1