use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class ResourceOperationSpecServiceTest method prepare.
private ComputeState prepare(String endpointType, String... ops) throws Throwable {
EndpointState endpoint = registerEndpoint(endpointType);
for (String op : ops) {
registerResourceOperation(endpointType, ResourceType.COMPUTE, op);
}
ComputeState computeState = new ComputeState();
computeState.endpointLink = endpoint.documentSelfLink;
return computeState;
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class ResourceOperationServiceTest method testGetResourceOperations.
@Test
public void testGetResourceOperations() throws Throwable {
EndpointState endpoint = registerEndpoint(this.endpointType);
ResourceOperationSpec spec1 = createResourceOperationSpec(endpoint.endpointType, ResourceType.COMPUTE, "testGetResourceOperations_1");
ResourceOperationSpec spec2 = createResourceOperationSpec(endpoint.endpointType, ResourceType.COMPUTE, "testGetResourceOperations_2");
spec2.targetCriteria = "false";
ResourceOperationSpec spec3 = createResourceOperationSpec(endpoint.endpointType, ResourceType.COMPUTE, "testGetResourceOperations_3");
spec3.targetCriteria = "true";
ResourceOperationSpec spec4 = createResourceOperationSpec(endpoint.endpointType, ResourceType.NETWORK, "testGetResourceOperations_4");
registerResourceOperation(spec1);
registerResourceOperation(spec2);
registerResourceOperation(spec3);
registerResourceOperation(spec4);
ComputeState computeState = new ComputeState();
computeState.descriptionLink = "dummy-descriptionLink";
computeState.endpointLink = endpoint.documentSelfLink;
ComputeState createdComputeState = registerComputeState(computeState);
String query = UriUtils.buildUriQuery(ResourceOperationService.QUERY_PARAM_RESOURCE, createdComputeState.documentSelfLink);
URI uri = UriUtils.buildUri(super.host, ResourceOperationService.SELF_LINK, query);
Operation operation = sendOperationSynchronously(Operation.createGet(uri).setReferer(super.host.getReferer()));
Assert.assertNotNull(operation);
String json = Utils.toJson(operation.getBodyRaw());
List<ResourceOperationSpec> list = Utils.fromJson(json, new TypeToken<List<ResourceOperationSpec>>() {
}.getType());
this.logger.info("list: " + list);
Assert.assertEquals(2, list.size());
Assert.assertNotNull(list.get(0));
Assert.assertNotNull(list.get(1));
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class BaseVSphereAdapterTest method createEndpoint.
protected EndpointState createEndpoint(Consumer<ComputeState> cs, Consumer<ComputeDescription> desc) throws Throwable {
EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
EndpointState endpoint = new EndpointState();
validateEndpoint.endpointState = endpoint;
endpoint.endpointType = PhotonModelConstants.EndpointType.vsphere.name();
endpoint.name = PhotonModelConstants.EndpointType.vsphere.name();
endpoint.regionId = this.datacenterId;
endpoint.endpointProperties = new HashMap<>();
endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.vcUsername != null ? this.vcUsername : "username");
endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.vcPassword != null ? this.vcPassword : "password");
endpoint.endpointProperties.put(HOST_NAME_KEY, this.vcUrl != null ? URI.create(this.vcUrl).toURL().getHost() : "hostname");
validateEndpoint.options = isMock() ? EnumSet.of(TaskOption.IS_MOCK) : null;
configureEndpoint(endpoint);
EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, validateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
EndpointAllocationTaskState taskState = this.host.getServiceState(EnumSet.noneOf(TestProperty.class), EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, outTask.documentSelfLink));
if (cs != null) {
cs.accept(this.host.getServiceState(EnumSet.noneOf(TestProperty.class), ComputeState.class, UriUtils.buildUri(this.host, taskState.endpointState.computeLink)));
}
if (desc != null) {
desc.accept(this.host.getServiceState(EnumSet.noneOf(TestProperty.class), ComputeDescription.class, UriUtils.buildUri(this.host, taskState.endpointState.computeDescriptionLink)));
}
this.resourcePool = this.host.getServiceState(EnumSet.noneOf(TestProperty.class), ResourcePoolState.class, UriUtils.buildUri(this.host, taskState.endpointState.resourcePoolLink));
this.auth = this.host.getServiceState(EnumSet.noneOf(TestProperty.class), AuthCredentialsServiceState.class, UriUtils.buildUri(this.host, taskState.endpointState.authCredentialsLink));
return taskState.endpointState;
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class BaseVSphereAdapterTest method createEndpointState.
/**
* This will help tango proxy adapter tests
* The endpoint can be enhanced to support tango
* adapters' required properties.
*/
protected EndpointState createEndpointState(ComputeState computeHost, ComputeDescription computeHostDescription) {
EndpointState ep = new EndpointState();
ep.id = nextName("endpoint");
ep.endpointType = EndpointType.vsphere.name();
ep.name = ep.id;
ep.authCredentialsLink = this.auth.documentSelfLink;
ep.computeLink = computeHost.documentSelfLink;
ep.computeDescriptionLink = computeHostDescription.documentSelfLink;
ep.resourcePoolLink = this.resourcePool.documentSelfLink;
return ep;
}
use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.
the class ResourceGroomerTaskServiceTest method createDeleteEndpoints.
/**
* Create and delete endpoint documents.
*/
private boolean createDeleteEndpoints() {
EndpointState state = new EndpointState();
state.endpointType = "Amazon Web Services";
state.id = UUID.randomUUID().toString();
state.name = state.id;
for (String endpointLink : ENDPOINTS_TO_BE_CREATED) {
state.documentSelfLink = endpointLink;
if (endpointLink.contains("tenant-1")) {
state.tenantLinks = Collections.singletonList(TENANT_LINK_1);
} else {
state.tenantLinks = Collections.singletonList(TENANT_LINK_2);
}
Operation postEp = Operation.createPost(this.host, EndpointService.FACTORY_LINK).setBody(state).setReferer(this.host.getUri());
Operation postResponse = this.host.waitForResponse(postEp);
if (postResponse.getStatusCode() != 200) {
return false;
}
}
for (String endpointLink : ENDPOINTS_TO_BE_DELETED) {
Operation deleteEp = Operation.createDelete(this.host, endpointLink).addPragmaDirective(Operation.PRAGMA_DIRECTIVE_FROM_MIGRATION_TASK).setReferer(this.host.getUri());
Operation deleteResponse = this.host.waitForResponse(deleteEp);
if (deleteResponse.getStatusCode() != 200) {
return false;
}
}
return true;
}
Aggregations