Search in sources :

Example 6 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class TestAWSMissingEnumerationResourcesService method getLinkedAccountComputeDescs.

private void getLinkedAccountComputeDescs(Request request, int expectedCount) {
    this.host.waitFor("Timeout waiting for getLinkedAccountComputeDescriptions()", () -> {
        ServiceDocumentQueryResult result = this.host.createAndWaitSimpleDirectQuery(getQuerySpecForComputeDesc(request), expectedCount, expectedCount);
        Collection<Object> values = result.documents.values();
        if (values.size() != expectedCount) {
            return false;
        }
        for (Object computeDesc : result.documents.values()) {
            ComputeDescription cDesc = Utils.fromJson(computeDesc, ComputeDescription.class);
            linkedAccountDescriptions.put(cDesc.name, cDesc);
            if (!cDesc.endpointLink.equals(request.primaryAccountCompute.endpointLink)) {
                return false;
            }
        }
        return true;
    });
}
Also used : ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult)

Example 7 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AWSEndpointAdapterService method computeDesc.

private BiConsumer<ComputeDescription, Retriever> computeDesc() {
    return (cd, r) -> {
        cd.regionId = r.get(REGION_KEY).orElse(null);
        cd.zoneId = r.get(ZONE_KEY).orElse(null);
        cd.environmentName = ComputeDescription.ENVIRONMENT_NAME_AWS;
        List<String> children = new ArrayList<>();
        children.add(ComputeType.ZONE.toString());
        cd.supportedChildren = children;
        cd.instanceAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_INSTANCE_ADAPTER);
        cd.enumerationAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_ENUMERATION_ADAPTER);
        cd.powerAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_POWER_ADAPTER);
        cd.diskAdapterReference = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_DISK_ADAPTER);
        {
            URI statsAdapterUri = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_STATS_ADAPTER);
            URI costStatsAdapterUri = AdapterUriUtil.buildPublicAdapterUri(getHost(), AWSUriPaths.AWS_COST_STATS_ADAPTER);
            cd.statsAdapterReferences = new LinkedHashSet<>();
            cd.statsAdapterReferences.add(costStatsAdapterUri);
            cd.statsAdapterReferences.add(statsAdapterUri);
            cd.statsAdapterReference = statsAdapterUri;
        }
    };
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) Utils(com.vmware.xenon.common.Utils) AmazonIdentityManagementClientBuilder(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE) EXTERNAL_ID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY) URI(java.net.URI) AWSCredentials(com.amazonaws.auth.AWSCredentials) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AmazonServiceException(com.amazonaws.AmazonServiceException) StatelessService(com.vmware.xenon.common.StatelessService) CompletionException(java.util.concurrent.CompletionException) Collectors(java.util.stream.Collectors) PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE(com.vmware.photon.controller.model.adapters.util.AdapterConstants.PHOTON_MODEL_ADAPTER_UNAUTHORIZED_MESSAGE_CODE) List(java.util.List) RequestType(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.RequestType) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) STATUS_CODE_UNAUTHORIZED(com.vmware.xenon.common.Operation.STATUS_CODE_UNAUTHORIZED) AWSUtils.getEc2AsyncClient(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.getEc2AsyncClient) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) PRIVATE_KEY_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEY_KEY) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) HashMap(java.util.HashMap) PRIVATE_KEYID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.PRIVATE_KEYID_KEY) ArrayList(java.util.ArrayList) Regions(com.amazonaws.regions.Regions) ZONE_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ZONE_KEY) 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) BiConsumer(java.util.function.BiConsumer) Retriever(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils.Retriever) EndpointType(com.vmware.photon.controller.model.constants.PhotonModelConstants.EndpointType) LinkedHashSet(java.util.LinkedHashSet) ServiceErrorResponse(com.vmware.xenon.common.ServiceErrorResponse) EndpointAdapterUtils(com.vmware.photon.controller.model.adapters.util.EndpointAdapterUtils) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) AmazonIdentityManagementClient(com.amazonaws.services.identitymanagement.AmazonIdentityManagementClient) ARN_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY) LocalizableValidationException(com.vmware.xenon.common.LocalizableValidationException) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) REGION_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.REGION_KEY) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) List(java.util.List) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 8 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AzureComputeEnumerationAdapterService method createComputeDescriptionForRegion.

private ComputeDescription createComputeDescriptionForRegion(EnumerationContext context, RegionInfo r) {
    ComputeDescriptionService.ComputeDescription cd = Utils.clone(context.parentCompute.description);
    cd.supportedChildren = new ArrayList<>();
    cd.supportedChildren.add(ComputeType.VM_GUEST.toString());
    cd.id = r.regionId;
    cd.documentSelfLink = generateRegionComputeDescriptionLinkId(r.regionId, context.request.endpointLink);
    cd.name = r.name;
    cd.regionId = r.regionId;
    cd.endpointLink = context.request.endpointLink;
    AdapterUtils.addToEndpointLinks(cd, context.request.endpointLink);
    // Book keeping information about the creation of the compute description in the system.
    if (cd.customProperties == null) {
        cd.customProperties = new HashMap<>();
    }
    cd.customProperties.put(SOURCE_TASK_LINK, ResourceEnumerationTaskService.FACTORY_LINK);
    return cd;
}
Also used : ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 9 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AzureSubscriptionEndpointCreationService method createSubscriptionEndpoint.

private void createSubscriptionEndpoint(EndpointState azureEaEndpoint, AzureSubscriptionEndpointCreationRequest request, Operation parentOp) {
    Operation authOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), AuthCredentialsService.FACTORY_LINK));
    Operation cdOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeDescriptionService.FACTORY_LINK));
    Operation csOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeService.FACTORY_LINK));
    Operation endPointOp = Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), EndpointService.FACTORY_LINK));
    AuthCredentialsServiceState authCredentialsState = createAuthCredentialsState(azureEaEndpoint, request);
    EndpointState endpointState = createEndpointState(azureEaEndpoint, request);
    ComputeDescription computeDescState = AzureUtils.constructAzureSubscriptionComputeDescription(endpointState.documentSelfLink, azureEaEndpoint.tenantLinks, request.subscriptionId, null, null, endpointState.computeLink);
    authOp.setBody(authCredentialsState);
    OperationSequence sequence = OperationSequence.create(authOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(authOp.getId());
        AuthCredentialsServiceState authState = o.getBody(AuthCredentialsServiceState.class);
        computeDescState.authCredentialsLink = authState.documentSelfLink;
        endpointState.authCredentialsLink = authState.documentSelfLink;
        cdOp.setBody(computeDescState);
    }).next(cdOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(cdOp.getId());
        ComputeDescription cd = o.getBody(ComputeDescription.class);
        ComputeState cs = AzureUtils.constructAzureSubscriptionComputeState(endpointState.documentSelfLink, cd.documentSelfLink, azureEaEndpoint.tenantLinks, request.subscriptionId, azureEaEndpoint.resourcePoolLink, getCustomPropertiesMap(endpointState, request), null, endpointState.computeLink);
        csOp.setBody(cs);
        endpointState.computeDescriptionLink = cd.documentSelfLink;
    }).next(csOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(csOp.getId());
        ComputeState cs = o.getBody(ComputeState.class);
        endpointState.computeLink = cs.documentSelfLink;
        endPointOp.setBody(endpointState);
    }).next(endPointOp).setCompletion((ops, exs) -> {
        if (exs != null) {
            handleFailure(exs, parentOp);
            return;
        }
        Operation o = ops.get(endPointOp.getId());
        EndpointState es = o.getBody(EndpointState.class);
        parentOp.setBody(es);
        parentOp.complete();
    });
    sequence.sendWith(this);
}
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) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) OperationSequence(com.vmware.xenon.common.OperationSequence) Operation(com.vmware.xenon.common.Operation)

Example 10 with ComputeDescription

use of com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription in project photon-model by vmware.

the class AzureSubscriptionsEnumerationService method createResources.

private void createResources(AzureSubscriptionsEnumerationContext enumerationContext, AzureCostComputeEnumerationStages nextStage) {
    // Go through new subscriptions and create corresponding ComputeState
    // and ComputeDescription for them
    Collection<ComputeState> computesToCreate = new ArrayList<>();
    // Create ComputeDescription
    Collection<Operation> createComputeDescOps = enumerationContext.idToSubscription.values().stream().map(subscription -> Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeDescriptionService.FACTORY_LINK)).setBody(AzureUtils.constructAzureSubscriptionComputeDescription(enumerationContext.parent.endpointLink, enumerationContext.parent.tenantLinks, subscription.entityId, null, null, enumerationContext.parent.documentSelfLink)).setCompletion((o, e) -> {
        if (e != null) {
            logSevere(() -> String.format("Compute description creation " + " failed for azure subscription %s", subscription.entityId));
            return;
        }
        ComputeDescription cd = o.getBody(ComputeDescription.class);
        String csName = AzureUtils.constructSubscriptionName(subscription);
        computesToCreate.add(AzureUtils.constructAzureSubscriptionComputeState(enumerationContext.parent.endpointLink, cd.documentSelfLink, enumerationContext.parent.tenantLinks, csName, enumerationContext.parent.resourcePoolLink, getPropertiesMap(enumerationContext, subscription, true), null, enumerationContext.parent.documentSelfLink));
    })).collect(Collectors.toList());
    joinOperationAndSendRequest(createComputeDescOps, enumerationContext, (subsEnumCtx) -> {
        // Now create the ComputeState
        Collection<Operation> createComputeOps = computesToCreate.stream().map(computeState -> Operation.createPost(UriUtils.extendUri(getInventoryServiceUri(), ComputeService.FACTORY_LINK)).setBody(computeState).setCompletion((o, e) -> {
            if (e != null) {
                logSevere(() -> String.format("Compute state creation failed for azure" + " subscription %s", computeState.name));
            }
        })).collect(Collectors.toList());
        joinOperationAndSendRequest(createComputeOps, subsEnumCtx, (enumCtx) -> {
            enumCtx.stage = nextStage;
            handleAzureSubscriptionsEnumerationRequest(enumCtx);
        });
    });
}
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) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation)

Aggregations

ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)78 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 Operation (com.vmware.xenon.common.Operation)21 ArrayList (java.util.ArrayList)21 QueryTask (com.vmware.xenon.services.common.QueryTask)17 Test (org.junit.Test)17 ComputeDescriptionService (com.vmware.photon.controller.model.resources.ComputeDescriptionService)15 ComputeService (com.vmware.photon.controller.model.resources.ComputeService)15 HashMap (java.util.HashMap)15 HashSet (java.util.HashSet)15 List (java.util.List)15 Utils (com.vmware.xenon.common.Utils)14 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)14 URI (java.net.URI)14 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)13 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)12 ServiceDocumentQueryResult (com.vmware.xenon.common.ServiceDocumentQueryResult)12 UriUtils (com.vmware.xenon.common.UriUtils)12 ComputeType (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType)11 EndpointState (com.vmware.photon.controller.model.resources.EndpointService.EndpointState)11