forked from michaelmosmann/embedmongo.flapdoodle.de
-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c14f954
commit beddf46
Showing
4 changed files
with
291 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
215 changes: 215 additions & 0 deletions
215
src/main/java/de/flapdoodle/embed/mongo/packageresolver/linux/AmazonPackageResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
package de.flapdoodle.embed.mongo.packageresolver.linux; | ||
|
||
import de.flapdoodle.embed.mongo.Command; | ||
import de.flapdoodle.embed.mongo.packageresolver.*; | ||
import de.flapdoodle.embed.process.config.store.DistributionPackage; | ||
import de.flapdoodle.embed.process.config.store.FileSet; | ||
import de.flapdoodle.embed.process.config.store.FileType; | ||
import de.flapdoodle.embed.process.config.store.ImmutableFileSet; | ||
import de.flapdoodle.embed.process.distribution.ArchiveType; | ||
import de.flapdoodle.embed.process.distribution.Distribution; | ||
import de.flapdoodle.os.BitSize; | ||
import de.flapdoodle.os.CPUType; | ||
import de.flapdoodle.os.OS; | ||
import de.flapdoodle.os.linux.AmazonVersion; | ||
|
||
import java.util.Optional; | ||
|
||
public class AmazonPackageResolver implements PackageFinder { | ||
|
||
private final ImmutablePlatformMatchRules rules; | ||
|
||
public AmazonPackageResolver(final Command command) { | ||
this.rules = rules(command); | ||
} | ||
|
||
@Override | ||
public Optional<DistributionPackage> packageFor(final Distribution distribution) { | ||
return rules.packageFor(distribution); | ||
} | ||
|
||
private static ImmutablePlatformMatchRules rules(final Command command) { | ||
final ImmutableFileSet fileSet = FileSet.builder().addEntry(FileType.Executable, command.commandName()).build(); | ||
|
||
/* | ||
* Amazon Linux 2 ARM 64 | ||
* -- | ||
* 4.4.3 - 4.4.0, 4.2.12 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 - 3.6.0, 3.4.23 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0, 2.6.12 - 2.6.0 | ||
* https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-amazon2-{}.tgz | ||
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.4, 4.2.16 - 4.2.13 | ||
*/ | ||
final PlatformMatchRule amazon2Arm = PlatformMatchRule.builder() | ||
.match(DistributionMatch.any( | ||
VersionRange.of("5.0.0", "5.0.2"), | ||
VersionRange.of("4.4.4", "4.4.9"), | ||
VersionRange.of("4.2.13", "4.2.16") | ||
) | ||
.andThen(PlatformMatch | ||
.withOs(OS.Linux) | ||
.withBitSize(BitSize.B64) | ||
.withCpuType(CPUType.ARM) | ||
.withVersion(AmazonVersion.AmazonLinux2) | ||
) | ||
) | ||
.finder(UrlTemplatePackageResolver.builder() | ||
.fileSet(fileSet) | ||
.archiveType(ArchiveType.TGZ) | ||
.urlTemplate("/linux/mongodb-linux-aarch64-amazon2-{version}.tgz") | ||
.build()) | ||
.build(); | ||
|
||
final PlatformMatchRule amazon2ArmTools = PlatformMatchRule.builder() | ||
.match(DistributionMatch.any( | ||
VersionRange.of("5.0.0", "5.0.2"), | ||
VersionRange.of("4.4.4", "4.4.9"), | ||
VersionRange.of("4.2.13", "4.2.16") | ||
) | ||
.andThen(PlatformMatch | ||
.withOs(OS.Linux) | ||
.withBitSize(BitSize.B64) | ||
.withCpuType(CPUType.ARM) | ||
.withVersion(AmazonVersion.AmazonLinux2) | ||
) | ||
) | ||
.finder(UrlTemplatePackageResolver.builder() | ||
.fileSet(fileSet) | ||
.archiveType(ArchiveType.TGZ) | ||
.urlTemplate("/tools/db/mongodb-database-tools-amazon2-arm64-{tools.version}.tgz") | ||
.build()) | ||
.build(); | ||
|
||
/* | ||
* Amazon Linux 2 x64 | ||
* -- | ||
* 4.2.4 - 4.2.4, 3.6.21 - 3.6.0, 3.4.23 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0, 2.6.12 - 2.6.0 | ||
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon2-{}.tgz | ||
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 | ||
*/ | ||
final PlatformMatchRule amazon2 = PlatformMatchRule.builder() | ||
.match(DistributionMatch.any( | ||
VersionRange.of("5.0.0", "5.0.2"), | ||
VersionRange.of("4.4.0", "4.4.9"), | ||
VersionRange.of("4.2.5", "4.2.16"), | ||
VersionRange.of("4.2.0", "4.2.3"), | ||
VersionRange.of("4.0.0", "4.0.26"), | ||
VersionRange.of("3.6.22", "3.6.22") | ||
) | ||
.andThen(PlatformMatch | ||
.withOs(OS.Linux) | ||
.withBitSize(BitSize.B64) | ||
.withCpuType(CPUType.X86) | ||
.withVersion(AmazonVersion.AmazonLinux2) | ||
) | ||
) | ||
.finder(UrlTemplatePackageResolver.builder() | ||
.fileSet(fileSet) | ||
.archiveType(ArchiveType.TGZ) | ||
.urlTemplate("/linux/mongodb-linux-x86_64-amazon2-{version}.tgz") | ||
.build()) | ||
.build(); | ||
|
||
final PlatformMatchRule amazon2tools = PlatformMatchRule.builder() | ||
.match(DistributionMatch.any( | ||
VersionRange.of("5.0.0", "5.0.2"), | ||
VersionRange.of("4.4.0", "4.4.9"), | ||
VersionRange.of("4.2.5", "4.2.16"), | ||
VersionRange.of("4.2.0", "4.2.3"), | ||
VersionRange.of("4.0.0", "4.0.26"), | ||
VersionRange.of("3.6.22", "3.6.22") | ||
) | ||
.andThen(PlatformMatch | ||
.withOs(OS.Linux) | ||
.withBitSize(BitSize.B64) | ||
.withCpuType(CPUType.X86) | ||
.withVersion(AmazonVersion.AmazonLinux2) | ||
) | ||
) | ||
.finder(UrlTemplatePackageResolver.builder() | ||
.fileSet(fileSet) | ||
.archiveType(ArchiveType.TGZ) | ||
.urlTemplate("/tools/db/mongodb-database-tools-amazon2-x86_64-{tools.version}.tgz") | ||
.build()) | ||
.build(); | ||
|
||
|
||
/* | ||
* Amazon Linux x64 | ||
* -- | ||
* 4.2.4 - 4.2.4, 3.4.8 - 3.4.8, 2.6.12 - 2.6.0 | ||
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-{}.tgz | ||
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 - 3.6.0, 3.4.23 - 3.4.9, 3.4.7 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0 | ||
*/ | ||
final PlatformMatchRule amazon = PlatformMatchRule.builder() | ||
.match(DistributionMatch.any( | ||
VersionRange.of("5.0.0", "5.0.2"), | ||
VersionRange.of("4.4.0", "4.4.9"), | ||
VersionRange.of("4.2.5", "4.2.16"), | ||
VersionRange.of("4.2.0", "4.2.3"), | ||
VersionRange.of("4.0.0", "4.0.26"), | ||
VersionRange.of("3.6.0", "3.6.22"), | ||
VersionRange.of("3.4.9", "3.4.23"), | ||
VersionRange.of("3.4.0", "3.4.7"), | ||
VersionRange.of("3.2.0", "3.2.21"), | ||
VersionRange.of("3.0.0", "3.0.14") | ||
) | ||
.andThen(PlatformMatch | ||
.withOs(OS.Linux) | ||
.withBitSize(BitSize.B64) | ||
.withCpuType(CPUType.X86) | ||
.withVersion(AmazonVersion.AmazonLinux) | ||
) | ||
) | ||
.finder(UrlTemplatePackageResolver.builder() | ||
.fileSet(fileSet) | ||
.archiveType(ArchiveType.TGZ) | ||
.urlTemplate("/linux/mongodb-linux-x86_64-amazon-{version}.tgz") | ||
.build()) | ||
.build(); | ||
|
||
final PlatformMatchRule amazontools = PlatformMatchRule.builder() | ||
.match(DistributionMatch.any( | ||
VersionRange.of("5.0.0", "5.0.2"), | ||
VersionRange.of("4.4.0", "4.4.9"), | ||
VersionRange.of("4.2.5", "4.2.16"), | ||
VersionRange.of("4.2.0", "4.2.3"), | ||
VersionRange.of("4.0.0", "4.0.26"), | ||
VersionRange.of("3.6.0", "3.6.22"), | ||
VersionRange.of("3.4.9", "3.4.23"), | ||
VersionRange.of("3.4.0", "3.4.7"), | ||
VersionRange.of("3.2.0", "3.2.21"), | ||
VersionRange.of("3.0.0", "3.0.14") | ||
) | ||
.andThen(PlatformMatch | ||
.withOs(OS.Linux) | ||
.withBitSize(BitSize.B64) | ||
.withCpuType(CPUType.X86) | ||
.withVersion(AmazonVersion.AmazonLinux) | ||
) | ||
) | ||
.finder(UrlTemplatePackageResolver.builder() | ||
.fileSet(fileSet) | ||
.archiveType(ArchiveType.TGZ) | ||
.urlTemplate("/tools/db/mongodb-database-tools-amazon-x86_64-{tools.version}.tgz") | ||
.build()) | ||
.build(); | ||
|
||
switch (command) { | ||
case MongoDump: | ||
case MongoImport: | ||
case MongoRestore: | ||
return PlatformMatchRules.empty() | ||
.withRules( | ||
amazon2ArmTools, | ||
amazon2tools, | ||
amazontools | ||
); | ||
default: | ||
return PlatformMatchRules.empty() | ||
.withRules( | ||
amazon2Arm, | ||
amazon2, | ||
amazon | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/test/java/de/flapdoodle/embed/mongo/packageresolver/linux/AmazonPackageResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.flapdoodle.embed.mongo.packageresolver.linux; | ||
|
||
import de.flapdoodle.embed.mongo.Command; | ||
import de.flapdoodle.embed.mongo.packageresolver.HtmlParserResultTester; | ||
import de.flapdoodle.embed.process.distribution.Distribution; | ||
import de.flapdoodle.embed.process.distribution.Version; | ||
import de.flapdoodle.os.CommonArchitecture; | ||
import de.flapdoodle.os.ImmutablePlatform; | ||
import de.flapdoodle.os.OS; | ||
import de.flapdoodle.os.Platform; | ||
import de.flapdoodle.os.linux.AmazonVersion; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class AmazonPackageResolverTest { | ||
/* | ||
* Amazon Linux 2 ARM 64 | ||
* https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-amazon2-{}.tgz | ||
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.4, 4.2.16 - 4.2.13 | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(strings = {"5.0.2 - 5.0.0", "4.4.9 - 4.4.4", "4.2.16 - 4.2.13"}) | ||
public void amazon2LinuxArm(String version) { | ||
assertThat(linuxWith(CommonArchitecture.ARM_64, AmazonVersion.AmazonLinux2), version) | ||
.resolvesTo("/linux/mongodb-linux-aarch64-amazon2-{}.tgz"); | ||
} | ||
|
||
/* | ||
* Amazon Linux 2 x64 | ||
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon2-{}.tgz | ||
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(strings = {"5.0.2 - 5.0.0", "4.4.9 - 4.4.0", "4.2.16 - 4.2.5", "4.2.3 - 4.2.0", "4.0.26 - 4.0.0", "3.6.22"}) | ||
public void amazon2Linux(String version) { | ||
assertThat(linuxWith(CommonArchitecture.X86_64, AmazonVersion.AmazonLinux2), version) | ||
.resolvesTo("/linux/mongodb-linux-x86_64-amazon2-{}.tgz"); | ||
} | ||
|
||
/* | ||
* Amazon Linux x64 | ||
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-{}.tgz | ||
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 - 3.6.0, 3.4.23 - 3.4.9, 3.4.7 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0 | ||
*/ | ||
@ParameterizedTest | ||
@ValueSource(strings = {"5.0.2 - 5.0.0", "4.4.9 - 4.4.0", "4.2.16 - 4.2.5", "4.2.3 - 4.2.0", "4.0.26 - 4.0.0", "3.6.22 - 3.6.0", "3.4.23 - 3.4.9", "3.4.7 - 3.4.0", "3.2.21 - 3.2.0", "3.0.14 - 3.0.0"}) | ||
public void amazonLinux(String version) { | ||
assertThat(linuxWith(CommonArchitecture.X86_64, AmazonVersion.AmazonLinux), version) | ||
.resolvesTo("/linux/mongodb-linux-x86_64-amazon-{}.tgz"); | ||
} | ||
|
||
private static Platform linuxWith(CommonArchitecture architecture, de.flapdoodle.os.Version version) { | ||
return ImmutablePlatform.builder() | ||
.operatingSystem(OS.Linux) | ||
.architecture(architecture) | ||
.version(version) | ||
.build(); | ||
} | ||
|
||
private static HtmlParserResultTester assertThat(Platform platform, String versionList) { | ||
return HtmlParserResultTester.with( | ||
new AmazonPackageResolver(Command.Mongo), | ||
version -> Distribution.of(Version.of(version), platform), | ||
versionList); | ||
} | ||
|
||
} |