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)));
}
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;
}
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));
}
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));
}
Aggregations