Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDombo authored Oct 20, 2022
2 parents a4d5414 + 9aa7c12 commit 271016f
Show file tree
Hide file tree
Showing 11 changed files with 475 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.1</version>
<version>2.13.4.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.13.2</version>
<version>2.13.4</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"deploymentId": "TestSimpleApp",
"configurationArn": "Test",
"components": {
"SimpleApp": {
"version": "1.0.0"
},
"GreenSignal": {
"version": "1.0.0"
}
},
"creationTimestamp": 1601276785085,
"failureHandlingPolicy": "ROLLBACK",
"componentUpdatePolicy": {
"timeout": 60,
"action": "NOTIFY_COMPONENTS"
},
"configurationValidationPolicy": {
"timeout": 60
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"deploymentId": "TestSimpleApp2",
"configurationArn": "Test",
"components": {
"SimpleApp": {
"version": "3.0.0"
}
},
"creationTimestamp": 1601276785085,
"failureHandlingPolicy": "ROLLBACK",
"componentUpdatePolicy": {
"timeout": 60,
"action": "NOTIFY_COMPONENTS"
},
"configurationValidationPolicy": {
"timeout": 60
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public void persistLastSuccessfulDeployment() {
private void persistPointerToLastFinishedDeployment(Path symlink) {
logger.atInfo().kv(LINK_LOG_KEY, symlink).log("Persist link to last deployment");
try {
Path deploymentPath = getDeploymentDirectoryPath();
cleanupPreviousDeployments(previousSuccessDir);
cleanupPreviousDeployments(previousFailureDir);

Path deploymentPath = getDeploymentDirectoryPath();
Files.createSymbolicLink(symlink, deploymentPath);
Files.delete(ongoingDir);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ public static DeploymentDocument convertFromDeploymentConfiguration(Configuratio
.deploymentId(config.getDeploymentId())
.requiredCapabilities(config.getRequiredCapabilities())
.deploymentPackageConfigurationList(convertComponents(config.getComponents()))
.groupName(parseGroupNameFromConfigurationArn(config)).timestamp(config.getCreationTimestamp());
.groupName(parseGroupNameFromConfigurationArn(config))
.timestamp(config.getCreationTimestamp());

convertThingGroupArns(builder, config);

if (config.getFailureHandlingPolicy() == null) {
// FailureHandlingPolicy should be provided per contract with CreateDeployment API.
// However if it is not, device could proceed with default for resilience.
Expand Down Expand Up @@ -201,6 +205,36 @@ private static String parseGroupNameFromConfigurationArn(Configuration config) {
return groupName;
}

@SuppressWarnings("PMD.PreserveStackTrace")
private static void convertThingGroupArns(DeploymentDocument.DeploymentDocumentBuilder deployDocBuilder,
Configuration config) throws InvalidRequestException {
if (Utils.isNotEmpty(config.getOnBehalfOf())) {
try {
// IoT thingGroupArn only gives thing group name without 'thinggroup/' prefix
String groupName = Arn.fromString(config.getOnBehalfOf()).resource().resource();
if (groupName != null) {
groupName = new StringBuilder(THING_GROUP_RESOURCE_NAME_PREFIX).append(groupName).toString();
}
deployDocBuilder.onBehalfOf(groupName);
} catch (IllegalArgumentException e) {
throw new InvalidRequestException("Malformed value for 'onBehalfOf' in deployment config.");
}
}

if (Utils.isNotEmpty(config.getParentTargetArn())) {
try {
// IoT thingGroupArn only gives thing group name without 'thinggroup/' prefix
String groupName = Arn.fromString(config.getParentTargetArn()).resource().resource();
if (groupName != null) {
groupName = new StringBuilder(THING_GROUP_RESOURCE_NAME_PREFIX).append(groupName).toString();
}
deployDocBuilder.parentGroupName(groupName);
} catch (IllegalArgumentException e) {
throw new InvalidRequestException("Malformed value for 'parentTargetArn' in deployment config.");
}
}
}

private static List<DeploymentPackageConfiguration> convertComponents(
@Nullable Map<String, ComponentUpdate> components) throws InvalidRequestException {
if (components == null || components.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package com.aws.greengrass.deployment.model;

import com.aws.greengrass.util.Utils;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
Expand Down Expand Up @@ -63,6 +65,12 @@ public class DeploymentDocument {
@JsonProperty("GroupName")
private String groupName;

@JsonProperty("OnBehalfOf")
private String onBehalfOf;

@JsonProperty("ParentGroupName")
private String parentGroupName;

@Setter
@JsonProperty("Timestamp")
private Long timestamp;
Expand All @@ -82,6 +90,17 @@ public class DeploymentDocument {
private DeploymentConfigurationValidationPolicy configurationValidationPolicy =
DeploymentConfigurationValidationPolicy.builder().build();


/**
* For sub-group deployments root group name is used otherwise group name.
*
* @return if available root group name, otherwise group name
*/
@JsonGetter("GroupName")
public String getGroupName() {
return Utils.isEmpty(onBehalfOf) ? groupName : onBehalfOf;
}

/**
* Get a list of root component names from the deploymentPackageConfigurationList.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public class Kernel {
YAMLMapper.builder().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET).build();
private static final List<String> SUPPORTED_CAPABILITIES =
Arrays.asList(DeploymentCapability.LARGE_CONFIGURATION.toString(),
DeploymentCapability.LINUX_RESOURCE_LIMITS.toString());
DeploymentCapability.LINUX_RESOURCE_LIMITS.toString(),
DeploymentCapability.SUBGROUP_DEPLOYMENTS.toString());

@Getter
private final Context context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,50 @@ public UnixRunWithGenerator getRunWithGenerator() {

@Override
public void createUser(String user) throws IOException {
runCmd("useradd -r -m " + user, o -> {
}, "Failed to create user");
try {
runCmd("useradd -r -m " + user, o -> {
}, "Failed to create user with useradd");
} catch (IOException e) {
try {
runCmd("adduser -S " + user, l -> {
}, "Failed to create user with adduser");
} catch (IOException ee) {
e.addSuppressed(ee);
throw e;
}
}
}

@Override
public void createGroup(String group) throws IOException {
runCmd("groupadd -r " + group, o -> {
}, "Failed to create group");
try {
runCmd("groupadd -r " + group, o -> {
}, "Failed to create group with groupadd");
} catch (IOException e) {
try {
runCmd("addgroup -S " + group, l -> {
}, "Failed to create group with addgroup");
} catch (IOException ee) {
e.addSuppressed(ee);
throw e;
}
}
}

@Override
public void addUserToGroup(String user, String group) throws IOException {
runCmd("usermod -a -G " + group + " " + user, o -> {
}, "Failed to add user to group");
try {
runCmd("usermod -a -G " + group + " " + user, o -> {
}, "Failed to add user to group with usermod");
} catch (IOException e) {
try {
runCmd("addgroup " + user + " " + group, l -> {
}, "Failed to add user to group with addgroup");
} catch (IOException ee) {
e.addSuppressed(ee);
throw e;
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract static class DRIntegration {
private final DeploymentDocument jobDoc = new DeploymentDocument("mockJob1", "mockarn",
Arrays.asList(new DeploymentPackageConfiguration("boto3", true, "1.9.128"),
new DeploymentPackageConfiguration("awscli", true, "1.16.144")), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, new ComponentUpdatePolicy(60, NOTIFY_COMPONENTS),
"mockGroup1", null, null, 1L, FailureHandlingPolicy.DO_NOTHING, new ComponentUpdatePolicy(60, NOTIFY_COMPONENTS),
DeploymentConfigurationValidationPolicy.builder().timeoutInSeconds(20).build());

private DependencyResolver resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void GIVEN_circular_dependency_for_root_component_WHEN_resolve_dependency_called
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1", Collections
.singletonList(
new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);

context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));

Expand Down Expand Up @@ -209,7 +209,7 @@ void GIVEN_circular_dependency_for_non_root_component_WHEN_resolve_dependency_ca
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1", Collections
.singletonList(
new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);

context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));

Expand Down Expand Up @@ -305,7 +305,7 @@ void GIVEN_component_B_WHEN_version_is_bumped_up_from_1_to_2_THEN_dependencies_o
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1", Collections
.singletonList(
new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);

context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));

Expand Down Expand Up @@ -363,7 +363,7 @@ void GIVEN_component_A_WHEN_resolve_dependencies_THEN_resolve_A_and_dependency_v
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1", Collections
.singletonList(
new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);

context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));

Expand Down Expand Up @@ -440,7 +440,7 @@ void GIVEN_component_C_WHEN_both_version_constrains_are_evaluated_THEN_C_2_is_se
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1", Collections
.singletonList(
new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);

groupToTargetComponentsTopics.lookupTopics("mockGroup1").lookupTopics(componentA)
.replaceAndWait(ImmutableMap.of(GROUP_TO_ROOT_COMPONENTS_VERSION_KEY, "1.0.0"));
Expand Down Expand Up @@ -510,7 +510,7 @@ void GIVEN_component_A_B2_WHEN_dependencies_overlap_THEN_satisfy_both() throws E
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1",
Arrays.asList(new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue()),
new DeploymentPackageConfiguration(componentB2, true, v1_1_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);

context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));
List<ComponentIdentifier> result = dependencyResolver.resolveDependencies(doc, new HashMap<>());
Expand Down Expand Up @@ -590,7 +590,7 @@ void GIVEN_component_A_B2_WHEN_dependencies_conflict_THEN_throws_no_available_ve
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1",
Arrays.asList(new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue()),
new DeploymentPackageConfiguration(componentB2, true, v1_1_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);

context.runOnPublishQueueAndWait(() -> System.out.println("Waiting for queue to finish updating the config"));
assertThrows(NoAvailableComponentVersionException.class,
Expand Down Expand Up @@ -660,7 +660,7 @@ void GIVEN_other_group_have_same_dependency_WHEN_deploy_current_group_THEN_resol
DeploymentDocument doc = new DeploymentDocument("mockId","mockJob1",
Arrays.asList(new DeploymentPackageConfiguration(componentA, true, v1_0_0.getValue()),
new DeploymentPackageConfiguration(componentB2, true, v1_1_0.getValue())), Collections.emptyList(),
"mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);
"mockGroup1", "mockGroup1", "mockGroup1", 1L, FailureHandlingPolicy.DO_NOTHING, componentUpdatePolicy, configurationValidationPolicy);


Map<String, Set<ComponentRequirementIdentifier>> otherGroupRootPackages = new HashMap<>();
Expand Down

0 comments on commit 271016f

Please sign in to comment.