use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class AzureLoadBalancerServiceTest method testCreateLoadBalancerWithNICTarget.
@Test
public void testCreateLoadBalancerWithNICTarget() throws Throwable {
LoadBalancerState loadBalancerState = provisionLoadBalancer(TaskStage.FINISHED, LoadBalancerTargetType.NIC);
assertNotNull(loadBalancerState.id);
assertNotEquals(loadBalancerState.id, this.loadBalancerName);
if (!this.isMock) {
// Verify that the load balancer was created.
LoadBalancerInner lbResponse = this.loadBalancerClient.getByResourceGroup(this.rgName, this.loadBalancerName);
assertEquals(this.loadBalancerName, lbResponse.name());
assertEquals(loadBalancerState.id, lbResponse.id());
// delete the load balancer
startLoadBalancerProvisioning(LoadBalancerInstanceRequest.InstanceRequestType.DELETE, loadBalancerState, TaskStage.FINISHED);
}
}
use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class AzureLoadBalancerServiceTest method testDeleteLoadBalancer.
@Test
public void testDeleteLoadBalancer() throws Throwable {
LoadBalancerState loadBalancerState = provisionLoadBalancer(TaskStage.FINISHED, null);
startLoadBalancerProvisioning(LoadBalancerInstanceRequest.InstanceRequestType.DELETE, loadBalancerState, TaskStage.FINISHED);
// verify load balancer state was deleted
try {
getLoadBalancerState(this.host, loadBalancerState.documentSelfLink);
} catch (Throwable e) {
assertTrue(e instanceof ServiceHost.ServiceNotFoundException);
}
if (!this.isMock) {
// Verify that the load balancer was deleted from Azure.
LoadBalancerInner sgResponse = this.loadBalancerClient.getByResourceGroup(this.rgName, this.loadBalancerName);
if (sgResponse != null) {
fail("Load Balancer should not exist in Azure.");
}
}
}
use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class AzureLoadBalancerServiceTest method createLoadBalancerState.
private LoadBalancerState createLoadBalancerState(String name, LoadBalancerTargetType loadBalancerTargetType) throws Throwable {
LoadBalancerState loadBalancerState = new LoadBalancerState();
loadBalancerState.id = name;
loadBalancerState.name = name;
loadBalancerState.instanceAdapterReference = UriUtils.buildUri(this.host, AzureLoadBalancerService.SELF_LINK);
loadBalancerState.endpointLink = endpointState.documentSelfLink;
loadBalancerState.tenantLinks = endpointState.tenantLinks;
loadBalancerState.regionId = this.regionId;
loadBalancerState.internetFacing = true;
loadBalancerState.subnetLinks = Stream.of(subnetState.documentSelfLink).collect(Collectors.toSet());
RouteConfiguration route = createRouteConfiguration();
loadBalancerState.routes = Stream.of(route).collect(Collectors.toList());
loadBalancerState.computeLinks = vmStates.stream().map(cs -> cs.documentSelfLink).collect(Collectors.toSet());
if (loadBalancerTargetType != null) {
switch(loadBalancerTargetType) {
case COMPUTE:
loadBalancerState.targetLinks = vmStates.stream().map(cs -> cs.documentSelfLink).collect(Collectors.toSet());
break;
case NIC:
loadBalancerState.targetLinks = vmStates.stream().map(cs -> cs.networkInterfaceLinks.stream().findFirst().get()).collect(Collectors.toSet());
break;
case BOTH:
// use boolean to toggle between compute link and NIC link
AtomicBoolean typeToggle = new AtomicBoolean(true);
loadBalancerState.targetLinks = vmStates.stream().map(cs -> {
typeToggle.set(!typeToggle.get());
if (typeToggle.get()) {
return cs.documentSelfLink;
} else {
return cs.networkInterfaceLinks.stream().findFirst().get();
}
}).collect(Collectors.toSet());
break;
case INVALID:
loadBalancerState.targetLinks = new HashSet<>();
loadBalancerState.targetLinks.add("123");
break;
default:
break;
}
}
if (securityGroupState != null) {
loadBalancerState.securityGroupLinks = Stream.of(securityGroupState.documentSelfLink).collect(Collectors.toList());
}
loadBalancerState.address = "1.1.1.1";
return postServiceSynchronously(LoadBalancerService.FACTORY_LINK, loadBalancerState, LoadBalancerState.class);
}
use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class LoadBalancerServiceTest method buildValidStartState.
public static LoadBalancerState buildValidStartState() {
LoadBalancerState loadBalancerState = new LoadBalancerState();
loadBalancerState.descriptionLink = LoadBalancerDescriptionService.FACTORY_LINK + "/lb-desc";
loadBalancerState.id = UUID.randomUUID().toString();
loadBalancerState.name = "lbName";
loadBalancerState.endpointLink = EndpointService.FACTORY_LINK + "/my-endpoint";
loadBalancerState.computeLinks = new HashSet<>();
loadBalancerState.computeLinks.add(ComputeService.FACTORY_LINK + "/a-compute");
loadBalancerState.targetLinks = new HashSet<>();
loadBalancerState.targetLinks.add(ComputeService.FACTORY_LINK + "/a-compute");
loadBalancerState.targetLinks.add(NetworkInterfaceService.FACTORY_LINK + "/a-nic");
loadBalancerState.subnetLinks = new HashSet<>();
loadBalancerState.subnetLinks.add(SubnetService.FACTORY_LINK + "/a-subnet");
loadBalancerState.securityGroupLinks = new ArrayList<>();
loadBalancerState.securityGroupLinks.add(SecurityGroupService.FACTORY_LINK + "/a-sg");
loadBalancerState.regionId = "regionId";
loadBalancerState.tenantLinks = new ArrayList<>();
loadBalancerState.tenantLinks.add("tenant-linkA");
RouteConfiguration route1 = new RouteConfiguration();
route1.protocol = Protocol.HTTP.name();
route1.port = "80";
route1.instanceProtocol = Protocol.HTTP.name();
route1.instancePort = "80";
route1.healthCheckConfiguration = new HealthCheckConfiguration();
route1.healthCheckConfiguration.protocol = Protocol.HTTP.name();
route1.healthCheckConfiguration.port = "80";
RouteConfiguration route2 = new RouteConfiguration();
route2.protocol = Protocol.HTTPS.name();
route2.port = "443";
route2.instanceProtocol = Protocol.HTTP.name();
route2.instancePort = "443";
loadBalancerState.routes = Arrays.asList(route1, route2);
return loadBalancerState;
}
Aggregations