Search in sources :

Example 1 with ComputeDescription

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

the class AWSComputeDescriptionEnumerationAdapterService method getLocalComputeDescriptions.

/**
 * Get all the compute descriptions already in the system and filtered by
 * - Supported Children (Docker Container)
 * - Environment name(AWS),
 * - Name (instance type),
 * - ZoneId(placement).
 * - Endpoint link
 */
private void getLocalComputeDescriptions(AWSComputeDescriptionCreationServiceContext context, AWSComputeDescCreationStage next) {
    QueryTask queryTask = getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(context.representativeComputeDescriptionSet, context.cdState.tenantLinks, context.cdState.regionId, context.cdState.parentComputeLink, context.cdState.endpointLink);
    // create the query to find an existing compute description
    QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((qrt, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Failure retrieving query results: %s", e.toString()));
            finishWithFailure(context, e);
            return;
        }
        if (qrt != null && qrt.results.documentCount > 0) {
            for (Object s : qrt.results.documents.values()) {
                ComputeDescription localComputeDescription = Utils.fromJson(s, ComputeDescription.class);
                context.localComputeDescriptionMap.put(getKeyForComputeDescriptionFromCD(localComputeDescription), localComputeDescription);
            }
            logFine(() -> String.format("%d compute descriptions found", context.localComputeDescriptionMap.size()));
        } else {
            logFine(() -> "No compute descriptions found");
        }
        context.creationStage = next;
        handleComputeDescriptionCreation(context);
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 2 with ComputeDescription

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

the class AWSComputeDescriptionEnumerationAdapterService method populateUpdateOperations.

private void populateUpdateOperations(AWSComputeDescriptionCreationServiceContext context, AWSComputeDescCreationStage next) {
    if (context.computeDescriptionsToBeUpdatedList == null || context.computeDescriptionsToBeUpdatedList.isEmpty()) {
        logFine(() -> "No local compute descriptions need to be updated");
        context.creationStage = next;
        handleComputeDescriptionCreation(context);
        return;
    }
    logFine(() -> String.format("Need to update %d local compute descriptions", context.computeDescriptionsToBeUpdatedList.size()));
    context.computeDescriptionsToBeUpdatedList.stream().forEach(entry -> {
        ComputeDescription cd = context.localComputeDescriptionMap.get(entry);
        if (StringUtils.isEmpty(cd.endpointLink)) {
            cd.endpointLink = context.cdState.endpointLink;
            sendRequest(Operation.createPatch(this.getHost(), cd.documentSelfLink).setReferer(this.getHost().getUri()).setBody(cd));
        }
    });
    context.computeDescriptionsToBeUpdatedList.stream().map(dk -> updateComputeDescriptionOperation(dk, context)).forEach(o -> context.enumerationOperations.add(o));
    context.creationStage = next;
    handleComputeDescriptionCreation(context);
}
Also used : ZoneData(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.ZoneData) QueryTask(com.vmware.xenon.services.common.QueryTask) InstanceDescKey(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.InstanceDescKey) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AWSEnumerationUtils.getKeyForComputeDescriptionFromCD(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getKeyForComputeDescriptionFromCD) Utils(com.vmware.xenon.common.Utils) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) AWSEnumerationUtils.getRepresentativeListOfCDsFromInstanceList(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getRepresentativeListOfCDsFromInstanceList) Map(java.util.Map) URI(java.net.URI) Instance(com.amazonaws.services.ec2.model.Instance) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) AdapterUriUtil(com.vmware.photon.controller.model.adapters.util.AdapterUriUtil) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) AWSEnumerationUtils.getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) Collections(java.util.Collections) AWSCostStatsService(com.vmware.photon.controller.model.adapters.awsadapter.AWSCostStatsService) AWSUriPaths(com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths) OperationJoin(com.vmware.xenon.common.OperationJoin) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)

Example 3 with ComputeDescription

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

the class AWSComputeStateCreationAdapterService method getRelatedComputeDescriptions.

/**
 * Looks up the compute descriptions associated with the compute states to be created in the
 * system.
 */
private void getRelatedComputeDescriptions(AWSComputeStateCreationContext context, AWSComputeStateCreationStage next) {
    // Get the related compute descriptions for all the compute states are to be updated and
    // created.
    Set<InstanceDescKey> representativeCDSet = getRepresentativeListOfCDsFromInstanceList(context.request.instancesToBeCreated, context.request.zones);
    representativeCDSet.addAll(getRepresentativeListOfCDsFromInstanceList(context.request.instancesToBeUpdated.values(), context.request.zones));
    if (representativeCDSet.isEmpty()) {
        context.creationStage = next;
        handleComputeStateCreateOrUpdate(context);
        return;
    }
    QueryTask queryTask = getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(representativeCDSet, context.request.tenantLinks, context.request.regionId, context.request.parentComputeLink, context.request.endpointLink);
    queryTask.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + QUERY_TASK_EXPIRY_MICROS;
    // create the query to find an existing compute description
    QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((qrt, e) -> {
        if (e != null) {
            logWarning(() -> String.format("Failure retrieving query results: %s", e.toString()));
            finishWithFailure(context, e);
            return;
        }
        if (qrt != null && qrt.results.documentCount > 0) {
            for (Object s : qrt.results.documents.values()) {
                ComputeDescription localComputeDescription = Utils.fromJson(s, ComputeDescription.class);
                context.computeDescriptionMap.put(getKeyForComputeDescriptionFromCD(localComputeDescription), localComputeDescription.documentSelfLink);
            }
            logFine(() -> String.format("%d compute descriptions found", context.computeDescriptionMap.size()));
        } else {
            logFine(() -> "No compute descriptions found");
        }
        context.creationStage = next;
        handleComputeStateCreateOrUpdate(context);
    });
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) InstanceDescKey(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.InstanceDescKey)

Example 4 with ComputeDescription

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

the class AWSMissingResourcesEnumerationService method createLinkedComputeStates.

/**
 *  creates new linked account endpoint states of a primary account
 * @param context
 */
private void createLinkedComputeStates(AwsMissingResourcesEnumContext context) {
    AtomicInteger completionCounter = new AtomicInteger(context.request.missingLinkedAccountIds.size());
    AtomicBoolean isSuccessful = new AtomicBoolean(true);
    context.request.missingLinkedAccountIds.forEach(linkedAccountId -> {
        ComputeDescription computeDescription = populateComputeDescription(context, linkedAccountId);
        ComputeState computeState = populateComputeState(context, linkedAccountId);
        computeState.descriptionLink = computeDescription.documentSelfLink;
        Operation csOp = Operation.createPost(this, ComputeService.FACTORY_LINK).setBody(computeState);
        Operation cdOp = Operation.createPost(this, ComputeDescriptionService.FACTORY_LINK).setBody(computeDescription);
        JoinedCompletionHandler completionHandler = (ops, exs) -> {
            if (exs != null && !exs.isEmpty()) {
                logWarning(() -> String.format("Error creating missing resources for" + " account with ID %s.", linkedAccountId));
                isSuccessful.set(false);
            } else {
                logInfo(() -> String.format("Created missing resources for account " + "with ID %s.", linkedAccountId));
            }
            if (completionCounter.decrementAndGet() == 0) {
                if (isSuccessful.get()) {
                    context.requestOp.complete();
                } else {
                    context.requestOp.fail(new Exception("Failed to create missing resources " + "for atleast one linked account."));
                }
            }
        };
        Operation.createGet(this, computeDescription.documentSelfLink).setReferer(this.getUri()).setCompletion((o, e) -> {
            if (e != null && (e instanceof ServiceNotFoundException || o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND)) {
                OperationSequence.create(cdOp).next(csOp).setCompletion(completionHandler).sendWith(this);
            } else {
                OperationSequence.create(csOp).setCompletion(completionHandler).sendWith(this);
            }
        }).sendWith(this);
    });
}
Also used : JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) UUID(java.util.UUID) JoinedCompletionHandler(com.vmware.xenon.common.OperationJoin.JoinedCompletionHandler) StandardCharsets(java.nio.charset.StandardCharsets) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) HashSet(java.util.HashSet) AWSConstants(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants) Utils(com.vmware.xenon.common.Utils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) OperationSequence(com.vmware.xenon.common.OperationSequence) AWSUriPaths(com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException) Operation(com.vmware.xenon.common.Operation) ServiceNotFoundException(com.vmware.xenon.common.ServiceHost.ServiceNotFoundException)

Example 5 with ComputeDescription

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

the class MockCostStatsAdapterService method getAccountDescription.

@Override
protected void getAccountDescription(AWSCostStatsCreationContext statsData, AWSCostStatsCreationStages next) {
    ComputeDescription compDesc = new ComputeDescription();
    compDesc.id = "123";
    compDesc.documentSelfLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, generateUuidFromStr(compDesc.id));
    Set<URI> statsAdapterReferences = new HashSet<>();
    statsAdapterReferences.add(UriUtils.buildUri("stats-adapter-references"));
    compDesc.statsAdapterReferences = statsAdapterReferences;
    statsData.accountId = TestAWSCostAdapterService.account1Id;
    ComputeStateWithDescription account1ComputeState = new ComputeStateWithDescription();
    account1ComputeState.documentSelfLink = TestAWSCostAdapterService.account1SelfLink;
    account1ComputeState.type = ComputeType.ENDPOINT_HOST;
    account1ComputeState.endpointLink = "endpoint1";
    account1ComputeState.endpointLinks = new HashSet<String>();
    account1ComputeState.endpointLinks.add("endpoint1");
    account1ComputeState.name = "account1";
    account1ComputeState.descriptionLink = UriUtils.buildUriPath(ComputeDescriptionService.FACTORY_LINK, generateUuidFromStr("123"));
    account1ComputeState.creationTimeMicros = Utils.getNowMicrosUtc();
    account1ComputeState.customProperties = new HashMap<>();
    account1ComputeState.customProperties.put(AWSConstants.AWS_ACCOUNT_ID_KEY, "account1Id");
    account1ComputeState.customProperties.put(EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE, EndpointType.aws.name());
    account1ComputeState.description = new ComputeDescription();
    account1ComputeState.description.statsAdapterReferences = statsAdapterReferences;
    account1ComputeState.tenantLinks = Collections.singletonList("tenant-1");
    statsData.computeDesc = account1ComputeState;
    statsData.awsAccountIdToComputeStates.put(TestAWSCostAdapterService.account1Id, Collections.singletonList(account1ComputeState));
    inferEndpointLink(statsData);
    getParentAuth(statsData, next);
}
Also used : ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) URI(java.net.URI) HashSet(java.util.HashSet)

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