use of com.vmware.photon.controller.model.resources.RouterService.RouterState 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.RouterService.RouterState in project photon-model by vmware.
the class EndpointRemovalTaskServiceTest method createRouterState.
private static void createRouterState(BaseModelTest test, String endpointLink, List<String> tenantLinks) throws Throwable {
RouterState router = new RouterState();
router.name = "router";
router.tenantLinks = tenantLinks;
router.endpointLink = endpointLink;
router.endpointLinks = new HashSet<String>();
router.endpointLinks.add(endpointLink);
router.type = "type";
test.postServiceSynchronously(RouterService.FACTORY_LINK, router, RouterState.class);
}
use of com.vmware.photon.controller.model.resources.RouterService.RouterState in project photon-model by vmware.
the class RouterServiceTest method buildValidStartState.
public static RouterState buildValidStartState() {
RouterState routerState = new RouterState();
routerState.id = UUID.randomUUID().toString();
routerState.name = "routerName";
routerState.endpointLink = EndpointService.FACTORY_LINK + "/my-endpoint";
routerState.regionId = "region1";
routerState.type = "type1";
routerState.tenantLinks = new ArrayList<>();
routerState.tenantLinks.add("tenant-linkA");
return routerState;
}
Aggregations