Search in sources :

Example 1 with ComponentPlatform

use of software.amazon.awssdk.services.greengrassv2data.model.ComponentPlatform in project aws-greengrass-nucleus by aws-greengrass.

the class ComponentServiceHelper method resolveComponentVersion.

/**
 * Resolve a component version with greengrass cloud service. The dependency resolution algorithm goes through the
 * dependencies node by node, so one component got resolve a time.
 *
 * @param componentName             component name to be resolve
 * @param localCandidateVersion     component local candidate version if available
 * @param versionRequirements       component dependents version requirement map
 * @return resolved component version and recipe
 * @throws NoAvailableComponentVersionException if no applicable version available in cloud service
 */
@SuppressWarnings("PMD.PreserveStackTrace")
ResolvedComponentVersion resolveComponentVersion(String componentName, Semver localCandidateVersion, Map<String, Requirement> versionRequirements) throws NoAvailableComponentVersionException {
    ComponentPlatform platform = ComponentPlatform.builder().attributes(platformResolver.getCurrentPlatform()).build();
    Map<String, String> versionRequirementsInString = versionRequirements.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toString()));
    ComponentCandidate candidate = ComponentCandidate.builder().componentName(componentName).componentVersion(localCandidateVersion == null ? null : localCandidateVersion.getValue()).versionRequirements(versionRequirementsInString).build();
    ResolveComponentCandidatesRequest request = ResolveComponentCandidatesRequest.builder().platform(platform).componentCandidates(Collections.singletonList(candidate)).build();
    ResolveComponentCandidatesResponse result;
    try {
        result = clientFactory.getGreengrassV2DataClient().resolveComponentCandidates(request);
    } catch (ResourceNotFoundException e) {
        logger.atDebug().kv("componentName", componentName).kv("versionRequirements", versionRequirements).log("No applicable version found in cloud registry", e);
        throw new NoAvailableComponentVersionException("No cloud component version satisfies the requirements.", componentName, versionRequirements);
    }
    Validate.isTrue(result.resolvedComponentVersions() != null && result.resolvedComponentVersions().size() == 1, "Component service returns invalid response. It should have one resolved component version");
    return result.resolvedComponentVersions().get(0);
}
Also used : ComponentPlatform(software.amazon.awssdk.services.greengrassv2data.model.ComponentPlatform) ResolvedComponentVersion(software.amazon.awssdk.services.greengrassv2data.model.ResolvedComponentVersion) NoAvailableComponentVersionException(com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException) GreengrassServiceClientFactory(com.aws.greengrass.util.GreengrassServiceClientFactory) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Requirement(com.vdurmont.semver4j.Requirement) Validate(org.apache.commons.lang3.Validate) Semver(com.vdurmont.semver4j.Semver) ResolveComponentCandidatesResponse(software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesResponse) Map(java.util.Map) ResourceNotFoundException(software.amazon.awssdk.services.greengrassv2data.model.ResourceNotFoundException) LogManager(com.aws.greengrass.logging.impl.LogManager) Collections(java.util.Collections) PlatformResolver(com.aws.greengrass.config.PlatformResolver) Logger(com.aws.greengrass.logging.api.Logger) ComponentCandidate(software.amazon.awssdk.services.greengrassv2data.model.ComponentCandidate) ResolveComponentCandidatesRequest(software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesRequest) ComponentPlatform(software.amazon.awssdk.services.greengrassv2data.model.ComponentPlatform) ResolveComponentCandidatesResponse(software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesResponse) NoAvailableComponentVersionException(com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException) ComponentCandidate(software.amazon.awssdk.services.greengrassv2data.model.ComponentCandidate) ResourceNotFoundException(software.amazon.awssdk.services.greengrassv2data.model.ResourceNotFoundException) Map(java.util.Map) ResolveComponentCandidatesRequest(software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesRequest)

Aggregations

NoAvailableComponentVersionException (com.aws.greengrass.componentmanager.exceptions.NoAvailableComponentVersionException)1 PlatformResolver (com.aws.greengrass.config.PlatformResolver)1 Logger (com.aws.greengrass.logging.api.Logger)1 LogManager (com.aws.greengrass.logging.impl.LogManager)1 GreengrassServiceClientFactory (com.aws.greengrass.util.GreengrassServiceClientFactory)1 Requirement (com.vdurmont.semver4j.Requirement)1 Semver (com.vdurmont.semver4j.Semver)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 Validate (org.apache.commons.lang3.Validate)1 ComponentCandidate (software.amazon.awssdk.services.greengrassv2data.model.ComponentCandidate)1 ComponentPlatform (software.amazon.awssdk.services.greengrassv2data.model.ComponentPlatform)1 ResolveComponentCandidatesRequest (software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesRequest)1 ResolveComponentCandidatesResponse (software.amazon.awssdk.services.greengrassv2data.model.ResolveComponentCandidatesResponse)1 ResolvedComponentVersion (software.amazon.awssdk.services.greengrassv2data.model.ResolvedComponentVersion)1 ResourceNotFoundException (software.amazon.awssdk.services.greengrassv2data.model.ResourceNotFoundException)1