Search in sources :

Example 36 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AWSInstanceTypeServiceTest method createEndpointState.

private EndpointState createEndpointState() throws Throwable {
    EndpointType endpointType = EndpointType.aws;
    EndpointState endpoint;
    {
        endpoint = new EndpointState();
        endpoint.endpointType = endpointType.name();
        endpoint.id = endpointType.name() + "-id";
        endpoint.name = endpointType.name() + "-name";
        endpoint.endpointProperties = new HashMap<>();
        endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.secretKey);
        endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.accessKey);
        endpoint.endpointProperties.put(REGION_KEY, Regions.US_EAST_1.getName());
    }
    EndpointAllocationTaskState allocateEndpoint = new EndpointAllocationTaskState();
    allocateEndpoint.endpointState = endpoint;
    allocateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    allocateEndpoint.taskInfo = new TaskState();
    allocateEndpoint.taskInfo.isDirect = true;
    allocateEndpoint.tenantLinks = Collections.singletonList(endpointType.name() + "-tenant");
    allocateEndpoint = com.vmware.photon.controller.model.tasks.TestUtils.doPost(this.host, allocateEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
    return allocateEndpoint.endpointState;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) HashMap(java.util.HashMap) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) TaskState(com.vmware.xenon.common.TaskState)

Example 37 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AWSPowerServiceTest method test.

@Test
public void test() throws Throwable {
    EndpointState endpoint = configureEndpoint();
    assertNotNull(endpoint.resourcePoolLink);
    ComputeState computeHost = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, endpoint.computeLink));
    assertNotNull(computeHost);
    ComputeDescription computeHostDesc = this.host.getServiceState(null, ComputeDescription.class, UriUtils.buildUri(this.host, endpoint.computeDescriptionLink));
    assertNotNull(computeHostDesc);
    assertNotNull("Power addpter must be configured", computeHostDesc.powerAdapterReference);
    boolean addNonExistingSecurityGroup = false;
    ComputeState cs = TestAWSSetupUtils.createAWSVMResource(this.host, computeHost, endpoint, getClass(), "trainingVM", zoneId, this.regionId, null, this.singleNicSpec, addNonExistingSecurityGroup, this.awsTestContext);
    this.computesToRemove.add(cs.documentSelfLink);
    assertEquals(PowerState.UNKNOWN, cs.powerState);
    ProvisionComputeTaskState state = new ProvisionComputeTaskState();
    state.computeLink = cs.documentSelfLink;
    state.isMockRequest = this.isMock;
    state.taskSubStage = ProvisionComputeTaskState.SubStage.CREATING_HOST;
    state = TestUtils.doPost(this.host, state, ProvisionComputeTaskState.class, UriUtils.buildUri(this.host, ProvisionComputeTaskService.FACTORY_LINK));
    this.host.waitForFinishedTask(ProvisionComputeTaskState.class, state.documentSelfLink);
    ComputeState compute = this.host.getServiceState(null, ComputeState.class, UriUtils.buildUri(this.host, cs.documentSelfLink));
    changePowerState(computeHostDesc, compute.documentSelfLink, PowerState.OFF);
    if (!this.isMock) {
        waitForInstancesToBeStopped(this.client, this.host, Arrays.asList(compute.id));
    }
    changePowerState(computeHostDesc, compute.documentSelfLink, PowerState.ON);
    if (!this.isMock) {
        final int errorRate = 0;
        waitForProvisioningToComplete(Arrays.asList(compute.id), this.host, this.client, errorRate);
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Test(org.junit.Test)

Example 38 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class AWSSubnetTaskServiceTest method createEndpointState.

private EndpointState createEndpointState() throws Throwable {
    EndpointState endpoint = new EndpointState();
    String endpointType = EndpointType.aws.name();
    endpoint.id = endpointType + "Id";
    endpoint.name = endpointType + "Name";
    endpoint.endpointType = endpointType;
    endpoint.tenantLinks = singletonList(endpointType + "Tenant");
    endpoint.authCredentialsLink = createAuthCredentialsState().documentSelfLink;
    return postServiceSynchronously(EndpointService.FACTORY_LINK, endpoint, EndpointState.class);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 39 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestAWSEndpointService method newEndpointState.

private EndpointState newEndpointState() {
    EndpointState endpoint = new EndpointState();
    endpoint.endpointType = EndpointType.aws.name();
    endpoint.name = EndpointType.aws.name();
    endpoint.regionId = this.regionId;
    endpoint.endpointProperties = new HashMap<>();
    endpoint.endpointProperties.put(PRIVATE_KEY_KEY, this.secretKey);
    endpoint.endpointProperties.put(PRIVATE_KEYID_KEY, this.accessKey);
    return endpoint;
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 40 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState in project photon-model by vmware.

the class TestAWSEndpointService method testCreateAndThenValidate.

@Test
public void testCreateAndThenValidate() throws Throwable {
    this.endpointTestsRunner.testCreateAndThenValidate(this.endpointState);
    // Tests that EndpointService QueryTasks can use SELECT_LINKS + EXPAND_LINKS
    Query query = Builder.create().addKindFieldClause(EndpointState.class).build();
    QueryTask queryTask = QueryTask.Builder.createDirectTask().addOptions(EnumSet.of(QueryOption.EXPAND_CONTENT, QueryOption.SELECT_LINKS, QueryOption.EXPAND_LINKS)).addLinkTerm(EndpointState.FIELD_NAME_AUTH_CREDENTIALS_LINK).setQuery(query).build();
    this.host.createQueryTaskService(queryTask, false, true, queryTask, null);
    ServiceDocumentQueryResult results = queryTask.results;
    assertEquals(Long.valueOf(1), results.documentCount);
    assertEquals(1, results.selectedLinks.size());
    assertEquals(1, results.selectedDocuments.size());
    QueryResultsProcessor processor = QueryResultsProcessor.create(results);
    for (EndpointState endpoint : processor.documents(EndpointState.class)) {
        String authCredentialSelfLink = endpoint.authCredentialsLink;
        assertNotNull(authCredentialSelfLink);
        assertNotNull(processor.selectedDocument(authCredentialSelfLink, AuthCredentialsServiceState.class));
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) QueryTask(com.vmware.xenon.services.common.QueryTask) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Query(com.vmware.xenon.services.common.QueryTask.Query) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

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