Search in sources :

Example 11 with ForwardingRule

use of com.google.api.services.compute.model.ForwardingRule in project cloudbreak by hortonworks.

the class GCPLoadBalancerMetadataCollectorTest method testCollectPublicAndPrivateLoadBalancer.

@Test
public void testCollectPublicAndPrivateLoadBalancer() {
    List<CloudResource> resources = new ArrayList<>();
    resources.add(createCloudResource(FORWARDING_RULE_NAME_1, ResourceType.GCP_FORWARDING_RULE));
    resources.add(createCloudResource(FORWARDING_RULE_NAME_2, ResourceType.GCP_FORWARDING_RULE));
    ForwardingRule publicFowardingRule = createPublicFowardingRule();
    ForwardingRule publicFowardingRule2 = createPrivateFowardingRule();
    when(forwardingRuleListResponse.getItems()).thenReturn(List.of(publicFowardingRule, publicFowardingRule2));
    List<CloudLoadBalancerMetadata> result = underTest.collectLoadBalancer(authenticatedContext, List.of(LoadBalancerType.PUBLIC, LoadBalancerType.PRIVATE), resources);
    assertEquals(2, result.size());
    Optional<CloudLoadBalancerMetadata> publicResult = result.stream().filter(p -> p.getType().equals(LoadBalancerType.PUBLIC)).findFirst();
    assertTrue(publicResult.isPresent());
    assertEquals(FORWARDING_RULE_NAME_1, publicResult.get().getName());
    assertEquals(FORWARDING_RULE_NAME_1, publicResult.get().getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
    assertEquals(PUBLIC_IP, publicResult.get().getIp());
    assertEquals(BACKEND_SERVICE_NAME, publicResult.get().getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(8080)));
    assertEquals(INSTANCE_GROUP_NAME, publicResult.get().getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(8080)));
    Optional<CloudLoadBalancerMetadata> privateResult = result.stream().filter(p -> p.getType().equals(LoadBalancerType.PRIVATE)).findFirst();
    assertTrue(privateResult.isPresent());
    assertEquals(FORWARDING_RULE_NAME_2, privateResult.get().getName());
    assertEquals(FORWARDING_RULE_NAME_2, privateResult.get().getStringParameter(GcpLoadBalancerMetadataView.LOADBALANCER_NAME));
    assertEquals(PRIVATE_IP, privateResult.get().getIp());
    assertEquals(BACKEND_SERVICE_NAME, privateResult.get().getStringParameter(GcpLoadBalancerMetadataView.getBackendServiceParam(443)));
    assertEquals(INSTANCE_GROUP_NAME, privateResult.get().getStringParameter(GcpLoadBalancerMetadataView.getInstanceGroupParam(443)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) GcpLoadBalancerTypeConverter(com.sequenceiq.cloudbreak.cloud.gcp.loadbalancer.GcpLoadBalancerTypeConverter) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Backend(com.google.api.services.compute.model.Backend) ForwardingRuleList(com.google.api.services.compute.model.ForwardingRuleList) BackendService(com.google.api.services.compute.model.BackendService) Mockito.lenient(org.mockito.Mockito.lenient) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) GcpLoadBalancerMetadataView(com.sequenceiq.cloudbreak.cloud.gcp.view.GcpLoadBalancerMetadataView) GcpComputeFactory(com.sequenceiq.cloudbreak.cloud.gcp.client.GcpComputeFactory) Location(com.sequenceiq.cloudbreak.cloud.model.Location) GcpStackUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil) CommonStatus(com.sequenceiq.common.api.type.CommonStatus) InjectMocks(org.mockito.InjectMocks) ResourceType(com.sequenceiq.common.api.type.ResourceType) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ForwardingRule(com.google.api.services.compute.model.ForwardingRule) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Test(org.junit.jupiter.api.Test) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) Optional(java.util.Optional) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Collections(java.util.Collections) Compute(com.google.api.services.compute.Compute) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ForwardingRule(com.google.api.services.compute.model.ForwardingRule) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.jupiter.api.Test)

Example 12 with ForwardingRule

use of com.google.api.services.compute.model.ForwardingRule in project cloudbreak by hortonworks.

the class GCPLoadBalancerMetadataCollectorTest method createPublicFowardingRule.

private ForwardingRule createPublicFowardingRule() {
    ForwardingRule forwardingRule = new ForwardingRule();
    forwardingRule.setLoadBalancingScheme("EXTERNAL");
    forwardingRule.setName(FORWARDING_RULE_NAME_1);
    forwardingRule.setIPAddress(PUBLIC_IP);
    forwardingRule.setPorts(List.of(PORT1));
    forwardingRule.setBackendService(BACKEND_SERVICE_NAME);
    return forwardingRule;
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule)

Example 13 with ForwardingRule

use of com.google.api.services.compute.model.ForwardingRule in project cloudbreak by hortonworks.

the class GcpForwardingRuleResourceBuilderTest method testBuild.

@Test
public void testBuild() throws Exception {
    mockCalls(LoadBalancerType.PRIVATE);
    List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
    ForwardingRule arg = forwardingRuleArg.getValue();
    Assert.assertEquals("https://www.googleapis.com/compute/v1/projects/id/global/networks/default-network", arg.getNetwork());
    Assert.assertEquals("https://www.googleapis.com/compute/v1/projects/id/regions/us-west2/subnetworks/default-subnet", arg.getSubnetwork());
    Assert.assertEquals("super", cloudResources.get(0).getName());
    Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Example 14 with ForwardingRule

use of com.google.api.services.compute.model.ForwardingRule in project cloudbreak by hortonworks.

the class GcpForwardingRuleResourceBuilderTest method buildForPublic.

@Test
public void buildForPublic() throws Exception {
    mockCalls(LoadBalancerType.PUBLIC);
    List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
    ForwardingRule arg = forwardingRuleArg.getValue();
    Assert.assertEquals(null, arg.getNetwork());
    Assert.assertEquals(null, arg.getSubnetwork());
    Assert.assertEquals("super", cloudResources.get(0).getName());
    Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
}
Also used : ForwardingRule(com.google.api.services.compute.model.ForwardingRule) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.jupiter.api.Test)

Aggregations

ForwardingRule (com.google.api.services.compute.model.ForwardingRule)14 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)11 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)9 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)8 Compute (com.google.api.services.compute.Compute)2 ForwardingRuleList (com.google.api.services.compute.model.ForwardingRuleList)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)2 IOException (java.io.IOException)2 List (java.util.List)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Backend (com.google.api.services.compute.model.Backend)1 BackendService (com.google.api.services.compute.model.BackendService)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 GcpComputeFactory (com.sequenceiq.cloudbreak.cloud.gcp.client.GcpComputeFactory)1 GcpLoadBalancerTypeConverter (com.sequenceiq.cloudbreak.cloud.gcp.loadbalancer.GcpLoadBalancerTypeConverter)1 GcpStackUtil (com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil)1 GcpLoadBalancerMetadataView (com.sequenceiq.cloudbreak.cloud.gcp.view.GcpLoadBalancerMetadataView)1