From f8206da9236cde2a29383a2c3b97ea2980c40a0a Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Thu, 22 Oct 2020 17:29:33 -0700 Subject: [PATCH] clean the stale code --- build.gradle | 8 - integ-test/build.gradle | 103 ----- .../main/java/com/amazon/aocagent/App.java | 52 --- .../amazon/aocagent/commands/Candidate.java | 65 ---- .../aocagent/commands/CommonOption.java | 143 ------- .../amazon/aocagent/commands/IntegTest.java | 75 ---- .../com/amazon/aocagent/commands/Release.java | 43 --- .../aocagent/commands/ResourceClean.java | 42 -- .../com/amazon/aocagent/commands/Setup.java | 91 ----- .../amazon/aocagent/enums/Architecture.java | 22 -- .../aocagent/enums/GenericConstants.java | 113 ------ .../amazon/aocagent/enums/LocalPackage.java | 56 --- .../com/amazon/aocagent/enums/OSType.java | 24 -- .../com/amazon/aocagent/enums/OTConfig.java | 30 -- .../amazon/aocagent/enums/PackageType.java | 25 -- .../com/amazon/aocagent/enums/S3Package.java | 72 ---- .../enums/SupportedOSDistribution.java | 27 -- .../com/amazon/aocagent/enums/TestAMI.java | 83 ---- .../com/amazon/aocagent/enums/TestCase.java | 82 ---- .../aocagent/exception/BaseException.java | 34 -- .../aocagent/exception/ExceptionCode.java | 75 ---- .../fileconfigs/ECSTaskDefTemplate.java | 31 -- .../fileconfigs/EksKubeConfigTemplate.java | 30 -- .../EksSidecarManifestTemplate.java | 28 -- .../aocagent/fileconfigs/ExpectedMetric.java | 30 -- .../aocagent/fileconfigs/ExpectedTrace.java | 31 -- .../aocagent/fileconfigs/FileConfig.java | 28 -- .../amazon/aocagent/fileconfigs/OTConfig.java | 30 -- .../helpers/CommandExecutionHelper.java | 161 -------- .../EKSTestOptionsValidationHelper.java | 132 ------- .../aocagent/helpers/MustacheHelper.java | 53 --- .../com/amazon/aocagent/helpers/OSHelper.java | 47 --- .../amazon/aocagent/helpers/RetryHelper.java | 74 ---- .../amazon/aocagent/helpers/Retryable.java | 20 - .../amazon/aocagent/helpers/SSHHelper.java | 142 ------- .../aocagent/helpers/TempDirHelper.java | 99 ----- .../emiterinstallers/OTEmitterInstaller.java | 28 -- .../OTMetricAndTraceEmitterInstaller.java | 117 ------ .../installers/otinstallers/ECSInstaller.java | 95 ----- .../installers/otinstallers/EKSInstaller.java | 90 ----- .../installers/otinstallers/OTInstaller.java | 34 -- .../otinstallers/OTPackageInstaller.java | 127 ------ .../otinstallers/SsmOTPackageInstaller.java | 118 ------ .../com/amazon/aocagent/models/Context.java | 105 ----- .../aocagent/models/EC2InstanceParams.java | 35 -- .../com/amazon/aocagent/models/Stack.java | 28 -- .../aocagent/models/TraceFromEmitter.java | 27 -- .../aocagent/services/AwsNetworkService.java | 71 ---- .../aocagent/services/CloudWatchService.java | 54 --- .../amazon/aocagent/services/EC2Service.java | 364 ------------------ .../amazon/aocagent/services/ECSService.java | 237 ------------ .../amazon/aocagent/services/EKSService.java | 50 --- .../amazon/aocagent/services/IAMService.java | 111 ------ .../amazon/aocagent/services/S3Service.java | 158 -------- .../amazon/aocagent/services/SSMService.java | 164 -------- .../amazon/aocagent/services/XRayService.java | 44 --- .../aocagent/tasks/DownloadCandidate.java | 75 ---- .../com/amazon/aocagent/tasks/EC2Clean.java | 84 ---- .../com/amazon/aocagent/tasks/ECSClean.java | 88 ----- .../com/amazon/aocagent/tasks/EKSClean.java | 93 ----- .../java/com/amazon/aocagent/tasks/ITask.java | 28 -- .../com/amazon/aocagent/tasks/IntegTest.java | 82 ---- .../aocagent/tasks/IntegTestFactory.java | 45 --- .../com/amazon/aocagent/tasks/S3Release.java | 118 ------ .../java/com/amazon/aocagent/tasks/Setup.java | 97 ----- .../amazon/aocagent/tasks/TaskFactory.java | 39 -- .../aocagent/tasks/UploadCandidate.java | 55 --- .../aocagent/testamis/A1AmazonLinuxAMI.java | 29 -- .../amazon/aocagent/testamis/A1RedHatAMI.java | 29 -- .../amazon/aocagent/testamis/A1SuseAMI.java | 29 -- .../amazon/aocagent/testamis/A1UbuntuAMI.java | 29 -- .../aocagent/testamis/AmazonLinuxAMI.java | 34 -- .../amazon/aocagent/testamis/Centos6AMI.java | 28 -- .../amazon/aocagent/testamis/CentosAMI.java | 35 -- .../amazon/aocagent/testamis/DebianAMI.java | 47 --- .../aocagent/testamis/EcsOptimizedAMI.java | 41 -- .../amazon/aocagent/testamis/ITestAMI.java | 54 --- .../amazon/aocagent/testamis/LinuxAMI.java | 120 ------ .../amazon/aocagent/testamis/RedHat6AMI.java | 28 -- .../amazon/aocagent/testamis/RedHatAMI.java | 34 -- .../com/amazon/aocagent/testamis/SuseAMI.java | 37 -- .../amazon/aocagent/testamis/UbuntuAMI.java | 37 -- .../amazon/aocagent/testamis/WindowsAMI.java | 111 ------ .../amazon/aocagent/testbeds/EC2TestBed.java | 96 ----- .../amazon/aocagent/testbeds/ECSTestBed.java | 136 ------- .../amazon/aocagent/testbeds/EKSTestBed.java | 39 -- .../com/amazon/aocagent/testbeds/TestBed.java | 24 -- .../aocagent/validators/BatchedValidator.java | 49 --- .../aocagent/validators/IValidator.java | 24 -- .../aocagent/validators/MetricValidator.java | 206 ---------- .../aocagent/validators/TraceValidator.java | 136 ------- integ-test/src/main/resources/checkstyle.xml | 333 ---------------- integ-test/src/main/resources/log4j2.xml | 13 - .../templates/config/defaultOTConfig.mustache | 29 -- .../templates/ecs/aoc-sidecar-ec2.mustache | 82 ---- .../ecs/aoc-sidecar-fargate.mustache | 81 ---- .../templates/eks/aoc-eks-sidecar.mustache | 53 --- .../templates/eks/kubeConfig.mustache | 24 -- .../validation/defaultExpectedMetric.mustache | 50 --- .../validation/defaultExpectedTrace.mustache | 8 - .../java/com/amazon/aocagent/AppTest.java | 28 -- .../aocagent/helpers/MustacheHelperTest.java | 44 --- .../validators/MetricMetricValidatorTest.java | 41 -- integ-test/src/test/resources/test.mustache | 1 - sample-apps/README.md | 1 - settings.gradle | 4 +- src/*.java.new | 14 - .../otel/collector/test/framework/App.java | 28 -- .../collector/test/framework/AppTest.java | 28 -- 109 files changed, 1 insertion(+), 7355 deletions(-) delete mode 100644 integ-test/build.gradle delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/App.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/commands/Candidate.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/commands/CommonOption.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/commands/IntegTest.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/commands/Release.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/commands/ResourceClean.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/commands/Setup.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/Architecture.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/GenericConstants.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/LocalPackage.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/OSType.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/OTConfig.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/PackageType.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/S3Package.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/SupportedOSDistribution.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/TestAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/enums/TestCase.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/exception/BaseException.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/exception/ExceptionCode.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ECSTaskDefTemplate.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksKubeConfigTemplate.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksSidecarManifestTemplate.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedMetric.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedTrace.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/fileconfigs/FileConfig.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/fileconfigs/OTConfig.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/CommandExecutionHelper.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/EKSTestOptionsValidationHelper.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/MustacheHelper.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/OSHelper.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/RetryHelper.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/Retryable.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/SSHHelper.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/helpers/TempDirHelper.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTEmitterInstaller.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTMetricAndTraceEmitterInstaller.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/ECSInstaller.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/EKSInstaller.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTInstaller.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTPackageInstaller.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/SsmOTPackageInstaller.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/models/Context.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/models/EC2InstanceParams.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/models/Stack.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/models/TraceFromEmitter.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/AwsNetworkService.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/CloudWatchService.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/EC2Service.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/ECSService.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/EKSService.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/IAMService.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/S3Service.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/SSMService.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/services/XRayService.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/DownloadCandidate.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/EC2Clean.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/ECSClean.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/EKSClean.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/ITask.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTest.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTestFactory.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/S3Release.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/Setup.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/TaskFactory.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/tasks/UploadCandidate.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/A1AmazonLinuxAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/A1RedHatAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/A1SuseAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/A1UbuntuAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/AmazonLinuxAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/Centos6AMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/CentosAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/DebianAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/EcsOptimizedAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/ITestAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/LinuxAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/RedHat6AMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/RedHatAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/SuseAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/UbuntuAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testamis/WindowsAMI.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testbeds/EC2TestBed.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testbeds/ECSTestBed.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testbeds/EKSTestBed.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/testbeds/TestBed.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/validators/BatchedValidator.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/validators/IValidator.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/validators/MetricValidator.java delete mode 100644 integ-test/src/main/java/com/amazon/aocagent/validators/TraceValidator.java delete mode 100755 integ-test/src/main/resources/checkstyle.xml delete mode 100644 integ-test/src/main/resources/log4j2.xml delete mode 100644 integ-test/src/main/resources/templates/config/defaultOTConfig.mustache delete mode 100644 integ-test/src/main/resources/templates/ecs/aoc-sidecar-ec2.mustache delete mode 100644 integ-test/src/main/resources/templates/ecs/aoc-sidecar-fargate.mustache delete mode 100644 integ-test/src/main/resources/templates/eks/aoc-eks-sidecar.mustache delete mode 100644 integ-test/src/main/resources/templates/eks/kubeConfig.mustache delete mode 100644 integ-test/src/main/resources/templates/validation/defaultExpectedMetric.mustache delete mode 100644 integ-test/src/main/resources/templates/validation/defaultExpectedTrace.mustache delete mode 100644 integ-test/src/test/java/com/amazon/aocagent/AppTest.java delete mode 100644 integ-test/src/test/java/com/amazon/aocagent/helpers/MustacheHelperTest.java delete mode 100644 integ-test/src/test/java/com/amazon/aocagent/validators/MetricMetricValidatorTest.java delete mode 100644 integ-test/src/test/resources/test.mustache delete mode 100644 sample-apps/README.md delete mode 100644 src/*.java.new delete mode 100644 src/main/java/aws/otel/collector/test/framework/App.java delete mode 100644 src/test/java/aws/otel/collector/test/framework/AppTest.java diff --git a/build.gradle b/build.gradle index e53ac5c41..407506476 100644 --- a/build.gradle +++ b/build.gradle @@ -9,9 +9,6 @@ plugins { // Apply the java plugin to add support for Java id 'java' - - // Apply the application plugin to add support for building a CLI application. - id 'application' } repositories { @@ -28,11 +25,6 @@ dependencies { testImplementation 'junit:junit:4.13' } -application { - // Define the main class for the application. - mainClassName = 'aws.otel.collector.test.framework.App' -} - allprojects { repositories { jcenter() diff --git a/integ-test/build.gradle b/integ-test/build.gradle deleted file mode 100644 index 3c6d6baf5..000000000 --- a/integ-test/build.gradle +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * This generated file contains a sample Java project to get you started. - * For more details take a look at the Java Quickstart chapter in the Gradle - * User Manual available at https://docs.gradle.org/6.5/userguide/tutorial_java_projects.html - */ - -plugins { - // Apply the java plugin to add support for Java - id 'java' - - // Apply the application plugin to add support for building a CLI application. - id 'application' - - // lombok - id "io.freefair.lombok" version "5.1.0" - - // check style - id 'checkstyle' - -} - -tasks.withType(Checkstyle) { - checkstyle { - toolVersion '8.33' - configFile = new File(projectDir, "src/main/resources/checkstyle.xml") - maxWarnings = 0 - ignoreFailures = false - } -} - -repositories { - // Use jcenter for resolving dependencies. - // You can declare any Maven/Ivy/file repository here. - jcenter() - - maven { - url "http://dl.bintray.com/steppschuh/Markdown-Generator" - } -} - -dependencies { - // This dependency is used by the application. - implementation 'com.google.guava:guava:29.0-jre' - - // Use JUnit test framework - testImplementation 'junit:junit:4.13' - - // log - compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7' - compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7' - - // command cli - compile 'info.picocli:picocli:4.3.2' - - compileOnly 'info.picocli:picocli-codegen:4.3.2' - - // aws sdk - implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.811') - implementation 'com.amazonaws:aws-java-sdk-s3' - implementation 'com.amazonaws:aws-java-sdk-ec2' - implementation 'com.amazonaws:aws-java-sdk-iam' - implementation 'com.amazonaws:aws-java-sdk-cloudwatch' - implementation 'com.amazonaws:aws-java-sdk-xray' - implementation 'com.amazonaws:aws-java-sdk-ecs' - implementation 'com.amazonaws:aws-java-sdk-eks' - implementation 'com.amazonaws:aws-java-sdk-ssm' - - testCompile group: 'junit', name: 'junit', version: '4.11' - - // ssh - compile group: 'com.jcraft', name: 'jsch', version: '0.1.54' - - // markdown - compile 'net.steppschuh.markdowngenerator:markdowngenerator:1.3.1.1' - - // mustache template - compile group: 'com.github.spullara.mustache.java', name: 'compiler', version: '0.8.9' - - // apache io utils - compile group: 'commons-io', name: 'commons-io', version: '2.4' - - // yaml reader - compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.11.1' - - // zip - implementation 'org.zeroturnaround:zt-zip:1.14' - - // json reader - implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.1' - - -} - -compileJava { - options.compilerArgs += ["-Aproject=${project.group}/${project.name}"] -} - -application { - // Define the main class for the application. - mainClassName = 'com.amazon.aocagent.App' -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/App.java b/integ-test/src/main/java/com/amazon/aocagent/App.java deleted file mode 100644 index 8f7ac9688..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/App.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -/* - * This Java source file was generated by the Gradle 'init' task. - */ - -package com.amazon.aocagent; - -import com.amazon.aocagent.commands.Candidate; -import com.amazon.aocagent.commands.IntegTest; -import com.amazon.aocagent.commands.Release; -import com.amazon.aocagent.commands.ResourceClean; -import com.amazon.aocagent.commands.Setup; -import lombok.extern.log4j.Log4j2; -import picocli.CommandLine; - -@CommandLine.Command( - name = "aoccicd", - mixinStandardHelpOptions = true, - version = "0.1", - description = "use for integtests and releases of the aocagent", - subcommands = { - IntegTest.class, - Release.class, - Candidate.class, - Setup.class, - ResourceClean.class - }) -@Log4j2 -public class App implements Runnable { - public static void main(String[] args) { - int exitCode = new CommandLine(new App()).execute(args); - System.exit(exitCode); - } - - @Override - public void run() { - log.info("Starting"); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/commands/Candidate.java b/integ-test/src/main/java/com/amazon/aocagent/commands/Candidate.java deleted file mode 100644 index 77618e71c..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/commands/Candidate.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.commands; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.tasks.TaskFactory; -import com.amazonaws.util.StringUtils; -import lombok.SneakyThrows; -import picocli.CommandLine; - -import java.nio.file.Files; -import java.nio.file.Paths; - -@CommandLine.Command( - name = "candidate", - mixinStandardHelpOptions = true, - description = "use for uploading and downloading the candidate packages") -public class Candidate implements Runnable { - @CommandLine.Mixin CommonOption commonOption = new CommonOption(); - - @CommandLine.Option( - names = {"-t", "--candidate-task"}, - description = "candidate task: DownloadCandidate, UploadCandidate", - defaultValue = "UploadCandidate") - private String candidateTask; - - @CommandLine.Option( - names = {"-g", "--github-sha"}, - description = "github sha, for example: e3f0e4ef43cc72e09b145d8a9c7b7357420d300f", - defaultValue = "") - private String githubSha; - - @SneakyThrows - @Override - public void run() { - Context context = commonOption.buildContext(); - - if (StringUtils.isNullOrEmpty(this.githubSha)) { - this.githubSha = - new String( - Files.readAllBytes( - Paths.get( - context.getLocalPackagesDir() - + "/" - + GenericConstants.GITHUB_SHA_FILE_NAME.getVal()))) - .trim(); - } - context.setGithubSha(this.githubSha); - TaskFactory.executeTask(candidateTask, context); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/commands/CommonOption.java b/integ-test/src/main/java/com/amazon/aocagent/commands/CommonOption.java deleted file mode 100644 index 7e948ebea..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/commands/CommonOption.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.commands; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.fileconfigs.ECSTaskDefTemplate; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.models.Stack; -import com.amazonaws.util.StringUtils; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import lombok.extern.log4j.Log4j2; -import picocli.CommandLine; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Map; - -@CommandLine.Command(footer = "Common footer") -@Log4j2 -public class CommonOption { - @CommandLine.Option( - names = {"-l", "--local-packages-dir"}, - description = - "read packages, version file from this directory, default value is build/packages", - defaultValue = "build/packages") - private String localPackagesDir; - - @CommandLine.Option( - names = {"-p", "--package-version"}, - description = "the package version, fetched from local-packages-dir/VERSION by default") - private String version; - - @CommandLine.Option( - names = {"-s", "--stack"}, - description = "stack file path, .aoc-stack.yml by default", - defaultValue = ".aoc-stack.yml") - private String stackFilePath; - - @CommandLine.Option( - names = {"-e", "--ecs-context"}, - description = "eg, -e ecsLaunchType=EC2 -e ecsDeployMode=SIDECAR", - defaultValue = "ecsLaunchType=EC2") - private Map ecsContexts; - - @CommandLine.Option( - names = {"-k", "--eks-context"}, - description = - "eg, -k eksClusterName=my-cluster-name " - + "-k kubectlPath=/my/kubectl/path " - + "-k kubeconfigPath=/my/kubeconfig/path " - + "-k awsAuthenticatorPath=/my/authenticator/path " - + "-k eksTestManifestName=testManifest") - private Map eksContexts; - - /** - * buildContext build the context object based on the command args. - * - * @return Context - * @throws IOException when the VERSION file is not found - */ - public Context buildContext() throws IOException, BaseException { - // build stack - Stack stack = this.buildStack(); - - Context context = new Context(); - - context.setStack(stack); - context.setStackFilePath(stackFilePath); - - // local package dir - context.setLocalPackagesDir(this.localPackagesDir); - - // get aoc version from the current working directory: "build/packages/VERSION" - if (StringUtils.isNullOrEmpty(this.version)) { - this.version = - new String( - Files.readAllBytes(Paths.get(this.localPackagesDir + "/VERSION")), - StandardCharsets.UTF_8) - .trim(); - } - context.setAgentVersion(this.version); - - setExtraContext(ecsContexts, context); - setExtraContext(eksContexts, context); - return context; - } - - private Stack buildStack() throws IOException, BaseException { - // read stack from .aoc-stack - if (!Files.exists(Paths.get(this.stackFilePath))) { - throw new BaseException(ExceptionCode.STACK_FILE_NOT_FOUND); - } - - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - return mapper.readValue( - new String(Files.readAllBytes(Paths.get(this.stackFilePath))), Stack.class); - } - - private void setExtraContext(Map extra, Context context) { - if (extra != null) { - extra - .entrySet() - .forEach( - e -> { - if (e.getKey().equals(GenericConstants.ECS_LAUNCH_TYPE.getVal())) { - context.setEcsLaunchType(e.getValue()); - } else if (e.getKey().equals(GenericConstants.ECS_DEPLOY_MODE.getVal())) { - context.setEcsDeploymentMode(e.getValue()); - } else if (e.getKey().equals(GenericConstants.ECS_TASK_DEF.getVal())) { - context.setEcsTaskDef(ECSTaskDefTemplate.valueOf(e.getValue())); - } else if (e.getKey().equals(GenericConstants.AUTHENTICATOR_PATH.getVal())) { - context.setIamAuthenticatorPath(e.getValue()); - } else if (e.getKey().equals(GenericConstants.EKS_CLUSTER_NAME.getVal())) { - context.setEksClusterName(e.getValue()); - } else if (e.getKey().equals(GenericConstants.KUBECTL_PATH.getVal())) { - context.setKubectlPath(e.getValue()); - } else if (e.getKey().equals(GenericConstants.KUBECONFIG_PATH.getVal())) { - context.setKubeconfigPath(e.getValue()); - } else if (e.getKey().equals(GenericConstants.TEST_MANIFEST_NAME.getVal())) { - context.setEksTestManifestName(e.getValue()); - } - }); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/commands/IntegTest.java b/integ-test/src/main/java/com/amazon/aocagent/commands/IntegTest.java deleted file mode 100644 index 2bff8c8ce..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/commands/IntegTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.commands; - -import com.amazon.aocagent.enums.TestAMI; -import com.amazon.aocagent.fileconfigs.ExpectedMetric; -import com.amazon.aocagent.fileconfigs.ExpectedTrace; -import com.amazon.aocagent.fileconfigs.OTConfig; -import com.amazon.aocagent.enums.TestCase; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.tasks.IntegTestFactory; -import lombok.SneakyThrows; -import picocli.CommandLine; - -@CommandLine.Command( - name = "integ-test", - mixinStandardHelpOptions = true, - description = "used for the integtests of the aocagent") -public class IntegTest implements Runnable { - @CommandLine.Mixin CommonOption commonOption = new CommonOption(); - - @CommandLine.Option( - names = {"-a", "--ami"}, - description = "Enum values: ${COMPLETION-CANDIDATES}, default: ${DEFAULT-VALUE}", - defaultValue = "AMAZON_LINUX") - private TestAMI testAMI; - - @CommandLine.Option( - names = {"-c", "--config"}, - description = "Enum values: ${COMPLETION-CANDIDATES}, default: ${DEFAULT-VALUE}", - defaultValue = "DEFAULT_OT_CONFIG") - private OTConfig otConfig; - - @CommandLine.Option( - names = {"--expected-metric"}, - description = "Enum values: ${COMPLETION-CANDIDATES}, default: ${DEFAULT-VALUE}", - defaultValue = "DEFAULT_EXPECTED_METRIC") - private ExpectedMetric expectedMetric; - - @CommandLine.Option( - names = {"--expected-trace"}, - description = "Enum values: ${COMPLETION-CANDIDATES}, default: ${DEFAULT-VALUE}", - defaultValue = "DEFAULT_EXPECTED_TRACE") - private ExpectedTrace expectedTrace; - - @CommandLine.Option( - names = {"-t", "--test-case"}, - description = "EC2_TEST,ECS_TEST,EKS_TEST", - defaultValue = "EC2_TEST") - private TestCase testCase; - - @SneakyThrows - @Override - public void run() { - Context context = commonOption.buildContext(); - context.setTestingAMI(testAMI.getTestAMIObj()); - context.setOtConfig(otConfig); - context.setExpectedMetric(expectedMetric); - context.setExpectedTrace(expectedTrace); - IntegTestFactory.runTestCase(testCase, context); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/commands/Release.java b/integ-test/src/main/java/com/amazon/aocagent/commands/Release.java deleted file mode 100644 index 7583cff2f..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/commands/Release.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.commands; - -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.tasks.TaskFactory; -import lombok.SneakyThrows; -import picocli.CommandLine; - -@CommandLine.Command( - name = "release", - mixinStandardHelpOptions = true, - description = "use for the release of the aocagent") -public class Release implements Runnable { - @CommandLine.Mixin CommonOption commonOption = new CommonOption(); - - @CommandLine.Option( - names = {"-t", "--release-task"}, - description = "S3Release, ECRRelease, UploadCandidate, DownloadCandidate", - defaultValue = "S3Release") - private String releaseTask; - - @SneakyThrows - @Override - public void run() { - Context context = commonOption.buildContext(); - - TaskFactory.executeTask(releaseTask, context); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/commands/ResourceClean.java b/integ-test/src/main/java/com/amazon/aocagent/commands/ResourceClean.java deleted file mode 100644 index db6485bdb..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/commands/ResourceClean.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.commands; - -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.tasks.TaskFactory; -import lombok.SneakyThrows; -import picocli.CommandLine; - -@CommandLine.Command( - name = "clean", - mixinStandardHelpOptions = true, - description = "use to clean resources of the aocintegtest") -public class ResourceClean implements Runnable { - @CommandLine.Mixin CommonOption commonOption = new CommonOption(); - - @CommandLine.Option( - names = {"-t", "--clean-task"}, - description = "EC2Clean, ECSClean, EKSClean", - defaultValue = "EC2Clean") - private String cleanTask; - - @SneakyThrows - @Override - public void run() { - Context context = commonOption.buildContext(); - TaskFactory.executeTask(cleanTask, context); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/commands/Setup.java b/integ-test/src/main/java/com/amazon/aocagent/commands/Setup.java deleted file mode 100644 index fdf8adefb..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/commands/Setup.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.commands; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.models.Stack; -import com.amazon.aocagent.tasks.TaskFactory; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import lombok.SneakyThrows; -import lombok.extern.log4j.Log4j2; -import picocli.CommandLine; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; - -@CommandLine.Command( - name = "setup", - mixinStandardHelpOptions = true, - description = "use for the stack setup of the aocintegtest") -@Log4j2 -public class Setup implements Runnable { - @CommandLine.Option( - names = {"-s", "--stack"}, - description = "stack file path, .aoc-stack.yml by default", - defaultValue = ".aoc-stack.yml") - private String stackFilePath; - - @SneakyThrows - @Override - public void run() { - Stack stack = null; - if (!Files.exists(Paths.get(this.stackFilePath))) { - log.info("no stack file at {}, Build stack with timestamp", this.stackFilePath); - stack = this.buildStackWithTimestamp(); - } else { - log.info("found stack file, Build stack from file"); - stack = this.buildStackFromFile(); - } - - Context context = new Context(); - context.setStackFilePath(this.stackFilePath); - context.setStack(stack); - TaskFactory.executeTask("Setup", context); - } - - private Stack buildStackWithTimestamp() { - Stack stack = new Stack(); - String timestamp = Long.toHexString(System.currentTimeMillis()); - - stack.setSshKeyS3BucketName( - String.join("-", GenericConstants.DEFAULT_SSH_KEY_S3_BUCKET_NAME.getVal(), timestamp)); - - stack.setS3ReleaseCandidateBucketName( - String.join("-", GenericConstants.DEFAULT_S3_RELEASE_CANDIDATE_BUCKET.getVal(), timestamp)); - - stack.setS3BucketName(String.join("-", GenericConstants.DEFAULT_S3_BUCKET.getVal(), timestamp)); - - stack.setTraceDataS3BucketName( - String.join("-", GenericConstants.DEFAULT_TRACE_S3_BUCKET_NAME.getVal(), timestamp)); - - stack.setTestingImageRepoName( - GenericConstants.DEFAULT_DOCKER_IMAGE_REPO_NAME.getVal() - ); - - stack.setTestingRegion(GenericConstants.DEFAULT_REGION.getVal()); - - return stack; - } - - private Stack buildStackFromFile() throws IOException { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - return mapper.readValue( - new String(Files.readAllBytes(Paths.get(this.stackFilePath))), Stack.class); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/Architecture.java b/integ-test/src/main/java/com/amazon/aocagent/enums/Architecture.java deleted file mode 100644 index 98d633bd4..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/Architecture.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -public enum Architecture { - AMD64, - ARM64, - ; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/GenericConstants.java b/integ-test/src/main/java/com/amazon/aocagent/enums/GenericConstants.java deleted file mode 100644 index 4f127dc7f..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/GenericConstants.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -import lombok.Getter; - -@Getter -public enum GenericConstants { - - // stack related - DEFAULT_STACK_FILE_PATH(".aoc-stack.yml"), - DEFAULT_REGION("us-west-2"), - DEFAULT_S3_RELEASE_CANDIDATE_BUCKET("aoc-release-candidate"), - DEFAULT_S3_BUCKET("aws-observability-collector-test"), - DEFAULT_SSH_KEY_S3_BUCKET_NAME("aoc-ssh-key"), - DEFAULT_TRACE_S3_BUCKET_NAME("trace-expected-data"), - DEFAULT_DOCKER_IMAGE_REPO_NAME("josephwy/aws-observability-collector"), - - // release related - PACKAGE_NAME_PREFIX("aws-observability-collector."), - LOCAL_PACKAGES_DIR("build/packages"), - GITHUB_SHA_FILE_NAME("GITHUB_SHA"), - - // ec2 related - EC2_INSTANCE_TAG_KEY("aoc-integ-test-tag"), - EC2_INSTANCE_TAG_VAL("aoc-integ-test"), - DEFAULT_SECURITY_GROUP_NAME("default"), - SECURITY_GROUP_NAME("aoc-integ-test-sp"), - IAM_ROLE_NAME("aoc-integ-test-iam-role"), - - // ssm related - UPDATE_SSM_AGENT_DOCUMENT("AWS-UpdateSSMAgent"), - RUN_POWER_SHELL_SCRIPT_DOCUMENT("AWS-RunPowerShellScript"), - - // ssh related - SSH_KEY_NAME("aoc-ssh-key-2020-07-22"), - SSH_CERT_LOCAL_PATH("sshkey.pem"), - SSH_TIMEOUT("30000"), // ms - - // retry - SLEEP_IN_MILLISECONDS("10000"), // ms - SLEEP_IN_SECONDS("30"), - MAX_RETRIES("10"), - - // task - TASK_RESPONSE_FILE_LOCATION("./task_response"), - - // configuration - EC2_CONFIG_PATH("/tmp/test.yml"), - EC2_WIN_CONFIG_PATH("C:\\test.yml"), - - // emitter - TRACE_EMITTER_ENDPOINT("http://localhost:4567/span0"), - SERVICE_NAMESPACE("AWSObservability"), - SERVICE_NAME("CloudWatchOTService"), - TRACE_EMITTER_DOCKER_IMAGE_URL("josephwy/integ-test-emitter:0.9"), - - // validator related - METRIC_NAMESPACE("default"), - - // release candidate related - CANDIDATE_PACK_TO("build/candidate.tar.gz"), - CANDIDATE_DOWNLOAD_TO("build/candidate-downloaded.tar.gz"), - CANDIDATE_UNPACK_TO("."), - - // ECS - ECS_LAUNCH_TYPE("ecsLaunchType"), - ECS_DEPLOY_MODE("ecsDeployMode"), - ECS_TASK_DEF("ecsTaskDef"), - EC2_INSTANCE_ECS_TAG_VAL("aoc-integ-test-ecs"), - ECS_SIDECAR_CLUSTER("aoc-sidecar-integ-test"), - - // EKS - AUTHENTICATOR_PATH("awsAuthenticatorPath"), - EKS_CLUSTER_NAME("eksClusterName"), - KUBECTL_PATH("kubectlPath"), - KUBECONFIG_PATH("kubeconfigPath"), - TEST_MANIFEST_NAME("eksTestManifestName"), - EKS_DEFAULT_TEST_MANIFEST("aoc-eks-sidecar"), - EKS_INTEG_TEST("EKSIntegTest"), - - //Windows - WINDOWS_CTL_PATH("'C:\\Program Files\\Amazon\\AwsObservabilityCollector" - + "\\aws-observability-collector-ctl.ps1'"), - - // common constants - EC2("EC2"), - FARGATE("FARGATE"), - DEFAULT("default"), - AOC_PREFIX("aoc-"), - AOC_PORT("55680"), - RESOURCE_CLEAN_THRESHOLD("120"), - ; - - private String val; - - GenericConstants(String val) { - this.val = val; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/LocalPackage.java b/integ-test/src/main/java/com/amazon/aocagent/enums/LocalPackage.java deleted file mode 100644 index 30b2ab238..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/LocalPackage.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -import lombok.Getter; - -import java.util.Arrays; - -@Getter -public enum LocalPackage { - LINUX_AMD64_RPM(OSType.LINUX, Architecture.AMD64, PackageType.RPM), - LINUX_ARM64_RPM(OSType.LINUX, Architecture.ARM64, PackageType.RPM), - DEBIAN_AMD64_DEB(OSType.DEBIAN, Architecture.AMD64, PackageType.DEB), - DEBIAN_ARM64_DEB(OSType.DEBIAN, Architecture.ARM64, PackageType.DEB), - WINDOWS_AMD64_MSI(OSType.WINDOWS, Architecture.AMD64, PackageType.MSI), - ; - - private PackageType packageType; - private Architecture architecture; - private OSType osType; - - LocalPackage(OSType osType, Architecture architecture, PackageType packageType) { - this.osType = osType; - this.architecture = architecture; - this.packageType = packageType; - } - - /** - * getFilePath generates the local path for the package. - * - * @param localPackagesDir is used as the "root" directory of the package - * @return the local path of the package - */ - public String getFilePath(String localPackagesDir) { - return String.join( - "/", - Arrays.asList( - localPackagesDir, - osType.name().toLowerCase(), - architecture.name().toLowerCase(), - GenericConstants.PACKAGE_NAME_PREFIX.getVal() + packageType.name().toLowerCase())); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/OSType.java b/integ-test/src/main/java/com/amazon/aocagent/enums/OSType.java deleted file mode 100644 index ffef723c0..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/OSType.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -public enum OSType { - LINUX, - DEBIAN, - WINDOWS, - DARWIN, - ; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/OTConfig.java b/integ-test/src/main/java/com/amazon/aocagent/enums/OTConfig.java deleted file mode 100644 index e1562dd42..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/OTConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -import lombok.Getter; - -@Getter -public enum OTConfig { - EC2_CONFIG("EC2Config"), - ; - - private String val; - - OTConfig(String val) { - this.val = val; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/PackageType.java b/integ-test/src/main/java/com/amazon/aocagent/enums/PackageType.java deleted file mode 100644 index ac57940b5..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/PackageType.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -public enum PackageType { - RPM, - DEB, - MSI, - PKG, - IMAGE, - ; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/S3Package.java b/integ-test/src/main/java/com/amazon/aocagent/enums/S3Package.java deleted file mode 100644 index 65a9cf4fc..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/S3Package.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -import lombok.Getter; - -import java.util.Arrays; - -@Getter -public enum S3Package { - AMAZON_LINUX_AMD64_RPM(SupportedOSDistribution.AMAZON_LINUX, LocalPackage.LINUX_AMD64_RPM), - AMAZON_LINUX_ARM64_RPM(SupportedOSDistribution.AMAZON_LINUX, LocalPackage.LINUX_ARM64_RPM), - REDHAT_AMD64_RPM(SupportedOSDistribution.REDHAT, LocalPackage.LINUX_AMD64_RPM), - REDHAT_ARM64_RPM(SupportedOSDistribution.REDHAT, LocalPackage.LINUX_ARM64_RPM), - SUSE_AMD64_RPM(SupportedOSDistribution.SUSE, LocalPackage.LINUX_AMD64_RPM), - SUSE_ARM64_RPM(SupportedOSDistribution.SUSE, LocalPackage.LINUX_ARM64_RPM), - CENTOS_AMD64_RPM(SupportedOSDistribution.CENTOS, LocalPackage.LINUX_AMD64_RPM), - CENTOS_ARM64_RPM(SupportedOSDistribution.CENTOS, LocalPackage.LINUX_ARM64_RPM), - UBUNTU_AMD64_DEB(SupportedOSDistribution.UBUNTU, LocalPackage.DEBIAN_AMD64_DEB), - UBUNTU_ARM64_DEB(SupportedOSDistribution.UBUNTU, LocalPackage.DEBIAN_ARM64_DEB), - DEBIAN_AMD64_DEB(SupportedOSDistribution.DEBIAN, LocalPackage.DEBIAN_AMD64_DEB), - DEBIAN_ARM64_DEB(SupportedOSDistribution.DEBIAN, LocalPackage.DEBIAN_ARM64_DEB), - WINDOWS_AMD64_MSI(SupportedOSDistribution.WINDOWS, LocalPackage.WINDOWS_AMD64_MSI), - ; - - private SupportedOSDistribution supportedOSDistribution; - private LocalPackage localPackage; - - S3Package(SupportedOSDistribution supportedOSDistribution, LocalPackage localPackage) { - this.supportedOSDistribution = supportedOSDistribution; - this.localPackage = localPackage; - } - - /** - * getS3Key generates the S3Key for the packages. - * - * @param packageVersion is used to construct the S3 Key - * @return the S3 key of the package - */ - public String getS3Key(String packageVersion) { - return String.join( - "/", - Arrays.asList( - supportedOSDistribution.name().toLowerCase(), - this.localPackage.getArchitecture().name().toLowerCase(), - packageVersion, - this.getPackageName())); - } - - /** - * getPackageName return the ot collector install package name. - * - * @return packageName - */ - public String getPackageName() { - return GenericConstants.PACKAGE_NAME_PREFIX.getVal() - + localPackage.getPackageType().name().toLowerCase(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/SupportedOSDistribution.java b/integ-test/src/main/java/com/amazon/aocagent/enums/SupportedOSDistribution.java deleted file mode 100644 index 0cae6ad42..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/SupportedOSDistribution.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -public enum SupportedOSDistribution { - AMAZON_LINUX, - REDHAT, - CENTOS, - SUSE, - UBUNTU, - DEBIAN, - WINDOWS, - ; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/TestAMI.java b/integ-test/src/main/java/com/amazon/aocagent/enums/TestAMI.java deleted file mode 100644 index ef4e7e271..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/TestAMI.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -import com.amazon.aocagent.testamis.A1AmazonLinuxAMI; -import com.amazon.aocagent.testamis.A1RedHatAMI; -import com.amazon.aocagent.testamis.A1SuseAMI; -import com.amazon.aocagent.testamis.A1UbuntuAMI; -import com.amazon.aocagent.testamis.AmazonLinuxAMI; -import com.amazon.aocagent.testamis.Centos6AMI; -import com.amazon.aocagent.testamis.CentosAMI; -import com.amazon.aocagent.testamis.DebianAMI; -import com.amazon.aocagent.testamis.EcsOptimizedAMI; -import com.amazon.aocagent.testamis.ITestAMI; -import com.amazon.aocagent.testamis.RedHat6AMI; -import com.amazon.aocagent.testamis.RedHatAMI; -import com.amazon.aocagent.testamis.SuseAMI; -import com.amazon.aocagent.testamis.UbuntuAMI; -import com.amazon.aocagent.testamis.WindowsAMI; -import lombok.Getter; - -@Getter -public enum TestAMI { - // Amazonlinux - AMAZON_LINUX(new AmazonLinuxAMI("ami-0a07be880014c7b8e")), - AMAZON_LINUX2(new AmazonLinuxAMI("ami-0873b46c45c11058d")), - A1_AMAZON_LINUX(new A1AmazonLinuxAMI("ami-091a6d6d0ed7b35fd")), - - // Suse - SUSE_15(new SuseAMI("ami-063c2d222d223d0e9")), - SUSE_12(new SuseAMI("ami-811794f9")), - A1_SUSE_15(new A1SuseAMI("ami-0bfc92b18fd79372c")), - - // redhat - REDHAT_8(new RedHatAMI("ami-079596bf7a949ddf8")), - REDHAT_7(new RedHatAMI("ami-078a6a18fb73909b2")), - REDHAT_6(new RedHat6AMI("ami-4dc28f7d")), - A1_REDHAT_8(new A1RedHatAMI("ami-0f7a968a2c17fb48b")), - A1_REDHAT_7(new A1RedHatAMI("ami-0e00026dd0f3688e2")), - - // centos - //CENTOS_8(new CentosAMI("ami-91ea11f1")), - CENTOS_7(new CentosAMI("ami-0bc06212a56393ee1")), - CENTOS_6(new Centos6AMI("ami-052ff42ae3be02b6a")), - - // debian - DEBIAN_10(new DebianAMI("ami-0bb8fb45872332e66")), - DEBIAN_9(new DebianAMI("ami-0ccb963e85bc5c856")), - //DEBIAN_8(new DebianAMI("ami-fde96b9d")), - - // ubuntu - UBUNTU_18_04(new UbuntuAMI("ami-0edf3b95e26a682df")), - UBUNTU_16_04(new UbuntuAMI("ami-6e1a0117")), - UBUNTU_14_04(new UbuntuAMI("ami-718c6909")), - A1_UBUNTU_18_04(new A1UbuntuAMI("ami-0db180c518750ee4f")), - A1_UBUNTU_16_04(new A1UbuntuAMI("ami-05e1b2aec3b47890f")), - - //Windows - WINDOWS_2019_BASE(new WindowsAMI("ami-09fa39d0afa9024db")), - - // ECS Optimized AMI - ECS_OPTIMIZED(new EcsOptimizedAMI("ami-004e1655142a7ea0d")), - ; - - private ITestAMI testAMIObj; - - TestAMI(ITestAMI testAMI) { - this.testAMIObj = testAMI; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/enums/TestCase.java b/integ-test/src/main/java/com/amazon/aocagent/enums/TestCase.java deleted file mode 100644 index a0062fabd..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/enums/TestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.enums; - -import com.amazon.aocagent.installers.emiterinstallers.OTEmitterInstaller; -import com.amazon.aocagent.installers.emiterinstallers.OTMetricAndTraceEmitterInstaller; -import com.amazon.aocagent.installers.otinstallers.ECSInstaller; -import com.amazon.aocagent.installers.otinstallers.EKSInstaller; -import com.amazon.aocagent.installers.otinstallers.OTInstaller; -import com.amazon.aocagent.installers.otinstallers.OTPackageInstaller; -import com.amazon.aocagent.installers.otinstallers.SsmOTPackageInstaller; -import com.amazon.aocagent.testbeds.EC2TestBed; -import com.amazon.aocagent.testbeds.ECSTestBed; -import com.amazon.aocagent.testbeds.EKSTestBed; -import com.amazon.aocagent.testbeds.TestBed; -import com.amazon.aocagent.validators.IValidator; -import com.amazon.aocagent.validators.MetricValidator; -import com.amazon.aocagent.validators.TraceValidator; -import lombok.Getter; - -import java.util.Arrays; -import java.util.List; - -@Getter -public enum TestCase { - EC2_TEST( - new EC2TestBed(), - new OTPackageInstaller(), - Arrays.asList(new OTMetricAndTraceEmitterInstaller()), - Arrays.asList(new MetricValidator(), new TraceValidator())), - - EC2_SSM_TEST( - new EC2TestBed(), - new SsmOTPackageInstaller(), - Arrays.asList(new OTMetricAndTraceEmitterInstaller()), - Arrays.asList(new MetricValidator(), new TraceValidator())), - - // run AOC with data emitter in ECS as sidecar - // tested both ECS fargate and EC2 modes - ECS_TEST( - new ECSTestBed(), - new ECSInstaller(), - Arrays.asList(), // data emitter is included in sidecar installer - Arrays.asList(new MetricValidator(), new TraceValidator())), - - // run AOC with data emitter in EKS as sidecar - EKS_TEST( - new EKSTestBed(), - new EKSInstaller(), - Arrays.asList(), // data emitter is included in sidecar installer - Arrays.asList(new MetricValidator(), new TraceValidator())), - ; - - private TestBed testBed; - private OTInstaller otInstaller; - private List otEmitterInstallerList; - private List validatorList; - - TestCase( - TestBed testBed, - OTInstaller otInstaller, - List otEmitterInstallerList, - List validatorList) { - this.testBed = testBed; - this.otInstaller = otInstaller; - this.otEmitterInstallerList = otEmitterInstallerList; - this.validatorList = validatorList; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/exception/BaseException.java b/integ-test/src/main/java/com/amazon/aocagent/exception/BaseException.java deleted file mode 100644 index a4caccb02..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/exception/BaseException.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.exception; - -import lombok.Getter; - -@Getter -public class BaseException extends Exception { - private int code; - private String message; - - public BaseException(ExceptionCode exceptionCode) { - this.code = exceptionCode.getCode(); - this.message = exceptionCode.getMessage(); - } - - public BaseException(ExceptionCode exceptionCode, String message) { - this.code = exceptionCode.getCode(); - this.message = message; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/exception/ExceptionCode.java b/integ-test/src/main/java/com/amazon/aocagent/exception/ExceptionCode.java deleted file mode 100644 index 7a44e98da..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/exception/ExceptionCode.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.exception; - -public enum ExceptionCode { - LOCAL_PACKAGE_NOT_EXIST(20000, "local package not exist"), - S3_KEY_ALREADY_EXIST(20001, "s3 key is existed already"), - SSH_COMMAND_FAILED(20002, "ssh command failed"), - LOGIN_USER_NOT_FOUND(20003, "login user not found"), - FAILED_AFTER_RETRY(20004, "failed after retry"), - EC2INSTANCE_STATUS_PENDING(20005, "ec2 instance status is pending"), - EC2INSTANCE_STATUS_BAD(20006, "ec2 instance status is bad"), - NO_MATCHED_S3_KEY(20007, "no matched s3 key for this ami"), - NO_MATCHED_DOWNLOADING_COMMAND(20008, "no matched downloading command for this ami"), - NO_MATCHED_PACKAGE_NAME(20009, "no matched package name for this ami"), - NO_MATCHED_INSTALLING_COMMAND(20010, "no matched installing command for this ami"), - NO_MATCHED_STARTING_COMMAND(20010, "no matched starting command for this ami"), - NO_MATCHED_DOCKER_INSTALLING_COMMAND(20010, "no matched docker installing command for this ami"), - COMMAND_FAILED_TO_EXECUTE(20011, "command failed to execute"), - STACK_FILE_NOT_FOUND(20012, "stack file not found, please setup it"), - S3_BUCKET_IS_EXISTED_IN_CURRENT_ACCOUNT(20013, "s3 bucket is already existed in your account"), - S3_BUCKET_IS_EXISTED_GLOBALLY(20014, "s3 bucket is already existed globally"), - NO_DEFAULT_SECURITY_GROUP(20015, "no default security group found"), - NO_AVAILABLE_SUBNET(20016, "no available subnet found for vcp"), - ECS_INSTANCE_NOT_READY(20030, "ecs container instance is not ready"), - ECS_CLUSTER_NOT_EXIST(20031, "ecs cluster is not existed"), - ECS_TASK_EXECUTION_FAIL(20032, "ecs cluster task failed to start"), - ECS_TASK_DEFINITION_PARSE_FAIL(20033, "fail to parse ecs task definition template"), - - EXPECTED_METRIC_NOT_FOUND(30001, "expected metric not found"), - - VERSION_NOT_MATCHED(40001, "version is not matched in the candidate package"), - GITHUB_SHA_NOT_MATCHED(40002, "github sha is not matched in the candidate package"), - - // validating errors - TRACE_ID_NOT_MATCHED(50001, "trace id not matched"), - TRACE_SPAN_LIST_NOT_MATCHED(50002, "trace span list has different length"), - TRACE_SPAN_NOT_MATCHED(50003, "trace span not matched"), - TRACE_LIST_NOT_MATCHED(50004, "trace list has different length"), - - // eks option errors - EKS_CLUSTER_UNAVAIL(60001, "cluster is not available"), - EKS_CLUSTER_NAME_UNAVAIL(60002, "cluster name is not available"), - EKS_KUBECTL_PATH_UNAVAIL(60003, "kubectl path is not available"), - EKS_IAM_AUTHENTICATOR_PATH_UNAVAIL(60004, "aws-iam-authenticator path is not available"), - ; - private int code; - private String message; - - ExceptionCode(int code, String message) { - this.code = code; - this.message = message; - } - - public int getCode() { - return code; - } - - public String getMessage() { - return message; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ECSTaskDefTemplate.java b/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ECSTaskDefTemplate.java deleted file mode 100644 index d48b6c259..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ECSTaskDefTemplate.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.fileconfigs; - -import lombok.Getter; - -@Getter -public enum ECSTaskDefTemplate implements FileConfig { - ECS_EC2_TEMPLATE("/templates/ecs/aoc-sidecar-ec2.mustache"), - ECS_FARGATE_TEMPLATE("/templates/ecs/aoc-sidecar-fargate.mustache"), - ; - - private String path; - - ECSTaskDefTemplate(String path) { - this.path = path; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksKubeConfigTemplate.java b/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksKubeConfigTemplate.java deleted file mode 100644 index 652e97833..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksKubeConfigTemplate.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.fileconfigs; - -import lombok.Getter; - -@Getter -public enum EksKubeConfigTemplate implements FileConfig { - KUBE_CONFIG_TEMPLATE("/templates/eks/kubeConfig.mustache"), - ; - - private String path; - - EksKubeConfigTemplate(String path) { - this.path = path; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksSidecarManifestTemplate.java b/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksSidecarManifestTemplate.java deleted file mode 100644 index 5d6de04cb..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/EksSidecarManifestTemplate.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.fileconfigs; - -import lombok.Getter; - -@Getter -public class EksSidecarManifestTemplate implements FileConfig { - - private String path; - - public EksSidecarManifestTemplate(String path) { - this.path = path; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedMetric.java b/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedMetric.java deleted file mode 100644 index 9628b0f04..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedMetric.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.fileconfigs; - -import lombok.Getter; - -@Getter -public enum ExpectedMetric implements FileConfig { - DEFAULT_EXPECTED_METRIC("/templates/validation/defaultExpectedMetric.mustache"), - ; - - private String path; - - ExpectedMetric(String path) { - this.path = path; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedTrace.java b/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedTrace.java deleted file mode 100644 index f13d7a87e..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/ExpectedTrace.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.fileconfigs; - -import com.amazon.aocagent.fileconfigs.FileConfig; -import lombok.Getter; - -@Getter -public enum ExpectedTrace implements FileConfig { - DEFAULT_EXPECTED_TRACE("/templates/validation/defaultExpectedTrace.mustache"), - ; - - private String path; - - ExpectedTrace(String path) { - this.path = path; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/FileConfig.java b/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/FileConfig.java deleted file mode 100644 index 2b33072be..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/FileConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.fileconfigs; - -/** - * Any file based config will need to implement this interface, - * so that the mustacheHelper could render it. - */ -public interface FileConfig { - /** - * get the mustache file path. - * @return file path - */ - String getPath(); -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/OTConfig.java b/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/OTConfig.java deleted file mode 100644 index d4baa70c6..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/fileconfigs/OTConfig.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.fileconfigs; - -import lombok.Getter; - -@Getter -public enum OTConfig implements FileConfig { - DEFAULT_OT_CONFIG("/templates/config/defaultOTConfig.mustache"), - ; - - private String path; - - OTConfig(String path) { - this.path = path; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/CommandExecutionHelper.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/CommandExecutionHelper.java deleted file mode 100644 index e5d9ffa40..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/CommandExecutionHelper.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazonaws.auth.AWSCredentials; -import com.amazonaws.auth.AWSSessionCredentials; -import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; -import lombok.RequiredArgsConstructor; -import lombok.extern.log4j.Log4j2; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.function.Consumer; - -@Log4j2 -public class CommandExecutionHelper { - /** - * Amount of time to wait for processes to finish. Probably way more time than needed, but want to - * pick a large value since the test will fail if the timeout is reached. - */ - private static final long TIMEOUT_IN_SECONDS = 360; - - private static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool(); - - /** - * Useful for sending the stdout/stderr of a child process to our logger. When started in its own - * thread, the thread will terminate automatically when the inputStream is given EOF (such as when - * a process connected to that stream is terminated). - * - *

Note that Java's Process object has some pretty confusing names, its 'getInputStream' and - * 'getErrorStream' return java InputStream's for OUR process to consume from. But they are the - * stdout/stderr of the child process represented by the Process object. - */ - @RequiredArgsConstructor - private static class StreamRedirecter implements Runnable { - - private final InputStream inputStream; - private final Consumer streamConsumer; - - public void run() { - BufferedReader reader = - new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); - reader.lines().forEach(streamConsumer); - } - } - - /** - * runChildProcess executes the command in a child process. - * - * @param command the command to be executed - * @return output of the command execution - * @throws BaseException when the command fails to execute - */ - public static String runChildProcess(String command) throws BaseException { - return runChildProcessInternal(command, new String[] {}); - } - - /** - * runChildProcessWithAWSCred executes the command in a child process with aws credential. - * - * @param command the command to be executed - * @return output of the command execution - * @throws BaseException when the command fails to execute - */ - public static String runChildProcessWithAWSCred(String command) throws BaseException { - // construct environment variable array - List envList = new ArrayList(); - AWSCredentials credentials = DefaultAWSCredentialsProviderChain.getInstance().getCredentials(); - envList.add("AWS_ACCESS_KEY_ID=" + credentials.getAWSAccessKeyId()); - envList.add("AWS_SECRET_ACCESS_KEY=" + credentials.getAWSSecretKey()); - if (credentials instanceof AWSSessionCredentials) { - AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) credentials; - envList.add("AWS_SESSION_TOKEN=" + sessionCredentials.getSessionToken()); - } - - return runChildProcessInternal(command, envList.toArray(new String[0])); - } - - /** - * runChildProcessWithEnvs executes the command in a child process with environment variables. - * - * @param command the command to be executed - * @param envs environment variables - * @return output of the command execution - * @throws BaseException when the command fails to execute - */ - public static String runChildProcessWithEnvs(String command, String[] envs) throws BaseException { - return runChildProcessInternal(command, envs); - } - - private static String runChildProcessInternal(String command, String[] envs) - throws BaseException { - log.info("execute command: {}", command); - StringBuilder output = new StringBuilder(); - - Process p; - Future stdoutFuture; - Future stderrFuture; - - try { - p = Runtime.getRuntime().exec(command, envs); - - // p is set up by default to just have pipes for its stdout/stderr, so those will buffer until - // we set up consumers - StreamRedirecter stdoutRedirector = - new StreamRedirecter( - p.getInputStream(), - s -> { - output.append(s).append("\n"); - }); - stdoutFuture = THREAD_POOL.submit(stdoutRedirector); - - StreamRedirecter stderrRedirector = new StreamRedirecter(p.getErrorStream(), log::error); - stderrFuture = THREAD_POOL.submit(stderrRedirector); - - } catch (IOException ioe) { - throw new RuntimeException(ioe); - } - - try { - stdoutFuture.get(TIMEOUT_IN_SECONDS, TimeUnit.SECONDS); - stderrFuture.get(TIMEOUT_IN_SECONDS, TimeUnit.SECONDS); - if (0 != p.waitFor()) { - throw new BaseException(ExceptionCode.COMMAND_FAILED_TO_EXECUTE); - } - } catch (InterruptedException | ExecutionException e) { - p.destroyForcibly(); - throw new RuntimeException(e); - } catch (TimeoutException e) { - p.destroyForcibly(); - throw new RuntimeException("Timed out while waiting for command to complete.", e); - } - return output.toString(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/EKSTestOptionsValidationHelper.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/EKSTestOptionsValidationHelper.java deleted file mode 100644 index 934317d72..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/EKSTestOptionsValidationHelper.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.fileconfigs.EksKubeConfigTemplate; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.EKSService; -import com.amazonaws.services.eks.model.Cluster; -import lombok.extern.log4j.Log4j2; -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.net.URL; - -@Log4j2 -public class EKSTestOptionsValidationHelper { - /** - * validate EKS test options. - * - * @param context test context - */ - public static void checkEKSTestOptions(Context context) throws Exception { - if (context.getEksClusterName() == null && context.getKubeconfigPath() == null) { - throw new BaseException(ExceptionCode.EKS_CLUSTER_NAME_UNAVAIL); - } - - if (context.getKubectlPath() == null) { - // set default kubectl path - downloadKubectl(context); - } - - if (context.getIamAuthenticatorPath() == null) { - // set default aws-iam-authenticator path - downloadIamAuthenticator(context); - } - - if (context.getKubeconfigPath() == null) { - // generate default kubeconfig. It requires a valid "iamAuthenticatorPath" in context - generateKubeconfig(context); - } - } - - private static void generateKubeconfig(Context context) throws Exception { - // composite kubeconfig - Cluster cluster = new EKSService(context.getStack().getTestingRegion()).getCluster(context); - context.setEksCertificate(cluster.getCertificateAuthority().getData()); - context.setEksEndpoint(cluster.getEndpoint()); - String kubeConfigContent = - new MustacheHelper().render(EksKubeConfigTemplate.KUBE_CONFIG_TEMPLATE, context); - - log.info("kubeConfigContent: \n" + kubeConfigContent); - - File kubeconfig = new File(context.getEksTestArtifactsDir().getPath().toFile(), "kubeconfig"); - FileUtils.writeStringToFile(kubeconfig, kubeConfigContent); - context.setKubeconfigPath(kubeconfig.getPath()); - } - - private static void downloadKubectl(Context context) throws Exception { - String urlTemplate = - "https://amazon-eks.s3.us-west-2.amazonaws.com/1.17.9/2020-08-04/bin/%s/amd64/%s"; - - String binaryName = null; - String os = null; - - if (OSHelper.isLinux()) { - binaryName = "kubectl"; - os = "linux"; - } - - if (OSHelper.isMac()) { - binaryName = "kubectl"; - os = "darwin"; - } - - if (os != null) { - context.setKubectlPath( - downloadBinary(String.format(urlTemplate, os, binaryName), binaryName, context)); - } else { - throw new BaseException(ExceptionCode.EKS_KUBECTL_PATH_UNAVAIL); - } - } - - private static void downloadIamAuthenticator(Context context) throws Exception { - String urlTemplate = - "https://amazon-eks.s3.us-west-2.amazonaws.com/1.17.9/2020-08-04/bin/%s/amd64/%s"; - - String binaryName = null; - String os = null; - - if (OSHelper.isLinux()) { - binaryName = "aws-iam-authenticator"; - os = "linux"; - } - - if (OSHelper.isMac()) { - binaryName = "aws-iam-authenticator"; - os = "darwin"; - } - - if (os != null) { - context.setIamAuthenticatorPath( - downloadBinary(String.format(urlTemplate, os, binaryName), binaryName, context)); - } else { - throw new BaseException(ExceptionCode.EKS_IAM_AUTHENTICATOR_PATH_UNAVAIL); - } - } - - private static String downloadBinary(String binaryUrl, String binaryName, Context context) - throws IOException { - File binaryFile = new File(context.getEksTestArtifactsDir().getPath().toFile(), binaryName); - - FileUtils.copyURLToFile(new URL(binaryUrl), binaryFile); - binaryFile.setExecutable(true); - return binaryFile.getPath(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/MustacheHelper.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/MustacheHelper.java deleted file mode 100644 index b4c64c1db..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/MustacheHelper.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -import com.amazon.aocagent.fileconfigs.FileConfig; -import com.github.mustachejava.DefaultMustacheFactory; -import com.github.mustachejava.Mustache; -import com.github.mustachejava.MustacheFactory; -import lombok.extern.log4j.Log4j2; -import org.apache.commons.io.IOUtils; - -import java.io.IOException; -import java.io.StringReader; -import java.io.StringWriter; - -@Log4j2 -public class MustacheHelper { - private MustacheFactory mustacheFactory = new DefaultMustacheFactory(); - - /** - * Render the template file with injecting the data. - * - * @param fileConfig any object implementing the FileConfig interface - * @param dataToInject the object to inject to the template - * @return generated content - * @throws IOException when the template file is not existed - */ - public String render(FileConfig fileConfig, Object dataToInject) throws IOException { - return render(fileConfig.getPath(), dataToInject); - } - - private String render(String path, Object dataToInject) throws IOException { - log.info("fetch config: {}", path); - String templateContent = IOUtils.toString(getClass().getResource(path)); - Mustache mustache = mustacheFactory.compile(new StringReader(templateContent), path); - StringWriter stringWriter = new StringWriter(); - mustache.execute(stringWriter, dataToInject).flush(); - return stringWriter.getBuffer().toString(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/OSHelper.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/OSHelper.java deleted file mode 100644 index da931263a..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/OSHelper.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -public class OSHelper { - private static String OS = System.getProperty("os.name").toLowerCase(); - - /** - * check whether current OS is Windows. - * - * @return current OS is Windows or not - */ - public static boolean isWindows() { - return OS.startsWith("win"); - } - - /** - * check whether current OS is MacOS X. - * - * @return current OS is MacOS X or not - */ - public static boolean isMac() { - return OS.startsWith("mac"); - } - - /** - * check whether current OS is Linux. - * - * @return current OS is Linux or not - */ - public static boolean isLinux() { - return OS.startsWith("linux") || OS.startsWith("ubuntu"); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/RetryHelper.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/RetryHelper.java deleted file mode 100644 index accdf624a..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/RetryHelper.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import lombok.extern.log4j.Log4j2; - -import java.util.concurrent.TimeUnit; - -@Log4j2 -public class RetryHelper { - /** - * retry executes the lambda, retry if the lambda throw exceptions. - * - * @param retryCount the total retry count - * @param sleepInMilliSeconds sleep time among retries - * @param retryable the lambda - * @throws Exception when the retry count is reached - */ - public static void retry(int retryCount, int sleepInMilliSeconds, Retryable retryable) - throws Exception { - while (retryCount-- > 0) { - try { - log.info("still can retry for {} times", retryCount); - retryable.execute(); - return; - } catch (Exception ex) { - log.error("exception during retry, you may ignore it", ex); - TimeUnit.MILLISECONDS.sleep(sleepInMilliSeconds); - } - } - - throw new BaseException(ExceptionCode.FAILED_AFTER_RETRY); - } - - /** - * retry executes lambda with default retry count(10) and sleep seconds(10). - * - * @param retryable the lambda - * @throws Exception when the retry count is reached - */ - public static void retry(Retryable retryable) throws Exception { - retry( - Integer.valueOf(GenericConstants.MAX_RETRIES.getVal()), - Integer.valueOf(GenericConstants.SLEEP_IN_MILLISECONDS.getVal()), - retryable); - } - - /** - * retry executes lambda with default sleeping seconds 10s. - * - * @param retryCount the total retry count - * @param retryable the lambda function to be executed - * @throws Exception when the retry count is reached - */ - public static void retry(int retryCount, Retryable retryable) throws Exception { - retry(retryCount, Integer.valueOf(GenericConstants.SLEEP_IN_MILLISECONDS.getVal()), retryable); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/Retryable.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/Retryable.java deleted file mode 100644 index d3fac205c..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/Retryable.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -public interface Retryable { - void execute() throws Exception; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/SSHHelper.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/SSHHelper.java deleted file mode 100644 index 13d66644c..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/SSHHelper.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.jcraft.jsch.Channel; -import com.jcraft.jsch.ChannelExec; -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.Session; -import lombok.extern.log4j.Log4j2; - -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -@Log4j2 -public class SSHHelper { - - private String loginUser; - private String host; - private String certificatePath; - - /** - * SSHHelper Constructor. - * - * @param loginUser the user used to login the host - * @param host the host ip/hostname - * @param certificatePath the ssh key path on the local - */ - public SSHHelper(String loginUser, String host, String certificatePath) { - this.loginUser = loginUser; - this.host = host; - this.certificatePath = certificatePath; - } - - public void isSSHReady() throws Exception { - this.executeCommands(Arrays.asList("uptime")); - } - - /** - * executeCommands executes a list of commands on the remote host. - * - * @param commands the list of the commands - * @throws Exception when commands execution fail - */ - public String executeCommands(List commands) throws Exception { - Channel channel = null; - Session session = null; - - try { - log.info("run remote commands on {}@{}, the rsa key is {}", loginUser, host, certificatePath); - JSch jsch = new JSch(); - - jsch.addIdentity(certificatePath); - session = jsch.getSession(loginUser, host); - Properties config = new Properties(); - config.put("StrictHostKeyChecking", "no"); - session.setConfig(config); - session.connect(); - session.setTimeout(Integer.parseInt(GenericConstants.SSH_TIMEOUT.getVal())); - - channel = session.openChannel("exec"); - ChannelExec channelExec = (ChannelExec) channel; - - String compositeCommand = String.join("&&", commands); - log.info("run remote commands: {}", compositeCommand); - channelExec.setCommand(compositeCommand); - channelExec.setPty(true); - - InputStream in = channel.getInputStream(); - InputStream err = ((ChannelExec) channel).getErrStream(); - channelExec.connect(); - log.info("connected"); - - StringBuilder outputBuffer = new StringBuilder(); - StringBuilder errorBuffer = new StringBuilder(); - byte[] tmp = new byte[1024]; - while (true) { - while (in.available() > 0) { - int i = in.read(tmp, 0, 1024); - if (i < 0) { - break; - } - outputBuffer.append(new String(tmp, 0, i, StandardCharsets.UTF_8)); - } - while (err.available() > 0) { - int i = err.read(tmp, 0, 1024); - if (i < 0) { - break; - } - errorBuffer.append(new String(tmp, 0, i, StandardCharsets.UTF_8)); - } - if (channel.isClosed()) { - if ((in.available() > 0) || (err.available() > 0)) { - continue; - } - log.info("exit-status: " + channel.getExitStatus()); - break; - } - log.info("pulling: wait for command finished"); - TimeUnit.MILLISECONDS.sleep( - Integer.parseInt(GenericConstants.SLEEP_IN_MILLISECONDS.getVal())); - } - - log.info("remote command executing std output: {}", outputBuffer.toString()); - log.info("remote command executing err output: {}", errorBuffer.toString()); - - if (channel.getExitStatus() != 0) { - throw new BaseException( - ExceptionCode.SSH_COMMAND_FAILED, "execute remote command failed " + compositeCommand); - } - - return outputBuffer.toString(); - - } finally { - if (channel != null) { - channel.disconnect(); - } - if (session != null) { - session.disconnect(); - } - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/helpers/TempDirHelper.java b/integ-test/src/main/java/com/amazon/aocagent/helpers/TempDirHelper.java deleted file mode 100644 index a59c3fb33..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/helpers/TempDirHelper.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -import com.amazon.aocagent.enums.GenericConstants; -import org.apache.commons.io.FileUtils; -import org.joda.time.DateTime; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Date; - -public class TempDirHelper { - private static String delimiter = "-"; - private static Path topLevelPath = Paths.get(System.getProperty("java.io.tmpdir"), "AOCTestTemp"); - - /** - * delete those temp dirs which was created 2 hours ago. - * - * @throws IOException fail to delete dirs - */ - public static void cleanTempDirs() throws IOException { - File[] subDirs = topLevelPath.toFile().listFiles(); - if (subDirs != null) { - for (File subdir : subDirs) { - String name = subdir.getName(); - String[] elements = name.split(delimiter); - if (elements.length == 2) { - String timestamp = elements[1]; - // delete dir if it was created two hours ago - if (new Date(Long.parseLong(timestamp)) - .before( - new DateTime() - .minusMinutes( - Integer.parseInt(GenericConstants.RESOURCE_CLEAN_THRESHOLD.getVal())) - .toDate())) { - FileUtils.deleteDirectory(subdir); - } - } else { - // delete the dir with unexpected subdir name - FileUtils.deleteDirectory(subdir); - } - } - } - } - - private Path path; - private String dirPrefix; - - /** - * constructor of TempDirHelper. - * - * @param dirPrefix prefix of the temp dir which is going to be created - */ - public TempDirHelper(String dirPrefix) { - this.dirPrefix = dirPrefix; - } - - /** - * get the temp dir created by this object. - * - * @return path - */ - public Path getPath() { - if (path == null) { - path = - Paths.get( - topLevelPath.toString(), - String.format("%s%s%d", dirPrefix, delimiter, System.currentTimeMillis())); - path.toFile().mkdir(); - } - return path; - } - - /** - * delete the temp dir created by this object. - * - * @throws IOException fail to delete file - */ - public void deletePath() throws IOException { - FileUtils.deleteDirectory(path.toFile()); - path = null; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTEmitterInstaller.java b/integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTEmitterInstaller.java deleted file mode 100644 index 5adfb0422..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTEmitterInstaller.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.installers.emiterinstallers; - -import com.amazon.aocagent.models.Context; - -public interface OTEmitterInstaller { - void init(Context context) throws Exception; - - /** - * Install the emitter and start it. - * @throws Exception when the emitter failed to install/start - */ - void installAndStart() throws Exception; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTMetricAndTraceEmitterInstaller.java b/integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTMetricAndTraceEmitterInstaller.java deleted file mode 100644 index c93e80641..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/installers/emiterinstallers/OTMetricAndTraceEmitterInstaller.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.installers.emiterinstallers; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.enums.TestAMI; -import com.amazon.aocagent.helpers.RetryHelper; -import com.amazon.aocagent.helpers.SSHHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.models.EC2InstanceParams; -import com.amazon.aocagent.services.EC2Service; -import com.amazon.aocagent.testamis.ITestAMI; -import com.amazonaws.services.ec2.model.Instance; -import com.amazonaws.services.ec2.model.ResourceType; -import com.amazonaws.services.ec2.model.Tag; -import com.amazonaws.services.ec2.model.TagSpecification; -import lombok.extern.log4j.Log4j2; - -import java.util.Arrays; - -@Log4j2 -public class OTMetricAndTraceEmitterInstaller implements OTEmitterInstaller { - Context context; - SSHHelper sshHelper; - EC2Service ec2Service; - - @Override - public void init(Context context) throws Exception { - this.context = context; - this.ec2Service = new EC2Service(context.getStack().getTestingRegion()); - this.launchEmitterInstance(); - } - - @Override - public void installAndStart() throws Exception { - // use host mode to interact with imds - String dockerCommand = - String.format( - "sudo docker run --network host " - + "-e S3_REGION=%s " - + "-e TRACE_DATA_BUCKET=%s -e TRACE_DATA_S3_KEY=%s " - + "-e OTEL_RESOURCE_ATTRIBUTES=service.namespace=%s,service.name=%s " - + "-e INSTANCE_ID=%s " - + "-e OTEL_OTLP_ENDPOINT=%s:55680 " - + "-d %s", - context.getStack().getTestingRegion(), - context.getStack().getTraceDataS3BucketName(), - context.getInstanceId(), // use instanceid as the s3 key of trace data - GenericConstants.SERVICE_NAMESPACE.getVal(), - GenericConstants.SERVICE_NAME.getVal(), - context.getInstanceId(), - context.getInstancePrivateIpAddress(), - GenericConstants.TRACE_EMITTER_DOCKER_IMAGE_URL.getVal()); - - RetryHelper.retry(() -> sshHelper.executeCommands(Arrays.asList(dockerCommand))); - - // wait until the trace emitter is ready to curl - String curlCommand = String.format("curl %s", GenericConstants.TRACE_EMITTER_ENDPOINT.getVal()); - RetryHelper.retry(() -> sshHelper.executeCommands(Arrays.asList(curlCommand))); - } - - private void launchEmitterInstance() throws Exception { - // launch a suse instance to install emitter, because some of the old platform doesn't support - // docker - // so we have to use a separate instance to run emitter and use the private address as the otlp - // endpoint - ITestAMI testAMI = TestAMI.SUSE_15.getTestAMIObj(); - - // tag instance for management - TagSpecification tagSpecification = - new TagSpecification() - .withResourceType(ResourceType.Instance) - .withTags( - new Tag( - GenericConstants.EC2_INSTANCE_TAG_KEY.getVal(), - GenericConstants.EC2_INSTANCE_TAG_VAL.getVal())); - - Instance instance = - ec2Service.launchInstance( - EC2InstanceParams.builder() - .amiId(testAMI.getAMIId()) - .instanceType(testAMI.getInstanceType()) - .iamRoleName(GenericConstants.IAM_ROLE_NAME.getVal()) - .securityGrpName(GenericConstants.SECURITY_GROUP_NAME.getVal()) - .tagSpecification(tagSpecification) - .arch(testAMI.getS3Package().getLocalPackage().getArchitecture()) - .sshKeyName(GenericConstants.SSH_KEY_NAME.getVal()) - .build()); - - // wait until the instance is ready to login - // init sshHelper - this.sshHelper = - new SSHHelper( - testAMI.getLoginUser(), - instance.getPublicIpAddress(), - GenericConstants.SSH_CERT_LOCAL_PATH.getVal()); - - log.info("wait until the emitter instance is ready to login"); - RetryHelper.retry(() -> sshHelper.isSSHReady()); - - // start docker service - RetryHelper.retry(() -> sshHelper.executeCommands(Arrays.asList("sudo service docker start"))); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/ECSInstaller.java b/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/ECSInstaller.java deleted file mode 100644 index 03772ac1b..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/ECSInstaller.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.installers.otinstallers; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.helpers.MustacheHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.ECSService; -import com.amazon.aocagent.services.IAMService; -import com.amazonaws.services.ecs.model.AssignPublicIp; -import com.amazonaws.services.ecs.model.AwsVpcConfiguration; -import com.amazonaws.services.ecs.model.LaunchType; -import com.amazonaws.services.ecs.model.NetworkConfiguration; -import com.amazonaws.services.ecs.model.RunTaskRequest; - -public class ECSInstaller implements OTInstaller { - private Context context; - private ECSService ecsService; - private IAMService iamService; - private MustacheHelper mustacheHelper; - - @Override - public void init(Context context) throws Exception { - this.context = context; - this.ecsService = new ECSService(context.getStack().getTestingRegion()); - this.iamService = new IAMService(context.getStack().getTestingRegion()); - this.mustacheHelper = new MustacheHelper(); - } - - @Override - public void installAndStart() throws Exception { - - // setup ecs context for filling task definition template - this.setupEcsContext(context); - - // create and run ECS target task definitions from template - final String taskDefinitionStr = mustacheHelper.render(context.getEcsTaskDef(), context); - - // register the task definition in ECS - ecsService.registerTaskDefinition(taskDefinitionStr); - - // create ecs run task request - RunTaskRequest taskRequest = this.getTaskRequest(this.context); - - // run ECS task - ecsService.runTaskDefinition(taskRequest); - } - - private void setupEcsContext(Context context) { - context.setAocImage(context.getStack().getTestingImageRepoName() - + ":" + context.getAgentVersion()); - context.setDataEmitterImage(GenericConstants.TRACE_EMITTER_DOCKER_IMAGE_URL.getVal()); - context.setRegion(context.getStack().getTestingRegion()); - String iamRoleArn = this.iamService.getRoleArn(GenericConstants.IAM_ROLE_NAME.getVal()); - context.setEcsTaskRoleArn(iamRoleArn); - context.setEcsExecutionRoleArn(iamRoleArn); - } - - private RunTaskRequest getTaskRequest(Context context) { - String launchType = context.getEcsLaunchType(); - if (launchType.equalsIgnoreCase(GenericConstants.EC2.getVal())) { - return new RunTaskRequest() - .withLaunchType(LaunchType.EC2) - .withTaskDefinition(GenericConstants.AOC_PREFIX.getVal() + launchType) - .withCluster(context.getEcsClusterName()) - .withCount(1); - } else { - return new RunTaskRequest() - .withLaunchType(LaunchType.FARGATE) - .withTaskDefinition(GenericConstants.AOC_PREFIX.getVal() + launchType) - .withCluster(context.getEcsClusterName()) - .withCount(1) - .withNetworkConfiguration( - new NetworkConfiguration() - .withAwsvpcConfiguration( - new AwsVpcConfiguration() - .withAssignPublicIp(AssignPublicIp.ENABLED) - .withSecurityGroups(context.getDefaultSecurityGrpId()) - .withSubnets(context.getDefaultSubnets().get(0).getSubnetId()))); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/EKSInstaller.java b/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/EKSInstaller.java deleted file mode 100644 index 94c73fd33..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/EKSInstaller.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.installers.otinstallers; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.fileconfigs.EksSidecarManifestTemplate; -import com.amazon.aocagent.helpers.CommandExecutionHelper; -import com.amazon.aocagent.helpers.MustacheHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.EKSService; -import lombok.extern.log4j.Log4j2; -import org.apache.commons.io.FileUtils; - -import java.io.File; - -@Log4j2 -public class EKSInstaller implements OTInstaller { - private Context context; - private EKSService eksService; - private MustacheHelper mustacheHelper; - - @Override - public void init(Context context) throws Exception { - this.context = context; - this.eksService = new EKSService(context.getStack().getTestingRegion()); - this.mustacheHelper = new MustacheHelper(); - } - - @Override - public void installAndStart() throws Exception { - setupEKSContext(context); - generateEKSTestManifestFile(context); - deployEKSTestManifestFile(context); - - log.info("EKS integ test {} has been deployed", context.getEksTestManifestName()); - } - - private void setupEKSContext(Context context) { - context.setAocImage( - context.getStack().getTestingImageRepoName() + ":" + context.getAgentVersion()); - context.setDataEmitterImage(GenericConstants.TRACE_EMITTER_DOCKER_IMAGE_URL.getVal()); - // Uses current timestamp as instance id which is used as a uniq test id - context.setInstanceId(String.valueOf(System.currentTimeMillis())); - if (context.getEksTestManifestName() == null) { - context.setEksTestManifestName(GenericConstants.EKS_DEFAULT_TEST_MANIFEST.getVal()); - } - } - - private void generateEKSTestManifestFile(Context context) throws Exception { - String manifestYamlContent = - mustacheHelper.render( - new EksSidecarManifestTemplate( - String.format("/templates/eks/%s.mustache", context.getEksTestManifestName())), - context); - - log.info("EKS sidecar integ test deployment yaml content:\n" + manifestYamlContent); - - FileUtils.writeStringToFile( - new File( - context.getEksTestArtifactsDir().getPath().toFile(), - String.format("%s.yml", context.getEksTestManifestName())), - manifestYamlContent); - } - - private void deployEKSTestManifestFile(Context context) throws Exception { - String command = - String.format( - "%s apply -f %s --kubeconfig %s", - context.getKubectlPath(), - new File( - context.getEksTestArtifactsDir().getPath().toFile(), - String.format("%s.yml", context.getEksTestManifestName())) - .getPath(), - context.getKubeconfigPath()); - CommandExecutionHelper.runChildProcessWithAWSCred(command); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTInstaller.java b/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTInstaller.java deleted file mode 100644 index ccecadf45..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTInstaller.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.installers.otinstallers; - -import com.amazon.aocagent.models.Context; - -public interface OTInstaller { - - /** - * Init context variables. - * @param context test context - * @throws Exception init exception - */ - void init(Context context) throws Exception; - - /** - * setup integration tests resources and execute the test cases. - * @throws Exception setup exception - */ - void installAndStart() throws Exception; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTPackageInstaller.java b/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTPackageInstaller.java deleted file mode 100644 index e727c3b1a..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/OTPackageInstaller.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.installers.otinstallers; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.helpers.MustacheHelper; -import com.amazon.aocagent.helpers.RetryHelper; -import com.amazon.aocagent.helpers.SSHHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.EC2Service; -import lombok.extern.log4j.Log4j2; - -import java.util.Arrays; - -@Log4j2 -public class OTPackageInstaller implements OTInstaller { - Context context; - SSHHelper sshHelper; - MustacheHelper mustacheHelper; - - @Override - public void init(Context context) throws Exception { - this.context = context; - - prepareSSHKey(this.context); - // init sshHelper - this.sshHelper = - new SSHHelper( - this.context.getTestingAMI().getLoginUser(), - this.context.getInstancePublicIpAddress(), - GenericConstants.SSH_CERT_LOCAL_PATH.getVal()); - - // wait until the instance is ready to login - log.info("wait until the instance is ready to login"); - RetryHelper.retry(() -> sshHelper.isSSHReady()); - // handle firewall - if (context.getTestingAMI().getDisableFirewallCommand() != null) { - sshHelper.executeCommands(Arrays.asList(context.getTestingAMI().getDisableFirewallCommand())); - } - - this.mustacheHelper = new MustacheHelper(); - } - - @Override - public void installAndStart() throws Exception { - downloadPackage(); - installPackage(); - configureAndStart(); - } - - private void downloadPackage() throws Exception { - // get downloading link - String s3Key = context.getTestingAMI().getS3Package().getS3Key(context.getAgentVersion()); - String downloadingLink = - "https://" + context.getStack().getS3BucketName() + ".s3.amazonaws.com/" + s3Key; - - // get downloading command - String downloadingCommand = - context - .getTestingAMI() - .getDownloadingCommand( - downloadingLink, - context.getTestingAMI().getS3Package().getPackageName()); - - // execute downloading command - RetryHelper.retry( - () -> { - sshHelper.executeCommands(Arrays.asList(downloadingCommand)); - }); - } - - private void installPackage() throws Exception { - // get installing command - String installingCommand = - context - .getTestingAMI() - .getInstallingCommand(context.getTestingAMI().getS3Package().getPackageName()); - - // execute installing command - RetryHelper.retry( - () -> { - sshHelper.executeCommands(Arrays.asList(installingCommand)); - }); - } - - private void configureAndStart() throws Exception { - // generate configuration file - String configContent = mustacheHelper.render(context.getOtConfig(), context); - - // write config onto the remote instance - String configuringCommand = context.getTestingAMI().getConfiguringCommand(configContent); - - RetryHelper.retry( - () -> { - sshHelper.executeCommands(Arrays.asList(configuringCommand)); - }); - // start ot collector - String startingCommand = context.getTestingAMI() - .getStartingCommand(GenericConstants.EC2_CONFIG_PATH.getVal()); - RetryHelper.retry( - () -> { - sshHelper.executeCommands(Arrays.asList(startingCommand)); - }); - } - - private void prepareSSHKey(final Context context) throws Exception { - EC2Service ec2Service = new EC2Service(context.getStack().getTestingRegion()); - // download the ssh keypair from s3 - ec2Service.downloadSSHKey( - context.getStack().getSshKeyS3BucketName(), - GenericConstants.SSH_KEY_NAME.getVal(), - GenericConstants.SSH_CERT_LOCAL_PATH.getVal()); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/SsmOTPackageInstaller.java b/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/SsmOTPackageInstaller.java deleted file mode 100644 index 997ef0b78..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/installers/otinstallers/SsmOTPackageInstaller.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.installers.otinstallers; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.helpers.MustacheHelper; -import com.amazon.aocagent.helpers.RetryHelper; -import com.amazon.aocagent.services.SSMService; -import com.amazon.aocagent.models.Context; -import lombok.extern.log4j.Log4j2; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@Log4j2 -public class SsmOTPackageInstaller implements OTInstaller { - Context context; - MustacheHelper mustacheHelper; - SSMService ssmService; - - @Override - public void init(Context context) throws Exception { - this.context = context; - - // init ssmService - this.ssmService = new SSMService(context.getRegion()); - RetryHelper.retry(Integer.valueOf(GenericConstants.MAX_RETRIES.getVal()), - Integer.valueOf(GenericConstants.SLEEP_IN_MILLISECONDS.getVal()) * 3, - () -> { - if (!ssmService.isInstanceReadyForSsm(this.context.getInstanceId())) { - log.error("Instance with ID " + this.context.getInstanceId() - + " not ready for SSM in time. Check EC2 console."); - throw new BaseException(ExceptionCode.EC2INSTANCE_STATUS_BAD); - } - }); - - ssmService.updateSsmAgentToLatest(context.getInstanceId()); - - this.mustacheHelper = new MustacheHelper(); - } - - @Override - public void installAndStart() throws Exception { - downloadPackage(); - installPackage(); - configureAndStart(); - } - - private void downloadPackage() throws Exception { - // get downloading link - String s3Key = context.getTestingAMI().getS3Package().getS3Key(context.getAgentVersion()); - String downloadingLink = - "https://" + context.getStack().getS3BucketName() + ".s3.amazonaws.com/" + s3Key; - - // get downloading command - String downloadingCommand = - context - .getTestingAMI() - .getSsmDownloadingCommand( - downloadingLink, - context.getTestingAMI().getS3Package().getPackageName()); - - // execute downloading command - ssmService.runShellScriptCommand(context.getInstanceId(), Arrays.asList(downloadingCommand), - context.getTestingAMI().getSSMDocument()); - - } - - private void installPackage() throws Exception { - // get installing command - String installingCommand = - context - .getTestingAMI() - .getSsmInstallingCommand(context.getTestingAMI().getS3Package().getPackageName()); - - // execute installing command - ssmService.runShellScriptCommand(context.getInstanceId(), Arrays.asList(installingCommand), - context.getTestingAMI().getSSMDocument()); - } - - private void configureAndStart() throws Exception { - // generate configuration file - String configContent = mustacheHelper.render(context.getOtConfig(), context); - - List ssmCommands = new ArrayList<>(); - // write config onto the remote instance - String configuringCommand = context.getTestingAMI().getSsmConfiguringCommand(configContent); - ssmCommands.add(configuringCommand); - - // start ot collector - String startingCommand = context.getTestingAMI() - .getSsmStartingCommand(); - ssmCommands.add(startingCommand); - //Disable firewall so that the emitter can send metrics to it - String disableFirewallCommand = context.getTestingAMI().getDisableFirewallCommand(); - if (disableFirewallCommand != null) { - ssmCommands.add(disableFirewallCommand); - } - ssmService.runShellScriptCommand(context.getInstanceId(), - ssmCommands, context.getTestingAMI().getSSMDocument()); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/models/Context.java b/integ-test/src/main/java/com/amazon/aocagent/models/Context.java deleted file mode 100644 index a29d1370c..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/models/Context.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.models; - -import com.amazon.aocagent.fileconfigs.ECSTaskDefTemplate; -import com.amazon.aocagent.fileconfigs.ExpectedMetric; -import com.amazon.aocagent.fileconfigs.ExpectedTrace; -import com.amazon.aocagent.fileconfigs.OTConfig; -import com.amazon.aocagent.helpers.TempDirHelper; -import com.amazon.aocagent.testamis.ITestAMI; -import com.amazonaws.services.ec2.model.Subnet; -import lombok.Data; - -import java.util.List; - -@Data -public class Context { - private String stackFilePath; - private Stack stack; - private String agentVersion; - private String localPackagesDir; - private ITestAMI testingAMI; - private String instanceId; - private String instancePublicIpAddress; - private String instancePrivateIpAddress; - private String githubSha; - private OTConfig otConfig; - private ExpectedMetric expectedMetric; - private ExpectedTrace expectedTrace; - private String expectedTraceId; - private List expectedSpanIdList; - - /** AWS account default Security Group Id. */ - private String defaultSecurityGrpId; - - /** AWS account default VPC Id. */ - private String defaultVpcId; - - /** AWS account default subnets. */ - private List defaultSubnets; - - /** ECS Service launch type. Eg, EC2 or Fargate. */ - private String ecsLaunchType; - - /** ECS deployment mode. Eg, SIDECAR or DaemonSet. */ - private String ecsDeploymentMode; - - /** ECS cluster name. */ - private String ecsClusterName; - - /** ECS task role arn. */ - private String ecsTaskRoleArn; - - /** ECS task execution role arn. */ - private String ecsExecutionRoleArn; - - /** ECS task def. */ - private ECSTaskDefTemplate ecsTaskDef; - - /** ECS data emitter image. */ - private String dataEmitterImage; - - /** AOC image for testing. */ - private String aocImage; - - /** Test resources region. */ - private String region; - - /** EKS cluster attributes. */ - private String eksEndpoint; - - /** EKS cluster certificate. */ - private String eksCertificate; - - /** EKS cluster name. */ - private String eksClusterName; - - /** kubectl binary path. */ - private String kubectlPath; - - /** kubeconfig path. */ - private String kubeconfigPath; - - /** EKS iam authenticator binary path. */ - private String iamAuthenticatorPath; - - /** EKS test manifest file name. */ - private String eksTestManifestName; - - /** EKS test artifacts dir. */ - private TempDirHelper eksTestArtifactsDir; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/models/EC2InstanceParams.java b/integ-test/src/main/java/com/amazon/aocagent/models/EC2InstanceParams.java deleted file mode 100644 index 80287f057..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/models/EC2InstanceParams.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.models; - -import com.amazon.aocagent.enums.Architecture; -import com.amazonaws.services.ec2.model.InstanceType; -import com.amazonaws.services.ec2.model.TagSpecification; -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class EC2InstanceParams { - String amiId; - String sshKeyName; - String securityGrpName; - String iamRoleName; - String userData; - InstanceType instanceType; - Architecture arch; - TagSpecification tagSpecification; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/models/Stack.java b/integ-test/src/main/java/com/amazon/aocagent/models/Stack.java deleted file mode 100644 index 8908689f3..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/models/Stack.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.models; - -import lombok.Data; - -@Data -public class Stack { - String testingRegion; - String s3ReleaseCandidateBucketName; - String s3BucketName; - String sshKeyS3BucketName; - String traceDataS3BucketName; - String testingImageRepoName; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/models/TraceFromEmitter.java b/integ-test/src/main/java/com/amazon/aocagent/models/TraceFromEmitter.java deleted file mode 100644 index 21e178225..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/models/TraceFromEmitter.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.models; - -import lombok.Data; - -import java.io.Serializable; -import java.util.List; - -@Data -public class TraceFromEmitter implements Serializable { - private String traceId; - private List spanIdList; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/AwsNetworkService.java b/integ-test/src/main/java/com/amazon/aocagent/services/AwsNetworkService.java deleted file mode 100644 index df35d006e..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/AwsNetworkService.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazonaws.services.ec2.AmazonEC2; -import com.amazonaws.services.ec2.AmazonEC2ClientBuilder; -import com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest; -import com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult; -import com.amazonaws.services.ec2.model.DescribeSubnetsRequest; -import com.amazonaws.services.ec2.model.DescribeSubnetsResult; -import com.amazonaws.services.ec2.model.Filter; - -public class AwsNetworkService { - - private AmazonEC2 ec2Client; - private String region; - - /** - * retrieve network param for running ECS. - * @param region client region - */ - public AwsNetworkService(String region) { - this.region = region; - ec2Client = AmazonEC2ClientBuilder.standard().withRegion(region).build(); - } - - /** - * describe the account default security group and get both group id and vpc id. - * @throws Exception fail to describe sec group - */ - public DescribeSecurityGroupsResult describeDefaultSecurityGroup() throws Exception { - DescribeSecurityGroupsRequest request = - new DescribeSecurityGroupsRequest().withGroupNames("default"); - DescribeSecurityGroupsResult result = ec2Client.describeSecurityGroups(request); - if (result.getSecurityGroups().isEmpty()) { - throw new BaseException(ExceptionCode.NO_DEFAULT_SECURITY_GROUP); - } - return result; - } - - /** - * describe the subnets by default VPC id. - * @param vpcId VPC Id - * @throws Exception fail to describe subnets - */ - public DescribeSubnetsResult describeVpcSubnets(String vpcId) throws Exception { - DescribeSubnetsRequest request = - new DescribeSubnetsRequest() - .withFilters(new Filter().withName("vpc-id").withValues(vpcId)); - DescribeSubnetsResult result = ec2Client.describeSubnets(request); - if (result.getSubnets().isEmpty()) { - throw new BaseException(ExceptionCode.NO_AVAILABLE_SUBNET); - } - return result; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/CloudWatchService.java b/integ-test/src/main/java/com/amazon/aocagent/services/CloudWatchService.java deleted file mode 100644 index 68fe0c2da..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/CloudWatchService.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazonaws.services.cloudwatch.AmazonCloudWatch; -import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder; -import com.amazonaws.services.cloudwatch.model.DimensionFilter; -import com.amazonaws.services.cloudwatch.model.ListMetricsRequest; -import com.amazonaws.services.cloudwatch.model.Metric; - -import java.util.List; - -/** a wrapper of cloudwatch client. */ -public class CloudWatchService { - AmazonCloudWatch amazonCloudWatch; - - /** - * Construct CloudWatch Service with region. - * - * @param region the region for CloudWatch - */ - public CloudWatchService(String region) { - amazonCloudWatch = AmazonCloudWatchClientBuilder.standard().withRegion(region).build(); - } - - /** - * listMetrics fetches metrics from CloudWatch. - * @param nameSpace the metric namespace on CloudWatch - * @param metricName the metric name on CloudWatch - * @return List of Metrics - */ - public List listMetrics( - final String nameSpace, - final String metricName) { - final ListMetricsRequest listMetricsRequest = - new ListMetricsRequest() - .withNamespace(nameSpace) - .withMetricName(metricName); - return amazonCloudWatch.listMetrics(listMetricsRequest).getMetrics(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/EC2Service.java b/integ-test/src/main/java/com/amazon/aocagent/services/EC2Service.java deleted file mode 100644 index 16af85cef..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/EC2Service.java +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.helpers.RetryHelper; -import com.amazon.aocagent.models.EC2InstanceParams; -import com.amazonaws.services.ec2.AmazonEC2; -import com.amazonaws.services.ec2.AmazonEC2ClientBuilder; -import com.amazonaws.services.ec2.model.AmazonEC2Exception; -import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; -import com.amazonaws.services.ec2.model.CreateKeyPairRequest; -import com.amazonaws.services.ec2.model.CreateKeyPairResult; -import com.amazonaws.services.ec2.model.CreateSecurityGroupRequest; -import com.amazonaws.services.ec2.model.DescribeInstancesRequest; -import com.amazonaws.services.ec2.model.DescribeInstancesResult; -import com.amazonaws.services.ec2.model.DescribeKeyPairsRequest; -import com.amazonaws.services.ec2.model.DescribeKeyPairsResult; -import com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest; -import com.amazonaws.services.ec2.model.Filter; -import com.amazonaws.services.ec2.model.IamInstanceProfileSpecification; -import com.amazonaws.services.ec2.model.Instance; -import com.amazonaws.services.ec2.model.InstanceStateName; -import com.amazonaws.services.ec2.model.IpPermission; -import com.amazonaws.services.ec2.model.IpRange; -import com.amazonaws.services.ec2.model.KeyPairInfo; -import com.amazonaws.services.ec2.model.Reservation; -import com.amazonaws.services.ec2.model.RunInstancesRequest; -import com.amazonaws.services.ec2.model.RunInstancesResult; -import com.amazonaws.services.ec2.model.SecurityGroup; -import com.amazonaws.services.ec2.model.TerminateInstancesRequest; -import com.google.common.base.Strings; -import lombok.extern.log4j.Log4j2; -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicReference; - -/** - * EC2Service is a wrapper of Amazon EC2 Client. - */ -@Log4j2 -public class EC2Service { - private static final String ERROR_CODE_KEY_PAIR_NOT_FOUND = "InvalidKeyPair.NotFound"; - private static final String ERROR_CODE_KEY_PAIR_ALREADY_EXIST = "InvalidKeyPair.Duplicate"; - private static final String ERROR_CODE_SECURITY_GROUP_ALREADY_EXIST = "InvalidGroup.Duplicate"; - private static final String ERROR_CODE_SECURITY_GROUP_NOT_FOUND = "InvalidGroup.NotFound"; - private AmazonEC2 amazonEC2; - private String region; - private S3Service s3Service; - private SSMService ssmService; - - /** - * Construct ec2 service base on region. - * - * @param region the region to launch ec2 instance - */ - public EC2Service(String region) throws Exception { - this.region = region; - amazonEC2 = AmazonEC2ClientBuilder.standard().withRegion(region).build(); - s3Service = new S3Service(region); - ssmService = new SSMService(region); - } - - public SSMService getSsmService() { - return ssmService; - } - - /** - * launchInstance launches one ec2 instance. - * - * @param params the instance setup configuration params - * @return InstanceID - */ - public Instance launchInstance(EC2InstanceParams params) - throws Exception { - // create request - RunInstancesRequest runInstancesRequest = - new RunInstancesRequest() - .withImageId(params.getAmiId()) - .withMonitoring(false) - .withMaxCount(1) - .withMinCount(1) - .withTagSpecifications(params.getTagSpecification()) - .withKeyName(params.getSshKeyName()) - .withSecurityGroupIds(getOrCreateSecurityGroupByName(params.getSecurityGrpName())) - .withIamInstanceProfile( - new IamInstanceProfileSpecification().withName(params.getIamRoleName())) - .withInstanceType(params.getInstanceType()); - if (!Strings.isNullOrEmpty(params.getUserData())) { - runInstancesRequest.withUserData(params.getUserData()); - } - - RunInstancesResult runInstancesResult = amazonEC2.runInstances(runInstancesRequest); - - // return the first instance since only one instance gets launched - Instance instance = runInstancesResult.getReservation().getInstances().get(0); - - // return the instance until it's ready - return getInstanceUntilReady(instance.getInstanceId()); - } - - /** - * listInstancesByTag gets ec2 instance info list based on the tag. - * - * @param tagName tag key name - * @param tagValue tag value - * @return the list of ec2 instance - */ - public List listInstancesByTag(String tagName, String tagValue) { - DescribeInstancesRequest describeInstancesRequest = - new DescribeInstancesRequest() - .withFilters(new Filter("tag:" + tagName).withValues(tagValue)); - - List instanceList = new ArrayList<>(); - - while (true) { - DescribeInstancesResult describeInstancesResult = - amazonEC2.describeInstances(describeInstancesRequest); - for (Reservation reservation : describeInstancesResult.getReservations()) { - instanceList.addAll(reservation.getInstances()); - } - - describeInstancesRequest.setNextToken(describeInstancesResult.getNextToken()); - if (describeInstancesRequest.getNextToken() == null) { - return instanceList; - } - } - } - - /** - * List all the ec2 instances. - * - * @return instance list - */ - public List listInstances() { - List instanceList = new ArrayList<>(); - DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest(); - while (true) { - DescribeInstancesResult describeInstancesResult = - amazonEC2.describeInstances(describeInstancesRequest); - for (Reservation reservation : describeInstancesResult.getReservations()) { - instanceList.addAll(reservation.getInstances()); - } - - describeInstancesRequest.setNextToken(describeInstancesResult.getNextToken()); - if (describeInstancesRequest.getNextToken() == null) { - return instanceList; - } - } - } - - /** - * terminateInstance terminates ec2 instances base on the instance id list. - * - * @param instanceIds ec2 instance ids to be terminated - */ - public void terminateInstance(List instanceIds) { - log.info("clean instances {}", instanceIds); - if (instanceIds.size() == 0) { - return; - } - TerminateInstancesRequest terminateInstancesRequest = - new TerminateInstancesRequest().withInstanceIds(instanceIds); - - amazonEC2.terminateInstances(terminateInstancesRequest); - } - - private Instance getInstanceUntilReady(String targetInstanceId) - throws Exception { - DescribeInstancesRequest describeInstancesRequest = - new DescribeInstancesRequest().withInstanceIds(targetInstanceId); - - AtomicReference runningInstance = new AtomicReference<>(); - RetryHelper.retry(Integer.valueOf(GenericConstants.MAX_RETRIES.getVal()), - Integer.valueOf(GenericConstants.SLEEP_IN_MILLISECONDS.getVal()) * 3, - () -> { - DescribeInstancesResult describeInstancesResult = - amazonEC2.describeInstances(describeInstancesRequest); - for (Reservation reservation : describeInstancesResult.getReservations()) { - for (Instance instance : reservation.getInstances()) { - if (!targetInstanceId.equals(instance.getInstanceId())) { - continue; - } - String instanceStateName = instance.getState().getName(); - if (!InstanceStateName.Running.toString().equals(instanceStateName)) { - throw new BaseException(ExceptionCode.EC2INSTANCE_STATUS_PENDING); - } - log.info("instance network is ready"); - runningInstance.set(instance); - } - } - }); - - return runningInstance.get(); - } - - /** - * createSSHKeyIfNotExisted creates the ssh keypair for ec2 login and upload it to s3 private - * bucket for future usage. - * - * @param keyPairName the keypair name used to login - * @param bucketToStore the s3 bucket name to store the sshkey pair - * @throws IOException on failing to write keypair to disk - * @throws BaseException on s3 uploading failure - */ - public void createSSHKeyIfNotExisted(String keyPairName, String bucketToStore) - throws IOException, BaseException { - if (isKeyPairExisted(keyPairName)) { - log.info("{} - ssh key pair existed", keyPairName); - return; - } - - try { - // create keypair - CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest(); - createKeyPairRequest.setKeyName(keyPairName); - CreateKeyPairResult createKeyPairResult = amazonEC2.createKeyPair(createKeyPairRequest); - String keyMaterial = createKeyPairResult.getKeyPair().getKeyMaterial(); - - // store the keypair to s3 for future usage - String keyPairFileName = keyPairName + ".pem"; - String keyPairLocalPath = "/tmp/" + keyPairFileName; - FileUtils.writeStringToFile(new File(keyPairLocalPath), keyMaterial); - S3Service s3Service = new S3Service(region); - s3Service.uploadS3ObjectWithPrivateAccess( - keyPairLocalPath, bucketToStore, keyPairFileName, false); - - } catch (AmazonEC2Exception e) { - if (!ERROR_CODE_KEY_PAIR_ALREADY_EXIST.equals(e.getErrorCode())) { - throw e; - } - } - } - - private boolean isKeyPairExisted(String keyPairName) { - try { - DescribeKeyPairsRequest describeKeyPairsRequest = new DescribeKeyPairsRequest(); - describeKeyPairsRequest.setKeyNames(Collections.singletonList(keyPairName)); - DescribeKeyPairsResult describeKeyPairsResult = - amazonEC2.describeKeyPairs(describeKeyPairsRequest); - List keyPairInfoList = describeKeyPairsResult.getKeyPairs(); - if (keyPairInfoList.isEmpty()) { - return false; - } - } catch (AmazonEC2Exception e) { - if (ERROR_CODE_KEY_PAIR_NOT_FOUND.equals(e.getErrorCode())) { - return false; - } else { - throw e; - } - } - return true; - } - - public void downloadSSHKey(String bucketName, String keyPairName, String toLocation) { - s3Service.downloadS3Object(bucketName, keyPairName + ".pem", toLocation); - } - - private String getOrCreateSecurityGroupByName(String groupName) { - try { - return getSecurityGroupByName(groupName); - } catch (AmazonEC2Exception e) { - if (ERROR_CODE_SECURITY_GROUP_NOT_FOUND.equals(e.getErrorCode())) { - return createSecurityGroup(groupName); - } - throw e; - } - } - - private String getSecurityGroupByName(String groupName) { - final List securityGroups = - amazonEC2 - .describeSecurityGroups(new DescribeSecurityGroupsRequest().withGroupNames(groupName)) - .getSecurityGroups(); - return securityGroups.get(0).getGroupId(); - } - - /** - * create SecurityGroup in the current aws account. - * - * @param groupName security group name - * @return the created security group id - */ - public String createSecurityGroup(String groupName) { - try { - // get the vpcId of default, it is always there and cannot be deleted. - List securityGroups = - amazonEC2 - .describeSecurityGroups( - new DescribeSecurityGroupsRequest() - .withGroupNames(GenericConstants.DEFAULT_SECURITY_GROUP_NAME.getVal())) - .getSecurityGroups(); - if (securityGroups.size() <= 0) { - throw new RuntimeException("Cannot get the default security group."); - } - String vpcId = securityGroups.get(0).getVpcId(); - - // create new security group and get the group id - final String groupId = - amazonEC2 - .createSecurityGroup( - new CreateSecurityGroupRequest() - .withGroupName(groupName) - .withDescription(groupName + " used for aoc integration test") - .withVpcId(vpcId)) - .getGroupId(); - - // add the incoming ip request permission - IpPermission sshIpPermission = new IpPermission(); - sshIpPermission - .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")) - .withIpProtocol("tcp") - .withFromPort(22) - .withToPort(22); - - IpPermission rdpIpPermission = new IpPermission(); - rdpIpPermission - .withIpv4Ranges(new IpRange().withCidrIp("0.0.0.0/0")) - .withIpProtocol("tcp") - .withFromPort(3389) - .withToPort(3389); - - // limit the oltp access within private - IpPermission oltpIpPermission = new IpPermission(); - rdpIpPermission - .withIpv4Ranges(new IpRange().withCidrIp("172.16.0.0/12")) - .withIpProtocol("tcp") - .withFromPort(Integer.valueOf(GenericConstants.AOC_PORT.getVal())) - .withToPort(Integer.valueOf(GenericConstants.AOC_PORT.getVal())); - - amazonEC2.authorizeSecurityGroupIngress( - new AuthorizeSecurityGroupIngressRequest() - .withGroupId(groupId) - .withIpPermissions(sshIpPermission, rdpIpPermission, oltpIpPermission)); - - return groupId; - } catch (AmazonEC2Exception e) { - if (ERROR_CODE_SECURITY_GROUP_ALREADY_EXIST.equals(e.getErrorCode())) { - return getSecurityGroupByName(groupName); - } - throw e; - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/ECSService.java b/integ-test/src/main/java/com/amazon/aocagent/services/ECSService.java deleted file mode 100644 index 980b58289..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/ECSService.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.helpers.RetryHelper; -import com.amazonaws.services.ecs.AmazonECS; -import com.amazonaws.services.ecs.AmazonECSClientBuilder; -import com.amazonaws.services.ecs.model.Cluster; -import com.amazonaws.services.ecs.model.CreateClusterRequest; -import com.amazonaws.services.ecs.model.CreateClusterResult; -import com.amazonaws.services.ecs.model.DeleteClusterRequest; -import com.amazonaws.services.ecs.model.DeregisterTaskDefinitionRequest; -import com.amazonaws.services.ecs.model.DescribeClustersRequest; -import com.amazonaws.services.ecs.model.DescribeClustersResult; -import com.amazonaws.services.ecs.model.DesiredStatus; -import com.amazonaws.services.ecs.model.ListClustersResult; -import com.amazonaws.services.ecs.model.ListTaskDefinitionsResult; -import com.amazonaws.services.ecs.model.ListTasksRequest; -import com.amazonaws.services.ecs.model.RegisterTaskDefinitionRequest; -import com.amazonaws.services.ecs.model.RegisterTaskDefinitionResult; -import com.amazonaws.services.ecs.model.RunTaskRequest; -import com.amazonaws.services.ecs.model.RunTaskResult; -import com.amazonaws.services.ecs.model.StopTaskRequest; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.extern.log4j.Log4j2; - -import java.util.List; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -@Log4j2 -public class ECSService { - private AmazonECS ecsClient; - private ObjectMapper jsonMapper; - - public ECSService(final String region) { - this.ecsClient = AmazonECSClientBuilder.standard().withRegion(region).build(); - this.jsonMapper = new ObjectMapper(); - } - - /** - * create ECS cluster for integ testing. - * @return cluster creation result - */ - public CreateClusterResult createCluster(final String clusterName) { - CreateClusterRequest request = - new CreateClusterRequest().withClusterName(clusterName); - log.info("creating ECS cluster: {}", clusterName); - return ecsClient.createCluster(request); - } - - /** - * create and register ecs task definition for both EC2 and fargate running mode. - * @param taskDef ecs task definition - * @return {@link RegisterTaskDefinitionResult} for registering ecs container defs - */ - public RegisterTaskDefinitionResult registerTaskDefinition(String taskDef) throws BaseException { - RegisterTaskDefinitionRequest request; - - try { - request = jsonMapper.readValue(taskDef, RegisterTaskDefinitionRequest.class); - } catch (Exception e) { - throw new BaseException(ExceptionCode.ECS_TASK_DEFINITION_PARSE_FAIL, e.getMessage()); - } - return ecsClient.registerTaskDefinition(request); - } - - /** - * create and run ECS task definitions based on the launch type. - * @param runTaskRequest ecs run task request - */ - public void runTaskDefinition(RunTaskRequest runTaskRequest) throws BaseException { - - final RunTaskResult runTaskResult = ecsClient.runTask(runTaskRequest); - runTaskResult - .getTasks() - .forEach(task -> log.info("Successfully running task [{}]", task.getTaskArn())); - - if (!runTaskResult.getFailures().isEmpty()) { - throw new BaseException( - ExceptionCode.ECS_TASK_EXECUTION_FAIL, runTaskResult.getFailures().toString()); - } - } - - /** - * clean ECS tasks resources. - * @throws InterruptedException fail to clean exception - */ - public void cleanTasks() throws Exception { - List clusters = this.listClusters(); - for (String clusterName : clusters) { - // clean up tasks - for (String taskArn : - ecsClient - .listTasks( - new ListTasksRequest() - .withCluster(clusterName) - .withDesiredStatus(DesiredStatus.RUNNING)) - .getTaskArns()) { - ecsClient.stopTask(new StopTaskRequest().withTask(taskArn).withCluster(clusterName)); - } - - // make sure there is no RUNNING status task remaining - RetryHelper.retry( - () -> { - if (ecsClient - .listTasks( - new ListTasksRequest() - .withCluster(clusterName) - .withDesiredStatus(DesiredStatus.RUNNING)) - .getTaskArns() - .isEmpty()) { - return; - } - }); - - log.info("finish metric validation"); - } - } - - /** - * clean ECS cluster. - */ - public void cleanCluster() { - for (String name : listClusters()) { - if (!name.startsWith(GenericConstants.ECS_SIDECAR_CLUSTER.getVal()) - || !isClusterTwoHrsOlder(name)) { - continue; - } - DeleteClusterRequest request = new DeleteClusterRequest().withCluster(name); - try { - ecsClient.deleteCluster(request); - } catch (Exception e) { - log.error("{} can't be deleted", name, e); - } - } - } - - private boolean isClusterTwoHrsOlder(String name) { - String createdTimestamp = name.substring(name.lastIndexOf("-") + 1); - if ((System.currentTimeMillis() - Long.valueOf(createdTimestamp)) - > TimeUnit.HOURS.toMillis(2)) { - return true; - } - return false; - } - - private List listClusters() { - ListClustersResult clusters = ecsClient.listClusters(); - return clusters.getClusterArns().stream() - .map(arn -> arn.substring(arn.lastIndexOf("/") + 1)) - .collect(Collectors.toList()); - } - - /** - * clean ECS tasks with prefix. - * @param prefix task prefix - */ - public void cleanTaskDefinitions(String prefix) { - ListTaskDefinitionsResult result = ecsClient.listTaskDefinitions(); - result.getTaskDefinitionArns().stream() - .filter(arn -> arn.indexOf(prefix) > 0) - .forEach( - arn -> - ecsClient.deregisterTaskDefinition( - new DeregisterTaskDefinitionRequest().withTaskDefinition(arn))); - log.info("result {}", result.getTaskDefinitionArns()); - } - - /** - * check if ECS Cluster has available container instance. - * @param clusterName cluster name - * @throws Exception fail to wait for container instance ready - */ - public void waitForContainerInstanceRegistered(String clusterName) throws Exception { - RetryHelper.retry( - () -> { - Optional clusterOpt = describeCluster(clusterName); - if (!clusterOpt.isPresent()) { - log.warn("{} is not created", clusterName); - throw new BaseException(ExceptionCode.ECS_CLUSTER_NOT_EXIST); - } - Cluster ecsCluster = clusterOpt.get(); - if (ecsCluster.getRegisteredContainerInstancesCount() == 0) { - log.warn( - "waiting for ecs container instance to be ready - {}", clusterName); - throw new BaseException(ExceptionCode.ECS_INSTANCE_NOT_READY); - } - }); - } - - /** - * describe ECS cluster. - * @param clusterName cluster name - * @return - */ - public Optional describeCluster(String clusterName) { - DescribeClustersRequest request = new DescribeClustersRequest().withClusters(clusterName); - DescribeClustersResult response = ecsClient.describeClusters(request); - List clusters = response.getClusters(); - if (clusters.isEmpty()) { - return Optional.ofNullable(null); - } - return Optional.of(clusters.get(0)); - } - - /** - * check if container instances are ready for using. - * @param clusterName cluster name - * @return - */ - public boolean isContainerInstanceAvail(String clusterName) { - Optional clusterOpt = describeCluster(clusterName); - if (!clusterOpt.isPresent()) { - return false; - } - Cluster cluster = clusterOpt.get(); - return cluster.getRegisteredContainerInstancesCount() > 0; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/EKSService.java b/integ-test/src/main/java/com/amazon/aocagent/services/EKSService.java deleted file mode 100644 index 2122fa699..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/EKSService.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.models.Context; -import com.amazonaws.services.eks.AmazonEKS; -import com.amazonaws.services.eks.AmazonEKSClient; -import com.amazonaws.services.eks.model.Cluster; -import com.amazonaws.services.eks.model.DescribeClusterRequest; -import com.amazonaws.services.eks.model.DescribeClusterResult; -import lombok.extern.log4j.Log4j2; - -@Log4j2 -public class EKSService { - private AmazonEKS eksClient; - - public EKSService(final String region) { - this.eksClient = AmazonEKSClient.builder().withRegion(region).build(); - } - - /** - * Get EKS Cluster. - * - * @param context test context - */ - public Cluster getCluster(Context context) throws BaseException { - DescribeClusterRequest describeClusterRequest = - new DescribeClusterRequest().withName(context.getEksClusterName()); - DescribeClusterResult describeClusterResult = eksClient.describeCluster(describeClusterRequest); - if (null == describeClusterResult.getCluster()) { - throw new BaseException(ExceptionCode.EKS_CLUSTER_UNAVAIL); - } - return describeClusterResult.getCluster(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/IAMService.java b/integ-test/src/main/java/com/amazon/aocagent/services/IAMService.java deleted file mode 100644 index 2c1169ede..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/IAMService.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazonaws.regions.Region; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.identitymanagement.AmazonIdentityManagement; -import com.amazonaws.services.identitymanagement.AmazonIdentityManagementClientBuilder; -import com.amazonaws.services.identitymanagement.model.AddRoleToInstanceProfileRequest; -import com.amazonaws.services.identitymanagement.model.AttachRolePolicyRequest; -import com.amazonaws.services.identitymanagement.model.CreateInstanceProfileRequest; -import com.amazonaws.services.identitymanagement.model.CreateRoleRequest; -import com.amazonaws.services.identitymanagement.model.CreateRoleResult; -import com.amazonaws.services.identitymanagement.model.GetRoleRequest; -import com.amazonaws.services.identitymanagement.model.GetRoleResult; -import com.amazonaws.services.identitymanagement.model.NoSuchEntityException; -import lombok.extern.log4j.Log4j2; - -@Log4j2 -public class IAMService { - private static final String DNS_SUFFIX = ".amazonaws.com"; - private static final String assumeEC2RolePolicyDoc = - "{\"Version\":\"2012-10-17\"," - + "\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2" - + DNS_SUFFIX - + "\", \"ecs-tasks" + DNS_SUFFIX + "\"]},\"Action\":[\"sts:AssumeRole\"]}]}"; - private AmazonIdentityManagement amazonIdentityManagement; - private Region region; - - /** - * Construct IAMService with region. - * - * @param region the region to build IAM - */ - public IAMService(String region) { - amazonIdentityManagement = - AmazonIdentityManagementClientBuilder.standard().withRegion(region).build(); - this.region = Region.getRegion(Regions.fromName(region)); - } - - /** - * createIAMRoleIfNotExisted creates/returns the iam role if it's not existed. - * - * @param iamRoleName the iam role name - * @return the iam role arn. - */ - public String createIAMRoleIfNotExisted(String iamRoleName) { - try { - return getRoleArn(iamRoleName); - } catch (NoSuchEntityException ex) { - return createIAMRole(iamRoleName); - } - } - - /** - * get IAM role arn per role name. - * @param iamRoleName role name - * @return role arn - */ - public String getRoleArn(String iamRoleName) { - GetRoleResult getRoleResult = - amazonIdentityManagement.getRole(new GetRoleRequest().withRoleName(iamRoleName)); - - return getRoleResult.getRole().getArn(); - } - - private String createIAMRole(String iamRoleName) { - CreateRoleRequest createRoleRequest = new CreateRoleRequest(); - createRoleRequest.setDescription("Used for AOC integration tests."); - createRoleRequest.setPath("/"); - createRoleRequest.setRoleName(iamRoleName); - createRoleRequest.setMaxSessionDuration(3600); // 1 hour - createRoleRequest.setAssumeRolePolicyDocument(assumeEC2RolePolicyDoc); - - CreateRoleResult createRoleResult = amazonIdentityManagement.createRole(createRoleRequest); - final String roleArn = createRoleResult.getRole().getArn(); - - AttachRolePolicyRequest attachRolePolicyRequest = new AttachRolePolicyRequest(); - attachRolePolicyRequest.setRoleName(iamRoleName); - - attachRolePolicyRequest.setPolicyArn( - String.format("arn:%s:iam::aws:policy/AdministratorAccess", region.getPartition())); - amazonIdentityManagement.attachRolePolicy(attachRolePolicyRequest); - - CreateInstanceProfileRequest createInstanceProfileRequest = new CreateInstanceProfileRequest(); - createInstanceProfileRequest.setInstanceProfileName(iamRoleName); - createInstanceProfileRequest.setPath("/"); - amazonIdentityManagement.createInstanceProfile(createInstanceProfileRequest); - - AddRoleToInstanceProfileRequest addRoleToInstanceProfileRequest = - new AddRoleToInstanceProfileRequest(); - addRoleToInstanceProfileRequest.setRoleName(iamRoleName); - addRoleToInstanceProfileRequest.setInstanceProfileName(iamRoleName); - amazonIdentityManagement.addRoleToInstanceProfile(addRoleToInstanceProfileRequest); - - return roleArn; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/S3Service.java b/integ-test/src/main/java/com/amazon/aocagent/services/S3Service.java deleted file mode 100644 index c3bca5ad1..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/S3Service.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import com.amazonaws.services.s3.model.GetObjectRequest; -import com.amazonaws.services.s3.model.HeadBucketRequest; -import com.amazonaws.services.s3.model.ObjectMetadata; -import com.amazonaws.services.s3.model.PutObjectRequest; -import lombok.extern.log4j.Log4j2; - -import java.io.File; - -/** S3Service is the wrapper of Amazon S3 Client. */ -@Log4j2 -public class S3Service { - private AmazonS3 amazonS3; - - public S3Service(String region) { - amazonS3 = AmazonS3ClientBuilder.standard().withRegion(region).build(); - } - - /** - * uploadS3Object uploads the localfile to the s3 bucket. - * - * @param localFilePath the path of local file to be - * @param bucketName the s3 bucket name - * @param key the s3 key name - * @param override override the s3 key if it's already existed when override is true - * @throws BaseException when the s3 key is already existed and override is false - */ - public void uploadS3Object(String localFilePath, String bucketName, String key, boolean override) - throws BaseException { - log.info("upload {}/{} to s3", bucketName, key); - this.uploadS3Object( - localFilePath, bucketName, key, override, false, null, CannedAccessControlList.PublicRead); - } - - private void uploadS3Object( - String localFilePath, - String bucketName, - String key, - boolean override, - boolean exceptionOnKeyExisting, - ObjectMetadata objectMetadata, - CannedAccessControlList accessControlList) - throws BaseException { - // create Bucket if not existed - if (!amazonS3.doesBucketExistV2(bucketName)) { - amazonS3.createBucket(bucketName); - } - - // check if the key is existed - if (!override && amazonS3.doesObjectExist(bucketName, key)) { - if (exceptionOnKeyExisting) { - throw new BaseException( - ExceptionCode.S3_KEY_ALREADY_EXIST, "s3 key is already existed: " + key); - } else { - log.warn("s3 key is already existed: {}, skip", key); - return; - } - } - - PutObjectRequest putObjectRequest = - new PutObjectRequest(bucketName, key, new File(localFilePath)) - .withCannedAcl(accessControlList); - if (objectMetadata != null) { - putObjectRequest.setMetadata(objectMetadata); - } - - amazonS3.putObject(putObjectRequest); - } - - /** - * uploadS3ObjectWithPrivateAccess uploads the locafile to the s3 bucket with private access. - * - * @param localFilePath the path of local file to be - * @param bucketName the s3 bucket name - * @param key the s3 key name - * @param override override the s3 key if it's already existed when override is true - * @throws BaseException when the s3 key is already existed and override is false - */ - public void uploadS3ObjectWithPrivateAccess( - String localFilePath, String bucketName, String key, boolean override) throws BaseException { - this.uploadS3Object( - localFilePath, bucketName, key, override, false, null, CannedAccessControlList.Private); - } - - /** - * downloadS3Object downloads the s3 object to local. - * - * @param bucketName the s3 bucket name - * @param key the s3 object key name - * @param toLocation the local location to download to - */ - public void downloadS3Object(String bucketName, String key, String toLocation) { - log.info("download s3 object {}/{}", bucketName, key); - amazonS3.getObject(new GetObjectRequest(bucketName, key), new File(toLocation)); - } - - /** - * getS3ObjectAsString get s3 object and transfer it to string. - * - * @param bucketName the s3 bucket name - * @param key the s3 object key name - * @return object content as string - */ - public String getS3ObjectAsString(String bucketName, String key) { - log.info("get s3 object as string {}/{}", bucketName, key); - return amazonS3.getObjectAsString(bucketName, key); - } - - /** - * create s3 bucket base on the bucket name. - * - * @param bucketName s3 bucket name - * @throws BaseException when the bucket is already existed globally, or the bucket is already - * existed in the current aws account. - */ - public void createBucket(String bucketName) throws BaseException { - // check if the bucket exist globally - if (!amazonS3.doesBucketExistV2(bucketName)) { - amazonS3.createBucket(bucketName); - return; - } - - // check if the bucket is already existed in the current aws account - HeadBucketRequest headBucketRequest = new HeadBucketRequest(bucketName); - try { - amazonS3.headBucket(headBucketRequest); - } catch (Exception ex) { - log.info(ex.getMessage()); - // this bucket is not existed in this account - throw new BaseException( - ExceptionCode.S3_BUCKET_IS_EXISTED_GLOBALLY, - "this bucket " + bucketName + " is existed globally"); - } - - throw new BaseException(ExceptionCode.S3_BUCKET_IS_EXISTED_IN_CURRENT_ACCOUNT); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/SSMService.java b/integ-test/src/main/java/com/amazon/aocagent/services/SSMService.java deleted file mode 100644 index d6a590227..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/SSMService.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement; -import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder; -import com.amazonaws.services.simplesystemsmanagement.model.Command; -import com.amazonaws.services.simplesystemsmanagement.model.CommandPlugin; -import com.amazonaws.services.simplesystemsmanagement.model.CommandStatus; -import com.amazonaws.services.simplesystemsmanagement.model.DescribeInstanceInformationRequest; -import com.amazonaws.services.simplesystemsmanagement.model.InstanceInformation; -import com.amazonaws.services.simplesystemsmanagement.model.InstanceInformationFilter; -import com.amazonaws.services.simplesystemsmanagement.model.InvalidInstanceIdException; -import com.amazonaws.services.simplesystemsmanagement.model.ListCommandInvocationsRequest; -import com.amazonaws.services.simplesystemsmanagement.model.ListCommandsRequest; -import com.amazonaws.services.simplesystemsmanagement.model.SendCommandRequest; -import lombok.extern.log4j.Log4j2; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -@Log4j2 -public class SSMService { - private AWSSimpleSystemsManagement ssmClient; - - /** - * SSMService Constructor. - * - * @param region AWS region used to init SSM Service - */ - public SSMService(String region) throws Exception { - AWSSimpleSystemsManagement ssm = AWSSimpleSystemsManagementClientBuilder.standard() - .withRegion(region).build(); - ssmClient = ssm; - } - - /** - * updateSsmAgentToLatest. - * - * @param instanceId the ID of the instance which needs to update ssm agent - */ - public void updateSsmAgentToLatest(final String instanceId) - throws InterruptedException { - final Command command = ssmClient.sendCommand(new SendCommandRequest() - .withInstanceIds(Collections.singleton(instanceId)) - .withDocumentName(GenericConstants.UPDATE_SSM_AGENT_DOCUMENT.getVal()) - .withTimeoutSeconds(180)).getCommand(); - trackCommandStatus(command); - } - - /** - * runShellScriptCommand. - * - * @param instanceId the ID of the instance which needs to update ssm agent - * @param commands list of commands which will be executed by ssm run command - * @param commandDocumentName SSM document name - */ - public void runShellScriptCommand(final String instanceId, final List commands, - final String commandDocumentName) throws InterruptedException { - Map> params = new HashMap<>(); - params.put("commands", commands); - final Command command = ssmClient.sendCommand(new SendCommandRequest() - .withInstanceIds(Collections.singleton(instanceId)) - .withDocumentName(commandDocumentName) - .withTimeoutSeconds(180) - .withParameters(params)).getCommand(); - if (!"Success".equals(trackCommandStatus(command))) { - throw new RuntimeException("On " + instanceId + ", failed to execute the command: " - + commands); - } - } - - private String trackCommandStatus(final Command command) throws InterruptedException { - log.info("Starting command {} for document {}", - command.getCommandId(), command.getDocumentName()); - String status = command.getStatus(); - int remainingRetrys = Integer.parseInt(GenericConstants.MAX_RETRIES.getVal()); - while (CommandStatus.fromValue(status) == CommandStatus.Pending - || CommandStatus.fromValue(status) == CommandStatus.InProgress - || CommandStatus.fromValue(status) == CommandStatus.Cancelling) { - if (remainingRetrys <= 0) { - break; - } - remainingRetrys--; - log.info("Command status : " + status + ". Sleeping for " - + Integer.parseInt(GenericConstants.SLEEP_IN_SECONDS.getVal()) + " seconds..."); - TimeUnit.SECONDS.sleep(Integer.parseInt(GenericConstants.SLEEP_IN_SECONDS.getVal())); - status = ssmClient.listCommands(new ListCommandsRequest() - .withCommandId(command.getCommandId())).getCommands().get(0).getStatus(); - } - StringBuffer sb = new StringBuffer(); - try { - List commandPlugins = ssmClient.listCommandInvocations( - new ListCommandInvocationsRequest() - .withCommandId(command.getCommandId()).withDetails(true) - ).getCommandInvocations().get(0).getCommandPlugins(); - for (CommandPlugin commandPlugin : commandPlugins) { - sb.append("Name: "); - sb.append(commandPlugin.getName()); - sb.append("\n"); - sb.append("Output: "); - sb.append(commandPlugin.getOutput()); - sb.append("\n"); - } - } catch (Exception e) { - log.error("Exception happened for ssm listCommandInvocations call", e); - } - log.info("Command {} for document {} completed with status {} : \n{}", - command.getCommandId(), command.getDocumentName(), status, sb.toString()); - - return status; - } - - /** - * isInstanceReadyForSsm. - * - * @param instanceId the ID of the instance which needs to check ssm agent status - */ - public boolean isInstanceReadyForSsm(final String instanceId) throws Exception { - if (getInstanceInformation(instanceId) == null) { - log.info("Instance " + instanceId + " is not ready for SSM yet. Sleeping for " - + Integer.parseInt(GenericConstants.SLEEP_IN_SECONDS.getVal()) + " seconds..."); - return false; - } - log.info("Instance " + instanceId + " is ready for SSM"); - return true; - } - - private InstanceInformation getInstanceInformation(final String instanceId) { - try { - InstanceInformationFilter instanceInformationFilter = new InstanceInformationFilter() - .withKey("InstanceIds").withValueSet(instanceId); - DescribeInstanceInformationRequest describeInstanceInformationRequest = - new DescribeInstanceInformationRequest() - .withInstanceInformationFilterList(Collections - .singletonList(instanceInformationFilter)); - - final List instances = - ssmClient.describeInstanceInformation(describeInstanceInformationRequest) - .getInstanceInformationList(); - return instances.size() > 0 ? instances.get(0) : null; - } catch (InvalidInstanceIdException ex) { - log.error("Invalid Instance ID where instance ID is " + instanceId, ex); - return null; - } - } -} \ No newline at end of file diff --git a/integ-test/src/main/java/com/amazon/aocagent/services/XRayService.java b/integ-test/src/main/java/com/amazon/aocagent/services/XRayService.java deleted file mode 100644 index e381c07b3..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/services/XRayService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.services; - -import com.amazonaws.services.xray.AWSXRay; -import com.amazonaws.services.xray.AWSXRayClientBuilder; -import com.amazonaws.services.xray.model.BatchGetTracesRequest; -import com.amazonaws.services.xray.model.BatchGetTracesResult; -import com.amazonaws.services.xray.model.Trace; - -import java.util.List; - -public class XRayService { - private AWSXRay awsxRay; - - public XRayService(String region) { - awsxRay = AWSXRayClientBuilder.standard().withRegion(region).build(); - } - - /** - * List trace objects by ids. - * @param traceIdList trace id list - * @return trace object list - */ - public List listTraceByIds(List traceIdList) { - BatchGetTracesResult batchGetTracesResult = - awsxRay.batchGetTraces(new BatchGetTracesRequest().withTraceIds(traceIdList)); - - return batchGetTracesResult.getTraces(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/DownloadCandidate.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/DownloadCandidate.java deleted file mode 100644 index 07fb30098..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/DownloadCandidate.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.helpers.CommandExecutionHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.S3Service; -import com.amazonaws.regions.Regions; - -import java.nio.file.Files; -import java.nio.file.Paths; - -public class DownloadCandidate implements ITask { - S3Service s3Service; - Context context; - - static String COMMAND_TO_UNPACK = "tar -zxvf %s -C %s"; - - @Override - public void init(Context context) throws Exception { - this.context = context; - this.s3Service = new S3Service(Regions.US_EAST_1.getName()); - } - - @Override - public void execute() throws Exception { - // download candidate package from s3 - s3Service.downloadS3Object( - context.getStack().getS3ReleaseCandidateBucketName(), - context.getGithubSha() + ".tar.gz", - GenericConstants.CANDIDATE_DOWNLOAD_TO.getVal()); - - // unpack the tarball into cwd since it already keeps the folder structure - CommandExecutionHelper.runChildProcess( - String.format( - COMMAND_TO_UNPACK, - GenericConstants.CANDIDATE_DOWNLOAD_TO.getVal(), - GenericConstants.CANDIDATE_UNPACK_TO.getVal())); - - // validate version - String versionFromFile = - new String(Files.readAllBytes(Paths.get(context.getLocalPackagesDir() + "/VERSION"))) - .trim(); - if (!context.getAgentVersion().equals(versionFromFile)) { - throw new BaseException( - ExceptionCode.VERSION_NOT_MATCHED, - "version is not matched " + versionFromFile + ":" + context.getAgentVersion()); - } - - // validate github sha - if (!context - .getGithubSha() - .equals( - new String(Files.readAllBytes(Paths.get(context.getLocalPackagesDir() + "/GITHUB_SHA"))) - .trim())) { - throw new BaseException(ExceptionCode.GITHUB_SHA_NOT_MATCHED); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/EC2Clean.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/EC2Clean.java deleted file mode 100644 index 9a07ba944..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/EC2Clean.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.EC2Service; -import com.amazonaws.services.ec2.model.Instance; -import com.amazonaws.services.ec2.model.Tag; -import lombok.extern.log4j.Log4j2; -import org.joda.time.DateTime; - -import java.util.ArrayList; -import java.util.List; - -@Log4j2 -public class EC2Clean implements ITask { - private EC2Service ec2Service; - - @Override - public void init(Context context) throws Exception { - ec2Service = new EC2Service(context.getStack().getTestingRegion()); - } - - @Override - public void execute() throws Exception { - // fetch all the instances - List instanceList = ec2Service.listInstances(); - - // filter instance older than 2 hours ago - List instanceIdListToBeTerminated = new ArrayList<>(); - - instanceList.forEach( - instance -> { - // skip the instance which is not running - if (!instance.getState().getName().equals("running")) { - return; - } - log.info("check instance {}, status: {}", instance.getInstanceId(), instance.getState()); - if (!instance - .getLaunchTime() - .before( - new DateTime() - .minusMinutes( - Integer.parseInt(GenericConstants.RESOURCE_CLEAN_THRESHOLD.getVal())) - .toDate())) { - return; - } - - if (instance.getTags().size() > 1) { - return; - } - - if (instance.getTags().size() == 1 - && !instance - .getTags() - .get(0) - .equals( - new Tag( - GenericConstants.EC2_INSTANCE_TAG_KEY.getVal(), - GenericConstants.EC2_INSTANCE_TAG_VAL.getVal()))) { - return; - } - - instanceIdListToBeTerminated.add(instance.getInstanceId()); - }); - - // terminate instance - ec2Service.terminateInstance(instanceIdListToBeTerminated); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/ECSClean.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/ECSClean.java deleted file mode 100644 index 62ca6839c..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/ECSClean.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.EC2Service; -import com.amazon.aocagent.services.ECSService; -import com.amazonaws.services.ec2.model.Instance; -import lombok.extern.log4j.Log4j2; -import org.joda.time.DateTime; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -@Log4j2 -public class ECSClean implements ITask { - private EC2Service ec2Service; - private ECSService ecsService; - - @Override - public void init(Context context) throws Exception { - this.ec2Service = new EC2Service(context.getStack().getTestingRegion()); - this.ecsService = new ECSService(context.getStack().getTestingRegion()); - } - - @Override - public void execute() throws Exception { - cleanTasks(); - cleanContainerInstances(); - cleanCluster(); - cleanTaskDefinitions(); - } - - private void cleanTaskDefinitions() { - ecsService.cleanTaskDefinitions(GenericConstants.AOC_PREFIX.getVal()); - } - - private void cleanCluster() { - ecsService.cleanCluster(); - } - - private void cleanContainerInstances() throws Exception { - List instanceList = - ec2Service.listInstancesByTag( - GenericConstants.EC2_INSTANCE_TAG_KEY.getVal(), - GenericConstants.EC2_INSTANCE_ECS_TAG_VAL.getVal()); - // filter instance older than 2 hours ago - List instanceIdListToBeTerminated = new ArrayList<>(); - - instanceList.forEach( - instance -> { - if (instance - .getLaunchTime() - .before( - new DateTime() - .minusMinutes( - Integer.parseInt(GenericConstants.RESOURCE_CLEAN_THRESHOLD.getVal())) - .toDate()) - && instance.getTags().size() == 1) { - instanceIdListToBeTerminated.add(instance.getInstanceId()); - } - }); - - log.info("terminating unused ec2 instances: {}", instanceIdListToBeTerminated); - // terminate instance - ec2Service.terminateInstance(instanceIdListToBeTerminated); - } - - private void cleanTasks() throws Exception { - ecsService.cleanTasks(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/EKSClean.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/EKSClean.java deleted file mode 100644 index 6f88862ad..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/EKSClean.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.helpers.CommandExecutionHelper; -import com.amazon.aocagent.helpers.EKSTestOptionsValidationHelper; -import com.amazon.aocagent.helpers.TempDirHelper; -import com.amazon.aocagent.models.Context; -import lombok.extern.log4j.Log4j2; -import org.joda.time.DateTime; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -@Log4j2 -public class EKSClean implements ITask { - private Context context; - - @Override - public void init(Context context) throws Exception { - context.setEksTestArtifactsDir(new TempDirHelper(GenericConstants.EKS_INTEG_TEST.getVal())); - EKSTestOptionsValidationHelper.checkEKSTestOptions(context); - this.context = context; - } - - @Override - public void execute() throws Exception { - cleanNamespaces(); - TempDirHelper.cleanTempDirs(); - } - - @Override - public void clean() throws Exception { - context.getEksTestArtifactsDir().deletePath(); - } - - private void cleanNamespaces() throws BaseException { - String command = - String.format( - "%s get ns --kubeconfig %s", context.getKubectlPath(), context.getKubeconfigPath()); - String result = CommandExecutionHelper.runChildProcessWithAWSCred(command); - - List namespaces = new ArrayList<>(); - String[] lines = result.split("\n"); - for (String line : lines) { - if (line.startsWith("eks-integ-test-")) { - // line example: "eks-integ-test-1599881334414 Active 10s" - String namespace = line.split(" ")[0]; - // extract creation time (in milliseconds) of the namespace, i.e. - // eks-integ-test-1599881334414 - String[] elements = namespace.split("-", 4); - if (elements.length == 4) { - String timestamp = elements[3]; - // add to target namespaces if it was created 2 hours ago - if (new Date(Long.parseLong(timestamp)) - .before( - new DateTime() - .minusMinutes( - Integer.parseInt(GenericConstants.RESOURCE_CLEAN_THRESHOLD.getVal())) - .toDate())) { - namespaces.add(namespace); - } - } - } - } - - log.info("Deleting old namespaces {}", namespaces); - for (String namespace : namespaces) { - command = - String.format( - "%s delete ns %s --kubeconfig %s", - context.getKubectlPath(), namespace, context.getKubeconfigPath()); - CommandExecutionHelper.runChildProcessWithAWSCred(command); - log.info("namespace {} has been deleted !", namespace); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/ITask.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/ITask.java deleted file mode 100644 index 0b893a064..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/ITask.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.models.Context; - -public interface ITask { - void init(final Context context) throws Exception; - - void execute() throws Exception; - - default void clean() throws Exception {} - - ; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTest.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTest.java deleted file mode 100644 index e61b99cd9..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.installers.emiterinstallers.OTEmitterInstaller; -import com.amazon.aocagent.installers.otinstallers.OTInstaller; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.testbeds.TestBed; -import com.amazon.aocagent.validators.BatchedValidator; -import com.amazon.aocagent.validators.IValidator; - -import java.util.List; - -public class IntegTest implements ITask { - TestBed testBed; - OTInstaller otInstaller; - List otEmitterInstallerList; - BatchedValidator batchedValidator; - Context context; - - /** - * Construct IntegTest Object. - * - * @param testBed the testbed, for example: EC2 - * @param otInstaller the installer for ot package - * @param otEmitterInstallerList the installers for the emitter image - * @param validatorList the validator list - */ - public IntegTest( - TestBed testBed, - OTInstaller otInstaller, - List otEmitterInstallerList, - List validatorList) { - this.testBed = testBed; - this.otInstaller = otInstaller; - this.otEmitterInstallerList = otEmitterInstallerList; - this.batchedValidator = new BatchedValidator(validatorList); - } - - @Override - public void init(Context context) throws Exception { - testBed.init(context); - } - - @Override - public void execute() throws Exception { - context = testBed.launchTestBed(); - - if (otInstaller != null) { - otInstaller.init(context); - otInstaller.installAndStart(); - } - - for (OTEmitterInstaller emitterInstaller : this.otEmitterInstallerList) { - emitterInstaller.init(context); - emitterInstaller.installAndStart(); - } - - batchedValidator.init(context); - batchedValidator.validate(); - } - - @Override - public void clean() throws Exception { - if (context.getEksTestArtifactsDir() != null) { - context.getEksTestArtifactsDir().deletePath(); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTestFactory.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTestFactory.java deleted file mode 100644 index 29404f157..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/IntegTestFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.TestCase; -import com.amazon.aocagent.models.Context; - -public class IntegTestFactory { - - /** - * run the testcase. - * - * @param testCase the testcase to run - * @param context the testing context - * @throws Exception when the test fails - */ - public static void runTestCase(TestCase testCase, Context context) throws Exception { - IntegTest integTest = - new IntegTest( - testCase.getTestBed(), - testCase.getOtInstaller(), - testCase.getOtEmitterInstallerList(), - testCase.getValidatorList()); - - try { - integTest.init(context); - integTest.execute(); - } finally { - integTest.clean(); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/S3Release.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/S3Release.java deleted file mode 100644 index 58e1a4ac6..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/S3Release.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.LocalPackage; -import com.amazon.aocagent.enums.S3Package; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.S3Service; -import com.amazonaws.regions.Regions; -import lombok.Setter; -import lombok.extern.log4j.Log4j2; -import net.steppschuh.markdowngenerator.table.Table; -import net.steppschuh.markdowngenerator.text.emphasis.BoldText; - -import java.nio.file.Files; -import java.nio.file.Paths; - -/** - * S3Release will upload the packages[rpm, deb, msi, pkg] into the configured S3 bucket. it will be - * used for AOC distribution as well as the pre-flight step in Integ-test to simulate the releases - * in the Testing Stack - */ -@Log4j2 -@Setter -public class S3Release implements ITask { - private Context context; - private S3Service s3Service; - private String s3Bucket; - - @Override - public void init(final Context context) throws Exception { - this.context = context; - - // the global bucket is in us-east-1 - s3Service = new S3Service(Regions.US_EAST_1.getName()); - // bucket name is globally unique, so we use different bucket name for different stacks - s3Bucket = context.getStack().getS3BucketName(); - } - - @Override - public void execute() throws Exception { - log.info("context: {}", this.context); - this.releasePackagesToS3(); - this.printOutDownloadingLinks(); - } - - private void printOutDownloadingLinks() throws Exception { - // generate a package download link table with markdown as part of release notes - Table.Builder tableBuilder = - new Table.Builder() - .withAlignment(Table.ALIGN_CENTER) - .addRow(new BoldText("Arch"), new BoldText("Platform"), new BoldText("Package")); - - for (S3Package s3Package : S3Package.values()) { - tableBuilder.addRow( - s3Package.getLocalPackage().getArchitecture().name(), - s3Package.getSupportedOSDistribution().name(), - "https://" - + this.s3Bucket - + ".s3.amazonaws.com/" - + s3Package.getS3Key(context.getAgentVersion())); - } - - log.info(tableBuilder.build().serialize()); - } - - /** - * releasePackagesToS3 upload all the packages to the S3 bucket. - * - * @throws BaseException when one of packages is not existed locally - */ - public void releasePackagesToS3() throws BaseException { - // validate if local packages are existed - validateLocalPackage(); - - // upload local packages to s3 with versioned key - uploadToS3(context.getAgentVersion(), false); - - // upload local packages to s3 with the "latest" key, override the key if it's existed - uploadToS3("latest", true); - } - - private void validateLocalPackage() throws BaseException { - for (LocalPackage builtPackage : LocalPackage.values()) { - // assuming the local directory is os/arch/version/ - String filePath = builtPackage.getFilePath(context.getLocalPackagesDir()); - if (!Files.exists(Paths.get(filePath))) { - throw new BaseException( - ExceptionCode.LOCAL_PACKAGE_NOT_EXIST, "local package not exist: " + filePath); - } - } - } - - private void uploadToS3(String packageVersion, boolean override) throws BaseException { - for (S3Package s3Package : S3Package.values()) { - s3Service.uploadS3Object( - s3Package.getLocalPackage().getFilePath(context.getLocalPackagesDir()), - s3Bucket, - s3Package.getS3Key(packageVersion), - override); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/Setup.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/Setup.java deleted file mode 100644 index 4aa9d06ad..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/Setup.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.EC2Service; -import com.amazon.aocagent.services.IAMService; -import com.amazon.aocagent.services.S3Service; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import lombok.extern.log4j.Log4j2; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - -/** - * This is the first task needed to be ran for any new developer, it creates the required aws - * resources in your testing aws account, we assume you have already configure your aws account - * credentials at ~/.aws/credentials, for more info about how to configure credentials please check - * https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html. - */ -@Log4j2 -public class Setup implements ITask { - EC2Service ec2Service; - S3Service s3Service; - Context context; - - @Override - public void init(Context context) throws Exception { - ec2Service = new EC2Service(context.getStack().getTestingRegion()); - s3Service = new S3Service(context.getStack().getTestingRegion()); - this.context = context; - } - - @Override - public void execute() throws Exception { - setupS3RelatedResources(); - setupEC2RelatedResources(); - dumpStack(); - } - - private void setupEC2RelatedResources() throws IOException, BaseException { - log.info("create iam role to give permissions to emit data to CloudWatch"); - IAMService iamService = new IAMService(context.getStack().getTestingRegion()); - iamService.createIAMRoleIfNotExisted(GenericConstants.IAM_ROLE_NAME.getVal()); - - log.info("create sshkey for ec2 instance login"); - ec2Service.createSSHKeyIfNotExisted( - GenericConstants.SSH_KEY_NAME.getVal(), context.getStack().getSshKeyS3BucketName()); - - log.info("create security group so that the instance could send requests out"); - ec2Service.createSecurityGroup(GenericConstants.SECURITY_GROUP_NAME.getVal()); - } - - private void setupS3RelatedResources() throws BaseException { - // setup all the required s3 buckets - for (String bucketName : - Arrays.asList( - context.getStack().getS3BucketName(), - context.getStack().getS3ReleaseCandidateBucketName(), - context.getStack().getSshKeyS3BucketName(), - context.getStack().getTraceDataS3BucketName())) { - try { - s3Service.createBucket(bucketName); - } catch (BaseException ex) { - // don't quit if the bucket is in the current account - if (ExceptionCode.S3_BUCKET_IS_EXISTED_IN_CURRENT_ACCOUNT.getCode() == ex.getCode()) { - log.info("the bucket {} is already in current account", bucketName); - } else { - throw ex; - } - } - } - } - - private void dumpStack() throws IOException { - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - mapper.writeValue(new File(this.context.getStackFilePath()), this.context.getStack()); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/TaskFactory.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/TaskFactory.java deleted file mode 100644 index cfb27c0f6..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/TaskFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.models.Context; - -public class TaskFactory { - /** - * execute task base on name. - * - * @param taskName the task name - * @param context the testing context - * @throws Exception when the task execution fails - */ - public static void executeTask(String taskName, Context context) throws Exception { - ITask task = - (ITask) - Class.forName(TaskFactory.class.getPackage().getName() + "." + taskName).newInstance(); - try { - task.init(context); - task.execute(); - } finally { - task.clean(); - } - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/tasks/UploadCandidate.java b/integ-test/src/main/java/com/amazon/aocagent/tasks/UploadCandidate.java deleted file mode 100644 index 4bf643c8f..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/tasks/UploadCandidate.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.tasks; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.helpers.CommandExecutionHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.S3Service; -import com.amazonaws.regions.Regions; - -/** - * upload the tested packages to s3 as release candidates, use git commit to distinguish the - * packages. - */ -public class UploadCandidate implements ITask { - S3Service s3Service; - Context context; - static String COMMAND_TO_PACK = "tar -czvf %s %s"; - - @Override - public void init(Context context) throws Exception { - this.context = context; - s3Service = new S3Service(Regions.US_EAST_1.getName()); - } - - @Override - public void execute() throws Exception { - // archive the candidate packages, build tarball from local-packages dir - CommandExecutionHelper.runChildProcess( - String.format( - COMMAND_TO_PACK, - GenericConstants.CANDIDATE_PACK_TO.getVal(), - context.getLocalPackagesDir())); - - // upload the zip file to s3 - s3Service.uploadS3ObjectWithPrivateAccess( - GenericConstants.CANDIDATE_PACK_TO.getVal(), - context.getStack().getS3ReleaseCandidateBucketName(), - context.getGithubSha() + ".tar.gz", - false); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1AmazonLinuxAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/A1AmazonLinuxAMI.java deleted file mode 100644 index b77182544..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1AmazonLinuxAMI.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; - -public class A1AmazonLinuxAMI extends AmazonLinuxAMI { - public A1AmazonLinuxAMI(String amiId) { - super(amiId); - } - - @Override - public S3Package getS3Package() { - return S3Package.AMAZON_LINUX_ARM64_RPM; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1RedHatAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/A1RedHatAMI.java deleted file mode 100644 index fd94dd2e2..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1RedHatAMI.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; - -public class A1RedHatAMI extends RedHatAMI { - public A1RedHatAMI(String amiId) { - super(amiId); - } - - @Override - public S3Package getS3Package() { - return S3Package.REDHAT_ARM64_RPM; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1SuseAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/A1SuseAMI.java deleted file mode 100644 index 094202c8e..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1SuseAMI.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; - -public class A1SuseAMI extends SuseAMI { - public A1SuseAMI(String amiId) { - super(amiId); - } - - @Override - public S3Package getS3Package() { - return S3Package.SUSE_ARM64_RPM; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1UbuntuAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/A1UbuntuAMI.java deleted file mode 100644 index e2ef768c7..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/A1UbuntuAMI.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; - -public class A1UbuntuAMI extends UbuntuAMI { - public A1UbuntuAMI(String amiId) { - super(amiId); - } - - @Override - public S3Package getS3Package() { - return S3Package.UBUNTU_ARM64_DEB; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/AmazonLinuxAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/AmazonLinuxAMI.java deleted file mode 100644 index 9cb24a099..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/AmazonLinuxAMI.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; - -public class AmazonLinuxAMI extends LinuxAMI { - public AmazonLinuxAMI(String amiId) { - super(amiId); - } - - @Override - public String getLoginUser() { - return "ec2-user"; - } - - @Override - public S3Package getS3Package() { - return S3Package.AMAZON_LINUX_AMD64_RPM; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/Centos6AMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/Centos6AMI.java deleted file mode 100644 index f8249b058..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/Centos6AMI.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -public class Centos6AMI extends CentosAMI { - public Centos6AMI(String amiId) { - super(amiId); - } - - @Override - public String getDisableFirewallCommand() { - return "sudo iptables -I INPUT -p tcp -m tcp --dport 55680 -j ACCEPT" - + "&& sudo service iptables save"; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/CentosAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/CentosAMI.java deleted file mode 100644 index 1f1258f97..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/CentosAMI.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; - -public class CentosAMI extends LinuxAMI { - public CentosAMI(String amiId) { - super(amiId); - } - - @Override - public String getLoginUser() { - return "centos"; - } - - @Override - public S3Package getS3Package() { - return S3Package.CENTOS_AMD64_RPM; - } - -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/DebianAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/DebianAMI.java deleted file mode 100644 index 3c343e970..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/DebianAMI.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; - -import java.util.Arrays; -import java.util.List; - -public class DebianAMI extends LinuxAMI { - public DebianAMI(String amiId) { - super(amiId); - } - - @Override - public String getLoginUser() { - return "admin"; - } - - @Override - public S3Package getS3Package() { - return S3Package.DEBIAN_AMD64_DEB; - } - - @Override - public String getDownloadingCommand(String fromUrl, String toLocation) { - return String.format("wget %s -O %s", fromUrl, toLocation); - } - - @Override - public String getInstallingCommand(String packagePath) { - return String.format("sudo dpkg -i %s", packagePath); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/EcsOptimizedAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/EcsOptimizedAMI.java deleted file mode 100644 index 1fd86dd84..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/EcsOptimizedAMI.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.S3Package; -import com.amazonaws.services.ec2.model.InstanceType; - -public class EcsOptimizedAMI extends LinuxAMI { - - public EcsOptimizedAMI(String amiId) { - super(amiId); - } - - @Override - public String getLoginUser() { - return null; - } - - @Override - public S3Package getS3Package() { - return null; - } - - @Override - public InstanceType getInstanceType() { - return InstanceType.T2Medium; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/ITestAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/ITestAMI.java deleted file mode 100644 index b23d5cc9d..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/ITestAMI.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.OSType; -import com.amazon.aocagent.enums.S3Package; -import com.amazonaws.services.ec2.model.InstanceType; - -import java.util.List; - -public interface ITestAMI { - String getAMIId(); - - boolean isUseSSM(); - - String getLoginUser(); - - S3Package getS3Package(); - - String getDownloadingCommand(String fromUrl, String toLocation); - - String getInstallingCommand(String packagePath); - - String getConfiguringCommand(String configContent); - - String getStartingCommand(String configPath); - - String getDisableFirewallCommand(); - - String getSsmDownloadingCommand(String fromUrl, String toLocation); - - String getSsmInstallingCommand(String packagePath); - - String getSsmConfiguringCommand(String configContent); - - String getSsmStartingCommand(); - - String getSSMDocument(); - - InstanceType getInstanceType(); -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testamis/LinuxAMI.java b/integ-test/src/main/java/com/amazon/aocagent/testamis/LinuxAMI.java deleted file mode 100644 index a7ce32c1b..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testamis/LinuxAMI.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testamis; - -import com.amazon.aocagent.enums.Architecture; -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.enums.OSType; -import com.amazon.aocagent.enums.S3Package; -import com.amazonaws.services.ec2.model.InstanceType; - -public abstract class LinuxAMI implements ITestAMI { - private String amiId; - private boolean useSSM; - - public LinuxAMI(String amiId) { - this(amiId, false); - } - - public LinuxAMI(String amiId, boolean useSSM) { - this.amiId = amiId; - this.useSSM = useSSM; - } - - @Override - public String getAMIId() { - return this.amiId; - } - - @Override - public boolean isUseSSM() { - return useSSM; - } - - @Override - public abstract String getLoginUser(); - - @Override - public abstract S3Package getS3Package(); - - @Override - public String getDownloadingCommand(String fromUrl, String toLocation) { - return String.format("curl -L %s -o %s", fromUrl, toLocation); - } - - @Override - public String getInstallingCommand(String packagePath) { - return String.format("sudo rpm -Uvh %s", packagePath); - } - - @Override - public String getConfiguringCommand(String configContent) { - return String.format( - "(\n" + "cat<> /etc/ecs/ecs.config"; - - @Override - public void init(Context context) throws Exception { - this.context = context; - this.ecsService = new ECSService(context.getStack().getTestingRegion()); - this.ec2Service = new EC2Service(context.getStack().getTestingRegion()); - this.networkService = new AwsNetworkService(context.getStack().getTestingRegion()); - } - - /** - * run AOC and data emitter on ECS fargate and EC2 instances. - * @return context params after setup ECS test bed - * @throws Exception failed to launch testbed - */ - @Override - public Context launchTestBed() throws Exception { - // ECS uses current timestamp as instance id - context.setInstanceId(String.valueOf(System.currentTimeMillis())); - // create ECS cluster - final String clusterName = this.generateEcsClusterName(context); - this.context.setEcsClusterName(clusterName); - if (!ecsService.describeCluster(clusterName).isPresent()) { - ecsService.createCluster(clusterName); - } - // get the default security group, vpc and subnets - // from the provided aws account - this.buildNetworkContext(context); - - // launch new EC2 container instance for EC2 mode - if (context.getEcsLaunchType().equalsIgnoreCase(GenericConstants.EC2.getVal()) - && !ecsService.isContainerInstanceAvail(clusterName)) { - log.info("launching up a container instance"); - EC2InstanceParams ec2InstanceParams = this.buildEc2ConfigForEcs(context); - Instance containerInstance = ec2Service.launchInstance(ec2InstanceParams); - log.info( - "created new ECS container instance: {} - {} ", - containerInstance.getInstanceId(), - containerInstance.getState().getName()); - ecsService.waitForContainerInstanceRegistered(clusterName); - } - - return this.context; - } - - private void buildNetworkContext(Context context) throws Exception { - DescribeSecurityGroupsResult securityGroupsResult = - networkService.describeDefaultSecurityGroup(); - SecurityGroup defaultGroup = securityGroupsResult.getSecurityGroups().get(0); - context.setDefaultSecurityGrpId(defaultGroup.getGroupId()); - context.setDefaultVpcId(defaultGroup.getVpcId()); - - DescribeSubnetsResult subnetsResult = - networkService.describeVpcSubnets(context.getDefaultVpcId()); - context.setDefaultSubnets(subnetsResult.getSubnets()); - } - - private String generateEcsClusterName(Context context) { - return GenericConstants.ECS_SIDECAR_CLUSTER.getVal() + "-" + context.getInstanceId(); - } - - /** - * build launching config for EC2 container instance. - * @param context test context - * @return {@link EC2InstanceParams} ecs launch params - */ - private EC2InstanceParams buildEc2ConfigForEcs(Context context) { - // tag instance for management - TagSpecification tagSpecification = - new TagSpecification() - .withResourceType(ResourceType.Instance) - .withTags( - new Tag( - GenericConstants.EC2_INSTANCE_TAG_KEY.getVal(), - GenericConstants.EC2_INSTANCE_ECS_TAG_VAL.getVal())); - String userData = - Base64.getEncoder() - .encodeToString( - String.format( - CONTAINER_INSTANCE_USER_DATA, context.getEcsClusterName()) - .getBytes()); - return EC2InstanceParams.builder() - .amiId(context.getTestingAMI().getAMIId()) - .instanceType(context.getTestingAMI().getInstanceType()) - .iamRoleName(GenericConstants.IAM_ROLE_NAME.getVal()) - .securityGrpName(GenericConstants.DEFAULT.getVal()) - .tagSpecification(tagSpecification) - .sshKeyName(GenericConstants.SSH_KEY_NAME.getVal()) - .userData(userData) - .build(); - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testbeds/EKSTestBed.java b/integ-test/src/main/java/com/amazon/aocagent/testbeds/EKSTestBed.java deleted file mode 100644 index 6d5ac5ec4..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testbeds/EKSTestBed.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testbeds; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.helpers.EKSTestOptionsValidationHelper; -import com.amazon.aocagent.helpers.TempDirHelper; -import com.amazon.aocagent.models.Context; -import lombok.extern.log4j.Log4j2; - -@Log4j2 -public class EKSTestBed implements TestBed { - private Context context; - - @Override - public void init(Context context) { - this.context = context; - } - - @Override - public Context launchTestBed() throws Exception { - context.setEksTestArtifactsDir(new TempDirHelper(GenericConstants.EKS_INTEG_TEST.getVal())); - EKSTestOptionsValidationHelper.checkEKSTestOptions(context); - return this.context; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/testbeds/TestBed.java b/integ-test/src/main/java/com/amazon/aocagent/testbeds/TestBed.java deleted file mode 100644 index 72c5ef73a..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/testbeds/TestBed.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.testbeds; - -import com.amazon.aocagent.models.Context; - -public interface TestBed { - void init(Context context) throws Exception; - - Context launchTestBed() throws Exception; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/validators/BatchedValidator.java b/integ-test/src/main/java/com/amazon/aocagent/validators/BatchedValidator.java deleted file mode 100644 index d3ad4cb41..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/validators/BatchedValidator.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.validators; - -import com.amazon.aocagent.models.Context; -import lombok.extern.log4j.Log4j2; - -import java.util.List; - -@Log4j2 -public class BatchedValidator { - List validatorList; - Context context; - - public BatchedValidator(List validatorList) { - this.validatorList = validatorList; - } - - /** - * validate runs all the validators configured. - * - * @throws Exception when the validation fails - */ - public void validate() throws Exception { - for (IValidator validator : this.validatorList) { - validator.init(context); - validator.validate(); - } - - log.info("Validation is passed!!!"); - } - - public void init(Context context) { - this.context = context; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/validators/IValidator.java b/integ-test/src/main/java/com/amazon/aocagent/validators/IValidator.java deleted file mode 100644 index f2c834f0f..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/validators/IValidator.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.validators; - -import com.amazon.aocagent.models.Context; - -public interface IValidator { - void init(Context context) throws Exception; - - void validate() throws Exception; -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/validators/MetricValidator.java b/integ-test/src/main/java/com/amazon/aocagent/validators/MetricValidator.java deleted file mode 100644 index 8fe46e042..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/validators/MetricValidator.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.validators; - -import com.amazon.aocagent.enums.GenericConstants; -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.helpers.MustacheHelper; -import com.amazon.aocagent.helpers.RetryHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.services.CloudWatchService; -import com.amazonaws.services.cloudwatch.model.Dimension; -import com.amazonaws.services.cloudwatch.model.Metric; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import lombok.extern.log4j.Log4j2; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; - -@Log4j2 -public class MetricValidator implements IValidator { - private static int MAX_RETRY_COUNT = 60; - private static final String DEFAULT_DIMENSION_NAME = "OTelLib"; - private static final String DEFAULT_DIMENSION_VALUE = "cloudwatch-otel"; - - private MustacheHelper mustacheHelper = new MustacheHelper(); - private Context context; - - @Override - public void validate() throws Exception { - log.info("Start metric validating"); - final List expectedMetricList = this.getExpectedMetricList(context); - CloudWatchService cloudWatchService = - new CloudWatchService(context.getStack().getTestingRegion()); - - RetryHelper.retry( - MAX_RETRY_COUNT, - () -> { - List metricList = - this.listMetricFromCloudWatch(cloudWatchService, expectedMetricList); - log.info("check if all the expected metrics are found"); - compareMetricLists(expectedMetricList, metricList); - - log.info("check if there're unexpected additional metric getting fetched"); - compareMetricLists(metricList, expectedMetricList); - }); - - log.info("finish metric validation"); - } - - /** - * Check if every metric in toBeChckedMetricList is in baseMetricList. - * - * @param toBeCheckedMetricList toBeCheckedMetricList - * @param baseMetricList baseMetricList - */ - private void compareMetricLists(List toBeCheckedMetricList, List baseMetricList) - throws BaseException { - log.info("compare two metric list {} {}", toBeCheckedMetricList, baseMetricList); - // load metrics into a hash set - Set metricSet = - new TreeSet<>( - (Metric o1, Metric o2) -> { - // check namespace - if (!o1.getNamespace().equals(o2.getNamespace())) { - return o1.getNamespace().compareTo(o2.getNamespace()); - } - - // check metric name - if (!o1.getMetricName().equals(o2.getMetricName())) { - return o1.getMetricName().compareTo(o2.getMetricName()); - } - - // sort and check dimensions - List dimensionList1 = o1.getDimensions(); - List dimensionList2 = o2.getDimensions(); - dimensionList1.sort(Comparator.comparing(Dimension::getName)); - dimensionList2.sort(Comparator.comparing(Dimension::getName)); - return dimensionList1.toString().compareTo(dimensionList2.toString()); - }); - for (Metric metric : baseMetricList) { - metricSet.add(metric); - } - - for (Metric metric : toBeCheckedMetricList) { - if (!metricSet.contains(metric)) { - throw new BaseException( - ExceptionCode.EXPECTED_METRIC_NOT_FOUND, - String.format( - "metric in toBeCheckedMetricList %s not found in baseMetricList: %s", - metric, metricSet)); - } - } - } - - private List getExpectedMetricList(Context context) throws IOException { - // get expected metrics as yaml from config - String yamlExpectedMetrics = mustacheHelper.render(context.getExpectedMetric(), context); - - // load metrics from yaml - ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - List expectedMetricList = - mapper.readValue( - yamlExpectedMetrics.getBytes(StandardCharsets.UTF_8), - new TypeReference>() {}); - - return rollupMetric(expectedMetricList); - } - - private List listMetricFromCloudWatch( - CloudWatchService cloudWatchService, List expectedMetricList) throws IOException { - Set metricNameSet = new HashSet(); - for (Metric metric : expectedMetricList) { - metricNameSet.add(metric.getMetricName()); - } - - // search by metric name - List result = new ArrayList<>(); - for (String metricName : metricNameSet) { - result.addAll( - cloudWatchService.listMetrics( - GenericConstants.SERVICE_NAMESPACE.getVal() - + "/" - + GenericConstants.SERVICE_NAME.getVal(), - metricName)); - } - - return result; - } - - private List rollupMetric(List metricList) { - List rollupMetricList = new ArrayList<>(); - for (Metric metric : metricList) { - // all dimension rollup - Metric allDimensionsMetric = new Metric(); - allDimensionsMetric.setMetricName(metric.getMetricName()); - allDimensionsMetric.setNamespace(metric.getNamespace()); - allDimensionsMetric.setDimensions(metric.getDimensions()); - allDimensionsMetric - .getDimensions() - .add(new Dimension().withName(DEFAULT_DIMENSION_NAME).withValue(DEFAULT_DIMENSION_VALUE)); - rollupMetricList.add(allDimensionsMetric); - - // zero dimension rollup - Metric zeroDimensionMetric = new Metric(); - zeroDimensionMetric.setNamespace(metric.getNamespace()); - zeroDimensionMetric.setMetricName(metric.getMetricName()); - zeroDimensionMetric.setDimensions( - Arrays.asList( - new Dimension().withName(DEFAULT_DIMENSION_NAME).withValue(DEFAULT_DIMENSION_VALUE))); - rollupMetricList.add(zeroDimensionMetric); - - // single dimension rollup - for (Dimension dimension : metric.getDimensions()) { - Metric singleDimensionMetric = new Metric(); - singleDimensionMetric.setNamespace(metric.getNamespace()); - singleDimensionMetric.setMetricName(metric.getMetricName()); - singleDimensionMetric.setDimensions( - Arrays.asList( - new Dimension() - .withName(DEFAULT_DIMENSION_NAME) - .withValue(DEFAULT_DIMENSION_VALUE))); - singleDimensionMetric.getDimensions().add(dimension); - rollupMetricList.add(singleDimensionMetric); - } - } - - return rollupMetricList; - } - - private String metricToString(Metric metric) { - StringBuffer strMetric = new StringBuffer(metric.getMetricName() + "/"); - for (Dimension dimension : metric.getDimensions()) { - strMetric.append(dimension.getName() + ":" + dimension.getValue()); - strMetric.append(","); - } - return strMetric.toString(); - } - - @Override - public void init(Context context) throws Exception { - this.context = context; - } -} diff --git a/integ-test/src/main/java/com/amazon/aocagent/validators/TraceValidator.java b/integ-test/src/main/java/com/amazon/aocagent/validators/TraceValidator.java deleted file mode 100644 index 5985524ea..000000000 --- a/integ-test/src/main/java/com/amazon/aocagent/validators/TraceValidator.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.validators; - -import com.amazon.aocagent.exception.BaseException; -import com.amazon.aocagent.exception.ExceptionCode; -import com.amazon.aocagent.helpers.MustacheHelper; -import com.amazon.aocagent.helpers.RetryHelper; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.models.TraceFromEmitter; -import com.amazon.aocagent.services.S3Service; -import com.amazon.aocagent.services.XRayService; -import com.amazonaws.services.xray.model.Segment; -import com.amazonaws.services.xray.model.Trace; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import lombok.extern.log4j.Log4j2; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - -@Log4j2 -public class TraceValidator implements IValidator { - private MustacheHelper mustacheHelper = new MustacheHelper(); - private static int MAX_RETRY_COUNT = 60; - private Context context; - private XRayService xrayService; - private S3Service s3Service; - - @Override - public void init(Context context) throws Exception { - this.context = context; - this.xrayService = new XRayService(context.getStack().getTestingRegion()); - this.s3Service = new S3Service(context.getStack().getTestingRegion()); - } - - @Override - public void validate() throws Exception { - List expectedTraceList = this.getExpectedTrace(); - expectedTraceList.sort(Comparator.comparing(Trace::getId)); - - RetryHelper.retry( - MAX_RETRY_COUNT, - () -> { - List traceList = - xrayService.listTraceByIds( - expectedTraceList.stream() - .map(trace -> trace.getId()) - .collect(Collectors.toList())); - - traceList.sort(Comparator.comparing(Trace::getId)); - - log.info("expectedTraceList: {}", expectedTraceList); - log.info("traceList got from backend: {}", traceList); - if (expectedTraceList.size() != traceList.size()) { - throw new BaseException(ExceptionCode.TRACE_LIST_NOT_MATCHED); - } - - for (int i = 0; i != expectedTraceList.size(); ++i) { - // remove the s3 span as the auto-instrumenting of s3 happens before we store trace data - // onto s3. - Trace trace = traceList.get(i); - trace.getSegments().removeIf(span -> span.getDocument().contains("AWS::S3")); - compareTwoTraces(expectedTraceList.get(i), trace); - } - }); - } - - private List getExpectedTrace() throws IOException { - // get expected trace from s3 - String strTraceData = - s3Service.getS3ObjectAsString( - context.getStack().getTraceDataS3BucketName(), - context.getInstanceId() // we use instanceid as the s3key - ); - log.info("get expected trace data from s3: {}", strTraceData); - - // load traceData from json, we use json instead of yaml because storing yaml in s3 will lose - // the spaces so that the yaml format will be invalid to read - ObjectMapper mapper = new ObjectMapper(new JsonFactory()); - TraceFromEmitter traceFromEmitter = - mapper.readValue(strTraceData.getBytes(StandardCharsets.UTF_8), - new TypeReference() {}); - - // convert the trace data into xray format - String yamlExpectedTrace = mustacheHelper.render(context.getExpectedTrace(), traceFromEmitter); - - // load xray trace from yaml - mapper = new ObjectMapper(new YAMLFactory()); - List expectedTraceList = - mapper.readValue( - yamlExpectedTrace.getBytes(StandardCharsets.UTF_8), - new TypeReference>() {}); - - return expectedTraceList; - } - - private void compareTwoTraces(Trace trace1, Trace trace2) throws BaseException { - // check trace id - if (!trace1.getId().equals(trace2.getId())) { - throw new BaseException(ExceptionCode.TRACE_ID_NOT_MATCHED); - } - - if (trace1.getSegments().size() != trace2.getSegments().size()) { - throw new BaseException(ExceptionCode.TRACE_SPAN_LIST_NOT_MATCHED); - } - trace1.getSegments().sort(Comparator.comparing(Segment::getId)); - trace2.getSegments().sort(Comparator.comparing(Segment::getId)); - - for (int i = 0; i != trace1.getSegments().size(); ++i) { - // check span id - if (!trace1.getSegments().get(i).getId() - .equals(trace2.getSegments().get(i).getId())) { - throw new BaseException(ExceptionCode.TRACE_SPAN_NOT_MATCHED); - } - } - } -} diff --git a/integ-test/src/main/resources/checkstyle.xml b/integ-test/src/main/resources/checkstyle.xml deleted file mode 100755 index 8caac5f63..000000000 --- a/integ-test/src/main/resources/checkstyle.xml +++ /dev/null @@ -1,333 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/integ-test/src/main/resources/log4j2.xml b/integ-test/src/main/resources/log4j2.xml deleted file mode 100644 index 35a6a3ccd..000000000 --- a/integ-test/src/main/resources/log4j2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/integ-test/src/main/resources/templates/config/defaultOTConfig.mustache b/integ-test/src/main/resources/templates/config/defaultOTConfig.mustache deleted file mode 100644 index e0e5b7fd5..000000000 --- a/integ-test/src/main/resources/templates/config/defaultOTConfig.mustache +++ /dev/null @@ -1,29 +0,0 @@ -extensions: - -receivers: - otlp: - protocols: - grpc: - endpoint: 0.0.0.0:55680 - - -processors: - -exporters: - logging: - loglevel: debug - awsxray: - local_mode: true - region: 'us-west-2' - awsemf: - local_mode: true - region: 'us-west-2' - -service: - pipelines: - traces: - receivers: [otlp] - exporters: [awsxray] - metrics: - receivers: [otlp] - exporters: [logging, awsemf] diff --git a/integ-test/src/main/resources/templates/ecs/aoc-sidecar-ec2.mustache b/integ-test/src/main/resources/templates/ecs/aoc-sidecar-ec2.mustache deleted file mode 100644 index 72db02c38..000000000 --- a/integ-test/src/main/resources/templates/ecs/aoc-sidecar-ec2.mustache +++ /dev/null @@ -1,82 +0,0 @@ -{ - "family": "aoc-EC2", - "taskRoleArn": "{{ecsTaskRoleArn}}", - "executionRoleArn": "{{ecsExecutionRoleArn}}", - "networkMode": "bridge", - "containerDefinitions": [ - { - "name": "aoc-emitter", - "image": "{{dataEmitterImage}}", - "portMappings": [], - "essential": true, - "command": [], - "environment": [ - { - "name": "OTEL_OTLP_ENDPOINT", - "value": "172.17.0.1:55680" - }, - { - "name": "INSTANCE_ID", - "value": "{{instanceId}}" - }, - { - "name": "OTEL_RESOURCE_ATTRIBUTES", - "value": "service.namespace=AWSObservability,service.name=CloudWatchOTService" - }, - { - "name": "S3_REGION", - "value": "{{stack.testingRegion}}" - }, - { - "name": "TRACE_DATA_BUCKET", - "value": "{{stack.traceDataS3BucketName}}" - }, - { - "name": "TRACE_DATA_S3_KEY", - "value": "{{instanceId}}" - } - ], - "dependsOn": [], - "logConfiguration": { - "logDriver": "awslogs", - "options": { - "awslogs-group": "/ecs/ecs-cwagent-sidecar-emitter", - "awslogs-region": "{{region}}", - "awslogs-stream-prefix": "ecs", - "awslogs-create-group": "True" - } - } - }, - { - "name": "aoc-collector", - "image": "{{aocImage}}", - "portMappings": [ - { - "containerPort": 55680, - "hostPort": 55680, - "protocol": "tcp" - } - ], - "essential": true, - "entryPoint": [], - "command": [], - "environment": [], - "environmentFiles": [], - "dependsOn": [], - "logConfiguration": { - "logDriver": "awslogs", - "options": { - "awslogs-group": "/ecs/ecs-cwagent-sidecar-collector", - "awslogs-region": "{{region}}", - "awslogs-stream-prefix": "ecs", - "awslogs-create-group": "True" - } - } - } - ], - "requiresCompatibilities": [ - "EC2" - ], - "cpu": "256", - "memory": "512" -} \ No newline at end of file diff --git a/integ-test/src/main/resources/templates/ecs/aoc-sidecar-fargate.mustache b/integ-test/src/main/resources/templates/ecs/aoc-sidecar-fargate.mustache deleted file mode 100644 index d260fddd1..000000000 --- a/integ-test/src/main/resources/templates/ecs/aoc-sidecar-fargate.mustache +++ /dev/null @@ -1,81 +0,0 @@ -{ - "family": "aoc-FARGATE", - "taskRoleArn": "{{ecsTaskRoleArn}}", - "executionRoleArn": "{{ecsExecutionRoleArn}}", - "networkMode": "awsvpc", - "containerDefinitions": [ - { - "name": "aoc-emitter", - "image": "{{dataEmitterImage}}", - "essential": true, - "entryPoint": [], - "command": [], - "environment": [ - { - "name": "OTEL_OTLP_ENDPOINT", - "value": "localhost:55680" - }, - { - "name": "INSTANCE_ID", - "value": "{{instanceId}}" - }, - { - "name": "OTEL_RESOURCE_ATTRIBUTES", - "value": "service.namespace=AWSObservability,service.name=CloudWatchOTService" - }, - { - "name": "S3_REGION", - "value": "{{stack.testingRegion}}" - }, - { - "name": "TRACE_DATA_BUCKET", - "value": "{{stack.traceDataS3BucketName}}" - }, - { - "name": "TRACE_DATA_S3_KEY", - "value": "{{instanceId}}" - } - ], - "dependsOn": [], - "logConfiguration": { - "logDriver": "awslogs", - "options": { - "awslogs-group": "/ecs/ecs-cwagent-sidecar-emitter", - "awslogs-region": "{{region}}", - "awslogs-stream-prefix": "ecs", - "awslogs-create-group": "True" - } - } - }, - { - "name": "aoc-collector", - "image": "{{aocImage}}", - "portMappings": [ - { - "containerPort": 55680, - "hostPort": 55680, - "protocol": "tcp" - } - ], - "essential": true, - "entryPoint": [], - "command": [], - "environment": [], - "dependsOn": [], - "logConfiguration": { - "logDriver": "awslogs", - "options": { - "awslogs-group": "/ecs/ecs-cwagent-sidecar-collector", - "awslogs-region": "{{region}}", - "awslogs-stream-prefix": "ecs", - "awslogs-create-group": "True" - } - } - } - ], - "requiresCompatibilities": [ - "FARGATE" - ], - "cpu": "256", - "memory": "512" -} \ No newline at end of file diff --git a/integ-test/src/main/resources/templates/eks/aoc-eks-sidecar.mustache b/integ-test/src/main/resources/templates/eks/aoc-eks-sidecar.mustache deleted file mode 100644 index 16f402200..000000000 --- a/integ-test/src/main/resources/templates/eks/aoc-eks-sidecar.mustache +++ /dev/null @@ -1,53 +0,0 @@ -# create namespace -apiVersion: v1 -kind: Namespace -metadata: - name: eks-integ-test-{{instanceId}} - labels: - name: eks-integ-test-{{instanceId}} ---- -# create deployment -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{eksTestManifestName}} - namespace: eks-integ-test-{{instanceId}} - labels: - name: {{eksTestManifestName}} -spec: - replicas: 1 - selector: - matchLabels: - name: {{eksTestManifestName}} - template: - metadata: - labels: - name: {{eksTestManifestName}} - spec: - containers: - - name: emitter - image: {{dataEmitterImage}} - env: - - name: OTEL_OTLP_ENDPOINT - value: "localhost:55680" - - name: INSTANCE_ID - value: "{{instanceId}}" - - name: OTEL_RESOURCE_ATTRIBUTES - value: "service.namespace=AWSObservability,service.name=CloudWatchOTService" - - name: S3_REGION - value: "{{stack.testingRegion}}" - - name: TRACE_DATA_BUCKET - value: "{{stack.traceDataS3BucketName}}" - - name: TRACE_DATA_S3_KEY - value: "{{instanceId}}" - imagePullPolicy: Always - - name: aoc-collector - image: {{aocImage}} - imagePullPolicy: Always - resources: - limits: - cpu: 256m - memory: 512Mi - requests: - cpu: 32m - memory: 24Mi diff --git a/integ-test/src/main/resources/templates/eks/kubeConfig.mustache b/integ-test/src/main/resources/templates/eks/kubeConfig.mustache deleted file mode 100644 index 775a2b3c8..000000000 --- a/integ-test/src/main/resources/templates/eks/kubeConfig.mustache +++ /dev/null @@ -1,24 +0,0 @@ -apiVersion: v1 -clusters: -- cluster: - server: {{eksEndpoint}} - certificate-authority-data: {{eksCertificate}} - name: kubernetes -contexts: -- context: - cluster: kubernetes - user: aws - name: aws -current-context: aws -kind: Config -preferences: {} -users: -- name: aws - user: - exec: - apiVersion: client.authentication.k8s.io/v1alpha1 - command: {{iamAuthenticatorPath}} - args: - - "token" - - "-i" - - "{{eksClusterName}}" diff --git a/integ-test/src/main/resources/templates/validation/defaultExpectedMetric.mustache b/integ-test/src/main/resources/templates/validation/defaultExpectedMetric.mustache deleted file mode 100644 index 16b70f555..000000000 --- a/integ-test/src/main/resources/templates/validation/defaultExpectedMetric.mustache +++ /dev/null @@ -1,50 +0,0 @@ -- - metricName: latency_{{instanceId}} - namespace: AWSObservability/CloudWatchOTService - dimensions: - - - name: apiName - value: /span0 - - - name: statusCode - value: 200 -- - metricName: latency_{{instanceId}} - namespace: AWSObservability/CloudWatchOTService - dimensions: - - - name: apiName - value: /span1 - - - name: statusCode - value: 200 -- - metricName: latency_{{instanceId}} - namespace: AWSObservability/CloudWatchOTService - dimensions: - - - name: apiName - value: /span2 - - - name: statusCode - value: 200 -- - metricName: latency_{{instanceId}} - namespace: AWSObservability/CloudWatchOTService - dimensions: - - - name: apiName - value: /span400 - - - name: statusCode - value: 400 -- - metricName: latency_{{instanceId}} - namespace: AWSObservability/CloudWatchOTService - dimensions: - - - name: apiName - value: /span500 - - - name: statusCode - value: 500 diff --git a/integ-test/src/main/resources/templates/validation/defaultExpectedTrace.mustache b/integ-test/src/main/resources/templates/validation/defaultExpectedTrace.mustache deleted file mode 100644 index 9d8d1b591..000000000 --- a/integ-test/src/main/resources/templates/validation/defaultExpectedTrace.mustache +++ /dev/null @@ -1,8 +0,0 @@ -- - id: {{TraceId}} - segments: - {{#spanIdList}} - - - id: {{.}} - {{/spanIdList}} - diff --git a/integ-test/src/test/java/com/amazon/aocagent/AppTest.java b/integ-test/src/test/java/com/amazon/aocagent/AppTest.java deleted file mode 100644 index 6f70612f0..000000000 --- a/integ-test/src/test/java/com/amazon/aocagent/AppTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -/* - * This Java source file was generated by the Gradle 'init' task. - */ - -package com.amazon.aocagent; - -import org.junit.Test; - -public class AppTest { - @Test - public void testAppHasAGreeting() { - App classUnderTest = new App(); - } -} diff --git a/integ-test/src/test/java/com/amazon/aocagent/helpers/MustacheHelperTest.java b/integ-test/src/test/java/com/amazon/aocagent/helpers/MustacheHelperTest.java deleted file mode 100644 index 12612e72d..000000000 --- a/integ-test/src/test/java/com/amazon/aocagent/helpers/MustacheHelperTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.helpers; - -import com.amazon.aocagent.fileconfigs.FileConfig; -import com.amazon.aocagent.models.Context; -import com.amazon.aocagent.models.Stack; -import org.junit.Test; - -import java.io.IOException; - -public class MustacheHelperTest { - - @Test - public void testMustache() throws IOException { - MustacheHelper mustacheHelper = new MustacheHelper(); - FileConfig fileConfig = new FileConfig() { - @Override - public String getPath() { - return "/test.mustache"; - } - }; - - Context context = new Context(); - Stack stack = new Stack(); - stack.setTraceDataS3BucketName("test"); - context.setStack(stack); - - System.out.println(mustacheHelper.render(fileConfig, context)); - } -} diff --git a/integ-test/src/test/java/com/amazon/aocagent/validators/MetricMetricValidatorTest.java b/integ-test/src/test/java/com/amazon/aocagent/validators/MetricMetricValidatorTest.java deleted file mode 100644 index 7286b975c..000000000 --- a/integ-test/src/test/java/com/amazon/aocagent/validators/MetricMetricValidatorTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.aocagent.validators; - -import com.amazon.aocagent.fileconfigs.ExpectedMetric; -import com.amazon.aocagent.models.Context; -import com.amazonaws.services.cloudwatch.model.Metric; -import org.junit.Test; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.List; - -public class MetricMetricValidatorTest { - - @Test - public void testGetExpectedMetricList() - throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Context context = new Context(); - context.setInstanceId("i-035a644c403f96199"); - context.setExpectedMetric(ExpectedMetric.DEFAULT_EXPECTED_METRIC); - - Method method = MetricValidator.class.getDeclaredMethod("getExpectedMetricList", Context.class); - method.setAccessible(true); - List metricList = (List) method.invoke(new MetricValidator(), context); - System.out.println(metricList); - } -} diff --git a/integ-test/src/test/resources/test.mustache b/integ-test/src/test/resources/test.mustache deleted file mode 100644 index 9d9ef74f0..000000000 --- a/integ-test/src/test/resources/test.mustache +++ /dev/null @@ -1 +0,0 @@ -{{stack.traceDataS3BucketName}} \ No newline at end of file diff --git a/sample-apps/README.md b/sample-apps/README.md deleted file mode 100644 index 0f48ab02b..000000000 --- a/sample-apps/README.md +++ /dev/null @@ -1 +0,0 @@ -# this folder contains all the sample apps \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index cbc52f48e..0ed14405b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,6 +8,4 @@ */ rootProject.name = 'aws-otel-collector-test-framework' -include 'integ-test' -include 'validator' -include ':sample-apps:java-sdk-emitter' \ No newline at end of file +include 'validator' \ No newline at end of file diff --git a/src/*.java.new b/src/*.java.new deleted file mode 100644 index acda24e6b..000000000 --- a/src/*.java.new +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ diff --git a/src/main/java/aws/otel/collector/test/framework/App.java b/src/main/java/aws/otel/collector/test/framework/App.java deleted file mode 100644 index a2dad9315..000000000 --- a/src/main/java/aws/otel/collector/test/framework/App.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -/* - * This Java source file was generated by the Gradle 'init' task. - */ -package aws.otel.collector.test.framework; - -public class App { - public String getGreeting() { - return "Hello world."; - } - - public static void main(String[] args) { - System.out.println(new App().getGreeting()); - } -} diff --git a/src/test/java/aws/otel/collector/test/framework/AppTest.java b/src/test/java/aws/otel/collector/test/framework/AppTest.java deleted file mode 100644 index 106313c86..000000000 --- a/src/test/java/aws/otel/collector/test/framework/AppTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -/* - * This Java source file was generated by the Gradle 'init' task. - */ -package aws.otel.collector.test.framework; - -import org.junit.Test; -import static org.junit.Assert.*; - -public class AppTest { - @Test public void testAppHasAGreeting() { - App classUnderTest = new App(); - assertNotNull("app should have a greeting", classUnderTest.getGreeting()); - } -}