Search in sources :

Example 61 with EndpointState

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

the class TestAWSSetupUtils method createAWSEndpointState.

public static EndpointState createAWSEndpointState(VerificationHost host, String authLink, String resPoolLink) throws Throwable {
    EndpointState endpoint = new EndpointState();
    endpoint.endpointType = EndpointType.aws.name();
    endpoint.id = EndpointType.aws.name() + "-id";
    endpoint.name = EndpointType.aws.name() + "-name";
    endpoint.authCredentialsLink = authLink;
    endpoint.endpointProperties = Collections.emptyMap();
    endpoint.tenantLinks = Collections.singletonList(EndpointType.aws.name() + "-tenant");
    endpoint.resourcePoolLink = resPoolLink;
    return TestUtils.doPost(host, endpoint, EndpointState.class, UriUtils.buildUri(host, EndpointService.FACTORY_LINK));
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState)

Example 62 with EndpointState

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

the class AWSInstanceTypeService method getEndpointState.

/**
 * Retrieve endpoint state by the provided endpointLink.
 */
private DeferredResult<Context> getEndpointState(Context context) {
    AssertUtil.assertNotEmpty(context.endpointLink, "endpointLink is required.");
    Operation endpointOp = Operation.createGet(UriUtils.buildUri(getHost(), context.endpointLink));
    return sendWithDeferredResult(endpointOp, EndpointState.class).thenApply(endpointState -> {
        // Store endpoint state in the context.
        context.endpointState = endpointState;
        return context;
    });
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) Operation(com.vmware.xenon.common.Operation)

Example 63 with EndpointState

use of com.vmware.photon.controller.model.resources.EndpointService.EndpointState 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 64 with EndpointState

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

the class AzureSubscriptionsEnumerationService method queryExistingComputeStatesOfEndpoints.

private void queryExistingComputeStatesOfEndpoints(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage, Collection<EndpointState> subscriptionEndpoints) {
    // Get the compute states for already existing subscription endpoints and
    // if needed patch them with custom properties
    Map<String, ComputeState> computeLinkToState = new ConcurrentHashMap<>();
    Collection<Operation> getComputeOps = subscriptionEndpoints.stream().map(endpointState -> Operation.createGet(UriUtils.extendUri(getInventoryServiceUri(), endpointState.computeLink)).setCompletion((o, t) -> {
        if (t != null) {
            logSevere(() -> String.format("Failed getting compute state" + "for  %s due to %s", endpointState.computeLink, Utils.toString(t)));
            return;
        }
        ComputeState cs = o.getBody(ComputeState.class);
        // Only add custom properties if it does not have it already
        if (!hasAzureEaCustomProperties(cs)) {
            ComputeState comWithProps = new ComputeState();
            String subscriptionId = endpointState.endpointProperties.get(EndpointConfigRequest.USER_LINK_KEY);
            comWithProps.customProperties = getPropertiesMap(enumerationContext, enumerationContext.idToSubscription.get(subscriptionId), false);
            computeLinkToState.put(cs.documentSelfLink, comWithProps);
        }
    })).collect(Collectors.toList());
    joinOperationAndSendRequest(getComputeOps, enumerationContext, (enumCtx) -> patchExitingSubscriptionComputes(enumCtx, nextStage, computeLinkToState));
}
Also used : QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) HashMap(java.util.HashMap) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) BaseAdapterContext(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ResourceRequest(com.vmware.photon.controller.model.adapterapi.ResourceRequest) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) Utils(com.vmware.xenon.common.Utils) EndpointConfigRequest(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Map(java.util.Map) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) AzureSubscription(com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription) URI(java.net.URI) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) BaseAdapterStage(com.vmware.photon.controller.model.adapters.util.BaseAdapterContext.BaseAdapterStage) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) UriUtils(com.vmware.xenon.common.UriUtils) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) Operation(com.vmware.xenon.common.Operation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 65 with EndpointState

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

the class AzureSubscriptionsEnumerationService method updateExistingResources.

private void updateExistingResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
    // Query the subscriptions which we want to create to check if they already exist
    Query azureSubscriptionEndpointQuery = createQueryForAzureSubscriptionEndpoints(enumerationContext);
    // Use max page size since we are collectDocuments EndpointStates
    QueryByPages<EndpointState> querySubscriptionEndpoints = new QueryByPages<>(getHost(), azureSubscriptionEndpointQuery, EndpointState.class, enumerationContext.parent.tenantLinks).setMaxPageSize(QueryUtils.MAX_RESULT_LIMIT).setClusterType(ServiceTypeCluster.INVENTORY_SERVICE);
    querySubscriptionEndpoints.collectDocuments(Collectors.toList()).whenComplete((subscriptionEndpoints, t) -> {
        if (t != null) {
            getFailureConsumer(enumerationContext).accept(t);
            return;
        }
        if (subscriptionEndpoints.isEmpty()) {
            enumerationContext.stage = nextStage;
            handleAzureSubscriptionsEnumerationRequest(enumerationContext);
            return;
        }
        queryExistingComputeStatesOfEndpoints(enumerationContext, nextStage, subscriptionEndpoints);
    });
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) Query(com.vmware.xenon.services.common.QueryTask.Query)

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