Skip to content

Commit

Permalink
Merge branch 'main' into diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-mage authored Oct 2, 2024
2 parents f6d6ef8 + 991fa35 commit 7cca606
Show file tree
Hide file tree
Showing 31 changed files with 619 additions and 245 deletions.
2 changes: 1 addition & 1 deletion conf/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ComponentName: aws.greengrass.Nucleus
ComponentType: aws.greengrass.nucleus
ComponentDescription: Core functionality for device side orchestration of deployments and lifecycle management for execution of Greengrass components and applications. This includes features such as starting, stopping, and monitoring execution of components and apps, inter-process communication server for communication between components, component installation and configuration management. This is a fundamental cornerstone of open-sourcing Greengrass, providing documentation and ability to debug Greengrass Core.
ComponentPublisher: AWS
ComponentVersion: '2.13.0'
ComponentVersion: '2.14.0'
ComponentConfiguration:
DefaultConfiguration:
iotDataEndpoint: ""
Expand Down
24 changes: 18 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.aws.greengrass</groupId>
<artifactId>nucleus</artifactId>
<version>2.13.0-SNAPSHOT</version>
<version>2.14.0-SNAPSHOT</version>
<packaging>jar</packaging>

<licenses>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.20.138</version>
<version>2.27.7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -139,7 +139,7 @@
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>greengrassv2-data</artifactId>
<version>2.20.x-SNAPSHOT</version>
<version>2.27.x-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>software.amazon.awssdk</groupId>
Expand Down Expand Up @@ -201,7 +201,7 @@
<dependency>
<groupId>org.zeroturnaround</groupId>
<artifactId>zt-process-killer</artifactId>
<version>1.10</version>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
Expand Down Expand Up @@ -238,7 +238,19 @@
When updating the version here, ensure you match the correct aws-crt version below.
Get the correct version from: https://github.com/aws/aws-iot-device-sdk-java-v2/blob/main/sdk/pom.xml#L45
!-->
<version>1.20.6-SECRET-SNAPSHOT</version>
<version>1.21.0</version>
<exclusions>
<exclusion>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>software.amazon.awssdk.crt</groupId>
<artifactId>aws-crt</artifactId>
<version>0.30.8</version>
<classifier>fips-where-available</classifier>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
Expand Down Expand Up @@ -846,7 +858,7 @@
<excludedGroups>E2E,E2E-INTRUSIVE</excludedGroups>
<groups></groups>
<greengrassjar.name>Greengrass</greengrassjar.name>
<lastVersion>2.12.0-SNAPSHOT</lastVersion>
<lastVersion>2.13.0-SNAPSHOT</lastVersion>
</properties>
<distributionManagement>
<snapshotRepository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,13 @@ static void setupPackageStore(Kernel kernel, ComponentIdentifier componentId, Co
artifactPath1_0_0.getParent().getParent(),
FileSystemPermission.Option.Recurse);

FileUtils.copyFile(jarFilePath.toFile(), artifact1_1_0.toFile());
FileUtils.copyFile(jarFilePath.toFile(), artifactPath1_0_0.toFile());

if (!artifact1_1_0.toFile().exists()) {
FileUtils.copyFile(jarFilePath.toFile(), artifact1_1_0.toFile());
}
if (!artifactPath1_0_0.toFile().exists()){
FileUtils.copyFile(jarFilePath.toFile(), artifactPath1_0_0.toFile());
}

for (ComponentIdentifier pluginId : pluginIds) {
Path artifactPath = e2ETestComponentStore.resolveArtifactDirectoryPath(pluginId)
.resolve(pluginId.getName() + JAR_FILE_EXTENSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import java.util.stream.Collectors;
import javax.inject.Inject;

import static com.aws.greengrass.deployment.errorcode.DeploymentErrorCode.COMPONENT_VERSION_NOT_VALID;

@NoArgsConstructor
public class DependencyResolver {
static final String NON_EXPLICIT_NUCLEUS_UPDATE_ERROR_MESSAGE_FMT = "The deployment attempts to update the "
Expand Down Expand Up @@ -71,6 +73,7 @@ public class DependencyResolver {
* @throws PackagingException for other component operation errors
* @throws InterruptedException InterruptedException
*/
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public List<ComponentIdentifier> resolveDependencies(DeploymentDocument document,
Map<String, Set<ComponentRequirementIdentifier>>
otherGroupsToRootComponents)
Expand All @@ -83,26 +86,36 @@ public List<ComponentIdentifier> resolveDependencies(DeploymentDocument document
// dependency tree.
Map<String, Map<String, Requirement>> componentNameToVersionConstraints = new HashMap<>();

// A map of component name to count of components that depend on it
Map<String, Integer> componentIncomingReferenceCount = new HashMap<>();

// A map of component name to its resolved version.
Map<String, ComponentMetadata> resolvedComponents = new HashMap<>();

// Get the target components with version requirements in the deployment document
List<String> targetComponentsToResolve = new ArrayList<>();
// Add the constraints of the target group to componentNameToVersionConstraints before
// trying to resolve the other group so that the resolved version will be compatible with
// both versions (if possible)
document.getDeploymentPackageConfigurationList().stream()
.filter(DeploymentPackageConfiguration::isRootComponent).forEach(e -> {
logger.atDebug().kv(COMPONENT_NAME_KEY, e.getPackageName()).kv(VERSION_KEY, e.getResolvedVersion())
.log("Found component configuration");
componentNameToVersionConstraints.putIfAbsent(e.getPackageName(), new HashMap<>());
for (DeploymentPackageConfiguration e : document.getDeploymentPackageConfigurationList()) {
if (e.isRootComponent()) {
logger.atDebug().kv(COMPONENT_NAME_KEY, e.getPackageName()).kv(VERSION_KEY, e.getResolvedVersion())
.log("Found component configuration");
componentNameToVersionConstraints.putIfAbsent(e.getPackageName(), new HashMap<>());
try {
componentNameToVersionConstraints.get(e.getPackageName())
.put(document.getGroupName(), Requirement.buildNPM(e.getResolvedVersion()));
targetComponentsToResolve.add(e.getPackageName());
});
} catch (Exception exception) {
throw new PackagingException(
String.format("Unsupported component version '%s' for component '%s'. For pre-release "
+ "versions, please start the version tag with a non-numeric character",
e.getResolvedVersion(),
e.getPackageName()),
exception, COMPONENT_VERSION_NOT_VALID);
}
targetComponentsToResolve.add(e.getPackageName());
}
}

// A map of component name to count of components that depend on it
Map<String, Integer> componentIncomingReferenceCount = new HashMap<>();

// A map of component name to its resolved version.
Map<String, ComponentMetadata> resolvedComponents = new HashMap<>();

Set<String> combinedTargetComponents = new LinkedHashSet<>(targetComponentsToResolve);
combinedTargetComponents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public DeploymentResult call() throws InterruptedException {
}
}

@SuppressWarnings({"PMD.AvoidCatchingGenericException"})
@SuppressWarnings({"PMD.AvoidCatchingGenericException", "PMD.AvoidRethrowingException"})
private Map<String, Set<ComponentRequirementIdentifier>> getNonTargetGroupToRootPackagesMap(
DeploymentDocument deploymentDocument)
throws DeploymentTaskFailureException, InterruptedException {
Expand All @@ -208,6 +208,8 @@ private Map<String, Set<ComponentRequirementIdentifier>> getNonTargetGroupToRoot
} else {
throw new DeploymentTaskFailureException("Error fetching thing group information", e);
}
} catch (InterruptedException e) {
throw e;
} catch (Exception e) {
if (isLocalDeployment && ThingGroupHelper.RETRYABLE_EXCEPTIONS.contains(e.getClass())) {
logger.atWarn().setCause(e).log("Failed to get thing group hierarchy, local deployment will proceed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,6 @@ private boolean validateNucleusConfig(CompletableFuture<DeploymentResult> totall
return true;
}

/**
* Completes the provided future when all the listed services are running.
*
* @param servicesToTrack services to track
* @param mergeTime time the merge was started, used to check if a service is broken due to the merge
* @param kernel kernel
* @throws InterruptedException if the thread is interrupted while waiting here
* @throws ServiceUpdateException if a service could not be updated
*/
// TODO - remove this in follow up CR for cancel deployment, it's being used by kernel update deployment
public static void waitForServicesToStart(Collection<GreengrassService> servicesToTrack, long mergeTime,
Kernel kernel)
throws InterruptedException, ServiceUpdateException {
// Relying on the fact that all service lifecycle steps should have timeouts,
// assuming this loop will not get stuck waiting forever
while (!areAllServiceInDesiredState(servicesToTrack, mergeTime, kernel)) {
Thread.sleep(WAIT_SVC_START_POLL_INTERVAL_MILLISEC); // hardcoded
}
}

/**
* Completes the provided future when all the listed services are running.
* Exits early if the future is cancelled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import javax.inject.Inject;

import static org.apache.commons.io.FileUtils.ONE_MB;
import static software.amazon.awssdk.services.s3.checksums.ChecksumConstant.CONTENT_LENGTH_HEADER;
import static software.amazon.awssdk.services.s3.internal.checksums.ChecksumConstant.CONTENT_LENGTH_HEADER;

public class DeploymentDocumentDownloader {
private static final Logger logger = LogManager.getLogger(DeploymentDocumentDownloader.class);
Expand Down
40 changes: 18 additions & 22 deletions src/main/java/com/aws/greengrass/deployment/DeploymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ protected void startup() throws InterruptedException {
// Handle IoT Jobs cancellation

if (currentDeploymentTaskMetadata != null && currentDeploymentTaskMetadata.getDeploymentType()
.equals(nextDeployment.getDeploymentType())
&& currentDeploymentTaskMetadata.isCancellable()) {
.equals(nextDeployment.getDeploymentType())) {
// Cancel the current deployment if it's an IoT Jobs deployment
// that is in progress and still cancellable.
logger.atInfo().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId())
Expand All @@ -238,8 +237,7 @@ protected void startup() throws InterruptedException {
.log("Canceling current deployment");
// Send interrupt signal to the deployment task.
cancelCurrentDeployment();
} else if (currentDeploymentTaskMetadata != null
&& !currentDeploymentTaskMetadata.isCancellable()) {
} else if (currentDeploymentTaskMetadata != null) {
// Ignore the cancelling signal if the deployment is NOT cancellable any more.
logger.atInfo().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId())
.kv(GG_DEPLOYMENT_ID_LOG_KEY_NAME,
Expand Down Expand Up @@ -500,22 +498,23 @@ private void cleanupGroupData(Topics deploymentGroupTopics, Topics groupLastDepl
private void cancelCurrentDeployment() {
if (currentDeploymentTaskMetadata.getDeploymentResultFuture() != null && !currentDeploymentTaskMetadata
.getDeploymentResultFuture().isCancelled()) {
if (currentDeploymentTaskMetadata.getDeploymentResultFuture().isDone() || !currentDeploymentTaskMetadata
.isCancellable()) {
if (currentDeploymentTaskMetadata.getDeploymentResultFuture().isDone()) {
logger.atInfo().log("Deployment already finished processing or cannot be cancelled");
} else {
boolean canCancelDeploymentUpdateAction = context.get(UpdateSystemPolicyService.class)
.discardPendingUpdateAction(((DefaultDeploymentTask) currentDeploymentTaskMetadata
.getDeploymentTask()).getDeployment().getGreengrassDeploymentId());
if (!canCancelDeploymentUpdateAction) {
logger.atWarn().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId())
.kv(GG_DEPLOYMENT_ID_LOG_KEY_NAME,
currentDeploymentTaskMetadata.getGreengrassDeploymentId())
.log("Cancelling deployment, changes may already have been applied. "
+ "Make a new deployment to revert the update");
DeploymentTask deploymentTask = currentDeploymentTaskMetadata.getDeploymentTask();
if (deploymentTask instanceof DefaultDeploymentTask) {
DefaultDeploymentTask defaultDeploymentTask = (DefaultDeploymentTask) deploymentTask;
context.get(UpdateSystemPolicyService.class)
.discardPendingUpdateAction(defaultDeploymentTask.getDeployment()
.getGreengrassDeploymentId());
}
logger.atWarn().kv(DEPLOYMENT_ID_LOG_KEY_NAME, currentDeploymentTaskMetadata.getDeploymentId())
.kv(GG_DEPLOYMENT_ID_LOG_KEY_NAME,
currentDeploymentTaskMetadata.getGreengrassDeploymentId())
.log("Cancelling deployment, changes may already have been applied. "
+ "Make a new deployment to revert the update");

currentDeploymentTaskMetadata.getDeploymentResultFuture().cancel(true);
currentDeploymentTaskMetadata.cancel(true);
DeploymentType deploymentType = currentDeploymentTaskMetadata.getDeploymentType();
if (DeploymentType.SHADOW.equals(deploymentType) || DeploymentType.LOCAL.equals(deploymentType)) {
deploymentStatusKeeper.persistAndPublishDeploymentStatus(
Expand All @@ -539,12 +538,10 @@ private void createNewDeployment(Deployment deployment) {
.log("Received deployment in the queue");

DeploymentTask deploymentTask;
boolean cancellable = true;
if (DEFAULT.equals(deployment.getDeploymentStage())) {
deploymentTask = createDefaultNewDeployment(deployment);
} else {
deploymentTask = createKernelUpdateDeployment(deployment);
cancellable = false;
if (DeploymentType.IOT_JOBS.equals(deployment.getDeploymentType())) {
// Keep track of IoT jobs for de-duplication
IotJobsHelper.getLatestQueuedJobs().addProcessedJob(deployment.getId());
Expand Down Expand Up @@ -633,8 +630,7 @@ private void createNewDeployment(Deployment deployment) {
logger.atInfo().kv("deployment", deployment.getId()).log("Started deployment execution");

currentDeploymentTaskMetadata =
new DeploymentTaskMetadata(deployment, deploymentTask, process, new AtomicInteger(1),
cancellable);
new DeploymentTaskMetadata(deployment, deploymentTask, process, new AtomicInteger(1));
}

/*
Expand Down Expand Up @@ -701,7 +697,7 @@ private void updateDeploymentResultAsRejected(Deployment deployment, DeploymentT
CompletableFuture<DeploymentResult> process = CompletableFuture.completedFuture(result);

currentDeploymentTaskMetadata =
new DeploymentTaskMetadata(deployment, deploymentTask, process, new AtomicInteger(1), false);
new DeploymentTaskMetadata(deployment, deploymentTask, process, new AtomicInteger(1));
}

private void updateDeploymentResultAsFailed(Deployment deployment, DeploymentTask deploymentTask,
Expand All @@ -715,7 +711,7 @@ private void updateDeploymentResultAsFailed(Deployment deployment, DeploymentTas
process = CompletableFuture.completedFuture(result);
}
currentDeploymentTaskMetadata =
new DeploymentTaskMetadata(deployment, deploymentTask, process, new AtomicInteger(1), false);
new DeploymentTaskMetadata(deployment, deploymentTask, process, new AtomicInteger(1));
}

private void updateStatusDetailsFromException(Map<String, Object> statusDetails, Throwable failureCause,
Expand Down
Loading

0 comments on commit 7cca606

Please sign in to comment.