Search in sources :

Example 6 with AzureSubscription

use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.

the class AzureSubscriptionEndpointsEnumerationServiceTest method testAddSecondAzureSubscription.

private void testAddSecondAzureSubscription() throws Throwable {
    // Request for creating computes for 1 Azure Subscriptions
    AzureSubscription subscription = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_ID_2);
    createAzureEndpointsForSubscriptions(Collections.singletonList(subscription));
    // Query the Endpoints to assert
    ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
    Assert.assertEquals(3, result.documents.size());
    // Assert the created Endpoint and other resources
    result.documents.remove(this.endpointLink);
    // Remove the endpoints created earlier
    this.createdEndpointLinks.forEach(endpoint -> result.documents.remove(endpoint));
    EndpointState endpointStateCreated = Utils.fromJson(result.documents.values().iterator().next(), EndpointState.class);
    assertCreatedEndpoint(endpointStateCreated, SUBSCRIPTION_ID_2);
    this.createdEndpointLinks.add(endpointStateCreated.documentSelfLink);
    // Assert the root compute under the endpoint
    ComputeState computeStateCreated = getServiceSynchronously(endpointStateCreated.computeLink, ComputeState.class);
    assertCreatedComputeState(computeStateCreated, SUBSCRIPTION_ID_2, ACCOUNT_ID_2);
    // Assert the partial AuthCredentialsState
    AuthCredentialsServiceState authCreated = getServiceSynchronously(endpointStateCreated.authCredentialsLink, AuthCredentialsServiceState.class);
    assertAuthCredentialState(authCreated, SUBSCRIPTION_ID_2);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)

Example 7 with AzureSubscription

use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.

the class AzureSubscriptionsEnumerationServiceTest method testConstructSubscriptionName.

@Test
public void testConstructSubscriptionName() {
    String subzId = "subscriptionId";
    String accountOwnerId = "account@ownerId.com";
    String accountName = "Account Name";
    String subzName = "Subscription Name";
    AzureSubscription subz = new AzureSubscription();
    subz.entityId = subzId;
    subz.parentEntityId = accountOwnerId;
    subz.parentEntityName = accountName;
    subz.entityName = subzName;
    String constructedSubzName = AzureUtils.constructSubscriptionName(subz);
    String correctSubzName = accountName + COMPUTE_NAME_SEPARATOR + subzName;
    Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
    // if account name is not available, subscription ID should be displayed
    subz.parentEntityName = null;
    correctSubzName = subzId;
    constructedSubzName = AzureUtils.constructSubscriptionName(subz);
    Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
    // if account name is not available, subscription ID should be displayed
    subz.parentEntityName = " ";
    correctSubzName = subzId;
    constructedSubzName = AzureUtils.constructSubscriptionName(subz);
    Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
    // if subscription name is not available, subscription ID should be displayed
    subz.entityName = " ";
    correctSubzName = subzId;
    constructedSubzName = AzureUtils.constructSubscriptionName(subz);
    Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
}
Also used : AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription) Test(org.junit.Test)

Example 8 with AzureSubscription

use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.

the class AzureSubscriptionsEnumerationServiceTest method testAddMoreAzureSubscriptions.

private void testAddMoreAzureSubscriptions() throws Throwable {
    // Request for creating computes for another Azure Subscriptions
    AzureSubscription subscription = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2);
    createAzureCostComputesForSubscriptions(Collections.singletonList(subscription));
    // 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, 4);
    // Remove compute for existing subscription
    ComputeState existingSubsCs = Utils.fromJson(queryTaskResponse.results.documents.remove(this.existingSubsComputeLink1), ComputeState.class);
    Assert.assertNotNull(existingSubsCs);
    Assert.assertNull(existingSubsCs.customProperties.get(PhotonModelConstants.AUTO_DISCOVERED_ENTITY));
    // Remove the already asserted computes
    this.createdComputeLinks.stream().forEach(computeLnk -> {
        queryTaskResponse.results.documents.remove(computeLnk);
    });
    // Get and assert the returned compute
    ComputeState cs = Utils.fromJson(queryTaskResponse.results.documents.values().iterator().next(), ComputeState.class);
    assertPropertiesOfComputeState(cs, ENROLLMENT_NUMNBER, SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2, this.compute.endpointLink, this.compute.tenantLinks);
    this.createdComputeLinks.add(cs.documentSelfLink);
}
Also used : ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) QueryTask(com.vmware.xenon.services.common.QueryTask) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)

Example 9 with AzureSubscription

use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription 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 10 with AzureSubscription

use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.

the class AzureSubscriptionsEnumerationServiceTest method getAzureSubscription.

private AzureSubscription getAzureSubscription(String subscriptionId, String accountId) {
    AzureSubscription subscription = new AzureSubscription();
    subscription.entityId = subscriptionId;
    subscription.parentEntityId = accountId;
    return subscription;
}
Also used : AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)

Aggregations

AzureSubscription (com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription)15 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)8 QueryTask (com.vmware.xenon.services.common.QueryTask)7 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)6 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)5 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)4 AzureService (com.vmware.photon.controller.model.adapters.azure.model.cost.AzureService)4 Sets (com.google.common.collect.Sets)3 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)3 ComputeStatsResponse (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse)3 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)3 EndpointConfigRequest (com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest)3 AzureUriPaths (com.vmware.photon.controller.model.adapters.azure.AzureUriPaths)3 AzureCostConstants (com.vmware.photon.controller.model.adapters.azure.constants.AzureCostConstants)3 INTERNAL_REQUEST_TIMEOUT_SECONDS (com.vmware.photon.controller.model.adapters.azure.constants.AzureCostConstants.INTERNAL_REQUEST_TIMEOUT_SECONDS)3 AzureSubscriptionsEnumerationService (com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionsEnumerationService)3 AzureSubscriptionsEnumerationRequest (com.vmware.photon.controller.model.adapters.azure.ea.enumeration.AzureSubscriptionsEnumerationService.AzureSubscriptionsEnumerationRequest)3 AzureCostHelper (com.vmware.photon.controller.model.adapters.azure.ea.utils.AzureCostHelper)3 AzureDetailedBillHandler (com.vmware.photon.controller.model.adapters.azure.ea.utils.AzureDetailedBillHandler)3 AzureResource (com.vmware.photon.controller.model.adapters.azure.model.cost.AzureResource)3