use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class AWSLoadBalancerService method updateLoadBalancerState.
private DeferredResult<AWSLoadBalancerContext> updateLoadBalancerState(AWSLoadBalancerContext context) {
LoadBalancerState loadBalancerState = new LoadBalancerState();
loadBalancerState.address = context.loadBalancerStateExpanded.address;
loadBalancerState.name = context.loadBalancerStateExpanded.name;
if (context.provisionedSecurityGroupState != null) {
loadBalancerState.securityGroupLinks = Collections.singletonList(context.provisionedSecurityGroupState.documentSelfLink);
}
Operation op = Operation.createPatch(this, context.loadBalancerStateExpanded.documentSelfLink);
op.setBody(loadBalancerState);
return this.sendWithDeferredResult(op).thenApply(ignore -> context);
}
use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class ResourceGroomerTaskService method populateEndpointLinksByDocumentLinks.
/**
* Helper for creating corresponding object and parsing the response for given documentKind
* to store selfLink and endpointLink.
*/
private static void populateEndpointLinksByDocumentLinks(Map<String, Object> documents, Map<String, Set<String>> endpointLinksByDocumentLinks, Map<String, String> endpointLinkByDocumentLinks) {
for (Object document : documents.values()) {
ServiceDocument doc = Utils.fromJson(document, ServiceDocument.class);
Set<String> endpointLinks = new HashSet<>();
if (doc.documentKind.equals(COMPUTE_STATE_DOCUMENT_KIND)) {
ComputeState state = Utils.fromJson(document, ComputeState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(DISK_STATE_DOCUMENT_KIND)) {
DiskState state = Utils.fromJson(document, DiskState.class);
if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
// skip resources that have never been attached to a particular endpoint
continue;
}
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(COMPUTE_DESCRIPTION_DOCUMENT_KIND)) {
ComputeDescription state = Utils.fromJson(document, ComputeDescription.class);
// only deleting discovered resources
if (!(state.customProperties != null && (ResourceEnumerationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK)) || EndpointAllocationTaskService.FACTORY_LINK.equals(state.customProperties.get(SOURCE_TASK_LINK))))) {
continue;
}
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(NETWORK_STATE_DOCUMENT_KIND)) {
NetworkState state = Utils.fromJson(document, NetworkState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(NETWORK_INTERFACE_STATE_DOCUMENT_KIND)) {
NetworkInterfaceState state = Utils.fromJson(document, NetworkInterfaceState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(SECURITY_GROUP_STATE_DOCUMENT_KIND)) {
SecurityGroupState state = Utils.fromJson(document, SecurityGroupState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(SUBNET_STATE_DOCUMENT_KIND)) {
SubnetState state = Utils.fromJson(document, SubnetState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(LOAD_BALANCER_DOCUMENT_KIND)) {
LoadBalancerState state = Utils.fromJson(document, LoadBalancerState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(STORAGE_DESCRIPTION_DOCUMENT_KIND)) {
StorageDescription state = Utils.fromJson(document, StorageDescription.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(RESOURCE_GROUP_DOCUMENT_KIND)) {
ResourceGroupState state = Utils.fromJson(document, ResourceGroupState.class);
if (state.customProperties != null && state.customProperties.containsKey(ResourceGroupService.PROPERTY_NAME_IS_USER_CREATED)) {
continue;
}
if (state.customProperties != null && state.customProperties.containsKey(ResourceUtils.CUSTOM_PROP_NO_ENDPOINT)) {
// skip resources that have never been attached to a particular endpoint
continue;
}
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(IMAGE_STATE_KIND)) {
ImageState state = Utils.fromJson(document, ImageState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(ROUTER_STATE_KIND)) {
RouterState state = Utils.fromJson(document, RouterState.class);
if (state.endpointLinks != null) {
state.endpointLinks.remove(null);
endpointLinks.addAll(state.endpointLinks);
}
endpointLinksByDocumentLinks.put(state.documentSelfLink, endpointLinks);
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.endpointLink != null ? state.endpointLink : EMPTY_STRING);
} else if (doc.documentKind.equals(AUTH_CREDENTIALS_SERVICE_STATE_KIND)) {
AuthCredentialsServiceState state = Utils.fromJson(document, AuthCredentialsServiceState.class);
if (state.customProperties != null && state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK) != null) {
endpointLinkByDocumentLinks.put(state.documentSelfLink, state.customProperties.get(CUSTOM_PROP_ENDPOINT_LINK));
} else {
endpointLinkByDocumentLinks.put(state.documentSelfLink, EMPTY_STRING);
}
}
}
}
use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class ProvisionLoadBalancerTaskServiceTest method buildValidStartState.
private static ProvisionLoadBalancerTaskService.ProvisionLoadBalancerTaskState buildValidStartState(BaseModelTest test, LoadBalancerInstanceRequest.InstanceRequestType requestType, boolean success) throws Throwable {
LoadBalancerState state = LoadBalancerServiceTest.buildValidStartState();
if (success) {
state.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockLoadBalancerInstanceSuccessAdapter.SELF_LINK);
} else {
state.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockLoadBalancerInstanceFailureAdapter.SELF_LINK);
}
LoadBalancerState returnState = test.postServiceSynchronously(LoadBalancerService.FACTORY_LINK, state, LoadBalancerState.class);
ProvisionLoadBalancerTaskService.ProvisionLoadBalancerTaskState startState = new ProvisionLoadBalancerTaskService.ProvisionLoadBalancerTaskState();
startState.requestType = requestType;
startState.loadBalancerLink = returnState.documentSelfLink;
startState.isMockRequest = true;
return startState;
}
use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class AWSLoadBalancerServiceTest method testCreateUpdateDeleteLoadBalancer.
@Test
public void testCreateUpdateDeleteLoadBalancer() throws Throwable {
// set name with invalid characters and more than 32 characters
this.lbName = generateLbName() + "-1234567890-1234567890-1234567890_;.,/";
LoadBalancerState lb = createLoadBalancerState(this.lbName);
// Provision load balancer
kickOffLoadBalancerProvision(InstanceRequestType.CREATE, lb.documentSelfLink, TaskStage.FINISHED);
lb = getServiceSynchronously(lb.documentSelfLink, LoadBalancerState.class);
this.lbName = lb.name;
if (!this.isMock) {
assertNotNull(lb.securityGroupLinks);
String securityGroupDocumentSelfLink = lb.securityGroupLinks.iterator().next();
assertNotNull(securityGroupDocumentSelfLink);
SecurityGroupState sgs = getServiceSynchronously(securityGroupDocumentSelfLink, SecurityGroupState.class);
this.sgId = sgs.id;
LoadBalancerDescription awsLoadBalancer = getAwsLoadBalancer(this.lbName);
assertNotNull(awsLoadBalancer);
assertEquals(awsLoadBalancer.getDNSName(), lb.address);
assertEquals("internet-facing", awsLoadBalancer.getScheme());
assertEquals(1, awsLoadBalancer.getInstances().size());
List<ListenerDescription> listeners = awsLoadBalancer.getListenerDescriptions();
assertEquals(2, listeners.size());
verifyListeners(lb.routes, listeners);
verifyHealthCheckConfiguration(lb.routes.get(0), awsLoadBalancer.getHealthCheck());
SecurityGroup securityGroup = getAwsSecurityGroup(sgs.id);
assertNotNull(securityGroup);
String lbSecGroupId = awsLoadBalancer.getSecurityGroups().stream().findFirst().orElse(null);
assertEquals(securityGroup.getGroupId(), lbSecGroupId);
}
// Update load balancer from 1 machines to 2 to simulate scale-out
if (!this.isMock) {
lb.computeLinks = new HashSet<>(Arrays.asList(this.cs1.documentSelfLink, this.cs2.documentSelfLink));
putServiceSynchronously(lb.documentSelfLink, lb);
}
kickOffLoadBalancerProvision(InstanceRequestType.UPDATE, lb.documentSelfLink, TaskStage.FINISHED);
if (!this.isMock) {
LoadBalancerDescription awsLoadBalancer = getAwsLoadBalancer(this.lbName);
assertNotNull(awsLoadBalancer);
assertEquals(2, awsLoadBalancer.getInstances().size());
// Update load balancer from 2 machines to 1 to simulate scale-in
lb.computeLinks = Collections.singleton(this.cs1.documentSelfLink);
putServiceSynchronously(lb.documentSelfLink, lb);
kickOffLoadBalancerProvision(InstanceRequestType.UPDATE, lb.documentSelfLink, TaskStage.FINISHED);
awsLoadBalancer = getAwsLoadBalancer(this.lbName);
assertNotNull(awsLoadBalancer);
assertEquals(1, awsLoadBalancer.getInstances().size());
}
kickOffLoadBalancerProvision(InstanceRequestType.DELETE, lb.documentSelfLink, TaskStage.FINISHED);
if (!this.isMock) {
assertNull(getAwsLoadBalancer(this.lbName));
assertNull(getAwsSecurityGroup(this.sgId));
}
this.lbName = null;
this.sgId = null;
}
use of com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState in project photon-model by vmware.
the class AzureLoadBalancerServiceTest method testCreateLoadBalancerWithMixedTarget.
@Test
public void testCreateLoadBalancerWithMixedTarget() throws Throwable {
LoadBalancerState loadBalancerState = provisionLoadBalancer(TaskStage.FINISHED, LoadBalancerTargetType.BOTH);
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);
}
}
Aggregations