use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class NetworkDeviceBackingFactoryTest method testNetworkStateBackingInfo.
@Test
public void testNetworkStateBackingInfo() {
this.network = new NetworkState();
this.network.name = UUID.randomUUID().toString();
this.network.customProperties = new HashMap<>();
VirtualDeviceBackingInfo deviceBackingInfo = NetworkDeviceBackingFactory.getNetworkDeviceBackingInfo(this.network);
assertTrue(deviceBackingInfo instanceof VirtualEthernetCardNetworkBackingInfo);
VirtualEthernetCardNetworkBackingInfo virtualEthernetCardNetworkBackingInfo = (VirtualEthernetCardNetworkBackingInfo) deviceBackingInfo;
assertEquals(this.network.name, virtualEthernetCardNetworkBackingInfo.getDeviceName());
}
use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class ModelUtils method createCompute.
public static ComputeService.ComputeStateWithDescription createCompute(BaseModelTest test, ComputeDescriptionService.ComputeDescription cd) throws Throwable {
ComputeService.ComputeState cs = new ComputeService.ComputeStateWithDescription();
cs.id = UUID.randomUUID().toString();
cs.name = cd.name;
cs.descriptionLink = cd.documentSelfLink;
cs.resourcePoolLink = null;
cs.address = "10.0.0.1";
cs.primaryMAC = "01:23:45:67:89:ab";
cs.powerState = ComputeService.PowerState.ON;
cs.adapterManagementReference = URI.create("https://esxhost-01:443/sdk");
cs.diskLinks = new ArrayList<>();
cs.diskLinks.add(createDiskState(test, cs.name).documentSelfLink);
cs.networkInterfaceLinks = new ArrayList<>();
EndpointState endpointState = createEndpoint(test);
NetworkState networkState = createNetwork(test, endpointState);
SubnetState subnetState = createSubnet(test, networkState, endpointState);
SubnetRangeState subnetRangeState = createSubnetRange(test, subnetState, "12.12.12.2", "12.12.12.120");
NetworkInterfaceState networkInterfaceState1 = createNetworkInterface(test, "nic-1", subnetState, networkState);
IPAddressState ipAddressState1 = createIpAddress(test, "12.12.12.2", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState1.documentSelfLink);
NetworkInterfaceState networkInterfaceState2 = createNetworkInterface(test, "nic-2", subnetState, networkState);
IPAddressState ipAddressState2 = createIpAddress(test, "12.12.12.3", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState2.documentSelfLink);
NetworkInterfaceState networkInterfaceState3 = createNetworkInterface(test, "nic-3", subnetState, networkState);
IPAddressState ipAddressState3 = createIpAddress(test, "12.12.12.4", IPAddressState.IPAddressStatus.ALLOCATED, subnetRangeState, networkInterfaceState3.documentSelfLink);
cs.networkInterfaceLinks.add(networkInterfaceState1.documentSelfLink);
cs.networkInterfaceLinks.add(networkInterfaceState2.documentSelfLink);
cs.networkInterfaceLinks.add(networkInterfaceState3.documentSelfLink);
cs.customProperties = new HashMap<>();
cs.customProperties.put(TEST_DESC_PROPERTY_NAME, TEST_DESC_PROPERTY_VALUE);
cs.tenantLinks = new ArrayList<>();
cs.tenantLinks.add("http://tenant");
ComputeService.ComputeState returnState = test.postServiceSynchronously(ComputeService.FACTORY_LINK, cs, ComputeService.ComputeState.class);
return ComputeService.ComputeStateWithDescription.create(cd, returnState);
}
use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState 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.NetworkService.NetworkState in project photon-model by vmware.
the class ProvisionNetworkTaskServiceTest method buildValidStartState.
private static ProvisionNetworkTaskService.ProvisionNetworkTaskState buildValidStartState(BaseModelTest test, NetworkInstanceRequest.InstanceRequestType requestType, boolean success) throws Throwable {
NetworkState nState = new NetworkState();
nState.authCredentialsLink = "authCredentialsLink";
nState.name = "firewall-name";
nState.regionId = "regionId";
nState.resourcePoolLink = "http://resourcePoolLink";
nState.subnetCIDR = "152.151.150.222/22";
if (success) {
nState.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockNetworkInstanceSuccessAdapter.SELF_LINK);
} else {
nState.instanceAdapterReference = UriUtils.buildUri(test.getHost(), MockAdapter.MockNetworkInstanceFailureAdapter.SELF_LINK);
}
nState.id = UUID.randomUUID().toString();
NetworkState returnState = test.postServiceSynchronously(NetworkService.FACTORY_LINK, nState, NetworkState.class);
ProvisionNetworkTaskService.ProvisionNetworkTaskState startState = new ProvisionNetworkTaskService.ProvisionNetworkTaskState();
startState.requestType = requestType;
startState.networkDescriptionLink = returnState.documentSelfLink;
startState.isMockRequest = true;
return startState;
}
use of com.vmware.photon.controller.model.resources.NetworkService.NetworkState in project photon-model by vmware.
the class AWSLoadBalancerServiceTest method createNetworkState.
private NetworkState createNetworkState(String id) throws Throwable {
NetworkState networkState = new NetworkState();
networkState.name = id;
networkState.id = id;
networkState.endpointLink = this.endpointState.documentSelfLink;
networkState.endpointLinks = new HashSet<String>();
networkState.endpointLinks.add(this.endpointState.documentSelfLink);
networkState.tenantLinks = this.endpointState.tenantLinks;
networkState.instanceAdapterReference = UriUtils.buildUri(this.host, AWSNetworkService.SELF_LINK);
networkState.resourcePoolLink = this.endpointState.resourcePoolLink;
networkState.regionId = this.endpointState.regionId;
return postServiceSynchronously(NetworkService.FACTORY_LINK, networkState, NetworkState.class);
}
Aggregations