Search in sources :

Example 16 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class AzureSubscriptionsEnumerationServiceTest method testAddNonEaAzureSubscriptionLater.

private void testAddNonEaAzureSubscriptionLater() throws Throwable {
    // Create Azure non-ea endpoints
    EndpointState nonEaEp3 = createNonEaEndpointState(SUBSCRIPTION_ID_2);
    EndpointAllocationTaskState state3 = createEndpoint(nonEaEp3);
    this.existingSubsComputeLink3 = state3.endpointState.computeLink;
    AzureSubscription subscription1 = getAzureSubscription(SUBSCRIPTION_ID_1, ACCOUNT_EMAIL_ID_1);
    AzureSubscription subscription2 = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2);
    AzureSubscription existingSubscription2 = getAzureSubscription(SUBSCRIPTION_EXISTING_2, ACCOUNT_EMAIL_ID_2);
    createAzureCostComputesForSubscriptions(Arrays.asList(subscription1, subscription2, existingSubscription2));
    // Query for Azure Computes created with CLIENT_ID as enrollment Number
    QueryTask task = createQueryTaskForAzureComputes(ENROLLMENT_NUMNBER, Collections.singletonList(TENANT_ID));
    QueryTask queryTaskResponse = executQuerySynchronously(task);
    assertQueryTaskResponse(queryTaskResponse, 7);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) QueryTask(com.vmware.xenon.services.common.QueryTask) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)

Example 17 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class TestAWSImageEnumerationTask 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);
    }
    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 = Arrays.asList(endpointType.name() + "-tenant");
    allocateEndpoint = 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) ImageEnumerationTaskState(com.vmware.photon.controller.model.tasks.ImageEnumerationTaskService.ImageEnumerationTaskState)

Example 18 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class TestAWSCostAdapterService method testAwsCostAdapterEndToEnd.

@Test
public void testAwsCostAdapterEndToEnd() throws Throwable {
    if (this.isMock || new LocalDate(DateTimeZone.UTC).getDayOfMonth() == 1) {
        return;
    }
    ResourcePoolState resourcePool = TestAWSSetupUtils.createAWSResourcePool(this.host);
    EndpointState endpointState = new EndpointState();
    endpointState.resourcePoolLink = resourcePool.documentSelfLink;
    endpointState.endpointType = PhotonModelConstants.EndpointType.aws.name();
    endpointState.name = "test-aws-endpoint";
    endpointState.endpointProperties = new HashMap<>();
    endpointState.endpointProperties.put(EndpointConfigRequest.PRIVATE_KEY_KEY, this.secretKey);
    endpointState.endpointProperties.put(EndpointConfigRequest.PRIVATE_KEYID_KEY, this.accessKey);
    EndpointAllocationTaskState endpointAllocationTaskState = new EndpointAllocationTaskState();
    endpointAllocationTaskState.endpointState = endpointState;
    endpointAllocationTaskState.tenantLinks = Collections.singletonList("tenant-1");
    EndpointAllocationTaskState returnState = postServiceSynchronously(EndpointAllocationTaskService.FACTORY_LINK, endpointAllocationTaskState, EndpointAllocationTaskState.class);
    EndpointAllocationTaskState completeState = this.waitForServiceState(EndpointAllocationTaskState.class, returnState.documentSelfLink, state -> TaskState.TaskStage.FINISHED.ordinal() <= state.taskInfo.stage.ordinal());
    System.setProperty(AWSCostStatsService.BILLS_BACK_IN_TIME_MONTHS_KEY, "1");
    triggerStatsCollection(resourcePool);
    verifyPersistedStats(completeState, AWSConstants.COST, 2);
    // Check if second iteration of adapter succeeds.
    triggerStatsCollection(resourcePool);
    verifyPersistedStats(completeState, AWSConstants.AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS, 2);
    System.clearProperty(AWSCostStatsService.BILLS_BACK_IN_TIME_MONTHS_KEY);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) LocalDate(org.joda.time.LocalDate) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 19 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class EndpointServiceTests method testShouldFailOnCreatingDuplicateEndpoint.

public void testShouldFailOnCreatingDuplicateEndpoint(EndpointState ep) throws Throwable {
    if (!this.isMock) {
        EndpointAllocationTaskState createEndpoint = new EndpointAllocationTaskState();
        createEndpoint.endpointState = ep;
        createEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
        createEndpoint.checkForEndpointUniqueness = Boolean.TRUE;
        EndpointAllocationTaskState outTask = TestUtils.doPost(this.host, createEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
        this.host.waitForFinishedTask(EndpointAllocationTaskState.class, outTask.documentSelfLink);
        EndpointAllocationTaskState taskState = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
        assertNotNull(taskState);
        assertNotNull(taskState.endpointState);
        ServiceDocument endpointState = taskState.endpointState;
        assertNotNull(endpointState.documentSelfLink);
        // check endpoint document was created
        getServiceSynchronously(endpointState.documentSelfLink, EndpointState.class);
        // Run the task again with the same endpoint
        EndpointAllocationTaskState duplicateEndpointTask = TestUtils.doPost(this.host, createEndpoint, EndpointAllocationTaskState.class, UriUtils.buildUri(this.host, EndpointAllocationTaskService.FACTORY_LINK));
        EndpointAllocationTaskState failedTask = this.host.waitForFailedTask(EndpointAllocationTaskState.class, duplicateEndpointTask.documentSelfLink);
        assertEquals(failedTask.taskInfo.stage, TaskState.TaskStage.FAILED);
    }
}
Also used : EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument)

Example 20 with EndpointAllocationTaskState

use of com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState in project photon-model by vmware.

the class EndpointServiceTests method testCreateEndpoint.

public void testCreateEndpoint(EndpointService.EndpointState ep) throws Throwable {
    EndpointAllocationTaskState validateEndpoint = new EndpointAllocationTaskState();
    validateEndpoint.endpointState = ep;
    validateEndpoint.options = this.isMock ? EnumSet.of(TaskOption.IS_MOCK) : null;
    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 = getServiceSynchronously(outTask.documentSelfLink, EndpointAllocationTaskState.class);
    assertNotNull(taskState);
    assertNotNull(taskState.endpointState);
    ServiceDocument endpointState = taskState.endpointState;
    assertNotNull(endpointState.documentSelfLink);
    // check endpoint document was created
    EndpointService.EndpointState endpoint = getServiceSynchronously(endpointState.documentSelfLink, EndpointService.EndpointState.class);
    assertNotNull(endpoint);
    assertNotNull(endpoint.authCredentialsLink);
    assertNotNull(endpoint.computeLink);
    assertNotNull(endpoint.computeDescriptionLink);
    AuthCredentialsService.AuthCredentialsServiceState credentials = getServiceSynchronously(endpoint.authCredentialsLink, AuthCredentialsService.AuthCredentialsServiceState.class);
    assertNotNull(credentials);
    assertEquals(ep.endpointProperties.get(PRIVATE_KEYID_KEY), credentials.privateKeyId);
    assertEquals(ep.endpointProperties.get(PRIVATE_KEY_KEY), credentials.privateKey);
    ComputeDescriptionService.ComputeDescription cd = getServiceSynchronously(endpoint.computeDescriptionLink, ComputeDescriptionService.ComputeDescription.class);
    assertNotNull(cd);
    assertEquals(credentials.documentSelfLink, cd.authCredentialsLink);
    assertEquals(this.regionId, cd.regionId);
    assertEquals(this.environmentName, cd.environmentName);
    ComputeService.ComputeState cs = getServiceSynchronously(endpoint.computeLink, ComputeService.ComputeState.class);
    assertNotNull(cs);
    assertNotNull(cs.adapterManagementReference);
    assertEquals(ComputeDescriptionService.ComputeDescription.ComputeType.ENDPOINT_HOST, cs.type);
    assertEquals(this.environmentName, cs.environmentName);
    assertEquals(ComputeService.PowerState.ON, cs.powerState);
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) EndpointAllocationTaskState(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState) ServiceDocument(com.vmware.xenon.common.ServiceDocument) EndpointService(com.vmware.photon.controller.model.resources.EndpointService) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService)

Aggregations

EndpointAllocationTaskState (com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService.EndpointAllocationTaskState)21 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)14 ServiceDocument (com.vmware.xenon.common.ServiceDocument)6 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)4 TaskState (com.vmware.xenon.common.TaskState)4 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)3 Before (org.junit.Before)3 EndpointType (com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType)2 BaseModelTest (com.vmware.photon.controller.model.helpers.BaseModelTest)2 EndpointService (com.vmware.photon.controller.model.resources.EndpointService)2 Operation (com.vmware.xenon.common.Operation)2 QueryTask (com.vmware.xenon.services.common.QueryTask)2 HashMap (java.util.HashMap)2 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)1 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)1 EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)1 INSTANCE_1_SELF_LINK (com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_1_SELF_LINK)1 INSTANCE_2_SELF_LINK (com.vmware.photon.controller.model.adapters.awsadapter.MockCostStatsAdapterService.INSTANCE_2_SELF_LINK)1 AwsServices (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices)1 AWSStatsNormalizer (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSStatsNormalizer)1