in src/main/java/com/awslabs/aws/greengrass/provisioner/implementations/helpers/BasicGreengrassHelper.java [262:342]
public String createFunctionDefinitionVersion(Set<Function> functions, FunctionIsolationMode defaultFunctionIsolationMode) {
functions = functions.stream()
.filter(this::notGgIpDetector)
.collect(Collectors.toSet());
ImmutableSet<Function> allFunctions = ImmutableSet.<Function>builder()
.addAll(functions)
.add(ggConstants.getGgIpDetectorFunction())
.build();
FunctionDefinitionVersion.Builder functionDefinitionVersionBuilder = FunctionDefinitionVersion.builder();
// Separate out the functions:
// - Functions that specify an isolation mode
// - Functions that don't specify an isolation mode
// - Functions that specify an isolation mode of NoContainer
Set<Function> functionsWithIsolationModeSpecified = allFunctions.stream()
.filter(function -> function.functionConfiguration().environment() != null)
.filter(function -> function.functionConfiguration().environment().execution() != null)
.filter(function -> function.functionConfiguration().environment().execution().isolationMode() != null)
.collect(Collectors.toSet());
Set<Function> functionsWithoutIsolationModeSpecified = allFunctions.stream()
.filter(function -> !functionsWithIsolationModeSpecified.contains(function))
.collect(Collectors.toSet());
Set<Function> functionsWithNoContainer = functionsWithIsolationModeSpecified.stream()
.filter(function -> function.functionConfiguration().environment().execution().isolationMode().equals(FunctionIsolationMode.NO_CONTAINER))
.collect(Collectors.toSet());
// Always scrub functions with the NoContainer isolation mode
ImmutableSet.Builder<Function> functionsToScrubBuilder = ImmutableSet.builder();
functionsToScrubBuilder.addAll(functionsWithNoContainer);
if (defaultFunctionIsolationMode.equals(FunctionIsolationMode.NO_CONTAINER)) {
log.warn("Default isolation mode is no container");
// Scrub all functions without an isolation mode specified
functionsToScrubBuilder.addAll(functionsWithoutIsolationModeSpecified);
} else {
log.info("Default isolation mode is Greengrass container");
}
functionDefinitionVersionBuilder.defaultConfig(
FunctionDefaultConfig.builder()
.execution(FunctionDefaultExecutionConfig.builder()
.isolationMode(defaultFunctionIsolationMode)
.build())
.build());
// Get the list of functions we need to scrub
Set<Function> functionsToScrub = functionsToScrubBuilder.build();
// Get the list of functions we don't need to scrub
Set<Function> nonScrubbedFunctions = allFunctions.stream()
.filter(function -> !functionsToScrub.contains(function))
.collect(Collectors.toSet());
// Scrub the necessary functions
Set<Function> scrubbedFunctions = functionsToScrub.stream()
.map(this::scrubFunctionForNoContainer)
.collect(Collectors.toSet());
// Merge the functions back together (scrubbed functions and the functions we don't need to scrub)
allFunctions = ImmutableSet.<Function>builder()
.addAll(scrubbedFunctions)
.addAll(nonScrubbedFunctions)
.build();
functionDefinitionVersionBuilder.functions(allFunctions);
CreateFunctionDefinitionRequest createFunctionDefinitionRequest = CreateFunctionDefinitionRequest.builder()
.name(DEFAULT)
.initialVersion(functionDefinitionVersionBuilder.build())
.build();
CreateFunctionDefinitionResponse createFunctionDefinitionResponse = greengrassClient.createFunctionDefinition(createFunctionDefinitionRequest);
return createFunctionDefinitionResponse.latestVersionArn();
}