Search in sources :

Example 41 with EndpointState

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;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState)

Example 42 with EndpointState

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));
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TypeToken(com.google.gson.reflect.TypeToken) ResourceOperationSpec(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperationSpecService.ResourceOperationSpec) Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) Test(org.junit.Test)

Example 43 with EndpointState

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;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TestProperty(com.vmware.xenon.common.test.TestProperty)

Example 44 with 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;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 45 with EndpointState

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;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) Operation(com.vmware.xenon.common.Operation)

Aggregations

EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)69 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)23 Operation (com.vmware.xenon.common.Operation)22 Test (org.junit.Test)16 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)15 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)14 EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)13 URI (java.net.URI)13 HashMap (java.util.HashMap)13 Query (com.vmware.xenon.services.common.QueryTask.Query)12 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)11 UriUtils (com.vmware.xenon.common.UriUtils)11 Utils (com.vmware.xenon.common.Utils)11 List (java.util.List)11 ImageState (com.vmware.photon.controller.model.resources.ImageService.ImageState)10 ServiceDocument (com.vmware.xenon.common.ServiceDocument)10 Collectors (java.util.stream.Collectors)10 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)9 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9