From cd675868e5bc3a39c9fcdb704ca5a4d018a7272e Mon Sep 17 00:00:00 2001 From: Gavin Burris <66969321+GavinBurris42@users.noreply.github.com> Date: Wed, 15 Nov 2023 14:09:35 -0600 Subject: [PATCH] Revert name change (#423) * Reverted small name changes in comments and documentation * Reverted remaming of EC2Fleet to Fleet * Reverted EC2Fleet to Fleet name changes. Changed EC2Fleet to EC2EC2Fleet * Reverted additional EC2Fleet to Fleet changes * Reverted EC2Fleet name change in EC2FleetLabelCloudConfigurationAsCodeTest * Fixed setting of ExcessCapacityTerminationPolicy in modify fleet request --- README.md | 10 +- docs/CONFIGURATION-AS-CODE.md | 12 +- ...tCloud.java => AbstractEC2FleetCloud.java} | 4 +- .../amazon/jenkins/ec2fleet/CloudNames.java | 2 +- .../amazon/jenkins/ec2fleet/CloudNanny.java | 10 +- ...EC2FleetAutoResubmitComputerLauncher.java} | 18 +- .../{FleetCloud.java => EC2FleetCloud.java} | 119 +++--- ...abelCloud.java => EC2FleetLabelCloud.java} | 76 ++-- ...ters.java => EC2FleetLabelParameters.java} | 4 +- ...Updater.java => EC2FleetLabelUpdater.java} | 8 +- .../{FleetNode.java => EC2FleetNode.java} | 16 +- ...omputer.java => EC2FleetNodeComputer.java} | 24 +- ...hecker.java => EC2FleetOnlineChecker.java} | 12 +- ...tatusInfo.java => EC2FleetStatusInfo.java} | 10 +- ...sWidget.java => EC2FleetStatusWidget.java} | 10 +- ....java => EC2FleetStatusWidgetUpdater.java} | 16 +- .../ec2fleet/EC2RetentionStrategy.java | 56 +-- .../jenkins/ec2fleet/FleetStateStats.java | 12 +- .../ec2fleet/NoDelayProvisionStrategy.java | 6 +- .../ec2fleet/aws/AwsPermissionChecker.java | 40 +- .../ec2fleet/aws/CloudFormationApi.java | 4 +- .../ec2fleet/fleet/AutoScalingGroupFleet.java | 2 +- .../jenkins/ec2fleet/fleet/EC2EC2Fleet.java | 163 ++++++++ .../jenkins/ec2fleet/fleet/EC2Fleet.java | 174 ++------ .../jenkins/ec2fleet/fleet/EC2Fleets.java | 57 +++ .../{SpotFleet.java => EC2SpotFleet.java} | 2 +- .../amazon/jenkins/ec2fleet/fleet/Fleet.java | 35 -- .../amazon/jenkins/ec2fleet/fleet/Fleets.java | 57 --- .../NodeHardwareScaler/config.jelly | 0 .../help-memoryGiBPerExecutor.html | 0 .../help-vCpuPerExecutor.html | 0 .../config.jelly | 0 .../help-cloudStatusIntervalSec.html | 0 .../help-disableTaskResubmit.html | 0 .../help-endpoint.html | 0 .../help-executorScaler.html | 0 .../help-fleet.html | 0 .../help-idleMinutes.html | 0 .../help-initOnlineTimeoutSec.html | 0 .../help-maxTotalUses.html | 0 .../help-minSpareSize.html | 0 .../help-name.html | 2 +- .../help-noDelayProvision.html | 0 .../help-numExecutors.html | 0 .../help-restrictUsage.html | 0 .../help-scaleExecutorsByWeight.html | 0 .../config.jelly | 0 .../configure-entries.jelly | 0 .../index.jelly | 2 +- .../ec2fleet/AutoResubmitIntegrationTest.java | 20 +- .../jenkins/ec2fleet/CloudNamesTest.java | 32 +- .../jenkins/ec2fleet/CloudNannyTest.java | 8 +- ...leetAutoResubmitComputerLauncherTest.java} | 24 +- ...EC2FleetCloudConfigurationAsCodeTest.java} | 33 +- ...tCloudTest.java => EC2FleetCloudTest.java} | 379 +++++++++--------- ...ory.java => EC2FleetCloudWithHistory.java} | 4 +- ...Meter.java => EC2FleetCloudWithMeter.java} | 4 +- ...eetLabelCloudConfigurationAsCodeTest.java} | 26 +- ...=> EC2FleetLabelCloudIntegrationTest.java} | 10 +- ....java => EC2FleetLabelParametersTest.java} | 20 +- ...est.java => EC2FleetNodeComputerTest.java} | 8 +- ...st.java => EC2FleetOnlineCheckerTest.java} | 24 +- ...a => EC2FleetStatusWidgetUpdaterTest.java} | 38 +- .../EC2RetentionStrategyIntegrationTest.java | 54 +-- .../ec2fleet/EC2RetentionStrategyTest.java | 6 +- .../jenkins/ec2fleet/IntegrationTest.java | 53 ++- ...DelayProvisionStrategyPerformanceTest.java | 7 +- .../NoDelayProvisionStrategyTest.java | 130 +++--- .../ec2fleet/ProvisionIntegrationTest.java | 66 +-- .../ec2fleet/ProvisionPerformanceTest.java | 6 +- .../com/amazon/jenkins/ec2fleet/RealTest.java | 8 +- .../jenkins/ec2fleet/UiIntegrationTest.java | 58 +-- ...EC2FleetTest.java => EC2EC2FleetTest.java} | 46 +-- ...otFleetTest.java => EC2SpotFleetTest.java} | 26 +- .../empty-name-configuration-as-code.yml | 0 .../max-configuration-as-code.yml | 0 .../min-configuration-as-code.yml | 0 .../name-required-configuration-as-code.yml | 0 .../empty-name-configuration-as-code.yml | 0 .../max-configuration-as-code.yml | 0 .../min-configuration-as-code.yml | 0 .../name-required-configuration-as-code.yml | 0 82 files changed, 1037 insertions(+), 1016 deletions(-) rename src/main/java/com/amazon/jenkins/ec2fleet/{AbstractFleetCloud.java => AbstractEC2FleetCloud.java} (79%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetAutoResubmitComputerLauncher.java => EC2FleetAutoResubmitComputerLauncher.java} (87%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetCloud.java => EC2FleetCloud.java} (92%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetLabelCloud.java => EC2FleetLabelCloud.java} (93%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetLabelParameters.java => EC2FleetLabelParameters.java} (92%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetLabelUpdater.java => EC2FleetLabelUpdater.java} (75%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetNode.java => EC2FleetNode.java} (74%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetNodeComputer.java => EC2FleetNodeComputer.java} (75%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetOnlineChecker.java => EC2FleetOnlineChecker.java} (92%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetStatusInfo.java => EC2FleetStatusInfo.java} (82%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetStatusWidget.java => EC2FleetStatusWidget.java} (57%) rename src/main/java/com/amazon/jenkins/ec2fleet/{FleetStatusWidgetUpdater.java => EC2FleetStatusWidgetUpdater.java} (79%) create mode 100644 src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2EC2Fleet.java create mode 100644 src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleets.java rename src/main/java/com/amazon/jenkins/ec2fleet/fleet/{SpotFleet.java => EC2SpotFleet.java} (99%) delete mode 100644 src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleet.java delete mode 100644 src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleets.java rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/NodeHardwareScaler/config.jelly (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/NodeHardwareScaler/help-memoryGiBPerExecutor.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/NodeHardwareScaler/help-vCpuPerExecutor.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/config.jelly (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-cloudStatusIntervalSec.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-disableTaskResubmit.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-endpoint.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-executorScaler.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-fleet.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-idleMinutes.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-initOnlineTimeoutSec.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-maxTotalUses.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-minSpareSize.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-name.html (68%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-noDelayProvision.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-numExecutors.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-restrictUsage.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/help-scaleExecutorsByWeight.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetLabelCloud => EC2FleetLabelCloud}/config.jelly (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetNode => EC2FleetNode}/configure-entries.jelly (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{FleetStatusWidget => EC2FleetStatusWidget}/index.jelly (93%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetAutoResubmitComputerLauncherTest.java => EC2FleetAutoResubmitComputerLauncherTest.java} (89%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetCloudConfigurationAsCodeTest.java => EC2FleetCloudConfigurationAsCodeTest.java} (77%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetCloudTest.java => EC2FleetCloudTest.java} (84%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetCloudWithHistory.java => EC2FleetCloudWithHistory.java} (95%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetCloudWithMeter.java => EC2FleetCloudWithMeter.java} (95%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetLabelCloudConfigurationAsCodeTest.java => EC2FleetLabelCloudConfigurationAsCodeTest.java} (80%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetLabelCloudIntegrationTest.java => EC2FleetLabelCloudIntegrationTest.java} (88%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetLabelParametersTest.java => EC2FleetLabelParametersTest.java} (69%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetNodeComputerTest.java => EC2FleetNodeComputerTest.java} (87%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetOnlineCheckerTest.java => EC2FleetOnlineCheckerTest.java} (82%) rename src/test/java/com/amazon/jenkins/ec2fleet/{FleetStatusWidgetUpdaterTest.java => EC2FleetStatusWidgetUpdaterTest.java} (68%) rename src/test/java/com/amazon/jenkins/ec2fleet/fleet/{EC2FleetTest.java => EC2EC2FleetTest.java} (90%) rename src/test/java/com/amazon/jenkins/ec2fleet/fleet/{SpotFleetTest.java => EC2SpotFleetTest.java} (92%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/empty-name-configuration-as-code.yml (100%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/max-configuration-as-code.yml (100%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/min-configuration-as-code.yml (100%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetCloud => EC2FleetCloud}/name-required-configuration-as-code.yml (100%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetLabelCloud => EC2FleetLabelCloud}/empty-name-configuration-as-code.yml (100%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetLabelCloud => EC2FleetLabelCloud}/max-configuration-as-code.yml (100%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetLabelCloud => EC2FleetLabelCloud}/min-configuration-as-code.yml (100%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{FleetLabelCloud => EC2FleetLabelCloud}/name-required-configuration-as-code.yml (100%) diff --git a/README.md b/README.md index c69edd0f..55b348c3 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ import hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy import com.cloudbees.plugins.credentials.* import com.cloudbees.plugins.credentials.domains.Domain import hudson.model.* -import com.amazon.jenkins.ec2fleet.FleetCloud +import com.amazon.jenkins.ec2fleet.EC2FleetCloud import jenkins.model.Jenkins // just modify this config other code just logic @@ -249,8 +249,8 @@ BasicSSHUserPrivateKey instanceCredentials = new BasicSSHUserPrivateKey( "my private key to ssh ec2 for jenkins" ) // find detailed information about parameters on plugin config page or -// https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java -FleetCloud fleetCloud = new FleetCloud( +// https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java +EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "", // fleetCloudName null, awsCredentials.id, @@ -277,9 +277,9 @@ FleetCloud fleetCloud = new FleetCloud( false, 180, null, - false, 30, - true + true, + new EC2FleetCloud.NoScaler() ) // get Jenkins instance diff --git a/docs/CONFIGURATION-AS-CODE.md b/docs/CONFIGURATION-AS-CODE.md index e59755e6..6bd410b9 100644 --- a/docs/CONFIGURATION-AS-CODE.md +++ b/docs/CONFIGURATION-AS-CODE.md @@ -4,9 +4,9 @@ ## Properties -### FleetCloud +### EC2FleetCloud -[Definition](https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java#L156-L179) +[Definition](https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java#L156-L179) | Property | Type | Required | Description | |----------------------------|---------|------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------| @@ -35,15 +35,15 @@ | cloudStatusIntervalSec | int | no, default ```10``` | | | noDelayProvision | boolean | no, default ```false``` | | -## FleetLabelCloud +## EC2FleetLabelCloud More about this type [here](LABEL-BASED-CONFIGURATION.md) -[Definition](https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.java#L123-L145) +[Definition](https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud.java#L123-L145) ## Examples -### FleetCloud (min set of properties) +### EC2FleetCloud (min set of properties) ```yaml jenkins: @@ -61,7 +61,7 @@ jenkins: maxSize: 10 ``` -### FleetCloud (All properties) +### EC2FleetCloud (All properties) ```yaml jenkins: diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/AbstractFleetCloud.java b/src/main/java/com/amazon/jenkins/ec2fleet/AbstractEC2FleetCloud.java similarity index 79% rename from src/main/java/com/amazon/jenkins/ec2fleet/AbstractFleetCloud.java rename to src/main/java/com/amazon/jenkins/ec2fleet/AbstractEC2FleetCloud.java index 5c913ea8..7f132c22 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/AbstractFleetCloud.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/AbstractEC2FleetCloud.java @@ -2,9 +2,9 @@ import hudson.slaves.Cloud; -public abstract class AbstractFleetCloud extends Cloud { +public abstract class AbstractEC2FleetCloud extends Cloud { - protected AbstractFleetCloud(String name) { + protected AbstractEC2FleetCloud(String name) { super(name); } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNames.java b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNames.java index 79f4ebf9..e752449c 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNames.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNames.java @@ -25,7 +25,7 @@ public static String generateUnique(final String proposedName) { ? Jenkins.get().clouds.stream().map(c -> c.name).collect(Collectors.toSet()) : Collections.emptySet(); - if (proposedName.equals(FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID) || proposedName.equals(FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID) || usedNames.contains(proposedName)) { + if (proposedName.equals(EC2FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID) || proposedName.equals(EC2FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID) || usedNames.contains(proposedName)) { return proposedName + "-" + generateSuffix(); } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java index b30feac8..4af14599 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java @@ -14,7 +14,7 @@ import java.util.logging.Logger; /** - * {@link CloudNanny} is responsible for periodically running update (i.e. sync-state-with-AWS) cycles for {@link FleetCloud}s. + * {@link CloudNanny} is responsible for periodically running update (i.e. sync-state-with-AWS) cycles for {@link EC2FleetCloud}s. */ @Extension @SuppressWarnings("unused") @@ -23,7 +23,7 @@ public class CloudNanny extends PeriodicWork { private static final Logger LOGGER = Logger.getLogger(CloudNanny.class.getName()); // the map should not hold onto fleet instances to allow deletion of fleets. - private final Map recurrenceCounters = Collections.synchronizedMap(new WeakHashMap<>()); + private final Map recurrenceCounters = Collections.synchronizedMap(new WeakHashMap<>()); @Override public long getRecurrencePeriod() { @@ -39,8 +39,8 @@ public long getRecurrencePeriod() { @Override protected void doRun() { for (final Cloud cloud : getClouds()) { - if (!(cloud instanceof FleetCloud)) continue; - final FleetCloud fleetCloud = (FleetCloud) cloud; + if (!(cloud instanceof EC2FleetCloud)) continue; + final EC2FleetCloud fleetCloud = (EC2FleetCloud) cloud; final AtomicInteger recurrenceCounter = getRecurrenceCounter(fleetCloud); @@ -70,7 +70,7 @@ private static List getClouds() { return Jenkins.get().clouds; } - private AtomicInteger getRecurrenceCounter(FleetCloud fleetCloud) { + private AtomicInteger getRecurrenceCounter(EC2FleetCloud fleetCloud) { AtomicInteger counter = new AtomicInteger(fleetCloud.getCloudStatusIntervalSec()); // If a counter already exists, return the value, otherwise set the new counter value and return it. AtomicInteger existing = recurrenceCounters.putIfAbsent(fleetCloud, counter); diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncher.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncher.java similarity index 87% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncher.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncher.java index 9574da7b..f23d9543 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncher.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncher.java @@ -22,23 +22,23 @@ import java.util.logging.Logger; /** - * The {@link FleetAutoResubmitComputerLauncher} is responsible for controlling: - * * how {@link FleetNodeComputer}s are launched - * * how {@link FleetNodeComputer}s connect to agents {@link FleetNode} + * The {@link EC2FleetAutoResubmitComputerLauncher} is responsible for controlling: + * * how {@link EC2FleetNodeComputer}s are launched + * * how {@link EC2FleetNodeComputer}s connect to agents {@link EC2FleetNode} * * This is wrapper for {@link ComputerLauncher} to get notification when agent was disconnected * and automatically resubmit {@link hudson.model.Queue.Task} if reason is unexpected termination * which usually means EC2 instance was interrupted. *

* This is optional feature, it's enabled by default, but could be disabled by - * {@link FleetCloud#isDisableTaskResubmit()} + * {@link EC2FleetCloud#isDisableTaskResubmit()} */ @SuppressWarnings("WeakerAccess") @ThreadSafe -public class FleetAutoResubmitComputerLauncher extends DelegatingComputerLauncher { +public class EC2FleetAutoResubmitComputerLauncher extends DelegatingComputerLauncher { private static final Level LOG_LEVEL = Level.INFO; - private static final Logger LOGGER = Logger.getLogger(FleetAutoResubmitComputerLauncher.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EC2FleetAutoResubmitComputerLauncher.class.getName()); /** * Delay which will be applied when job {@link Queue#scheduleInternal(Queue.Task, int, List)} @@ -46,7 +46,7 @@ public class FleetAutoResubmitComputerLauncher extends DelegatingComputerLaunche */ private static final int RESCHEDULE_QUIET_PERIOD_SEC = 10; - public FleetAutoResubmitComputerLauncher(final ComputerLauncher launcher) { + public EC2FleetAutoResubmitComputerLauncher(final ComputerLauncher launcher) { super(launcher); } @@ -72,14 +72,14 @@ public FleetAutoResubmitComputerLauncher(final ComputerLauncher launcher) { */ @SuppressFBWarnings( value = "BC_UNCONFIRMED_CAST", - justification = "to ignore FleetNodeComputer cast") + justification = "to ignore EC2FleetNodeComputer cast") @Override public void afterDisconnect(final SlaveComputer computer, final TaskListener listener) { // according to jenkins docs could be null in edge cases, check ComputerLauncher.afterDisconnect if (computer == null) return; // in some multi-thread edge cases cloud could be null for some time, just be ok with that - final AbstractFleetCloud cloud = ((FleetNodeComputer) computer).getCloud(); + final AbstractEC2FleetCloud cloud = ((EC2FleetNodeComputer) computer).getCloud(); if (cloud == null) { LOGGER.warning("Cloud is null for computer " + computer.getDisplayName() + ". This should be autofixed in a few minutes, if not please create an issue for the plugin"); diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java similarity index 92% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java index 7f147a53..a2585524 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java @@ -2,8 +2,8 @@ import com.amazon.jenkins.ec2fleet.aws.AwsPermissionChecker; import com.amazon.jenkins.ec2fleet.aws.RegionHelper; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.*; import com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsHelper; @@ -11,7 +11,10 @@ import hudson.Extension; import hudson.ExtensionPoint; import hudson.model.*; -import hudson.slaves.*; +import hudson.slaves.Cloud; +import hudson.slaves.ComputerConnector; +import hudson.slaves.NodeProperty; +import hudson.slaves.NodeProvisioner; import hudson.util.FormValidation; import hudson.util.ListBoxModel; import hudson.util.ListBoxModel.Option; @@ -49,19 +52,19 @@ import java.util.stream.Collectors; /** - * The {@link FleetCloud} contains the main configuration values used while creating Jenkins nodes. - * FleetCloud can represent either an AWS EC2 Spot Fleet or an AWS AutoScalingGroup. + * The {@link EC2FleetCloud} contains the main configuration values used while creating Jenkins nodes. + * EC2FleetCloud can represent either an AWS EC2 Spot Fleet or an AWS AutoScalingGroup. * * Responsibilities include: * * maintain the configuration values set by user for the Cloud. - * User-initiated changes to such configuration will result in a new FleetCloud object. See {@link Cloud}. - * * provision new EC2 capacity along with supporting provisioning checks for FleetCloud - * * keep {@link FleetStateStats} in sync with state on the AWS side via {@link FleetCloud#update()} + * User-initiated changes to such configuration will result in a new EC2FleetCloud object. See {@link Cloud}. + * * provision new EC2 capacity along with supporting provisioning checks for EC2FleetCloud + * * keep {@link FleetStateStats} in sync with state on the AWS side via {@link EC2FleetCloud#update()} * * provide helper methods to extract certain state values * * provide helper methods to schedule termination of compute / nodes */ @SuppressWarnings({"unused", "WeakerAccess"}) -public class FleetCloud extends AbstractFleetCloud { +public class EC2FleetCloud extends AbstractEC2FleetCloud { public static final String EC2_INSTANCE_TAG_NAMESPACE = "ec2-fleet-plugin"; public static final String EC2_INSTANCE_CLOUD_NAME_TAG = EC2_INSTANCE_TAG_NAMESPACE + ":cloud-name"; @@ -76,13 +79,13 @@ public class FleetCloud extends AbstractFleetCloud { private static final int DEFAULT_MAX_TOTAL_USES = -1; private static final SimpleFormatter sf = new SimpleFormatter(); - private static final Logger LOGGER = Logger.getLogger(FleetCloud.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EC2FleetCloud.class.getName()); private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor(); /** - * Replaced with {@link FleetCloud#awsCredentialsId} + * Replaced with {@link EC2FleetCloud#awsCredentialsId} *

- * Plugin is using {@link FleetCloud#computerConnector} for node connection credentials + * Plugin is using {@link EC2FleetCloud#computerConnector} for node connection credentials * on UI it's introduced same field credentialsId as we, so it's undefined * which field will be use for operations from UI. *

@@ -123,7 +126,7 @@ public class FleetCloud extends AbstractFleetCloud { private final Integer maxTotalUses; /** - * @see FleetAutoResubmitComputerLauncher + * @see EC2FleetAutoResubmitComputerLauncher */ private final boolean disableTaskResubmit; @@ -133,9 +136,9 @@ public class FleetCloud extends AbstractFleetCloud { private final boolean noDelayProvision; /** - * {@link FleetCloud#update()} updating this field, this is one thread + * {@link EC2FleetCloud#update()} updating this field, this is one thread * related to {@link CloudNanny}. At the same time {@link EC2RetentionStrategy} - * call {@link FleetCloud#scheduleToTerminate(String, boolean, EC2AgentTerminationReason)} to terminate instance when it is free + * call {@link EC2FleetCloud#scheduleToTerminate(String, boolean, EC2AgentTerminationReason)} to terminate instance when it is free * and uses this field to know the current capacity. *

* It could be situation that stats is outdated and plugin will make wrong decision, @@ -152,35 +155,35 @@ public class FleetCloud extends AbstractFleetCloud { private transient ArrayList> plannedNodeScheduledFutures; - // Counter to keep track of planned nodes per FleetCloud, used in node's display name + // Counter to keep track of planned nodes per EC2FleetCloud, used in node's display name private transient AtomicInteger plannedNodeCounter = new AtomicInteger(1); @DataBoundConstructor - public FleetCloud(@Nonnull final String name, - final String awsCredentialsId, - final @Deprecated String credentialsId, - final String region, - final String endpoint, - final String fleet, - final String labelString, - final String fsRoot, - final ComputerConnector computerConnector, - final boolean privateIpUsed, - final boolean alwaysReconnect, - final Integer idleMinutes, - final int minSize, - final int maxSize, - final int minSpareSize, - final int numExecutors, - final boolean addNodeOnlyIfRunning, - final boolean restrictUsage, - final String maxTotalUses, - final boolean disableTaskResubmit, - final Integer initOnlineTimeoutSec, - final Integer initOnlineCheckIntervalSec, - final Integer cloudStatusIntervalSec, - final boolean noDelayProvision, - final ExecutorScaler executorScaler) { + public EC2FleetCloud(@Nonnull final String name, + final String awsCredentialsId, + final @Deprecated String credentialsId, + final String region, + final String endpoint, + final String fleet, + final String labelString, + final String fsRoot, + final ComputerConnector computerConnector, + final boolean privateIpUsed, + final boolean alwaysReconnect, + final Integer idleMinutes, + final int minSize, + final int maxSize, + final int minSpareSize, + final int numExecutors, + final boolean addNodeOnlyIfRunning, + final boolean restrictUsage, + final String maxTotalUses, + final boolean disableTaskResubmit, + final Integer initOnlineTimeoutSec, + final Integer initOnlineCheckIntervalSec, + final Integer cloudStatusIntervalSec, + final boolean noDelayProvision, + final ExecutorScaler executorScaler) { super(StringUtils.isNotBlank(name) ? name : CloudNames.generateUnique(BASE_DEFAULT_FLEET_CLOUD_ID)); init(); this.credentialsId = credentialsId; @@ -212,7 +215,7 @@ public FleetCloud(@Nonnull final String name, this.executorScaler = executorScaler == null ? new NoScaler().withNumExecutors(this.numExecutors) : executorScaler.withNumExecutors(this.numExecutors); if (fleet != null) { - this.stats = Fleets.get(fleet).getState( + this.stats = EC2Fleets.get(fleet).getState( getAwsCredentialsId(), region, endpoint, getFleet()); } } @@ -222,9 +225,9 @@ public boolean isNoDelayProvision() { } /** - * Deprecated.Use {@link FleetCloud#awsCredentialsId} + * Deprecated.Use {@link EC2FleetCloud#awsCredentialsId} * - * See {@link FleetCloud#awsCredentialsId} documentation. Don't use fields directly to be able + * See {@link EC2FleetCloud#awsCredentialsId} documentation. Don't use fields directly to be able * get old version of plugin and for new. * * @return credentials ID @@ -443,9 +446,9 @@ public synchronized Collection provision(@Nonnull f // create a ScheduledFuture that will cancel the planned node future after a timeout. // This protects us from leaving planned nodes stranded within Jenkins NodeProvisioner when the Fleet - // is updated or removed before it can scale. After scaling, FleetOnlineChecker will cancel the future + // is updated or removed before it can scale. After scaling, EC2FleetOnlineChecker will cancel the future // if something happens to the Fleet. - // TODO: refactor to consolidate logic with FleetOnlineChecker + // TODO: refactor to consolidate logic with EC2FleetOnlineChecker final ScheduledFuture scheduledFuture = EXECUTOR.schedule(() -> { if (completableFuture.isDone()) { return; @@ -471,10 +474,10 @@ public FleetStateStats update() { // Make a snapshot of current cloud state to work with. // We should always work with the snapshot since data could be modified in another thread - FleetStateStats currentState = Fleets.get(fleet).getState( + FleetStateStats currentState = EC2Fleets.get(fleet).getState( getAwsCredentialsId(), region, endpoint, getFleet()); - // Some Fleet implementations (e.g. SpotFleet) reflect their state only at the end of modification + // Some Fleet implementations (e.g. EC2SpotFleet) reflect their state only at the end of modification if (currentState.getState().isModifying()) { info("Fleet '%s' is currently under modification. Skipping update", currentState.getFleetId()); synchronized (this) { @@ -575,7 +578,7 @@ private FleetStateStats updateByState( // For example, if we remove an instance and add an instance the net change is 0, but we still make the API call. // This lets us update the fleet settings with NoTermination policy, which lets us terminate instances on our own if (currentToAdd > 0 || currentInstanceIdsToTerminate.size() > 0 || targetCapacity != currentState.getNumDesired()) { - Fleets.get(fleet).modify( + EC2Fleets.get(fleet).modify( getAwsCredentialsId(), region, endpoint, fleet, targetCapacity, minSize, maxSize); info("Set target capacity to '%s'", targetCapacity); } @@ -621,7 +624,7 @@ public void run() { final Set jenkinsInstances = new HashSet<>(); for (final Node node : jenkins.getNodes()) { - if (node instanceof FleetNode && ((FleetCloud)((FleetNode) node).getCloud()).getFleet().equals(fleet)) { + if (node instanceof EC2FleetNode && ((EC2FleetCloud)((EC2FleetNode) node).getCloud()).getFleet().equals(fleet)) { jenkinsInstances.add(node.getNodeName()); } } @@ -709,7 +712,7 @@ public void run() { * If ignoreMinConstraints is false and target capacity falls below minSize OR minSpareSize thresholds, then reject termination. * Else if ignoreMinConstraints is true, schedule instance for termination even if it breaches minSize OR minSpareSize *

- * Real termination will happens in {@link FleetCloud#update()} which is periodically called by + * Real termination will happens in {@link EC2FleetCloud#update()} which is periodically called by * {@link CloudNanny}. So there could be some lag between the decision to terminate the node * and actual termination, you can find max lag size in {@link CloudNanny#getRecurrencePeriod()} *

@@ -827,10 +830,10 @@ private void addNewAgent(final AmazonEC2 ec2, final Instance instance, FleetStat int effectiveNumExecutors = this.executorScaler.scale(instance.getInstanceType(), stats, ec2); - final FleetAutoResubmitComputerLauncher computerLauncher = new FleetAutoResubmitComputerLauncher( + final EC2FleetAutoResubmitComputerLauncher computerLauncher = new EC2FleetAutoResubmitComputerLauncher( computerConnector.launch(address, TaskListener.NULL)); final Node.Mode nodeMode = restrictUsage ? Node.Mode.EXCLUSIVE : Node.Mode.NORMAL; - final FleetNode node = new FleetNode(instanceId, "Fleet agent for " + instanceId, + final EC2FleetNode node = new EC2FleetNode(instanceId, "Fleet agent for " + instanceId, effectiveFsRoot, effectiveNumExecutors, nodeMode, labelString, new ArrayList>(), this.name, computerLauncher, maxTotalUses); @@ -855,7 +858,7 @@ private void addNewAgent(final AmazonEC2 ec2, final Instance instance, FleetStat // Use getters for timeout and interval as they provide a default value // when a user installs a new plugin version and doesn't recreate the cloud - FleetOnlineChecker.start(node, future, + EC2FleetOnlineChecker.start(node, future, TimeUnit.SECONDS.toMillis(getInitOnlineTimeoutSec()), TimeUnit.SECONDS.toMillis(getInitOnlineCheckIntervalSec())); } @@ -866,14 +869,14 @@ private int getCurrentSpareInstanceCount(final FleetStateStats currentState, fin final Jenkins jenkins = Jenkins.get(); int currentBusyInstances = 0; for (final Computer computer : jenkins.getComputers()) { - if (computer instanceof FleetNodeComputer && !computer.isIdle()) { + if (computer instanceof EC2FleetNodeComputer && !computer.isIdle()) { final Node compNode = computer.getNode(); if (compNode == null) { continue; } // Do not count computer if it is not a part of the given fleet - if (!Objects.equals(((FleetCloud)((FleetNodeComputer) computer).getCloud()).getFleet(), currentState.getFleetId())) { + if (!Objects.equals(((EC2FleetCloud)((EC2FleetNodeComputer) computer).getCloud()).getFleet(), currentState.getFleetId())) { continue; } currentBusyInstances++; @@ -981,8 +984,8 @@ public ListBoxModel doFillFleetItems(@QueryParameter final boolean showAllFleets final ListBoxModel model = new ListBoxModel(); model.add(0, new Option("- please select -", "", true)); try { - for (final Fleet Fleet : Fleets.all()) { - Fleet.describe( + for (final EC2Fleet EC2Fleet : EC2Fleets.all()) { + EC2Fleet.describe( awsCredentialsId, region, endpoint, model, fleet, showAllFleets); } } catch (final Exception ex) { diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud.java similarity index 93% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud.java index 7669c2ee..324bbb13 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud.java @@ -4,8 +4,8 @@ import com.amazon.jenkins.ec2fleet.aws.CloudFormationApi; import com.amazon.jenkins.ec2fleet.aws.EC2Api; import com.amazon.jenkins.ec2fleet.aws.RegionHelper; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; -import com.amazon.jenkins.ec2fleet.fleet.SpotFleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2SpotFleet; import com.amazonaws.services.cloudformation.AmazonCloudFormation; import com.amazonaws.services.cloudformation.model.StackStatus; import com.amazonaws.services.ec2.AmazonEC2; @@ -59,7 +59,7 @@ * @see CloudNanny */ @SuppressWarnings({"unused", "WeakerAccess"}) -public class FleetLabelCloud extends AbstractFleetCloud { +public class EC2FleetLabelCloud extends AbstractEC2FleetCloud { public static final String EC2_INSTANCE_TAG_NAMESPACE = "ec2-fleet-plugin"; public static final String EC2_INSTANCE_CLOUD_NAME_TAG = EC2_INSTANCE_TAG_NAMESPACE + ":cloud-name"; @@ -74,7 +74,7 @@ public class FleetLabelCloud extends AbstractFleetCloud { // private static final String NEW_EC2_KEY_PAIR_VALUE = "- New Key Pair -"; private static final SimpleFormatter sf = new SimpleFormatter(); - private static final Logger LOGGER = Logger.getLogger(FleetLabelCloud.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EC2FleetLabelCloud.class.getName()); private final String awsCredentialsId; private final String region; @@ -95,7 +95,7 @@ public class FleetLabelCloud extends AbstractFleetCloud { private final String ec2KeyPairName; /** - * @see FleetAutoResubmitComputerLauncher + * @see EC2FleetAutoResubmitComputerLauncher */ private final boolean disableTaskResubmit; @@ -107,25 +107,25 @@ public class FleetLabelCloud extends AbstractFleetCloud { private transient Map states; @DataBoundConstructor - public FleetLabelCloud(final String name, - final String awsCredentialsId, - final String region, - final String endpoint, - final String fsRoot, - final ComputerConnector computerConnector, - final boolean privateIpUsed, - final boolean alwaysReconnect, - final Integer idleMinutes, - final int minSize, - final int maxSize, - final int numExecutors, - final boolean restrictUsage, - final boolean disableTaskResubmit, - final Integer initOnlineTimeoutSec, - final Integer initOnlineCheckIntervalSec, - final Integer cloudStatusIntervalSec, - final boolean noDelayProvision, - final String ec2KeyPairName) { + public EC2FleetLabelCloud(final String name, + final String awsCredentialsId, + final String region, + final String endpoint, + final String fsRoot, + final ComputerConnector computerConnector, + final boolean privateIpUsed, + final boolean alwaysReconnect, + final Integer idleMinutes, + final int minSize, + final int maxSize, + final int numExecutors, + final boolean restrictUsage, + final boolean disableTaskResubmit, + final Integer initOnlineTimeoutSec, + final Integer initOnlineCheckIntervalSec, + final Integer cloudStatusIntervalSec, + final boolean noDelayProvision, + final String ec2KeyPairName) { super(StringUtils.isNotBlank(name) ? name : CloudNames.generateUnique(BASE_DEFAULT_FLEET_CLOUD_ID)); init(); this.awsCredentialsId = awsCredentialsId; @@ -286,7 +286,7 @@ public synchronized Collection provision(@Nonnull f continue; } - final FleetLabelParameters parameters = new FleetLabelParameters(state.getKey()); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(state.getKey()); final int maxSize = parameters.getIntOrDefault("maxSize", this.maxSize); if (cap >= maxSize) { @@ -362,7 +362,7 @@ public void update() { final Set fleetIds = new HashSet<>(); for (State state : states.values()) fleetIds.add(state.fleetId); - final Map currentStats = new SpotFleet().getStateBatch( + final Map currentStats = new EC2SpotFleet().getStateBatch( getAwsCredentialsId(), region, endpoint, fleetIds); for (State state : currentStates.values()) { // todo what if we don't find this fleet in map @@ -407,7 +407,7 @@ private void updateByState(final Map states) { // todo fix negative value // we do update any time even real capacity was not update like remove one add one to // update fleet settings with NoTermination so we can terminate instances on our own - Fleets.get(state.fleetId).modify( + EC2Fleets.get(state.fleetId).modify( getAwsCredentialsId(), region, endpoint, state.fleetId, state.targetCapacity, minSize, maxSize); info("Update fleet target capacity to %s", state.targetCapacity); } @@ -458,8 +458,8 @@ public void run() { // currentJenkinsNodes contains all registered Jenkins nodes related to this cloud final Set jenkinsInstances = new HashSet<>(); for (final Node node : jenkins.getNodes()) { - if (node instanceof FleetNode) { - final FleetNode node1 = (FleetNode) node; + if (node instanceof EC2FleetNode) { + final EC2FleetNode node1 = (EC2FleetNode) node; // cloud and label are same if (node1.getCloud() == this && node1.getLabelString().equals(entry.getKey())) { jenkinsInstances.add(node.getNodeName()); @@ -553,7 +553,7 @@ public synchronized boolean scheduleToTerminate(final String instanceId, final b } // We can't remove instances beyond minSize unless ignoreMinConstraints is true - final FleetLabelParameters parameters = new FleetLabelParameters(node.getLabelString()); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(node.getLabelString()); final int minSize = parameters.getIntOrDefault("minSize", this.minSize); if (!ignoreMinConstraints && (minSize > 0 && state.stats.getNumDesired() - state.instanceIdsToTerminate.size() <= minSize)) { info("Not terminating %s because we need a minimum of %s instances running.", instanceId, minSize); @@ -620,11 +620,11 @@ private void addNewAgent( effectiveNumExecutors = numExecutors; } - final FleetAutoResubmitComputerLauncher computerLauncher = new FleetAutoResubmitComputerLauncher( + final EC2FleetAutoResubmitComputerLauncher computerLauncher = new EC2FleetAutoResubmitComputerLauncher( computerConnector.launch(address, TaskListener.NULL)); final Node.Mode nodeMode = restrictUsage ? Node.Mode.EXCLUSIVE : Node.Mode.NORMAL; - //TODO: Add maxTotalUses to FleetLabelCloud similar to FleetCloud - final FleetNode node = new FleetNode(instanceId, "Fleet agent for " + instanceId, + //TODO: Add maxTotalUses to EC2FleetLabelCloud similar to EC2FleetCloud + final EC2FleetNode node = new EC2FleetNode(instanceId, "Fleet agent for " + instanceId, effectiveFsRoot, effectiveNumExecutors, nodeMode, labelString, new ArrayList>(), this.name, computerLauncher, -1); @@ -648,8 +648,8 @@ private void addNewAgent( } // use getters for timeout and interval as they provide default value - // when user just install new version and did't recreate fleet - FleetOnlineChecker.start(node, future, + // when user just install new version and didn't recreate fleet + EC2FleetOnlineChecker.start(node, future, TimeUnit.SECONDS.toMillis(getInitOnlineTimeoutSec()), TimeUnit.SECONDS.toMillis(getInitOnlineCheckIntervalSec())); } @@ -703,7 +703,7 @@ public void updateStacks() { for (final Item item : Jenkins.get().getAllItems()) { if (!(item instanceof AbstractProject)) continue; final AbstractProject abstractProject = (AbstractProject) item; - // assinged label could be null + // assigned label could be null final String labelString = StringUtils.defaultString(abstractProject.getAssignedLabelString()); if (labelString.startsWith(name)) { @@ -786,8 +786,8 @@ public void run() { } @Override - public FleetLabelCloud.DescriptorImpl getDescriptor() { - return (FleetLabelCloud.DescriptorImpl) super.getDescriptor(); + public EC2FleetLabelCloud.DescriptorImpl getDescriptor() { + return (EC2FleetLabelCloud.DescriptorImpl) super.getDescriptor(); } @Extension diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelParameters.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParameters.java similarity index 92% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelParameters.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParameters.java index b49cbba7..cea3e9ac 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelParameters.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParameters.java @@ -5,11 +5,11 @@ import java.util.Map; @ThreadSafe -public class FleetLabelParameters { +public class EC2FleetLabelParameters { private final Map parameters; - public FleetLabelParameters(final String label) { + public EC2FleetLabelParameters(final String label) { parameters = parse(label); } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelUpdater.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelUpdater.java similarity index 75% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelUpdater.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelUpdater.java index 0a636f25..6ad5f087 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelUpdater.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelUpdater.java @@ -12,9 +12,9 @@ // todo make configurable @Extension @SuppressWarnings("unused") -public class FleetLabelUpdater extends PeriodicWork { +public class EC2FleetLabelUpdater extends PeriodicWork { - private static final Logger LOGGER = Logger.getLogger(FleetLabelUpdater.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EC2FleetLabelUpdater.class.getName()); @Override public long getRecurrencePeriod() { @@ -24,8 +24,8 @@ public long getRecurrencePeriod() { @Override protected void doRun() { for (Cloud cloud : Jenkins.get().clouds) { - if (!(cloud instanceof FleetLabelCloud)) continue; - final FleetLabelCloud ec2FleetLabelCloud = (FleetLabelCloud) cloud; + if (!(cloud instanceof EC2FleetLabelCloud)) continue; + final EC2FleetLabelCloud ec2FleetLabelCloud = (EC2FleetLabelCloud) cloud; try { ec2FleetLabelCloud.updateStacks(); } catch (Throwable t) { diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetNode.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNode.java similarity index 74% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetNode.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNode.java index 81ff8c57..0379ee3d 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetNode.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNode.java @@ -17,18 +17,18 @@ import java.util.logging.Logger; /** - * The {@link FleetNode} represents an agent running on an EC2 instance, responsible for creating {@link FleetNodeComputer}. + * The {@link EC2FleetNode} represents an agent running on an EC2 instance, responsible for creating {@link EC2FleetNodeComputer}. */ -public class FleetNode extends Slave implements EphemeralNode { - private static final Logger LOGGER = Logger.getLogger(FleetNode.class.getName()); +public class EC2FleetNode extends Slave implements EphemeralNode { + private static final Logger LOGGER = Logger.getLogger(EC2FleetNode.class.getName()); private String cloudName; private String instanceId; private final int maxTotalUses; private int usesRemaining; - public FleetNode(final String instanceId, final String nodeDescription, final String remoteFS, final int numExecutors, final Mode mode, final String label, - final List> nodeProperties, final String cloudName, ComputerLauncher launcher, final int maxTotalUses) throws IOException, Descriptor.FormException { + public EC2FleetNode(final String instanceId, final String nodeDescription, final String remoteFS, final int numExecutors, final Mode mode, final String label, + final List> nodeProperties, final String cloudName, ComputerLauncher launcher, final int maxTotalUses) throws IOException, Descriptor.FormException { //noinspection deprecation super(instanceId, nodeDescription, remoteFS, numExecutors, mode, label, launcher, RetentionStrategy.NOOP, nodeProperties); @@ -81,11 +81,11 @@ public String getDisplayName() { @Override public Computer createComputer() { - return new FleetNodeComputer(this); + return new EC2FleetNodeComputer(this); } - public AbstractFleetCloud getCloud() { - return (AbstractFleetCloud) Jenkins.get().getCloud(cloudName); + public AbstractEC2FleetCloud getCloud() { + return (AbstractEC2FleetCloud) Jenkins.get().getCloud(cloudName); } public DescriptorImpl getDescriptor() { diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetNodeComputer.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputer.java similarity index 75% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetNodeComputer.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputer.java index 1e5ea772..ec5e3125 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetNodeComputer.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputer.java @@ -11,15 +11,15 @@ import java.util.logging.Logger; /** - * The {@link FleetNodeComputer} represents the running state of {@link FleetNode} that holds executors. + * The {@link EC2FleetNodeComputer} represents the running state of {@link EC2FleetNode} that holds executors. * @see hudson.model.Computer */ @ThreadSafe -public class FleetNodeComputer extends SlaveComputer { - private static final Logger LOGGER = Logger.getLogger(FleetNodeComputer.class.getName()); +public class EC2FleetNodeComputer extends SlaveComputer { + private static final Logger LOGGER = Logger.getLogger(EC2FleetNodeComputer.class.getName()); private boolean isMarkedForDeletion; - public FleetNodeComputer(final FleetNode agent) { + public EC2FleetNodeComputer(final EC2FleetNode agent) { super(agent); this.isMarkedForDeletion = false; } @@ -29,18 +29,18 @@ public boolean isMarkedForDeletion() { } @Override - public FleetNode getNode() { - return (FleetNode) super.getNode(); + public EC2FleetNode getNode() { + return (EC2FleetNode) super.getNode(); } @CheckForNull public String getInstanceId() { - FleetNode node = getNode(); + EC2FleetNode node = getNode(); return node == null ? null : node.getInstanceId(); } - public AbstractFleetCloud getCloud() { - final FleetNode node = getNode(); + public AbstractEC2FleetCloud getCloud() { + final EC2FleetNode node = getNode(); return node == null ? null : node.getCloud(); } @@ -53,7 +53,7 @@ public AbstractFleetCloud getCloud() { @Nonnull @Override public String getDisplayName() { - final FleetNode node = getNode(); + final EC2FleetNode node = getNode(); if(node != null) { final int totalUses = node.getMaxTotalUses(); if(totalUses != -1) { @@ -72,10 +72,10 @@ public String getDisplayName() { @Override public HttpResponse doDoDelete() throws IOException { checkPermission(DELETE); - final FleetNode node = getNode(); + final EC2FleetNode node = getNode(); if (node != null) { final String instanceId = node.getInstanceId(); - final AbstractFleetCloud cloud = node.getCloud(); + final AbstractEC2FleetCloud cloud = node.getCloud(); if (cloud != null && StringUtils.isNotBlank(instanceId)) { cloud.scheduleToTerminate(instanceId, false, EC2AgentTerminationReason.AGENT_DELETED); // Persist a flag here as the cloud objects can be re-created on user-initiated changes, hence, losing track of instance ids scheduled to terminate. diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetOnlineChecker.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineChecker.java similarity index 92% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetOnlineChecker.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineChecker.java index 4c5702f5..29ee9580 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetOnlineChecker.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineChecker.java @@ -32,19 +32,19 @@ *

* Based on https://github.com/jenkinsci/ec2-plugin/blob/master/src/main/java/hudson/plugins/ec2/EC2Cloud.java#L640 * - * @see FleetCloud - * @see FleetNode + * @see EC2FleetCloud + * @see EC2FleetNode */ @SuppressWarnings("WeakerAccess") @ThreadSafe -class FleetOnlineChecker implements Runnable { +class EC2FleetOnlineChecker implements Runnable { - private static final Logger LOGGER = Logger.getLogger(FleetOnlineChecker.class.getName()); + private static final Logger LOGGER = Logger.getLogger(EC2FleetOnlineChecker.class.getName()); // use daemon thread, so no problem when stop jenkins private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory()); public static void start(final Node node, final CompletableFuture future, final long timeout, final long interval) { - EXECUTOR.execute(new FleetOnlineChecker(node, future, timeout, interval)); + EXECUTOR.execute(new EC2FleetOnlineChecker(node, future, timeout, interval)); } private final long start; @@ -53,7 +53,7 @@ public static void start(final Node node, final CompletableFuture future, private final long timeout; private final long interval; - private FleetOnlineChecker( + private EC2FleetOnlineChecker( final Node node, final CompletableFuture future, final long timeout, final long interval) { this.start = System.currentTimeMillis(); this.node = node; diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusInfo.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusInfo.java similarity index 82% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusInfo.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusInfo.java index 9397aec7..3999f79d 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusInfo.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusInfo.java @@ -6,16 +6,16 @@ import java.util.Objects; /** - * This consumed by jelly file FleetStatusWidget/index.jelly + * This consumed by jelly file EC2FleetStatusWidget/index.jelly * to render fleet information about all fleets, don't forget to update it * if you change fields name * - * @see FleetStatusWidget + * @see EC2FleetStatusWidget * @see CloudNanny */ @SuppressWarnings({"WeakerAccess", "unused"}) @ThreadSafe -public class FleetStatusInfo extends Widget { +public class EC2FleetStatusInfo extends Widget { private final String id; private final String state; @@ -23,7 +23,7 @@ public class FleetStatusInfo extends Widget { private final int numActive; private final int numDesired; - public FleetStatusInfo(String id, String state, String label, int numActive, int numDesired) { + public EC2FleetStatusInfo(String id, String state, String label, int numActive, int numDesired) { this.id = id; this.state = state; this.label = label; @@ -39,7 +39,7 @@ public String getId() { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - FleetStatusInfo that = (FleetStatusInfo) o; + EC2FleetStatusInfo that = (EC2FleetStatusInfo) o; return numActive == that.numActive && numDesired == that.numDesired && Objects.equals(id, that.id) && diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidget.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget.java similarity index 57% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidget.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget.java index e7908eb1..315b97a0 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidget.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget.java @@ -9,20 +9,20 @@ /** * This class should be thread safe, consumed by Jenkins and updated - * by {@link FleetStatusWidgetUpdater} + * by {@link EC2FleetStatusWidgetUpdater} */ @Extension @ThreadSafe -public class FleetStatusWidget extends Widget { +public class EC2FleetStatusWidget extends Widget { - private volatile List statusList = Collections.emptyList(); + private volatile List statusList = Collections.emptyList(); - public void setStatusList(final List statusList) { + public void setStatusList(final List statusList) { this.statusList = statusList; } @SuppressWarnings("unused") - public List getStatusList() { + public List getStatusList() { return statusList; } } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdater.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java similarity index 79% rename from src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdater.java rename to src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java index f69114a7..75c863a8 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdater.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java @@ -10,12 +10,12 @@ import java.util.List; /** - * @see FleetCloud - * @see FleetStatusWidget + * @see EC2FleetCloud + * @see EC2FleetStatusWidget */ @Extension @SuppressWarnings("unused") -public class FleetStatusWidgetUpdater extends PeriodicWork { +public class EC2FleetStatusWidgetUpdater extends PeriodicWork { @Override public long getRecurrencePeriod() { @@ -30,21 +30,21 @@ public long getRecurrencePeriod() { */ @Override protected void doRun() { - final List info = new ArrayList<>(); + final List info = new ArrayList<>(); for (final Cloud cloud : getClouds()) { - if (!(cloud instanceof FleetCloud)) continue; - final FleetCloud fleetCloud = (FleetCloud) cloud; + if (!(cloud instanceof EC2FleetCloud)) continue; + final EC2FleetCloud fleetCloud = (EC2FleetCloud) cloud; final FleetStateStats stats = fleetCloud.getStats(); // could be when plugin just started and not yet updated, ok to skip if (stats == null) continue; - info.add(new FleetStatusInfo( + info.add(new EC2FleetStatusInfo( fleetCloud.getFleet(), stats.getState().getDetailed(), fleetCloud.getLabelString(), stats.getNumActive(), stats.getNumDesired())); } for (final Widget w : getWidgets()) { - if (w instanceof FleetStatusWidget) ((FleetStatusWidget) w).setStatusList(info); + if (w instanceof EC2FleetStatusWidget) ((EC2FleetStatusWidget) w).setStatusList(info); } } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategy.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategy.java index 99a88111..655b7273 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategy.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategy.java @@ -13,24 +13,24 @@ import java.util.logging.Logger; /** - * The {@link EC2RetentionStrategy} controls when to take {@link FleetNodeComputer} offline, bring it back online, or even to destroy it. + * The {@link EC2RetentionStrategy} controls when to take {@link EC2FleetNodeComputer} offline, bring it back online, or even to destroy it. */ -public class EC2RetentionStrategy extends RetentionStrategy implements ExecutorListener { +public class EC2RetentionStrategy extends RetentionStrategy implements ExecutorListener { private static final Logger LOGGER = Logger.getLogger(EC2RetentionStrategy.class.getName()); private static final int RE_CHECK_IN_A_MINUTE = 1; /** * Will be called under {@link hudson.model.Queue#withLock(Runnable)} * - * @param fc FleetNodeComputer + * @param fc EC2FleetNodeComputer * @return delay in min before next run */ @SuppressFBWarnings( value = "BC_UNCONFIRMED_CAST", - justification = "to ignore FleetNodeComputer cast") + justification = "to ignore EC2FleetNodeComputer cast") @Override - public long check(final FleetNodeComputer fc) { - final AbstractFleetCloud cloud = fc.getCloud(); + public long check(final EC2FleetNodeComputer fc) { + final AbstractEC2FleetCloud cloud = fc.getCloud(); LOGGER.fine(String.format("Checking if node '%s' is idle ", fc.getName())); @@ -41,7 +41,7 @@ public long check(final FleetNodeComputer fc) { return RE_CHECK_IN_A_MINUTE; } - // Ensure that the FleetCloud cannot be mutated from under us while + // Ensure that the EC2FleetCloud cannot be mutated from under us while // we're doing this check // Ensure nobody provisions onto this node until we've done // checking @@ -58,14 +58,14 @@ public long check(final FleetNodeComputer fc) { EC2AgentTerminationReason reason; // Determine the reason for termination from specific to generic use cases. // Reasoning for checking all cases of termination initiated by the plugin: - // A user-initiated change to cloud configuration creates a new FleetCloud object, erasing class fields containing data like instance IDs to terminate. + // A user-initiated change to cloud configuration creates a new EC2FleetCloud object, erasing class fields containing data like instance IDs to terminate. // Hence, determine the reasons for termination here using persisted fields for accurate handling of termination. if (fc.isMarkedForDeletion()) { reason = EC2AgentTerminationReason.AGENT_DELETED; } else if (cloud.hasExcessCapacity()) { reason = EC2AgentTerminationReason.EXCESS_CAPACITY; - } else if (cloud instanceof FleetCloud && !((FleetCloud) cloud).hasUnlimitedUsesForNodes() - && ((FleetNode)node).getUsesRemaining() <= 0) { + } else if (cloud instanceof EC2FleetCloud && !((EC2FleetCloud) cloud).hasUnlimitedUsesForNodes() + && ((EC2FleetNode)node).getUsesRemaining() <= 0) { reason = EC2AgentTerminationReason.MAX_TOTAL_USES_EXHAUSTED; } else if (isIdleForTooLong(cloud, fc)) { reason = EC2AgentTerminationReason.IDLE_FOR_TOO_LONG; @@ -97,12 +97,12 @@ public long check(final FleetNodeComputer fc) { } @Override - public void start(FleetNodeComputer c) { + public void start(EC2FleetNodeComputer c) { LOGGER.log(Level.INFO, "Connecting to instance: " + c.getDisplayName()); c.connect(false); } - private boolean isIdleForTooLong(final AbstractFleetCloud cloud, final Computer computer) { + private boolean isIdleForTooLong(final AbstractEC2FleetCloud cloud, final Computer computer) { final int idleMinutes = cloud.getIdleMinutes(); if (idleMinutes <= 0) return false; @@ -122,25 +122,25 @@ private boolean isIdleForTooLong(final AbstractFleetCloud cloud, final Computer @Override public void taskAccepted(Executor executor, Queue.Task task) { - final FleetNodeComputer computer = (FleetNodeComputer) executor.getOwner(); + final EC2FleetNodeComputer computer = (EC2FleetNodeComputer) executor.getOwner(); if (computer != null) { - final FleetNode fleetNode = computer.getNode(); - if (fleetNode != null) { - final int maxTotalUses = fleetNode.getMaxTotalUses(); + final EC2FleetNode ec2FleetNode = computer.getNode(); + if (ec2FleetNode != null) { + final int maxTotalUses = ec2FleetNode.getMaxTotalUses(); if (maxTotalUses <= -1) { // unlimited uses LOGGER.fine("maxTotalUses set to unlimited (" + maxTotalUses + ") for agent " + computer.getName()); } else { // limited uses - if (fleetNode.getUsesRemaining() > 1) { - fleetNode.decrementUsesRemaining(); - LOGGER.info("Agent " + computer.getName() + " has " + fleetNode.getUsesRemaining() + " builds left"); - } else if (fleetNode.getUsesRemaining() == 1) { // current task should be the last task for this agent + if (ec2FleetNode.getUsesRemaining() > 1) { + ec2FleetNode.decrementUsesRemaining(); + LOGGER.info("Agent " + computer.getName() + " has " + ec2FleetNode.getUsesRemaining() + " builds left"); + } else if (ec2FleetNode.getUsesRemaining() == 1) { // current task should be the last task for this agent LOGGER.info(String.format("maxTotalUses drained - suspending agent %s after current build", computer.getName())); computer.setAcceptingTasks(false); - fleetNode.decrementUsesRemaining(); + ec2FleetNode.decrementUsesRemaining(); } else { // don't decrement when usesRemaining=0, as -1 has a special meaning. LOGGER.warning(String.format("Agent %s accepted a task after being suspended!!! MaxTotalUses: %d, uses remaining: %d", - computer.getName(), fleetNode.getMaxTotalUses(), fleetNode.getUsesRemaining())); + computer.getName(), ec2FleetNode.getMaxTotalUses(), ec2FleetNode.getUsesRemaining())); } } } @@ -170,15 +170,15 @@ private void postJobAction(final Executor executor, final Throwable throwable) { TimeUnit.MILLISECONDS.toSeconds(executor.getElapsedTime()))); } - final FleetNodeComputer computer = (FleetNodeComputer) executor.getOwner(); + final EC2FleetNodeComputer computer = (EC2FleetNodeComputer) executor.getOwner(); if (computer != null) { - final FleetNode fleetNode = computer.getNode(); - if (fleetNode != null) { - final AbstractFleetCloud cloud = fleetNode.getCloud(); + final EC2FleetNode ec2FleetNode = computer.getNode(); + if (ec2FleetNode != null) { + final AbstractEC2FleetCloud cloud = ec2FleetNode.getCloud(); if (computer.countBusy() <= 1 && !computer.isAcceptingTasks()) { - LOGGER.info("Calling scheduleToTerminate for node " + fleetNode.getNodeName() + " due to exhausted maxTotalUses."); + LOGGER.info("Calling scheduleToTerminate for node " + ec2FleetNode.getNodeName() + " due to exhausted maxTotalUses."); // Schedule instance for termination even if it breaches minSize and minSpareSize constraints - cloud.scheduleToTerminate(fleetNode.getNodeName(), true, EC2AgentTerminationReason.MAX_TOTAL_USES_EXHAUSTED); + cloud.scheduleToTerminate(ec2FleetNode.getNodeName(), true, EC2AgentTerminationReason.MAX_TOTAL_USES_EXHAUSTED); } } } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStateStats.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStateStats.java index a52a3c57..05e8a056 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStateStats.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStateStats.java @@ -1,7 +1,5 @@ package com.amazon.jenkins.ec2fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.SpotFleet; import com.amazonaws.services.ec2.model.BatchState; import javax.annotation.Nonnegative; @@ -12,7 +10,7 @@ import java.util.Set; /** - * @see FleetCloud + * @see EC2FleetCloud */ @SuppressWarnings({"unused"}) @ThreadSafe @@ -20,7 +18,7 @@ public final class FleetStateStats { /** * Abstract state of different implementation of - * {@link Fleet} + * {@link com.amazon.jenkins.ec2fleet.fleet.EC2Fleet} */ public static class State { @@ -54,12 +52,12 @@ public State(final boolean active, final boolean modifying, final String detaile * Is underline fleet is updating so we need to suppress update * until modification will be completed and fleet state will be stabilized. * - * This is important only for {@link SpotFleet} + * This is important only for {@link com.amazon.jenkins.ec2fleet.fleet.EC2SpotFleet} * as it has delay between update request and actual update of target capacity, while * {@link com.amazon.jenkins.ec2fleet.fleet.AutoScalingGroupFleet} does it in sync with * update call. * - * Consumed by {@link FleetCloud#update()} + * Consumed by {@link EC2FleetCloud#update()} * * @return true or false */ @@ -69,7 +67,7 @@ public boolean isModifying() { /** * Fleet is good to be used for plugin, it will be shown on UI as option to use - * and plugin will use it for provision {@link FleetCloud#provision(hudson.slaves.Cloud.CloudState, int)} ()} and de-provision + * and plugin will use it for provision {@link EC2FleetCloud#provision(hudson.slaves.Cloud.CloudState, int)} ()} and de-provision * otherwise activity will be ignored until state will not be updated. * * @return true or false diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategy.java b/src/main/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategy.java index cbeb3049..cc3d426a 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategy.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategy.java @@ -50,8 +50,8 @@ public NodeProvisioner.StrategyDecision apply(final NodeProvisioner.StrategyStat break; } - if (!(c instanceof FleetCloud)) { - LOGGER.log(Level.FINE, "label [{0}]: cloud {1} is not an FleetCloud, continuing...", + if (!(c instanceof EC2FleetCloud)) { + LOGGER.log(Level.FINE, "label [{0}]: cloud {1} is not an EC2FleetCloud, continuing...", new Object[]{label, c.getDisplayName()}); continue; } @@ -63,7 +63,7 @@ public NodeProvisioner.StrategyDecision apply(final NodeProvisioner.StrategyStat continue; } - if (!((FleetCloud) c).isNoDelayProvision()) { + if (!((EC2FleetCloud) c).isNoDelayProvision()) { LOGGER.log(Level.FINE, "label [{0}]: cloud {1} does not use No Delay Provision Strategy, continuing...", new Object[]{label, c.getDisplayName()}); continue; diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/aws/AwsPermissionChecker.java b/src/main/java/com/amazon/jenkins/ec2fleet/aws/AwsPermissionChecker.java index 4bae3e03..9c1a7e72 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/aws/AwsPermissionChecker.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/aws/AwsPermissionChecker.java @@ -2,7 +2,7 @@ import com.amazon.jenkins.ec2fleet.Registry; import com.amazon.jenkins.ec2fleet.fleet.AutoScalingGroupFleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import com.amazonaws.services.autoscaling.AmazonAutoScalingClient; import com.amazonaws.services.autoscaling.model.AmazonAutoScalingException; import com.amazonaws.services.ec2.AmazonEC2; @@ -44,31 +44,31 @@ public List getMissingPermissions(final String fleet) { final AmazonEC2 ec2Client = Registry.getEc2Api().connect(awsCrendentialsId, regionName, endpoint); final List missingPermissions = new ArrayList<>(getMissingCommonPermissions(ec2Client)); if(StringUtils.isBlank(fleet)) { // Since we don't know the fleet type, show all permissions - missingPermissions.addAll(getMissingPermissionsForSpotFleet(ec2Client, fleet)); - missingPermissions.addAll(getMissingPermissionsForEC2Fleet(ec2Client, fleet)); + missingPermissions.addAll(getMissingPermissionsForEC2SpotFleet(ec2Client, fleet)); + missingPermissions.addAll(getMissingPermissionsForEC2EC2Fleet(ec2Client, fleet)); missingPermissions.addAll(getMissingPermissionsForASG()); - } else if(Fleets.isSpotFleet(fleet)) { - missingPermissions.addAll(getMissingPermissionsForSpotFleet(ec2Client, fleet)); - } else if(Fleets.isEC2Fleet(fleet)) { - missingPermissions.addAll(getMissingPermissionsForEC2Fleet(ec2Client, fleet)); + } else if(EC2Fleets.isEC2SpotFleet(fleet)) { + missingPermissions.addAll(getMissingPermissionsForEC2SpotFleet(ec2Client, fleet)); + } else if(EC2Fleets.isEC2EC2Fleet(fleet)) { + missingPermissions.addAll(getMissingPermissionsForEC2EC2Fleet(ec2Client, fleet)); } else { missingPermissions.addAll(getMissingPermissionsForASG()); } return missingPermissions; } - private List getMissingPermissionsForSpotFleet(final AmazonEC2 ec2Client, final String fleet) { - final List missingFleetPermissions = new ArrayList<>(); + private List getMissingPermissionsForEC2SpotFleet(final AmazonEC2 ec2Client, final String fleet) { + final List missingEC2SpotFleetPermissions = new ArrayList<>(); if(!hasDescribeSpotFleetRequestsPermission(ec2Client, fleet)) { - missingFleetPermissions.add(FleetAPI.DescribeSpotFleetRequests.name()); + missingEC2SpotFleetPermissions.add(FleetAPI.DescribeSpotFleetRequests.name()); } if(!hasDescribeSpotFleetInstancesPermission(ec2Client, fleet)) { - missingFleetPermissions.add(FleetAPI.DescribeSpotFleetInstances.name()); + missingEC2SpotFleetPermissions.add(FleetAPI.DescribeSpotFleetInstances.name()); } if(!hasModifySpotFleetRequestPermission(ec2Client, fleet)) { - missingFleetPermissions.add(FleetAPI.ModifySpotFleetRequest.name()); + missingEC2SpotFleetPermissions.add(FleetAPI.ModifySpotFleetRequest.name()); } - return missingFleetPermissions; + return missingEC2SpotFleetPermissions; } private List getMissingCommonPermissions(final AmazonEC2 ec2Client) { @@ -94,31 +94,31 @@ private List getMissingPermissionsForASG() { return missingAsgPermissions; } - private List getMissingPermissionsForEC2Fleet(final AmazonEC2 ec2Client, final String fleet) { + private List getMissingPermissionsForEC2EC2Fleet(final AmazonEC2 ec2Client, final String fleet) { final List missingFleetPermissions = new ArrayList<>(); - if(!hasDescribeEC2FleetRequestsPermission(ec2Client, fleet)) { + if(!hasDescribeEC2EC2FleetRequestsPermission(ec2Client, fleet)) { missingFleetPermissions.add(FleetAPI.DescribeFleets.name()); } - if(!hasDescribeEC2FleetInstancesPermission(ec2Client, fleet)) { + if(!hasDescribeEC2EC2FleetInstancesPermission(ec2Client, fleet)) { missingFleetPermissions.add(FleetAPI.DescribeFleetInstances.name()); } - if(!hasModifyEC2FleetRequestPermission(ec2Client, fleet)) { + if(!hasModifyEC2EC2FleetRequestPermission(ec2Client, fleet)) { missingFleetPermissions.add(FleetAPI.ModifyFleet.name()); } return missingFleetPermissions; } - private boolean hasModifyEC2FleetRequestPermission(final AmazonEC2 ec2Client, final String fleet) { + private boolean hasModifyEC2EC2FleetRequestPermission(final AmazonEC2 ec2Client, final String fleet) { final DryRunResult dryRunResult = ec2Client.dryRun(new ModifyFleetRequest().withFleetId(fleet)); return dryRunResult.getDryRunResponse().getStatusCode() != UNAUTHORIZED_STATUS_CODE; } - private boolean hasDescribeEC2FleetInstancesPermission(final AmazonEC2 ec2Client, final String fleet) { + private boolean hasDescribeEC2EC2FleetInstancesPermission(final AmazonEC2 ec2Client, final String fleet) { final DryRunResult dryRunResult = ec2Client.dryRun(new DescribeFleetInstancesRequest().withFleetId(fleet)); return dryRunResult.getDryRunResponse().getStatusCode() != UNAUTHORIZED_STATUS_CODE; } - private boolean hasDescribeEC2FleetRequestsPermission(final AmazonEC2 ec2Client, final String fleet) { + private boolean hasDescribeEC2EC2FleetRequestsPermission(final AmazonEC2 ec2Client, final String fleet) { final DryRunResult dryRunResult = ec2Client.dryRun(new DescribeFleetsRequest().withFleetIds(fleet)); return dryRunResult.getDryRunResponse().getStatusCode() != UNAUTHORIZED_STATUS_CODE; } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/aws/CloudFormationApi.java b/src/main/java/com/amazon/jenkins/ec2fleet/aws/CloudFormationApi.java index e2cfb342..3c083273 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/aws/CloudFormationApi.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/aws/CloudFormationApi.java @@ -1,6 +1,6 @@ package com.amazon.jenkins.ec2fleet.aws; -import com.amazon.jenkins.ec2fleet.FleetLabelParameters; +import com.amazon.jenkins.ec2fleet.EC2FleetLabelParameters; import com.amazonaws.ClientConfiguration; import com.amazonaws.regions.Region; import com.amazonaws.regions.RegionUtils; @@ -64,7 +64,7 @@ public void delete(final AmazonCloudFormation client, final String stackId) { public void create( final AmazonCloudFormation client, final String fleetName, final String keyName, final String parametersString) { - final FleetLabelParameters parameters = new FleetLabelParameters(parametersString); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(parametersString); try { final String type = parameters.getOrDefault("type", "ec2-spot-fleet"); diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleet.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleet.java index 4ce111a3..50f5b456 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleet.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/AutoScalingGroupFleet.java @@ -32,7 +32,7 @@ import java.util.stream.Collectors; @ThreadSafe -public class AutoScalingGroupFleet implements Fleet { +public class AutoScalingGroupFleet implements EC2Fleet { @Override public void describe( diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2EC2Fleet.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2EC2Fleet.java new file mode 100644 index 00000000..367bef10 --- /dev/null +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2EC2Fleet.java @@ -0,0 +1,163 @@ +package com.amazon.jenkins.ec2fleet.fleet; + +import com.amazon.jenkins.ec2fleet.FleetStateStats; +import com.amazon.jenkins.ec2fleet.Registry; +import com.amazonaws.services.ec2.AmazonEC2; +import com.amazonaws.services.ec2.model.*; +import hudson.util.ListBoxModel; +import org.springframework.util.ObjectUtils; + +import java.util.*; + +public class EC2EC2Fleet implements EC2Fleet { + @Override + public void describe(String awsCredentialsId, String regionName, String endpoint, ListBoxModel model, String selectedId, boolean showAll) { + final AmazonEC2 client = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); + String token = null; + do { + final DescribeFleetsRequest request = new DescribeFleetsRequest(); + request.withNextToken(token); + final DescribeFleetsResult result = client.describeFleets(request); + for(final FleetData fleetData : result.getFleets()) { + final String curFleetId = fleetData.getFleetId(); + final boolean selected = ObjectUtils.nullSafeEquals(selectedId, curFleetId); + if (selected || showAll || isActiveAndMaintain(fleetData)) { + final String displayStr = "EC2 Fleet - " + curFleetId + + " (" + fleetData.getFleetState() + ")" + + " (" + fleetData.getType() + ")"; + model.add(new ListBoxModel.Option(displayStr, curFleetId, selected)); + } + } + token = result.getNextToken(); + } while (token != null); + } + + private static boolean isActiveAndMaintain(final FleetData fleetData) { + return FleetType.Maintain.toString().equals(fleetData.getType()) && isActive(fleetData); + } + + private static boolean isActive(final FleetData fleetData) { + return BatchState.Active.toString().equals(fleetData.getFleetState()) + || BatchState.Modifying.toString().equals(fleetData.getFleetState()) + || BatchState.Submitted.toString().equals(fleetData.getFleetState()); + } + + private static boolean isModifying(final FleetData fleetData) { + return BatchState.Submitted.toString().equals(fleetData.getFleetState()) + || BatchState.Modifying.toString().equals(fleetData.getFleetState()); + } + + @Override + public void modify(String awsCredentialsId, String regionName, String endpoint, String id, int targetCapacity, int min, int max) { + final ModifyFleetRequest request = new ModifyFleetRequest(); + request.setFleetId(id); + request.setTargetCapacitySpecification(new TargetCapacitySpecificationRequest().withTotalTargetCapacity(targetCapacity)); + request.setExcessCapacityTerminationPolicy("no-termination"); + + final AmazonEC2 ec2 = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); + ec2.modifyFleet(request); + } + + @Override + public FleetStateStats getState(String awsCredentialsId, String regionName, String endpoint, String id) { + final AmazonEC2 ec2 = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); + + final DescribeFleetsRequest request = new DescribeFleetsRequest(); + request.setFleetIds(Collections.singleton(id)); + final DescribeFleetsResult result = ec2.describeFleets(request); + if (result.getFleets().isEmpty()) + throw new IllegalStateException("Fleet " + id + " doesn't exist"); + + final FleetData fleetData = result.getFleets().get(0); + final List templateConfigs = fleetData.getLaunchTemplateConfigs(); + + // Index configured instance types by weight: + final Map instanceTypeWeights = new HashMap<>(); + for (FleetLaunchTemplateConfig templateConfig : templateConfigs) { + for (FleetLaunchTemplateOverrides launchOverrides : templateConfig.getOverrides()) { + final String instanceType = launchOverrides.getInstanceType(); + if (instanceType == null) continue; + + final Double instanceWeight = launchOverrides.getWeightedCapacity(); + final Double existingWeight = instanceTypeWeights.get(instanceType); + if (instanceWeight == null || (existingWeight != null && existingWeight >= instanceWeight)) { + continue; + } + instanceTypeWeights.put(instanceType, instanceWeight); + } + } + + return new FleetStateStats(id, + fleetData.getTargetCapacitySpecification().getTotalTargetCapacity(), + new FleetStateStats.State( + isActive(fleetData), + isModifying(fleetData), + fleetData.getFleetState()), + getActiveFleetInstances(ec2, id), + instanceTypeWeights); + } + + private Set getActiveFleetInstances(AmazonEC2 ec2, String fleetId) { + String token = null; + final Set instances = new HashSet<>(); + do { + final DescribeFleetInstancesRequest request = new DescribeFleetInstancesRequest(); + request.setFleetId(fleetId); + request.setNextToken(token); + final DescribeFleetInstancesResult result = ec2.describeFleetInstances(request); + for (final ActiveInstance instance : result.getActiveInstances()) { + instances.add(instance.getInstanceId()); + } + + token = result.getNextToken(); + } while (token != null); + return instances; + } + + private static class State { + String id; + Set instances; + FleetData fleetData; + } + + @Override + public Map getStateBatch(String awsCredentialsId, String regionName, String endpoint, Collection ids) { + final AmazonEC2 ec2 = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); + + List states = new ArrayList<>(); + for (String id : ids) { + final State s = new State(); + s.id = id; + states.add(s); + } + + for (State state : states) { + state.instances = getActiveFleetInstances(ec2, state.id); + } + + final DescribeFleetsRequest request = new DescribeFleetsRequest(); + request.setFleetIds(ids); + final DescribeFleetsResult result = ec2.describeFleets(request); + + for (FleetData fleetData: result.getFleets()) { + for (State state : states) { + if (state.id.equals(fleetData.getFleetId())) state.fleetData = fleetData; + } + } + + Map r = new HashMap<>(); + for (State state : states) { + if(state.fleetData != null) { + r.put(state.id, new FleetStateStats(state.id, + state.fleetData.getTargetCapacitySpecification().getTotalTargetCapacity(), + new FleetStateStats.State( + isActive(state.fleetData), + isModifying(state.fleetData), + state.fleetData.getFleetState()), + state.instances, + Collections.emptyMap())); + } + } + return r; + } +} diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleet.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleet.java index c7851998..a72d5281 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleet.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleet.java @@ -1,163 +1,35 @@ package com.amazon.jenkins.ec2fleet.fleet; import com.amazon.jenkins.ec2fleet.FleetStateStats; -import com.amazon.jenkins.ec2fleet.Registry; -import com.amazonaws.services.ec2.AmazonEC2; -import com.amazonaws.services.ec2.model.*; import hudson.util.ListBoxModel; -import org.springframework.util.ObjectUtils; -import java.util.*; +import java.util.Collection; +import java.util.Map; -public class EC2Fleet implements Fleet { - @Override - public void describe(String awsCredentialsId, String regionName, String endpoint, ListBoxModel model, String selectedId, boolean showAll) { - final AmazonEC2 client = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); - String token = null; - do { - final DescribeFleetsRequest request = new DescribeFleetsRequest(); - request.withNextToken(token); - final DescribeFleetsResult result = client.describeFleets(request); - for(final FleetData fleetData : result.getFleets()) { - final String curFleetId = fleetData.getFleetId(); - final boolean selected = ObjectUtils.nullSafeEquals(selectedId, curFleetId); - if (selected || showAll || isActiveAndMaintain(fleetData)) { - final String displayStr = "EC2 Fleet - " + curFleetId + - " (" + fleetData.getFleetState() + ")" + - " (" + fleetData.getType() + ")"; - model.add(new ListBoxModel.Option(displayStr, curFleetId, selected)); - } - } - token = result.getNextToken(); - } while (token != null); - } +/** + * Hide details of access to EC2 Fleet depending on implementation like EC2 Fleet, Spot Fleet, + * or Auto Scaling Group. + * + * @see EC2EC2Fleet + * @see EC2SpotFleet + * @see AutoScalingGroupFleet + */ +public interface EC2Fleet { - private static boolean isActiveAndMaintain(final FleetData fleetData) { - return FleetType.Maintain.toString().equals(fleetData.getType()) && isActive(fleetData); - } + void describe( + final String awsCredentialsId, final String regionName, final String endpoint, + final ListBoxModel model, final String selectedId, final boolean showAll); - private static boolean isActive(final FleetData fleetData) { - return BatchState.Active.toString().equals(fleetData.getFleetState()) - || BatchState.Modifying.toString().equals(fleetData.getFleetState()) - || BatchState.Submitted.toString().equals(fleetData.getFleetState()); - } + void modify( + final String awsCredentialsId, final String regionName, final String endpoint, + final String id, final int targetCapacity, int min, int max); - private static boolean isModifying(final FleetData fleetData) { - return BatchState.Submitted.toString().equals(fleetData.getFleetState()) - || BatchState.Modifying.toString().equals(fleetData.getFleetState()); - } + FleetStateStats getState( + final String awsCredentialsId, final String regionName, final String endpoint, + final String id); - @Override - public void modify(String awsCredentialsId, String regionName, String endpoint, String id, int targetCapacity, int min, int max) { - final ModifyFleetRequest request = new ModifyFleetRequest(); - request.setFleetId(id); - request.setTargetCapacitySpecification(new TargetCapacitySpecificationRequest().withTotalTargetCapacity(targetCapacity)); - request.setExcessCapacityTerminationPolicy("NoTermination"); + Map getStateBatch( + final String awsCredentialsId, final String regionName, final String endpoint, + final Collection ids); - final AmazonEC2 ec2 = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); - ec2.modifyFleet(request); - } - - @Override - public FleetStateStats getState(String awsCredentialsId, String regionName, String endpoint, String id) { - final AmazonEC2 ec2 = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); - - final DescribeFleetsRequest request = new DescribeFleetsRequest(); - request.setFleetIds(Collections.singleton(id)); - final DescribeFleetsResult result = ec2.describeFleets(request); - if (result.getFleets().isEmpty()) - throw new IllegalStateException("Fleet " + id + " doesn't exist"); - - final FleetData fleetData = result.getFleets().get(0); - final List templateConfigs = fleetData.getLaunchTemplateConfigs(); - - // Index configured instance types by weight: - final Map instanceTypeWeights = new HashMap<>(); - for (FleetLaunchTemplateConfig templateConfig : templateConfigs) { - for (FleetLaunchTemplateOverrides launchOverrides : templateConfig.getOverrides()) { - final String instanceType = launchOverrides.getInstanceType(); - if (instanceType == null) continue; - - final Double instanceWeight = launchOverrides.getWeightedCapacity(); - final Double existingWeight = instanceTypeWeights.get(instanceType); - if (instanceWeight == null || (existingWeight != null && existingWeight >= instanceWeight)) { - continue; - } - instanceTypeWeights.put(instanceType, instanceWeight); - } - } - - return new FleetStateStats(id, - fleetData.getTargetCapacitySpecification().getTotalTargetCapacity(), - new FleetStateStats.State( - isActive(fleetData), - isModifying(fleetData), - fleetData.getFleetState()), - getActiveFleetInstances(ec2, id), - instanceTypeWeights); - } - - private Set getActiveFleetInstances(AmazonEC2 ec2, String fleetId) { - String token = null; - final Set instances = new HashSet<>(); - do { - final DescribeFleetInstancesRequest request = new DescribeFleetInstancesRequest(); - request.setFleetId(fleetId); - request.setNextToken(token); - final DescribeFleetInstancesResult result = ec2.describeFleetInstances(request); - for (final ActiveInstance instance : result.getActiveInstances()) { - instances.add(instance.getInstanceId()); - } - - token = result.getNextToken(); - } while (token != null); - return instances; - } - - private static class State { - String id; - Set instances; - FleetData fleetData; - } - - @Override - public Map getStateBatch(String awsCredentialsId, String regionName, String endpoint, Collection ids) { - final AmazonEC2 ec2 = Registry.getEc2Api().connect(awsCredentialsId, regionName, endpoint); - - List states = new ArrayList<>(); - for (String id : ids) { - final State s = new State(); - s.id = id; - states.add(s); - } - - for (State state : states) { - state.instances = getActiveFleetInstances(ec2, state.id); - } - - final DescribeFleetsRequest request = new DescribeFleetsRequest(); - request.setFleetIds(ids); - final DescribeFleetsResult result = ec2.describeFleets(request); - - for (FleetData fleetData: result.getFleets()) { - for (State state : states) { - if (state.id.equals(fleetData.getFleetId())) state.fleetData = fleetData; - } - } - - Map r = new HashMap<>(); - for (State state : states) { - if(state.fleetData != null) { - r.put(state.id, new FleetStateStats(state.id, - state.fleetData.getTargetCapacitySpecification().getTotalTargetCapacity(), - new FleetStateStats.State( - isActive(state.fleetData), - isModifying(state.fleetData), - state.fleetData.getFleetState()), - state.instances, - Collections.emptyMap())); - } - } - return r; - } } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleets.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleets.java new file mode 100644 index 00000000..82b97aa4 --- /dev/null +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleets.java @@ -0,0 +1,57 @@ +package com.amazon.jenkins.ec2fleet.fleet; + +import org.apache.commons.lang.StringUtils; + +import javax.annotation.concurrent.ThreadSafe; +import java.util.Arrays; +import java.util.List; + +@ThreadSafe +public class EC2Fleets { + + private static final String EC2_SPOT_FLEET_PREFIX = "sfr-"; + private static final EC2SpotFleet EC2_SPOT_FLEET = new EC2SpotFleet(); + + private static final String EC2_EC2_FLEET_PREFIX = "fleet-"; + private static final EC2EC2Fleet EC2_EC2_FLEET = new EC2EC2Fleet(); + + private static EC2Fleet GET = null; + + private EC2Fleets() { + throw new UnsupportedOperationException("util class"); + } + + public static List all() { + return Arrays.asList( + new EC2SpotFleet(), + new EC2EC2Fleet(), + new AutoScalingGroupFleet() + ); + } + + public static EC2Fleet get(final String id) { + if (GET != null) return GET; + + if (isEC2SpotFleet(id)) { + return EC2_SPOT_FLEET; + } else if(isEC2EC2Fleet(id)) { + return EC2_EC2_FLEET; + } else { + return new AutoScalingGroupFleet(); + } + } + + public static boolean isEC2SpotFleet(final String fleet) { + return StringUtils.startsWith(fleet, EC2_SPOT_FLEET_PREFIX); + } + + public static boolean isEC2EC2Fleet(final String fleet) { + return StringUtils.startsWith(fleet, EC2_EC2_FLEET_PREFIX); + } + + // Visible for testing + public static void setGet(EC2Fleet ec2Fleet) { + GET = ec2Fleet; + } + +} diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleet.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleet.java similarity index 99% rename from src/main/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleet.java rename to src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleet.java index c839d848..ada18da2 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleet.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleet.java @@ -31,7 +31,7 @@ * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-requests.html#spot-fleet-states */ @ThreadSafe -public class SpotFleet implements Fleet { +public class EC2SpotFleet implements EC2Fleet { @Override public void describe( diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleet.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleet.java deleted file mode 100644 index d8e7cd52..00000000 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleet.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.amazon.jenkins.ec2fleet.fleet; - -import com.amazon.jenkins.ec2fleet.FleetStateStats; -import hudson.util.ListBoxModel; - -import java.util.Collection; -import java.util.Map; - -/** - * Hide details of access to EC2 Fleet depending on implementation like EC2 Fleet or Spot Fleet - * or Auto Scaling Group. - * - * @see EC2Fleet - * @see SpotFleet - * @see AutoScalingGroupFleet - */ -public interface Fleet { - - void describe( - final String awsCredentialsId, final String regionName, final String endpoint, - final ListBoxModel model, final String selectedId, final boolean showAll); - - void modify( - final String awsCredentialsId, final String regionName, final String endpoint, - final String id, final int targetCapacity, int min, int max); - - FleetStateStats getState( - final String awsCredentialsId, final String regionName, final String endpoint, - final String id); - - Map getStateBatch( - final String awsCredentialsId, final String regionName, final String endpoint, - final Collection ids); - -} diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleets.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleets.java deleted file mode 100644 index 6310413c..00000000 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleets.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.amazon.jenkins.ec2fleet.fleet; - -import org.apache.commons.lang.StringUtils; - -import javax.annotation.concurrent.ThreadSafe; -import java.util.Arrays; -import java.util.List; - -@ThreadSafe -public class Fleets { - - private static final String EC2_SPOT_FLEET_PREFIX = "sfr-"; - private static final SpotFleet EC2_SPOT_FLEET = new SpotFleet(); - - private static final String EC2_FLEET_PREFIX = "fleet-"; - private static final EC2Fleet EC2_FLEET = new EC2Fleet(); - - private static Fleet GET = null; - - private Fleets() { - throw new UnsupportedOperationException("util class"); - } - - public static List all() { - return Arrays.asList( - new SpotFleet(), - new EC2Fleet(), - new AutoScalingGroupFleet() - ); - } - - public static Fleet get(final String id) { - if (GET != null) return GET; - - if (isSpotFleet(id)) { - return EC2_SPOT_FLEET; - } else if(isEC2Fleet(id)) { - return EC2_FLEET; - } else { - return new AutoScalingGroupFleet(); - } - } - - public static boolean isSpotFleet(final String fleet) { - return StringUtils.startsWith(fleet, EC2_SPOT_FLEET_PREFIX); - } - - public static boolean isEC2Fleet(final String fleet) { - return StringUtils.startsWith(fleet, EC2_FLEET_PREFIX); - } - - // Visible for testing - public static void setGet(Fleet fleet) { - GET = fleet; - } - -} diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/NodeHardwareScaler/config.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/NodeHardwareScaler/config.jelly similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/NodeHardwareScaler/config.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/NodeHardwareScaler/config.jelly diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/NodeHardwareScaler/help-memoryGiBPerExecutor.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/NodeHardwareScaler/help-memoryGiBPerExecutor.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/NodeHardwareScaler/help-memoryGiBPerExecutor.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/NodeHardwareScaler/help-memoryGiBPerExecutor.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/NodeHardwareScaler/help-vCpuPerExecutor.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/NodeHardwareScaler/help-vCpuPerExecutor.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/NodeHardwareScaler/help-vCpuPerExecutor.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/NodeHardwareScaler/help-vCpuPerExecutor.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/config.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/config.jelly similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/config.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/config.jelly diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-cloudStatusIntervalSec.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-cloudStatusIntervalSec.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-cloudStatusIntervalSec.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-cloudStatusIntervalSec.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-disableTaskResubmit.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-disableTaskResubmit.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-disableTaskResubmit.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-disableTaskResubmit.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-endpoint.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-endpoint.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-endpoint.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-endpoint.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-executorScaler.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-executorScaler.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-executorScaler.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-executorScaler.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-fleet.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-fleet.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-fleet.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-fleet.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-idleMinutes.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-idleMinutes.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-idleMinutes.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-idleMinutes.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-initOnlineTimeoutSec.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-initOnlineTimeoutSec.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-initOnlineTimeoutSec.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-initOnlineTimeoutSec.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-maxTotalUses.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-maxTotalUses.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-maxTotalUses.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-maxTotalUses.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-minSpareSize.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-minSpareSize.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-minSpareSize.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-minSpareSize.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-name.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-name.html similarity index 68% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-name.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-name.html index 5f49dbdf..5d0a195f 100644 --- a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-name.html +++ b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-name.html @@ -1,5 +1,5 @@

- Provide a name for this Fleet Cloud/Fleet Label Cloud. If no name is provided, then a default of 'FleetCloud' for a FleetCloud or 'FleetCloudLabel' for a FleetLabelCloud will be used for the name. + Provide a name for this EC2 Fleet Cloud/EC2 Fleet Label Cloud. If no name is provided, then a default of 'FleetCloud' for a EC2FleetCloud or 'FleetCloudLabel' for a EC2FleetLabelCloud will be used for the name.

Could be used in Groovy as cloud identifier. diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-noDelayProvision.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-noDelayProvision.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-noDelayProvision.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-noDelayProvision.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-numExecutors.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-numExecutors.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-numExecutors.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-numExecutors.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-restrictUsage.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-restrictUsage.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-restrictUsage.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-restrictUsage.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-scaleExecutorsByWeight.html b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-scaleExecutorsByWeight.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-scaleExecutorsByWeight.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-scaleExecutorsByWeight.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/config.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/config.jelly similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/config.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/config.jelly diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetNode/configure-entries.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetNode/configure-entries.jelly similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetNode/configure-entries.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetNode/configure-entries.jelly diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetStatusWidget/index.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget/index.jelly similarity index 93% rename from src/main/resources/com/amazon/jenkins/ec2fleet/FleetStatusWidget/index.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget/index.jelly index 0875b072..f08b6281 100644 --- a/src/main/resources/com/amazon/jenkins/ec2fleet/FleetStatusWidget/index.jelly +++ b/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget/index.jelly @@ -1,6 +1,6 @@ - + diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/AutoResubmitIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/AutoResubmitIntegrationTest.java index 06a9a537..a76e64b7 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/AutoResubmitIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/AutoResubmitIntegrationTest.java @@ -1,8 +1,8 @@ package com.amazon.jenkins.ec2fleet; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.DescribeInstancesRequest; import com.amazonaws.services.ec2.model.DescribeInstancesResult; @@ -43,18 +43,18 @@ @SuppressWarnings({"deprecation"}) public class AutoResubmitIntegrationTest extends IntegrationTest { - private FleetCloud.ExecutorScaler noScaling; + private EC2FleetCloud.ExecutorScaler noScaling; @Before public void before() { - Fleet fleet = mock(Fleet.class); + EC2Fleet ec2Fleet = mock(EC2Fleet.class); - Fleets.setGet(fleet); + EC2Fleets.setGet(ec2Fleet); EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); - when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())).thenReturn( + when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())).thenReturn( new FleetStateStats("", 1, FleetStateStats.State.active(), Collections.singleton("i-1"), Collections.emptyMap())); @@ -72,12 +72,12 @@ public void before() { instance ))); - noScaling = new FleetCloud.NoScaler(); + noScaling = new EC2FleetCloud.NoScaler(); } @Test public void should_successfully_resubmit_freestyle_task() throws Exception { - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, 0, 0, @@ -113,7 +113,7 @@ public void should_successfully_resubmit_freestyle_task() throws Exception { @Test public void should_successfully_resubmit_parametrized_task() throws Exception { - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, 0, 0, @@ -169,7 +169,7 @@ public void should_successfully_resubmit_parametrized_task() throws Exception { @Test public void should_not_resubmit_if_disabled() throws Exception { - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 0, 1, false, true, "-1", true, 0, 0, 10, false, noScaling); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java index 80d8cdfb..434f8a28 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java @@ -9,11 +9,11 @@ public class CloudNamesTest { @Rule public JenkinsRule j = new JenkinsRule(); - private final FleetCloud.ExecutorScaler noScaling = new FleetCloud.NoScaler(); + private final EC2FleetCloud.ExecutorScaler noScaling = new EC2FleetCloud.NoScaler(); @Test public void isUnique_true() { - j.jenkins.clouds.add(new FleetCloud("SomeDefaultName", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("SomeDefaultName", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -24,7 +24,7 @@ public void isUnique_true() { @Test public void isUnique_false() { - j.jenkins.clouds.add(new FleetCloud("SomeDefaultName", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("SomeDefaultName", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -35,13 +35,13 @@ public void isUnique_false() { @Test public void isDuplicated_false() { - j.jenkins.clouds.add(new FleetCloud("TestCloud", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("TestCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling)); - j.jenkins.clouds.add(new FleetCloud("TestCloud2", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("TestCloud2", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -52,13 +52,13 @@ public void isDuplicated_false() { @Test public void isDuplicated_true() { - j.jenkins.clouds.add(new FleetCloud("TestCloud", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("TestCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling)); - j.jenkins.clouds.add(new FleetCloud("TestCloud", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("TestCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -74,7 +74,7 @@ public void generateUnique_noSuffix() { @Test public void generateUnique_addsSuffixOnlyWhenNeeded() { - j.jenkins.clouds.add(new FleetCloud("UniqueCloud-1", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("UniqueCloud-1", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -85,13 +85,13 @@ public void generateUnique_addsSuffixOnlyWhenNeeded() { @Test public void generateUnique_addsSuffixCorrectly() { - j.jenkins.clouds.add(new FleetCloud("UniqueCloud", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("UniqueCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling)); - j.jenkins.clouds.add(new FleetCloud("UniqueCloud-1", null, null, null, null, null, + j.jenkins.clouds.add(new EC2FleetCloud("UniqueCloud-1", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -104,33 +104,33 @@ public void generateUnique_addsSuffixCorrectly() { @Test public void generateUnique_emptyStringInConstructor() { - FleetCloud fleetCloud = new FleetCloud("", null, null, null, null, null, + EC2FleetCloud fleetCloud = new EC2FleetCloud("", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); - FleetLabelCloud fleetLabelCloud = new FleetLabelCloud("", null, null, + EC2FleetLabelCloud fleetLabelCloud = new EC2FleetLabelCloud("", null, null, null, null, new LocalComputerConnector(j), false, false, 0, 0, 0, 1, false, false, 0, 0, 2, false, null); Assert.assertEquals(("FleetCloud".length() + CloudNames.SUFFIX_LENGTH + 1), fleetCloud.name.length()); - Assert.assertTrue(fleetCloud.name.startsWith(FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); + Assert.assertTrue(fleetCloud.name.startsWith(EC2FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); Assert.assertEquals(("FleetLabelCloud".length() + CloudNames.SUFFIX_LENGTH + 1), fleetLabelCloud.name.length()); - Assert.assertTrue(fleetLabelCloud.name.startsWith(FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); + Assert.assertTrue(fleetLabelCloud.name.startsWith(EC2FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); } @Test public void generateUnique_nonEmptyStringInConstructor() { - FleetCloud fleetCloud = new FleetCloud("UniqueCloud", null, null, null, null, null, + EC2FleetCloud fleetCloud = new EC2FleetCloud("UniqueCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); - FleetLabelCloud fleetLabelCloud = new FleetLabelCloud("UniqueLabelCloud", null, null, + EC2FleetLabelCloud fleetLabelCloud = new EC2FleetLabelCloud("UniqueLabelCloud", null, null, null, null, new LocalComputerConnector(j), false, false, 0, 0, 0, 1, false, false, 0, 0, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java index 22cf2c62..fb4075cf 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNannyTest.java @@ -30,10 +30,10 @@ public class CloudNannyTest { @Mock - private FleetCloud cloud1; + private EC2FleetCloud cloud1; @Mock - private FleetCloud cloud2; + private EC2FleetCloud cloud2; private List clouds = new ArrayList<>(); @@ -48,7 +48,7 @@ public class CloudNannyTest { private AtomicInteger recurrenceCounter1 = new AtomicInteger(); private AtomicInteger recurrenceCounter2 = new AtomicInteger(); - private Map recurrenceCounters = Collections.synchronizedMap(new WeakHashMap<>()); + private Map recurrenceCounters = Collections.synchronizedMap(new WeakHashMap<>()); @Before public void before() throws Exception { @@ -96,7 +96,7 @@ public void shouldUpdateCloudAndDoNothingIfNoWidgets() { } @Test - public void shouldIgnoreNonFleetClouds() { + public void shouldIgnoreNonEC2FleetClouds() { clouds.add(cloud1); Cloud nonEc2FleetCloud = mock(Cloud.class); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncherTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java similarity index 89% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncherTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java index 0389aefb..06974bf6 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncherTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java @@ -36,7 +36,7 @@ @SuppressWarnings("ArraysAsListWithZeroOrOneArgument") @RunWith(PowerMockRunner.class) @PrepareForTest({Jenkins.class, Queue.class, WorkflowJob.class, WorkflowRun.class}) -public class FleetAutoResubmitComputerLauncherTest { +public class EC2FleetAutoResubmitComputerLauncherTest { @Mock private ComputerLauncher baseComputerLauncher; @@ -62,7 +62,7 @@ public class FleetAutoResubmitComputerLauncherTest { private Slave agent; @Mock - private FleetNodeComputer computer; + private EC2FleetNodeComputer computer; @Mock private Jenkins jenkins; @@ -83,10 +83,10 @@ public class FleetAutoResubmitComputerLauncherTest { private Queue.Task task2; @Mock - private FleetNode fleetNode; + private EC2FleetNode fleetNode; @Mock - private FleetCloud cloud; + private EC2FleetCloud cloud; @Mock private WorkflowJob workflowJob; @@ -127,7 +127,7 @@ public void before() { @Test public void afterDisconnect_should_do_nothing_if_still_online() { when(computer.isOffline()).thenReturn(false); - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verifyZeroInteractions(queue); } @@ -136,7 +136,7 @@ public void afterDisconnect_should_do_nothing_if_still_online() { public void afterDisconnect_should_do_nothing_if_offline_but_no_executable() { when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); when(executor1.getCurrentExecutable()).thenReturn(null); - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verifyZeroInteractions(queue); } @@ -144,7 +144,7 @@ public void afterDisconnect_should_do_nothing_if_offline_but_no_executable() { @Test public void taskCompleted_should_resubmit_task_if_offline_and_has_executable() { when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verify(queue).schedule2(eq(task1), anyInt(), eq(Collections.emptyList())); verifyZeroInteractions(queue); @@ -154,14 +154,14 @@ public void taskCompleted_should_resubmit_task_if_offline_and_has_executable() { public void taskCompleted_should_not_resubmit_task_if_offline_but_disabled() { when(cloud.isDisableTaskResubmit()).thenReturn(true); when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verifyZeroInteractions(queue); } @Test public void taskCompleted_should_resubmit_task_for_all_executors() { - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verify(queue).schedule2(eq(task1), anyInt(), eq(Collections.emptyList())); verify(queue).schedule2(eq(task2), anyInt(), eq(Collections.emptyList())); @@ -170,7 +170,7 @@ public void taskCompleted_should_resubmit_task_for_all_executors() { @Test public void taskCompleted_should_abort_executors_during_resubmit() { - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verify(executor1).interrupt(Result.ABORTED, new EC2ExecutorInterruptionCause("i-12")); verify(executor2).interrupt(Result.ABORTED, new EC2ExecutorInterruptionCause("i-12")); @@ -180,7 +180,7 @@ public void taskCompleted_should_abort_executors_during_resubmit() { public void taskCompleted_should_resubmit_task_with_actions() { when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); when(executable1.getActions()).thenReturn(Arrays.asList(action1)); - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verify(queue).schedule2(eq(task1), anyInt(), eq(Arrays.asList(action1))); verifyZeroInteractions(queue); @@ -192,7 +192,7 @@ public void taskCompleted_should_resubmit_task_with_failed_build_actions() { when(workflowJob.getLastFailedBuild()).thenReturn(workflowRun); when(workflowRun.getActions(any())).thenReturn((Collections.singletonList(action1))); when(computer.getExecutors()).thenReturn(Arrays.asList(executor1)); - new FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verify(queue).schedule2(eq(workflowJob), anyInt(), eq(Arrays.asList(action1))); verify(workflowRun, times(1)).getActions(any()); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudConfigurationAsCodeTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudConfigurationAsCodeTest.java similarity index 77% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudConfigurationAsCodeTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudConfigurationAsCodeTest.java index 24ce863a..163a4f8f 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudConfigurationAsCodeTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudConfigurationAsCodeTest.java @@ -1,9 +1,10 @@ package com.amazon.jenkins.ec2fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import hudson.plugins.sshslaves.SSHConnector; import hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy; +import hudson.slaves.Cloud; import io.jenkins.plugins.casc.ConfiguratorException; import io.jenkins.plugins.casc.misc.ConfiguredWithCode; import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule; @@ -23,32 +24,32 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class FleetCloudConfigurationAsCodeTest { +public class EC2FleetCloudConfigurationAsCodeTest { @Rule public JenkinsRule jenkinsRule = new JenkinsConfiguredWithCodeRule(); @Before public void before() { - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); - when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); + when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) .thenReturn(new FleetStateStats("", 2, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-1", "i-2")), Collections.emptyMap())); } @Test @ConfiguredWithCode( - value = "FleetCloud/name-required-configuration-as-code.yml", + value = "EC2FleetCloud/name-required-configuration-as-code.yml", expected = ConfiguratorException.class, message = "error configuring 'jenkins' with class io.jenkins.plugins.casc.core.JenkinsConfigurator configurator") public void configurationWithNullName_shouldFail() { } @Test - @ConfiguredWithCode("FleetCloud/min-configuration-as-code.yml") + @ConfiguredWithCode("EC2FleetCloud/min-configuration-as-code.yml") public void shouldCreateCloudFromMinConfiguration() { assertEquals(jenkinsRule.jenkins.clouds.size(), 1); - FleetCloud cloud = (FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); + EC2FleetCloud cloud = (EC2FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); assertEquals("ec2-fleet", cloud.name); assertEquals(cloud.getRegion(), null); @@ -64,7 +65,7 @@ public void shouldCreateCloudFromMinConfiguration() { assertEquals(cloud.getNumExecutors(), 1); assertEquals(cloud.isAddNodeOnlyIfRunning(), false); assertEquals(cloud.isRestrictUsage(), false); - assertEquals(cloud.getExecutorScaler().getClass(), FleetCloud.NoScaler.class); + assertEquals(cloud.getExecutorScaler().getClass(), EC2FleetCloud.NoScaler.class); assertEquals(cloud.getInitOnlineTimeoutSec(), 180); assertEquals(cloud.getInitOnlineCheckIntervalSec(), 15); assertEquals(cloud.getCloudStatusIntervalSec(), 10); @@ -73,10 +74,10 @@ public void shouldCreateCloudFromMinConfiguration() { } @Test - @ConfiguredWithCode("FleetCloud/max-configuration-as-code.yml") + @ConfiguredWithCode("EC2FleetCloud/max-configuration-as-code.yml") public void shouldCreateCloudFromMaxConfiguration() { assertEquals(jenkinsRule.jenkins.clouds.size(), 1); - FleetCloud cloud = (FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); + EC2FleetCloud cloud = (EC2FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); assertEquals("ec2-fleet", cloud.name); assertEquals(cloud.getRegion(), "us-east-2"); @@ -92,7 +93,7 @@ public void shouldCreateCloudFromMaxConfiguration() { assertEquals(cloud.getNumExecutors(), 12); assertEquals(cloud.isAddNodeOnlyIfRunning(), true); assertEquals(cloud.isRestrictUsage(), true); - assertEquals(cloud.getExecutorScaler().getClass(), FleetCloud.WeightedScaler.class); + assertEquals(cloud.getExecutorScaler().getClass(), EC2FleetCloud.WeightedScaler.class); assertEquals(cloud.getInitOnlineTimeoutSec(), 181); assertEquals(cloud.getInitOnlineCheckIntervalSec(), 13); assertEquals(cloud.getCloudStatusIntervalSec(), 11); @@ -105,13 +106,13 @@ public void shouldCreateCloudFromMaxConfiguration() { } @Test - @ConfiguredWithCode("FleetCloud/empty-name-configuration-as-code.yml") + @ConfiguredWithCode("EC2FleetCloud/empty-name-configuration-as-code.yml") public void configurationWithEmptyName_shouldUseDefault() { assertEquals(jenkinsRule.jenkins.clouds.size(), 3); - for (FleetCloud cloud : jenkinsRule.jenkins.clouds.getAll(FleetCloud.class)){ + for (EC2FleetCloud cloud : jenkinsRule.jenkins.clouds.getAll(EC2FleetCloud.class)){ - assertTrue(cloud.name.startsWith(FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); + assertTrue(cloud.name.startsWith(EC2FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); assertEquals(("FleetCloud".length() + CloudNames.SUFFIX_LENGTH + 1), cloud.name.length()); } } diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java similarity index 84% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java index 0faff254..fe045214 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java @@ -1,11 +1,12 @@ package com.amazon.jenkins.ec2fleet; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -import com.amazon.jenkins.ec2fleet.fleet.*; -import com.amazon.jenkins.ec2fleet.fleet.SpotFleet; +import com.amazon.jenkins.ec2fleet.fleet.AutoScalingGroupFleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2SpotFleet; import com.amazon.jenkins.ec2fleet.aws.RegionInfo; import com.amazon.jenkins.ec2fleet.aws.AwsPermissionChecker; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; import com.amazonaws.regions.RegionUtils; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.AmazonEC2Client; @@ -72,9 +73,9 @@ @SuppressWarnings("unchecked") @RunWith(PowerMockRunner.class) -@PrepareForTest({Jenkins.class, FleetCloud.class, FleetCloud.DescriptorImpl.class, - LabelFinder.class, FleetStateStats.class, Fleets.class, FleetNodeComputer.class}) -public class FleetCloudTest { +@PrepareForTest({Jenkins.class, EC2FleetCloud.class, EC2FleetCloud.DescriptorImpl.class, + LabelFinder.class, FleetStateStats.class, EC2Fleets.class, EC2FleetNodeComputer.class}) +public class EC2FleetCloudTest { private SpotFleetRequestConfig spotFleetRequestConfig1; private SpotFleetRequestConfig spotFleetRequestConfig2; @@ -89,7 +90,7 @@ public class FleetCloudTest { private Jenkins jenkins; @Mock - private Fleet fleet; + private EC2Fleet ec2Fleet; @Mock private EC2Api ec2Api; @@ -98,14 +99,14 @@ public class FleetCloudTest { private AmazonEC2 amazonEC2; @Mock - private FleetNodeComputer idleComputer; + private EC2FleetNodeComputer idleComputer; @Mock - private FleetNodeComputer busyComputer; + private EC2FleetNodeComputer busyComputer; - private FleetCloud.ExecutorScaler noScaling; + private EC2FleetCloud.ExecutorScaler noScaling; - private FleetCloud.ExecutorScaler weightedScaling; + private EC2FleetCloud.ExecutorScaler weightedScaling; private int MiB_TO_GiB_MULTIPLIER = 1024; @@ -138,8 +139,8 @@ public void before() { Registry.setEc2Api(ec2Api); - PowerMockito.mockStatic(Fleets.class); - when(Fleets.get(anyString())).thenReturn(fleet); + PowerMockito.mockStatic(EC2Fleets.class); + when(EC2Fleets.get(anyString())).thenReturn(ec2Fleet); PowerMockito.mockStatic(FleetStateStats.class); PowerMockito.mockStatic(LabelFinder.class); @@ -150,8 +151,8 @@ public void before() { PowerMockito.when(idleComputer.isIdle()).thenReturn(true); PowerMockito.when(busyComputer.isIdle()).thenReturn(false); - noScaling = new FleetCloud.NoScaler(); - weightedScaling = new FleetCloud.WeightedScaler(); + noScaling = new EC2FleetCloud.NoScaler(); + weightedScaling = new EC2FleetCloud.WeightedScaler(); } @@ -162,7 +163,7 @@ public void after() { @Test public void canProvision_fleetIsNull(){ - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", null, "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -175,7 +176,7 @@ public void canProvision_fleetIsNull(){ @Test public void canProvision_restrictUsageLabelIsNull(){ - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, true, "-1", false, 0, 0, @@ -188,7 +189,7 @@ public void canProvision_restrictUsageLabelIsNull(){ @Test public void canProvision_LabelNotInLabelString(){ - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -201,7 +202,7 @@ public void canProvision_LabelNotInLabelString(){ @Test public void canProvision_LabelInLabelString(){ - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "label1 momo", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -221,11 +222,11 @@ public void provision_shouldProvisionNoneWhenMaxReached() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -247,11 +248,11 @@ public void provision_shouldProvisionNoneWhenMaxReachedAndNumExecutorsMoreOne() // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 8, 0, 3, true, false, "-1", false, 0, 0, @@ -273,11 +274,11 @@ public void provision_shouldProvisionNoneWhenMaxReachedAndNumExecutorsMoreOne1() // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 8, 0, 3, true, false, "-1", false, 0, 0, @@ -299,11 +300,11 @@ public void provision_shouldProvisionNoneWhenExceedMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 9, 0, 1, true, false, "-1", false, 0, 0, @@ -325,11 +326,11 @@ public void provision_shouldProvisionIfBelowMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -351,11 +352,11 @@ public void provision_shouldProvisionNoMoreMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -377,11 +378,11 @@ public void provision_shouldProvisionNoMoreMaxWhenMultipleCallBeforeUpdate() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -408,10 +409,10 @@ public void provision_shouldProvisionNoneIfNotYetUpdated() { when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); // Don't set the status - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(null); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, 0, @@ -431,10 +432,10 @@ public void scheduleToTerminate_shouldNotRemoveIfStatsNotUpdated() { when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); // Don't set the status - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(null); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, 0, @@ -452,11 +453,11 @@ public void scheduleToTerminate_notRemoveIfBelowMin() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, @@ -477,11 +478,11 @@ public void scheduleToTerminate_notRemoveIfEqualMin() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, @@ -502,12 +503,12 @@ public void scheduleToTerminate_notRemoveIfEqualMinSpare() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); when(jenkins.getComputers()).thenReturn(new Computer[0]); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 5, 1, 1, true, false, "-1", false, 0, 0, @@ -528,11 +529,11 @@ public void scheduleToTerminate_remove() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, @@ -554,11 +555,11 @@ public void scheduleToTerminate_upToZeroNodes() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, 0, @@ -585,11 +586,11 @@ public void scheduleToTerminate_removeNoMoreMinIfCalledMultipleBeforeUpdate() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, @@ -618,11 +619,11 @@ public void update_shouldDoNothingIfNoTerminationOrProvisionAndFleetIsEmpty() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, @@ -642,11 +643,11 @@ public void update_shouldIncreaseTargetCapacityWhenProvisioned() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -661,7 +662,7 @@ public void update_shouldIncreaseTargetCapacityWhenProvisioned() { fleetCloud.update(); // then - verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); + verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); } @Test @@ -671,10 +672,10 @@ public void update_shouldResetTerminateAndProvision() { final FleetStateStats currentState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(currentState); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -689,7 +690,7 @@ public void update_shouldResetTerminateAndProvision() { fleetCloud.update(); // then - verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(6), eq(0), eq(10)); + verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(6), eq(0), eq(10)); assertEquals(0, fleetCloud.getInstanceIdsToTerminate().size()); assertEquals(0, fleetCloud.getToAdd()); } @@ -699,11 +700,11 @@ public void update_shouldNotIncreaseMoreThenMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -720,7 +721,7 @@ public void update_shouldNotIncreaseMoreThenMax() { fleetCloud.update(); // then - verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(0), eq(0), eq(10)); + verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(0), eq(0), eq(10)); assertEquals(0, fleetCloud.getInstanceIdsToTerminate().size()); assertEquals(0, fleetCloud.getToAdd()); } @@ -730,11 +731,11 @@ public void update_shouldNotCountScheduledToTerminateWhenScaleUp() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -750,7 +751,7 @@ public void update_shouldNotCountScheduledToTerminateWhenScaleUp() { fleetCloud.update(); // then - verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(5), eq(0), eq(10)); + verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(5), eq(0), eq(10)); assertEquals(0, fleetCloud.getInstanceIdsToTerminate().size()); assertEquals(0, fleetCloud.getToAdd()); } @@ -760,11 +761,11 @@ public void update_shouldDecreaseTargetCapacityAndTerminateInstancesIfScheduled( // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 4, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -780,7 +781,7 @@ public void update_shouldDecreaseTargetCapacityAndTerminateInstancesIfScheduled( fleetCloud.update(); // then - verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); + verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); verify(ec2Api).terminateInstances(amazonEC2, new HashSet<>(Arrays.asList("i-1", "i-2"))); } @@ -799,13 +800,13 @@ public void update_shouldAddNodeIfAnyNewDescribed() throws IOException { when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, @@ -841,13 +842,13 @@ public void update_shouldTagNewNodesBeforeAdding() throws IOException { when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-0", "i-1")), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 2, 0, 1, false, false, "-1", false, @@ -877,13 +878,13 @@ public void update_shouldTagNewNodesBeforeAddingWithFleetName() throws IOExcepti when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("my-fleet", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("my-fleet", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, @@ -918,13 +919,13 @@ public void update_givenFailedTaggingShouldIgnoreExceptionAndAddNode() throws IO when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, @@ -947,7 +948,7 @@ public void update_shouldAddNodeIfAnyNewDescribed_restrictUsage() throws IOExcep // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); @@ -962,7 +963,7 @@ public void update_shouldAddNodeIfAnyNewDescribed_restrictUsage() throws IOExcep mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1000,14 +1001,14 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightProvidedButNotEnabled when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.singletonMap(instanceType, 1.1))); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1035,12 +1036,12 @@ public void update_givenManuallyUpdatedFleetShouldCorrectLocalTargetCapacityToKe final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-0", "i-1")), Collections.emptyMap()); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, @@ -1057,7 +1058,7 @@ public void update_givenManuallyUpdatedFleetShouldCorrectLocalTargetCapacityToKe // then // should reset list to empty - verify(fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); + verify(ec2Fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); Assert.assertEquals(0, fleetCloud.getPlannedNodesCache().size()); } @@ -1072,12 +1073,12 @@ public void update_shouldTrimPlannedNodesIfExceedTargetCapacity() throws IOExcep final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, @@ -1120,12 +1121,12 @@ public void update_shouldTrimPlannedNodesBasedOnUpdatedTargetCapacityIfProvision final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - final FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, @@ -1143,7 +1144,7 @@ public Object answer(InvocationOnMock invocation) { fleetCloud.provision(new Cloud.CloudState(null, 0), 1); return null; } - }).when(fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); + }).when(ec2Fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); // when fleetCloud.update(); @@ -1172,12 +1173,12 @@ public void update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd() throws IO final FleetStateStats initState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0,1, false, true, "-1", false, @@ -1196,7 +1197,7 @@ public void update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd() throws IO } /** - * See {@link FleetCloudTest#update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd()} + * See {@link EC2FleetCloudTest#update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd()} */ @Test public void update_shouldUpdateStateWithFleetTargetCapacityMinusToTerminate() throws IOException { @@ -1218,12 +1219,12 @@ public void update_shouldUpdateStateWithFleetTargetCapacityMinusToTerminate() th final FleetStateStats initState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap()); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10,0, 1, false, true, "-1", false, @@ -1253,12 +1254,12 @@ public void update_shouldTerminateIdleOrNullInstancesOnly() { put("i-2", new Instance().withPublicIpAddress("p-ip").withInstanceId("i-2")); put("i-3", new Instance().withPublicIpAddress("p-ip").withInstanceId("i-3")); }}); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-1", "i-2", "i-3")), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 2, 0, 1, false, false, "-1", false, @@ -1299,10 +1300,10 @@ public void update_shouldUpdateStateWithMinSpare() throws IOException { final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, minSpareSize, 1, false, true, "-1", false, @@ -1336,14 +1337,14 @@ public void update_shouldAddNodeWithScaledNumExecutors_whenWeightPresentAndEnabl when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 2.0))); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1378,14 +1379,14 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightPresentAndEnabledButF when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap("diff-t", 2.0))); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1420,14 +1421,14 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 1.44))); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1462,20 +1463,20 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 1.5))); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, 10, false, weightedScaling); - ArgumentCaptor nodeCaptor = ArgumentCaptor.forClass(FleetNode.class); + ArgumentCaptor nodeCaptor = ArgumentCaptor.forClass(EC2FleetNode.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when @@ -1504,15 +1505,15 @@ public void update_shouldAddNodeWithScaledToOneNumExecutors_whenWeightPresentBut when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.emptyMap())); - PowerMockito.doThrow(new UnsupportedOperationException("Test exception")).when(fleet) + PowerMockito.doThrow(new UnsupportedOperationException("Test exception")).when(ec2Fleet) .modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1550,14 +1551,14 @@ public void update_givenFailedModifyShouldNotUpdateToAddToDelete() throws IOExce when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, .1))); mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1596,7 +1597,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti FleetStateStats.State.modifying(""), Collections.singleton(instanceId), Collections.singletonMap(instanceType, .1)); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn(stats); + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn(stats); final FleetStateStats initialState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), @@ -1605,7 +1606,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti mockNodeCreatingPart(); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1620,7 +1621,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti // then Assert.assertSame(initialState, newStats); Assert.assertSame(initialState, fleetCloud.getStats()); - verify(fleet, never()).modify(any(String.class), any(String.class), any(String.class), any(String.class), anyInt(), anyInt(), anyInt()); + verify(ec2Fleet, never()).modify(any(String.class), any(String.class), any(String.class), any(String.class), anyInt(), anyInt(), anyInt()); verify(jenkins, never()).addNode(any(Node.class)); } @@ -1629,13 +1630,13 @@ public void update_scheduledFuturesExecutesAfterTimeout() throws IOException, In // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); final int timeout = 1; - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0,1, true, false, "-1", false, timeout, 0, @@ -1660,13 +1661,13 @@ public void update_scheduledFuturesIsCancelledAfterUpdate() throws IOException, // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); final int timeout = 1; - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0,1, true, false, "-1", false, timeout, 0, @@ -1689,11 +1690,11 @@ public void update_scheduledFuturesIsCancelledAfterUpdate() throws IOException, @Test public void update_shouldScaleUpToMinSize() { // given - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 1, 1, 0,1, false, true, "-1", false, @@ -1733,15 +1734,15 @@ public void update_whenScalingByNodeHardwareWithLessVCPUs_shouldScaleExecutorsBy when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud.NodeHardwareScaler nodeHardwareScaler = new FleetCloud.NodeHardwareScaler(1, 1); + EC2FleetCloud.NodeHardwareScaler nodeHardwareScaler = new EC2FleetCloud.NodeHardwareScaler(1, 1); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -1785,15 +1786,15 @@ public void update_whenScalingByNodeHardwareWithLessMemory_shouldScaleExecutorsB when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud.NodeHardwareScaler nodeHardwareScaler = new FleetCloud.NodeHardwareScaler(2, 2); + EC2FleetCloud.NodeHardwareScaler nodeHardwareScaler = new EC2FleetCloud.NodeHardwareScaler(2, 2); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -1837,15 +1838,15 @@ public void update_whenScalingByNodeHardwareWithNoVCPUs_shouldScaleExecutorsByMe when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud.NodeHardwareScaler nodeHardwareScaler = new FleetCloud.NodeHardwareScaler(0, 1); + EC2FleetCloud.NodeHardwareScaler nodeHardwareScaler = new EC2FleetCloud.NodeHardwareScaler(0, 1); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -1889,15 +1890,15 @@ public void update_whenScalingByNodeHardwareWithNoMemory_shouldScaleExecutorsByV when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud.NodeHardwareScaler nodeHardwareScaler = new FleetCloud.NodeHardwareScaler(2, 0); + EC2FleetCloud.NodeHardwareScaler nodeHardwareScaler = new EC2FleetCloud.NodeHardwareScaler(2, 0); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -1941,15 +1942,15 @@ public void update_whenScalingByNodeHardwareByMemoryWithLowMemory_shouldSetOneEx when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud.NodeHardwareScaler nodeHardwareScaler = new FleetCloud.NodeHardwareScaler(0, 4); + EC2FleetCloud.NodeHardwareScaler nodeHardwareScaler = new EC2FleetCloud.NodeHardwareScaler(0, 4); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -1993,15 +1994,15 @@ public void update_whenScalingByNodeHardwareByVCPUsWithLowVCPUCount_shouldSetOne when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud.NodeHardwareScaler nodeHardwareScaler = new FleetCloud.NodeHardwareScaler(5, 0); + EC2FleetCloud.NodeHardwareScaler nodeHardwareScaler = new EC2FleetCloud.NodeHardwareScaler(5, 0); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -2045,15 +2046,15 @@ public void update_whenScalingByNodeHardwareWithNoVCPUsAndNoMemory_shouldSetExec when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - FleetCloud.NodeHardwareScaler nodeHardwareScaler = new FleetCloud.NodeHardwareScaler(0, 0); + EC2FleetCloud.NodeHardwareScaler nodeHardwareScaler = new EC2FleetCloud.NodeHardwareScaler(0, 0); - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 3, true, false, "-1", false, 0, @@ -2073,7 +2074,7 @@ public void update_whenScalingByNodeHardwareWithNoVCPUsAndNoMemory_shouldSetExec @Test public void removeScheduledFutures_success() { // given - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -2094,7 +2095,7 @@ public void removeScheduledFutures_success() { @Test public void removeScheduledFutures_scheduledFutureIsEmpty() { // given - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -2113,7 +2114,7 @@ public void removeScheduledFutures_scheduledFutureIsEmpty() { @Test public void removeScheduledFutures_numToRemoveIsZero() { // given - FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -2136,7 +2137,7 @@ public void descriptorImpl_doFillRegionItems_returnStaticRegionsIfApiCallFailed( AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class); when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(amazonEC2Client); - ListBoxModel r = new FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); HashSet staticRegions = new HashSet<>(RegionInfo.getRegionNames()); staticRegions.addAll(RegionUtils.getRegions().stream().map(com.amazonaws.regions.Region::getName).collect(Collectors.toSet())); @@ -2150,7 +2151,7 @@ public void descriptorImpl_doTestConnection_NoMissingPermissions() throws Except when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(new ArrayList<>()); PowerMockito.whenNew(AwsPermissionChecker.class).withAnyArguments().thenReturn(awsPermissionChecker); - final FormValidation formValidation = new FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); Assert.assertTrue(formValidation.getMessage().contains("Success")); } @@ -2161,7 +2162,7 @@ public void descriptorImpl_doTestConnection_missingDescribeInstancePermission() when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(Collections.singletonList(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); PowerMockito.whenNew(AwsPermissionChecker.class).withAnyArguments().thenReturn(awsPermissionChecker); - final FormValidation formValidation = new FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); } @@ -2176,7 +2177,7 @@ public void descriptorImpl_doTestConnection_missingMultiplePermissions() throws when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(missingPermissions); PowerMockito.whenNew(AwsPermissionChecker.class).withAnyArguments().thenReturn(awsPermissionChecker); - final FormValidation formValidation = new FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.CreateTags.name())); @@ -2188,7 +2189,7 @@ public void descriptorImpl_doFillRegionItems_returnStaticRegionsAndDynamic() { when(ec2Api.connect(anyString(), nullable(String.class), nullable(String.class))).thenReturn(amazonEC2Client); when(amazonEC2Client.describeRegions()).thenReturn(new DescribeRegionsResult().withRegions(new Region().withRegionName("dynamic-region"))); - ListBoxModel r = new FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); HashSet staticRegions = new HashSet<>(RegionInfo.getRegionNames()); staticRegions.addAll(RegionUtils.getRegions().stream().map(com.amazonaws.regions.Region::getName).collect(Collectors.toSet())); @@ -2204,7 +2205,7 @@ public void descriptorImpl_doFillRegionItems_shouldDisplayRegionCodeWhenRegionDe when(ec2Api.connect(anyString(), nullable(String.class), nullable(String.class))).thenReturn(amazonEC2Client); when(amazonEC2Client.describeRegions()).thenReturn(new DescribeRegionsResult().withRegions(new Region().withRegionName(dynamicRegion))); - final ListBoxModel regionsListBoxModel = new FleetCloud.DescriptorImpl().doFillRegionItems(""); + final ListBoxModel regionsListBoxModel = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); boolean isPresent = false; for (final ListBoxModel.Option item : regionsListBoxModel) { @@ -2227,7 +2228,7 @@ public void descriptorImpl_doFillRegionItems_shouldDisplayVirginiaDescription() when(ec2Api.connect(anyString(), nullable(String.class), nullable(String.class))).thenReturn(amazonEC2Client); when(amazonEC2Client.describeRegions()).thenReturn(new DescribeRegionsResult().withRegions(new Region().withRegionName(regionName))); - final ListBoxModel regionsListBoxModel = new FleetCloud.DescriptorImpl().doFillRegionItems(""); + final ListBoxModel regionsListBoxModel = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); boolean isPresent = false; for (final ListBoxModel.Option item : regionsListBoxModel) { @@ -2247,9 +2248,9 @@ public void descriptorImpl_doFillRegionItems_returnConsistOrderBetweenCalls() { when(ec2Api.connect(anyString(), nullable(String.class), nullable(String.class))).thenReturn(amazonEC2Client); when(amazonEC2Client.describeRegions()).thenReturn(new DescribeRegionsResult().withRegions(new Region().withRegionName("dynamic-region"))); - ListBoxModel r1 = new FleetCloud.DescriptorImpl().doFillRegionItems(""); - ListBoxModel r2 = new FleetCloud.DescriptorImpl().doFillRegionItems(""); - ListBoxModel r3 = new FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r1 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r2 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r3 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); assertEquals(r1.toString(), r2.toString()); assertEquals(r2.toString(), r3.toString()); @@ -2257,19 +2258,19 @@ public void descriptorImpl_doFillRegionItems_returnConsistOrderBetweenCalls() { @Test public void descriptorImpl_doCheckFleetName_validName() { - FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet("FleetCloud"); + FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet("FleetCloud"); assertEquals(formValidation.kind, Kind.OK); } @Test public void descriptorImpl_doCheckFleetName_invalidName() { - FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet(null); + FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet(null); assertEquals(formValidation.kind, Kind.ERROR); } @Test - public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyFleet() { - ListBoxModel r = new FleetCloud.DescriptorImpl().doFillFleetItems( + public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyEC2Fleet() { + ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); assertEquals(1, r.size()); @@ -2277,12 +2278,12 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyFleet() { } @Test - public void descriptorImpl_doFillFleetItems_returnFleetsProvidedByAllFleets() { - final Fleet ec2SpotFleet = mock(SpotFleet.class); - final Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); - when(Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); + public void descriptorImpl_doFillFleetItems_returnFleetsProvidedByAllEC2Fleets() { + final EC2Fleet ec2SpotFleet = mock(EC2SpotFleet.class); + final EC2Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); + when(EC2Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); - ListBoxModel r = new FleetCloud.DescriptorImpl().doFillFleetItems( + ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); assertEquals(1, r.size()); @@ -2293,14 +2294,14 @@ public void descriptorImpl_doFillFleetItems_returnFleetsProvidedByAllFleets() { @Test public void descriptorImpl_doFillFleetItems_returnEmptyListIfAnyException() { - final Fleet ec2SpotFleet = mock(SpotFleet.class); + final EC2Fleet ec2SpotFleet = mock(EC2SpotFleet.class); doThrow(new RuntimeException("test")).when(ec2SpotFleet).describe( anyString(), anyString(), anyString(), any(ListBoxModel.class), anyString(), anyBoolean()); - final Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); - when(Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); + final EC2Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); + when(EC2Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); - ListBoxModel r = new FleetCloud.DescriptorImpl().doFillFleetItems( + ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); assertEquals(1, r.size()); @@ -2309,153 +2310,153 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfAnyException() { @Test public void descriptorImpl_doCheckFleet_default() { - FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet(""); + FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet(""); assertEquals(formValidation.kind, Kind.ERROR); } @Test public void descriptorImpl_doCheckFleet_nonDefault() { - FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet("ASG1"); + FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet("ASG1"); assertEquals(formValidation.kind, Kind.OK); } @Test public void getDisplayName_returnDisplayName() { - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 1, true, false, "-1", false , 0, 0, 10, false, noScaling); - assertEquals(fleetCloud.getDisplayName(), "CloudName"); + assertEquals(ec2FleetCloud.getDisplayName(), "CloudName"); } @Test public void getAwsCredentialsId_returnNull_whenNoCredentialsIdOrAwsCredentialsId() { - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "TestCloud", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 1, true, false, "-1", false, 0, 0, 10, false, noScaling); - Assert.assertNull(fleetCloud.getAwsCredentialsId()); + Assert.assertNull(ec2FleetCloud.getAwsCredentialsId()); } @Test public void getAwsCredentialsId_returnValue_whenCredentialsIdPresent() { - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "TestCloud", null, "Opa", null, null, null, null, null, null, false, false, null, 0, 1, 0, 1, true, false, "-1", false , 0, 0, 10, false, noScaling); - assertEquals("Opa", fleetCloud.getAwsCredentialsId()); + assertEquals("Opa", ec2FleetCloud.getAwsCredentialsId()); } @Test public void getAwsCredentialsId_returnValue_whenAwsCredentialsIdPresent() { - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "TestCloud", "Opa", null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 1, true, false, "-1", false , 0, 0, 10, false, noScaling); - assertEquals("Opa", fleetCloud.getAwsCredentialsId()); + assertEquals("Opa", ec2FleetCloud.getAwsCredentialsId()); } @Test public void getAwsCredentialsId_returnAwsCredentialsId_whenAwsCredentialsIdAndCredentialsIdPresent() { - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "TestCloud", "A", "B", null, null, null, null, null, null, false, false, null, 0, 1, 0, 1, true, false, "-1", false , 0, 0, 10, false, noScaling); - assertEquals("A", fleetCloud.getAwsCredentialsId()); + assertEquals("A", ec2FleetCloud.getAwsCredentialsId()); } // todo create test cases update failed to modify fleet @Test public void getCloudStatusInterval_returnCloudStatusInterval() { - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 1, true, false, "-1", false , 0, 0, 45, false, noScaling); - assertEquals(45, fleetCloud.getCloudStatusIntervalSec()); + assertEquals(45, ec2FleetCloud.getCloudStatusIntervalSec()); } @Test public void create_numExecutorsLessThenOneShouldUpgradedToOne() { - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 0, true, false, "-1", false , 0, 0, 45, false, noScaling); - assertEquals(1, fleetCloud.getNumExecutors()); + assertEquals(1, ec2FleetCloud.getNumExecutors()); } @Test public void hasUnlimitedUsesForNodes_shouldReturnTrueWhenUnlimited() { final int maxTotalUses = -1; - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 0, true, false, String.valueOf(maxTotalUses), false , 0, 0, 45, false, noScaling); - assertTrue(fleetCloud.hasUnlimitedUsesForNodes()); + assertTrue(ec2FleetCloud.hasUnlimitedUsesForNodes()); } @Test public void hasUnlimitedUsesForNodes_shouldReturnDefaultTrueForNull() { final String maxTotalUses = null; - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 0, true, false, maxTotalUses, false , 0, 0, 45, false, noScaling); - assertTrue(fleetCloud.hasUnlimitedUsesForNodes()); + assertTrue(ec2FleetCloud.hasUnlimitedUsesForNodes()); } @Test public void hasUnlimitedUsesForNodes_shouldReturnDefaultTrueForEmptyString() { final String maxTotalUses = ""; - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 0, true, false, maxTotalUses, false , 0, 0, 45, false, noScaling); - assertTrue(fleetCloud.hasUnlimitedUsesForNodes()); + assertTrue(ec2FleetCloud.hasUnlimitedUsesForNodes()); } @Test public void hasUnlimitedUsesForNodes_shouldReturnFalseWhenLimited() { final int maxTotalUses = 5; - FleetCloud fleetCloud = new FleetCloud( + EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, 0, true, false, String.valueOf(maxTotalUses), false , 0, 0, 45, false, noScaling); - assertFalse(fleetCloud.hasUnlimitedUsesForNodes()); + assertFalse(ec2FleetCloud.hasUnlimitedUsesForNodes()); } private void mockNodeCreatingPart() { diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithHistory.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithHistory.java similarity index 95% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithHistory.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithHistory.java index 81f4400e..00bc83e6 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithHistory.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithHistory.java @@ -8,11 +8,11 @@ import java.util.concurrent.CopyOnWriteArrayList; -public class FleetCloudWithHistory extends FleetCloud { +public class EC2FleetCloudWithHistory extends EC2FleetCloud { public CopyOnWriteArrayList provisionTimes = new CopyOnWriteArrayList<>(); - public FleetCloudWithHistory( + public EC2FleetCloudWithHistory( String name, String awsCredentialsId, String credentialsId, String region, String endpoint, String fleet, String labelString, String fsRoot, ComputerConnector computerConnector, boolean privateIpUsed, boolean alwaysReconnect, Integer idleMinutes, Integer minSize, Integer maxSize, Integer minSpareSize, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithMeter.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithMeter.java similarity index 95% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithMeter.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithMeter.java index a730ea26..7b0167d3 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithMeter.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithMeter.java @@ -7,13 +7,13 @@ import java.util.Collection; -public class FleetCloudWithMeter extends FleetCloud { +public class EC2FleetCloudWithMeter extends EC2FleetCloud { public final Meter updateMeter = new Meter("update"); public final Meter provisionMeter = new Meter("provision"); public final Meter removeMeter = new Meter("remove"); - public FleetCloudWithMeter( + public EC2FleetCloudWithMeter( String name, String awsCredentialsId, String credentialsId, String region, String endpoint, String fleet, String labelString, String fsRoot, ComputerConnector computerConnector, boolean privateIpUsed, boolean alwaysReconnect, Integer idleMinutes, Integer minSize, Integer maxSize, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudConfigurationAsCodeTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudConfigurationAsCodeTest.java similarity index 80% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudConfigurationAsCodeTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudConfigurationAsCodeTest.java index 2e8b1710..f554d147 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudConfigurationAsCodeTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudConfigurationAsCodeTest.java @@ -1,7 +1,7 @@ package com.amazon.jenkins.ec2fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import hudson.plugins.sshslaves.SSHConnector; import hudson.plugins.sshslaves.verifiers.NonVerifyingKeyVerificationStrategy; import io.jenkins.plugins.casc.ConfiguratorException; @@ -25,31 +25,31 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class FleetLabelCloudConfigurationAsCodeTest { +public class EC2FleetLabelCloudConfigurationAsCodeTest { @Rule public JenkinsRule jenkinsRule = new JenkinsConfiguredWithCodeRule(); @Before public void before() { - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); + final EC2Fleet fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(fleet); when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) .thenReturn(new FleetStateStats("", 2, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-1", "i-2")), Collections.emptyMap())); } @Test @ConfiguredWithCode( - value = "FleetLabelCloud/name-required-configuration-as-code.yml", + value = "EC2FleetLabelCloud/name-required-configuration-as-code.yml", expected = ConfiguratorException.class, message = "error configuring 'jenkins' with class io.jenkins.plugins.casc.core.JenkinsConfigurator configurator") public void configurationWithNullName_shouldFail() { } @Test - @ConfiguredWithCode("FleetLabelCloud/min-configuration-as-code.yml") + @ConfiguredWithCode("EC2FleetLabelCloud/min-configuration-as-code.yml") public void shouldCreateCloudFromMinConfiguration() { assertEquals(jenkinsRule.jenkins.clouds.size(), 1); - FleetLabelCloud cloud = (FleetLabelCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet-label"); + EC2FleetLabelCloud cloud = (EC2FleetLabelCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet-label"); assertEquals("ec2-fleet-label", cloud.name); assertNull(cloud.getRegion()); @@ -71,10 +71,10 @@ public void shouldCreateCloudFromMinConfiguration() { } @Test - @ConfiguredWithCode("FleetLabelCloud/max-configuration-as-code.yml") + @ConfiguredWithCode("EC2FleetLabelCloud/max-configuration-as-code.yml") public void shouldCreateCloudFromMaxConfiguration() { assertEquals(jenkinsRule.jenkins.clouds.size(), 1); - FleetLabelCloud cloud = (FleetLabelCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet-label"); + EC2FleetLabelCloud cloud = (EC2FleetLabelCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet-label"); assertEquals("ec2-fleet-label", cloud.name); assertEquals(cloud.getRegion(), "us-east-2"); @@ -100,13 +100,13 @@ public void shouldCreateCloudFromMaxConfiguration() { } @Test - @ConfiguredWithCode("FleetLabelCloud/empty-name-configuration-as-code.yml") + @ConfiguredWithCode("EC2FleetLabelCloud/empty-name-configuration-as-code.yml") public void configurationWithEmptyName_shouldUseDefault() { assertEquals(jenkinsRule.jenkins.clouds.size(), 3); - for (FleetLabelCloud cloud : jenkinsRule.jenkins.clouds.getAll(FleetLabelCloud.class)){ + for (EC2FleetLabelCloud cloud : jenkinsRule.jenkins.clouds.getAll(EC2FleetLabelCloud.class)){ - assertTrue(cloud.name.startsWith(FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); + assertTrue(cloud.name.startsWith(EC2FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); assertEquals(("FleetLabelCloud".length() + CloudNames.SUFFIX_LENGTH + 1), cloud.name.length()); } } diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudIntegrationTest.java similarity index 88% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudIntegrationTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudIntegrationTest.java index d290fea7..4f61a3c0 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudIntegrationTest.java @@ -17,7 +17,7 @@ import static org.mockito.ArgumentMatchers.any; -public class FleetLabelCloudIntegrationTest extends IntegrationTest { +public class EC2FleetLabelCloudIntegrationTest extends IntegrationTest { @BeforeClass public static void beforeClass() { @@ -26,10 +26,10 @@ public static void beforeClass() { @Test public void should_create_stack_and_provision_node_for_task_execution() throws Exception { - mockFleetApiToSpotFleet(InstanceStateName.Running); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); mockCloudFormationApi(); - FleetLabelCloud cloud = new FleetLabelCloud("FleetLabel", "credId", "region", + EC2FleetLabelCloud cloud = new EC2FleetLabelCloud("FleetLabel", "credId", "region", null, null, new LocalComputerConnector(j), false, false, 0, 0, 0, 1, false, false, 0, 0, @@ -55,10 +55,10 @@ public void run() { @Test public void should_delete_resources_if_label_unused() throws Exception { - mockFleetApiToSpotFleet(InstanceStateName.Running); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); final AmazonCloudFormation amazonCloudFormation = mockCloudFormationApi(); - FleetLabelCloud cloud = new FleetLabelCloud("FleetLabel", "credId", "region", + EC2FleetLabelCloud cloud = new EC2FleetLabelCloud("FleetLabel", "credId", "region", null, null, new LocalComputerConnector(j), false, false, 0, 0, 0, 1, false, false, 0, 0, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelParametersTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParametersTest.java similarity index 69% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelParametersTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParametersTest.java index e249e5c3..c49b3a0d 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelParametersTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParametersTest.java @@ -3,23 +3,23 @@ import org.junit.Assert; import org.junit.Test; -public class FleetLabelParametersTest { +public class EC2FleetLabelParametersTest { @Test public void parse_emptyForEmptyString() { - final FleetLabelParameters parameters = new FleetLabelParameters(""); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(""); Assert.assertNull(parameters.get("aa")); } @Test public void parse_emptyForNullString() { - final FleetLabelParameters parameters = new FleetLabelParameters(null); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(null); Assert.assertNull(parameters.get("aa")); } @Test public void parse_forString() { - final FleetLabelParameters parameters = new FleetLabelParameters("a=1,b=2"); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("a=1,b=2"); Assert.assertEquals("1", parameters.get("a")); Assert.assertEquals("2", parameters.get("b")); Assert.assertNull(parameters.get("c")); @@ -27,7 +27,7 @@ public void parse_forString() { @Test public void get_caseInsensitive() { - final FleetLabelParameters parameters = new FleetLabelParameters("aBc=1"); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("aBc=1"); Assert.assertEquals("1", parameters.get("aBc")); Assert.assertEquals("1", parameters.get("ABC")); Assert.assertEquals("1", parameters.get("abc")); @@ -38,7 +38,7 @@ public void get_caseInsensitive() { @Test public void parse_withFleetNamePrefixSkipItAndProvideParameters() { - final FleetLabelParameters parameters = new FleetLabelParameters("AA_a=1,b=2"); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("AA_a=1,b=2"); Assert.assertEquals("1", parameters.get("a")); Assert.assertEquals("2", parameters.get("b")); Assert.assertNull(parameters.get("c")); @@ -46,7 +46,7 @@ public void parse_withFleetNamePrefixSkipItAndProvideParameters() { @Test public void parse_withEmptyFleetNamePrefixSkipItAndProvideParameters() { - final FleetLabelParameters parameters = new FleetLabelParameters("_a=1,b=2"); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("_a=1,b=2"); Assert.assertEquals("1", parameters.get("a")); Assert.assertEquals("2", parameters.get("b")); Assert.assertNull(parameters.get("c")); @@ -54,20 +54,20 @@ public void parse_withEmptyFleetNamePrefixSkipItAndProvideParameters() { @Test public void parse_withEmptyFleetNamePrefixAndEmptyParametersReturnsEmpty() { - final FleetLabelParameters parameters = new FleetLabelParameters("_"); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("_"); Assert.assertNull(parameters.get("c")); } @Test public void parse_skipParameterWithoutValue() { - final FleetLabelParameters parameters = new FleetLabelParameters("withoutValue,b=2"); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("withoutValue,b=2"); Assert.assertEquals("2", parameters.get("b")); Assert.assertNull(parameters.get("withoutValue")); } @Test public void parse_skipParameterWithEmptyValue() { - final FleetLabelParameters parameters = new FleetLabelParameters("withoutValue=,b=2"); + final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("withoutValue=,b=2"); Assert.assertEquals("2", parameters.get("b")); Assert.assertNull(parameters.get("withoutValue")); } diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetNodeComputerTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java similarity index 87% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetNodeComputerTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java index 23bdded5..684aaafc 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetNodeComputerTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java @@ -17,10 +17,10 @@ @RunWith(PowerMockRunner.class) @PrepareForTest({Jenkins.class, Queue.class}) -public class FleetNodeComputerTest { +public class EC2FleetNodeComputerTest { @Mock - private FleetNode agent; + private EC2FleetNode agent; @Mock private Jenkins jenkins; @@ -43,7 +43,7 @@ public void getDisplayName_returns_node_display_name_for_default_maxTotalUses() when(agent.getDisplayName()).thenReturn("a n"); when(agent.getMaxTotalUses()).thenReturn(-1); - FleetNodeComputer computer = spy(new FleetNodeComputer(agent)); + EC2FleetNodeComputer computer = spy(new EC2FleetNodeComputer(agent)); doReturn(agent).when(computer).getNode(); Assert.assertEquals("a n", computer.getDisplayName()); @@ -54,7 +54,7 @@ public void getDisplayName_returns_builds_left_for_non_default_maxTotalUses() { when(agent.getDisplayName()).thenReturn("a n"); when(agent.getMaxTotalUses()).thenReturn(1); - FleetNodeComputer computer = spy(new FleetNodeComputer(agent)); + EC2FleetNodeComputer computer = spy(new EC2FleetNodeComputer(agent)); doReturn(agent).when(computer).getNode(); Assert.assertEquals("a n Builds left: 1 ", computer.getDisplayName()); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetOnlineCheckerTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java similarity index 82% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetOnlineCheckerTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java index e5ea3947..25f3691e 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetOnlineCheckerTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java @@ -25,13 +25,13 @@ @RunWith(PowerMockRunner.class) -@PrepareForTest({FleetOnlineChecker.class, FleetNode.class, Jenkins.class, Computer.class}) -public class FleetOnlineCheckerTest { +@PrepareForTest({EC2FleetOnlineChecker.class, EC2FleetNode.class, Jenkins.class, Computer.class}) +public class EC2FleetOnlineCheckerTest { private CompletableFuture future = new CompletableFuture<>(); @Mock - private FleetNode node; + private EC2FleetNode node; @Mock private Computer computer; @@ -41,7 +41,7 @@ public class FleetOnlineCheckerTest { @Before public void before() throws Exception { - when(node.getDisplayName()).thenReturn("MockFleetCloud i-1"); + when(node.getDisplayName()).thenReturn("MockEC2FleetCloud i-1"); PowerMockito.mockStatic(Jenkins.class); @@ -50,14 +50,14 @@ public void before() throws Exception { // final method PowerMockito.when(node.toComputer()).thenReturn(computer); - PowerMockito.whenNew(FleetNode.class).withAnyArguments().thenReturn(node); + PowerMockito.whenNew(EC2FleetNode.class).withAnyArguments().thenReturn(node); } @Test public void shouldStopImmediatelyIfFutureIsCancelled() throws InterruptedException, ExecutionException { future.cancel(true); - FleetOnlineChecker.start(node, future, 0, 0); + EC2FleetOnlineChecker.start(node, future, 0, 0); try { future.get(); Assert.fail(); @@ -68,7 +68,7 @@ public void shouldStopImmediatelyIfFutureIsCancelled() throws InterruptedExcepti @Test public void shouldStopAndFailFutureIfTimeout() { - FleetOnlineChecker.start(node, future, 100, 50); + EC2FleetOnlineChecker.start(node, future, 100, 50); try { future.get(); Assert.fail(); @@ -83,14 +83,14 @@ public void shouldStopAndFailFutureIfTimeout() { public void shouldFinishWithNodeWhenSuccessfulConnect() throws InterruptedException, ExecutionException { PowerMockito.when(computer.isOnline()).thenReturn(true); - FleetOnlineChecker.start(node, future, TimeUnit.MINUTES.toMillis(1), 0); + EC2FleetOnlineChecker.start(node, future, TimeUnit.MINUTES.toMillis(1), 0); Assert.assertSame(node, future.get()); } @Test public void shouldFinishWithNodeWhenTimeoutIsZeroWithoutCheck() throws InterruptedException, ExecutionException { - FleetOnlineChecker.start(node, future, 0, 0); + EC2FleetOnlineChecker.start(node, future, 0, 0); Assert.assertSame(node, future.get()); verifyNoInteractions(computer); @@ -98,7 +98,7 @@ public void shouldFinishWithNodeWhenTimeoutIsZeroWithoutCheck() throws Interrupt @Test public void shouldSuccessfullyFinishAndNoWaitIfIntervalIsZero() throws ExecutionException, InterruptedException { - FleetOnlineChecker.start(node, future, 10, 0); + EC2FleetOnlineChecker.start(node, future, 10, 0); Assert.assertSame(node, future.get()); verifyNoInteractions(computer); @@ -112,7 +112,7 @@ public void shouldWaitIfOffline() throws InterruptedException, ExecutionExceptio .thenReturn(false) .thenReturn(true); - FleetOnlineChecker.start(node, future, 100, 10); + EC2FleetOnlineChecker.start(node, future, 100, 10); Assert.assertSame(node, future.get()); verify(computer, times(3)).connect(false); @@ -127,7 +127,7 @@ public void shouldWaitIfComputerIsNull() throws InterruptedException, ExecutionE .thenReturn(null) .thenReturn(computer); - FleetOnlineChecker.start(node, future, 100, 10); + EC2FleetOnlineChecker.start(node, future, 100, 10); Assert.assertSame(node, future.get()); verify(computer, times(1)).isOnline(); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdaterTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java similarity index 68% rename from src/test/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdaterTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java index a5828a64..73980aaa 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdaterTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java @@ -23,20 +23,20 @@ import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) -@PrepareForTest(FleetStatusWidgetUpdater.class) -public class FleetStatusWidgetUpdaterTest { +@PrepareForTest(EC2FleetStatusWidgetUpdater.class) +public class EC2FleetStatusWidgetUpdaterTest { @Mock - private FleetCloud cloud1; + private EC2FleetCloud cloud1; @Mock - private FleetCloud cloud2; + private EC2FleetCloud cloud2; @Mock - private FleetStatusWidget widget1; + private EC2FleetStatusWidget widget1; @Mock - private FleetStatusWidget widget2; + private EC2FleetStatusWidget widget2; private List widgets = new ArrayList<>(); @@ -50,9 +50,9 @@ public class FleetStatusWidgetUpdaterTest { @Before public void before() throws Exception { - PowerMockito.mockStatic(FleetStatusWidgetUpdater.class); - PowerMockito.when(FleetStatusWidgetUpdater.class, "getClouds").thenReturn(clouds); - PowerMockito.when(FleetStatusWidgetUpdater.class, "getWidgets").thenReturn(widgets); + PowerMockito.mockStatic(EC2FleetStatusWidgetUpdater.class); + PowerMockito.when(EC2FleetStatusWidgetUpdater.class, "getClouds").thenReturn(clouds); + PowerMockito.when(EC2FleetStatusWidgetUpdater.class, "getWidgets").thenReturn(widgets); when(cloud1.getLabelString()).thenReturn("a"); when(cloud2.getLabelString()).thenReturn(""); @@ -63,13 +63,13 @@ public void before() throws Exception { when(cloud2.getStats()).thenReturn(stats2); } - private FleetStatusWidgetUpdater getMockFleetStatusWidgetUpdater() { - return Whitebox.newInstance(FleetStatusWidgetUpdater.class); + private EC2FleetStatusWidgetUpdater getMockEC2FleetStatusWidgetUpdater() { + return Whitebox.newInstance(EC2FleetStatusWidgetUpdater.class); } @Test public void shouldDoNothingIfNoCloudsAndWidgets() { - getMockFleetStatusWidgetUpdater().doRun(); + getMockEC2FleetStatusWidgetUpdater().doRun(); } @Test @@ -77,13 +77,13 @@ public void shouldDoNothingIfNoWidgets() { clouds.add(cloud1); clouds.add(cloud2); - getMockFleetStatusWidgetUpdater().doRun(); + getMockEC2FleetStatusWidgetUpdater().doRun(); verifyZeroInteractions(widget1, widget2); } @Test - public void shouldIgnoreNonFleetClouds() { + public void shouldIgnoreNonEC2FleetClouds() { clouds.add(cloud1); Cloud nonEc2FleetCloud = mock(Cloud.class); @@ -91,7 +91,7 @@ public void shouldIgnoreNonFleetClouds() { widgets.add(widget2); - getMockFleetStatusWidgetUpdater().doRun(); + getMockEC2FleetStatusWidgetUpdater().doRun(); verify(cloud1).getStats(); verifyZeroInteractions(nonEc2FleetCloud); @@ -104,11 +104,11 @@ public void shouldUpdateCloudCollectAllResultAndUpdateWidgets() { widgets.add(widget1); - getMockFleetStatusWidgetUpdater().doRun(); + getMockEC2FleetStatusWidgetUpdater().doRun(); verify(widget1).setStatusList(Arrays.asList( - new FleetStatusInfo(cloud1.getFleet(), stats1.getState().getDetailed(), cloud1.getLabelString(), stats1.getNumActive(), stats1.getNumDesired()), - new FleetStatusInfo(cloud2.getFleet(), stats2.getState().getDetailed(), cloud2.getLabelString(), stats2.getNumActive(), stats2.getNumDesired()) + new EC2FleetStatusInfo(cloud1.getFleet(), stats1.getState().getDetailed(), cloud1.getLabelString(), stats1.getNumActive(), stats1.getNumDesired()), + new EC2FleetStatusInfo(cloud2.getFleet(), stats2.getState().getDetailed(), cloud2.getLabelString(), stats2.getNumActive(), stats2.getNumDesired()) )); } @@ -122,7 +122,7 @@ public void shouldIgnoreNonEc2FleetWidgets() { widgets.add(widget1); - getMockFleetStatusWidgetUpdater().doRun(); + getMockEC2FleetStatusWidgetUpdater().doRun(); verify(widget1).setStatusList(any(List.class)); verifyZeroInteractions(nonEc2FleetWidget); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java index ce472743..9cf38a6c 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java @@ -1,11 +1,13 @@ package com.amazon.jenkins.ec2fleet; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.DescribeInstancesRequest; import com.amazonaws.services.ec2.model.DescribeInstancesResult; +import com.amazonaws.services.ec2.model.DescribeSpotFleetRequestsRequest; +import com.amazonaws.services.ec2.model.DescribeSpotFleetRequestsResult; import com.amazonaws.services.ec2.model.Instance; import com.amazonaws.services.ec2.model.InstanceState; import com.amazonaws.services.ec2.model.InstanceStateName; @@ -37,19 +39,19 @@ public class EC2RetentionStrategyIntegrationTest extends IntegrationTest { - private final FleetCloud.ExecutorScaler noScaling = new FleetCloud.NoScaler(); + private final EC2FleetCloud.ExecutorScaler noScaling = new EC2FleetCloud.NoScaler(); private AmazonEC2 amazonEC2; @Before public void before() { - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); final EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); amazonEC2 = mock(AmazonEC2.class); - when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) + when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) .thenReturn(new FleetStateStats("", 2, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-1", "i-2")), Collections.emptyMap())); when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); @@ -72,7 +74,7 @@ public void before() { @Test public void shouldTerminateNodeMarkedForDeletion() throws Exception { - final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 0, 0, 1, false, true, "-1", false, 0, 0, 999, false, noScaling); // Set initial jenkins nodes @@ -81,8 +83,8 @@ public void shouldTerminateNodeMarkedForDeletion() throws Exception { assertAtLeastOneNode(); - FleetNode node = (FleetNode) j.jenkins.getNode("i-1"); - FleetNodeComputer c = (FleetNodeComputer) node.toComputer(); + EC2FleetNode node = (EC2FleetNode) j.jenkins.getNode("i-1"); + EC2FleetNodeComputer c = (EC2FleetNodeComputer) node.toComputer(); c.doDoDelete(); // mark node for termination node.getRetentionStrategy().check(c); @@ -96,7 +98,7 @@ public void shouldTerminateNodeMarkedForDeletion() throws Exception { @Test public void shouldTerminateExcessCapacity() throws Exception { - final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 0, 0, 1, false, true, "-1", false, 0, 0, 999, false, noScaling); // Set initial jenkins nodes @@ -111,8 +113,8 @@ public void shouldTerminateExcessCapacity() throws Exception { Thread.sleep(1000 * 61); // Manually trigger the retention check because it's super flaky whether it actually gets triggered for (final Node node : j.jenkins.getNodes()) { - if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { - FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); + if (node instanceof EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { + EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -135,14 +137,14 @@ public void shouldNotTerminateExcessCapacityWhenNodeIsBusy() throws Exception { List rs = enqueTask(10, 90); triggerSuggestReviewNow(); - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 2, 2, 0, 1, false, true, "-1", false, 0, 0, 999, false, noScaling); j.jenkins.clouds.add(cloud); cloud.update(); assertAtLeastOneNode(); - cloud = new FleetCloud("TestCloud", "credId", null, "region", + cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 0, 0, 1, false, true, "-1", false, 0, 0, 99, false, noScaling); j.jenkins.clouds.clear(); @@ -154,8 +156,8 @@ public void shouldNotTerminateExcessCapacityWhenNodeIsBusy() throws Exception { Thread.sleep(1000 * 61); // Manually trigger the retention check because it's super flaky whether it actually gets triggered for (final Node node : j.jenkins.getNodes()) { - if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { - FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); + if (node instanceof EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { + EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -167,7 +169,7 @@ public void shouldNotTerminateExcessCapacityWhenNodeIsBusy() throws Exception { @Test public void shouldTerminateIdleNodesAfterIdleTimeout() throws Exception { - final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 2, 0, 1, false, true, "-1", false, 0, 0, 99, false, noScaling); j.jenkins.clouds.add(cloud); @@ -181,8 +183,8 @@ public void shouldTerminateIdleNodesAfterIdleTimeout() throws Exception { Thread.sleep(1000 * 61); // Manually trigger the retention check because it's super flaky whether it actually gets triggered for (final Node node : j.jenkins.getNodes()) { - if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { - FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); + if (node instanceof EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { + EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -198,7 +200,7 @@ public void shouldTerminateIdleNodesAfterIdleTimeout() throws Exception { @Test public void shouldNotTerminateBelowMinSize() throws Exception { - final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 2, 5, 0, 1, false, true, "-1", false, 0, 0, 30, false, noScaling); j.jenkins.clouds.add(cloud); @@ -210,8 +212,8 @@ public void shouldNotTerminateBelowMinSize() throws Exception { Thread.sleep(1000 * 61); // Manually trigger the retention check because it's super flaky whether it actually gets triggered for (final Node node : j.jenkins.getNodes()) { - if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { - FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); + if (node instanceof EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { + EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -222,7 +224,7 @@ public void shouldNotTerminateBelowMinSize() throws Exception { @Test public void shouldNotTerminateBelowMinSpareSize() throws Exception { - final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 5, 2, 1, false, true, "-1", false, 0, 0, 30, false, noScaling); j.jenkins.clouds.add(cloud); @@ -234,8 +236,8 @@ public void shouldNotTerminateBelowMinSpareSize() throws Exception { Thread.sleep(1000 * 61); // Manually trigger the retention check because it's super flaky whether it actually gets triggered for (final Node node : j.jenkins.getNodes()) { - if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { - FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); + if (node instanceof EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { + EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -251,7 +253,7 @@ public void shouldTerminateWhenMaxTotalUsesIsExhausted() throws Exception { final int maxTotalUses = 2; final int taskSleepTime = 1; - FleetCloud cloud = spy(new FleetCloud("testCloud", "credId", null, "region", + EC2FleetCloud cloud = spy(new EC2FleetCloud("testCloud", "credId", null, "region", null, "fId", label, null, new LocalComputerConnector(j), false, false, 0, 0, 10, 0, 1, false, true, String.valueOf(maxTotalUses), true, 0, 0, 10, false, noScaling)); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java index 947078d3..24e3b408 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java @@ -31,13 +31,13 @@ public class EC2RetentionStrategyTest { @Mock - private FleetCloud cloud; + private EC2FleetCloud cloud; @Mock - private FleetNodeComputer computer; + private EC2FleetNodeComputer computer; @Mock - private FleetNode node; + private EC2FleetNode node; @Mock private Queue.Task task; diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java index 061c78e8..2e4d450b 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java @@ -2,9 +2,9 @@ import com.amazon.jenkins.ec2fleet.aws.CloudFormationApi; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; -import com.amazon.jenkins.ec2fleet.fleet.SpotFleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2SpotFleet; import com.amazonaws.services.cloudformation.AmazonCloudFormation; import com.amazonaws.services.cloudformation.model.CreateStackRequest; import com.amazonaws.services.cloudformation.model.CreateStackResult; @@ -16,7 +16,22 @@ import com.amazonaws.services.cloudformation.model.Stack; import com.amazonaws.services.cloudformation.model.StackStatus; import com.amazonaws.services.ec2.AmazonEC2; -import com.amazonaws.services.ec2.model.*; +import com.amazonaws.services.ec2.model.ActiveInstance; +import com.amazonaws.services.ec2.model.DescribeInstancesRequest; +import com.amazonaws.services.ec2.model.DescribeInstancesResult; +import com.amazonaws.services.ec2.model.DescribeSpotFleetInstancesRequest; +import com.amazonaws.services.ec2.model.DescribeSpotFleetInstancesResult; +import com.amazonaws.services.ec2.model.DescribeSpotFleetRequestsRequest; +import com.amazonaws.services.ec2.model.DescribeSpotFleetRequestsResult; +import com.amazonaws.services.ec2.model.Instance; +import com.amazonaws.services.ec2.model.InstanceState; +import com.amazonaws.services.ec2.model.InstanceStateName; +import com.amazonaws.services.ec2.model.ModifySpotFleetRequestRequest; +import com.amazonaws.services.ec2.model.Reservation; +import com.amazonaws.services.ec2.model.SpotFleetRequestConfig; +import com.amazonaws.services.ec2.model.SpotFleetRequestConfigData; +import com.amazonaws.services.ec2.model.TerminateInstancesRequest; +import com.amazonaws.services.ec2.model.TerminateInstancesResult; import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.Functions; @@ -89,7 +104,7 @@ public void after() { // restore Registry.setEc2Api(new EC2Api()); Registry.setCloudFormationApi(new CloudFormationApi()); - Fleets.setGet(null); + EC2Fleets.setGet(null); } protected static void turnOffJenkinsTestTimout() { @@ -216,7 +231,7 @@ public void run() { }, TimeUnit.MINUTES.toMillis(3)); } - protected static void waitFirstStats(final FleetCloud cloud) { + protected static void waitFirstStats(final EC2FleetCloud cloud) { System.out.println("waiting first stats for cloud"); tryUntil(new Runnable() { @Override @@ -305,19 +320,19 @@ public T answer(InvocationOnMock invocation) throws Throwable { } - protected void mockFleetApiToSpotFleet(final InstanceStateName instanceStateName) { - mockFleetApiToSpotFleetWithDelay(instanceStateName, 0, 0); + protected void mockEc2FleetApiToEc2SpotFleet(final InstanceStateName instanceStateName) { + mockEc2FleetApiToEc2SpotFleetWithDelay(instanceStateName, 0, 0); } - protected void mockFleetApiToSpotFleet(final InstanceStateName instanceStateName, final int initialTargetCapacity) { - mockFleetApiToSpotFleetWithDelay(instanceStateName, initialTargetCapacity, 0); + protected void mockEc2FleetApiToEc2SpotFleet(final InstanceStateName instanceStateName, final int initialTargetCapacity) { + mockEc2FleetApiToEc2SpotFleetWithDelay(instanceStateName, initialTargetCapacity, 0); } - protected void mockFleetApiToSpotFleetWithDelay(final InstanceStateName instanceStateName, final long delayMillis) { - mockFleetApiToSpotFleetWithDelay(instanceStateName, 0, delayMillis); + protected void mockEc2FleetApiToEc2SpotFleetWithDelay(final InstanceStateName instanceStateName, final long delayMillis) { + mockEc2FleetApiToEc2SpotFleetWithDelay(instanceStateName, 0, delayMillis); } - protected void mockFleetApiToSpotFleetWithDelay(final InstanceStateName instanceStateName, final int initialTargetCapacity, final long delayMillis) { + protected void mockEc2FleetApiToEc2SpotFleetWithDelay(final InstanceStateName instanceStateName, final int initialTargetCapacity, final long delayMillis) { EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); @@ -355,7 +370,7 @@ public Object answer(InvocationOnMock invocationOnMock) { final AtomicInteger targetCapacity = new AtomicInteger(0); // force to use spot fleet - Fleets.setGet(new SpotFleet()); + EC2Fleets.setGet(new EC2SpotFleet()); when(amazonEC2.modifySpotFleetRequest(any(ModifySpotFleetRequestRequest.class))) .then(AnswerWithDelay.get(new Answer() { @@ -471,7 +486,7 @@ public Object answer(InvocationOnMock invocation) { return amazonCloudFormation; } - protected void mockFleetApi() { + protected void mockEc2FleetApi() { EC2Api ec2Api = mock(EC2Api.class); Registry.setEc2Api(ec2Api); @@ -488,8 +503,8 @@ public Object answer(InvocationOnMock invocationOnMock) { final AtomicInteger targetCapacity = new AtomicInteger(0); - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); doAnswer(new Answer() { @Override @@ -498,9 +513,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { targetCapacity.set(argument.getTargetCapacity()); return null; } - }).when(fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); + }).when(ec2Fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); - when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())).thenAnswer(new Answer() { + when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())).thenAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { final Set instanceIds = new HashSet<>(); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyPerformanceTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyPerformanceTest.java index 350f0876..7a6b1882 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyPerformanceTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyPerformanceTest.java @@ -1,6 +1,7 @@ package com.amazon.jenkins.ec2fleet; import com.amazonaws.services.ec2.model.InstanceStateName; +import hudson.model.FreeStyleBuild; import hudson.model.queue.QueueTaskFuture; import hudson.slaves.ComputerConnector; import hudson.slaves.NodeProvisioner; @@ -25,7 +26,7 @@ */ @Ignore public class NoDelayProvisionStrategyPerformanceTest extends IntegrationTest { - private final FleetCloud.ExecutorScaler noScaling = new FleetCloud.NoScaler(); + private final EC2FleetCloud.ExecutorScaler noScaling = new EC2FleetCloud.NoScaler(); @BeforeClass public static void beforeClass() { @@ -49,11 +50,11 @@ private void test(final boolean noDelay) throws IOException, InterruptedExceptio final int scheduleInterval = 15; final int batchSize = 9; - mockFleetApiToSpotFleetWithDelay(InstanceStateName.Running, 500); + mockEc2FleetApiToEc2SpotFleetWithDelay(InstanceStateName.Running, 500); final ComputerConnector computerConnector = new LocalComputerConnector(j); final String label = "momo"; - final FleetCloudWithHistory cloud = new FleetCloudWithHistory(null, "credId", null, "region", + final EC2FleetCloudWithHistory cloud = new EC2FleetCloudWithHistory(null, "credId", null, "region", null, "fId", label, null, computerConnector, false, false, 1, 0, maxWorkers, 0, 1, true, false, false, 0, 0, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java index 9fcfd26b..66c487c7 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java @@ -55,18 +55,18 @@ public void before() { @Test public void givenNoRequiredCapacity_shouldDoNotScale() { - final FleetCloud fleetCloud = mock(FleetCloud.class); - clouds.add(fleetCloud); + final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud); strategy.apply(state); - verify(fleetCloud, never()).canProvision(any(Cloud.CloudState.class)); + verify(ec2FleetCloud, never()).canProvision(any(Cloud.CloudState.class)); } @Test public void givenAvailableSameAsRequiredCapacity_shouldDoNotScale() { - final FleetCloud fleetCloud = mock(FleetCloud.class); - clouds.add(fleetCloud); + final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud); when(snapshot.getQueueLength()).thenReturn(10); when(snapshot.getAvailableExecutors()).thenReturn(10); @@ -74,7 +74,7 @@ public void givenAvailableSameAsRequiredCapacity_shouldDoNotScale() { NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED, strategy.apply(state)); - verify(fleetCloud, never()).canProvision(any(Cloud.CloudState.class)); + verify(ec2FleetCloud, never()).canProvision(any(Cloud.CloudState.class)); } @Test @@ -101,15 +101,15 @@ public void givenEC2CloudWithDisabledNoDelay_shouldDoNotScale() { when(snapshot.getQueueLength()).thenReturn(10); when(state.getLabel()).thenReturn(label); - final FleetCloud fleetCloud = mock(FleetCloud.class); - clouds.add(fleetCloud); - when(fleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud.isNoDelayProvision()).thenReturn(false); + final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud); + when(ec2FleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud.isNoDelayProvision()).thenReturn(false); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); - verify(fleetCloud, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(ec2FleetCloud, never()).provision(any(Cloud.CloudState.class), anyInt()); } @Test @@ -117,14 +117,14 @@ public void givenEC2CloudWhichCannotProvision_shouldDoNotScale() { when(snapshot.getQueueLength()).thenReturn(10); when(state.getLabel()).thenReturn(label); - final FleetCloud fleetCloud = mock(FleetCloud.class); - clouds.add(fleetCloud); - when(fleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(false); + final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud); + when(ec2FleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(false); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); - verify(fleetCloud, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(ec2FleetCloud, never()).provision(any(Cloud.CloudState.class), anyInt()); } @Test @@ -133,24 +133,24 @@ public void givenEC2CloudsWithEnabledNoDelayAndWithout_shouldDoScalingForOne() { when(state.getLabel()).thenReturn(label); when(state.getAdditionalPlannedCapacity()).thenReturn(0); - final FleetCloud fleetCloud1 = mock(FleetCloud.class); - clouds.add(fleetCloud1); - final FleetCloud fleetCloud2 = mock(FleetCloud.class); - clouds.add(fleetCloud2); - when(fleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud1.isNoDelayProvision()).thenReturn(true); - when(fleetCloud2.isNoDelayProvision()).thenReturn(false); + final EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud1); + final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud2); + when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true); + when(ec2FleetCloud2.isNoDelayProvision()).thenReturn(false); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); ArgumentCaptor cloudStateArgCaptor = ArgumentCaptor.forClass(Cloud.CloudState.class); - verify(fleetCloud1, times(1)).provision(cloudStateArgCaptor.capture(), eq(10)); + verify(ec2FleetCloud1, times(1)).provision(cloudStateArgCaptor.capture(), eq(10)); Assert.assertEquals(label, cloudStateArgCaptor.getValue().getLabel()); Assert.assertEquals(0, cloudStateArgCaptor.getValue().getAdditionalPlannedCapacity()); - verify(fleetCloud2, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(ec2FleetCloud2, never()).provision(any(Cloud.CloudState.class), anyInt()); } @Test @@ -158,15 +158,15 @@ public void givenEC2CloudsWhenOneCanCoverCapacity_shouldDoScalingForFirstOnly() when(snapshot.getQueueLength()).thenReturn(2); when(state.getLabel()).thenReturn(label); - final FleetCloud fleetCloud1 = mock(FleetCloud.class); - clouds.add(fleetCloud1); - final FleetCloud fleetCloud2 = mock(FleetCloud.class); - clouds.add(fleetCloud2); - when(fleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud1.isNoDelayProvision()).thenReturn(true); - when(fleetCloud2.isNoDelayProvision()).thenReturn(true); - when(fleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList( + final EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud1); + final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud2); + when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true); + when(ec2FleetCloud2.isNoDelayProvision()).thenReturn(true); + when(ec2FleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList( new NodeProvisioner.PlannedNode("", new CompletableFuture<>(), 1), new NodeProvisioner.PlannedNode("", new CompletableFuture<>(), 1) )); @@ -174,8 +174,8 @@ public void givenEC2CloudsWhenOneCanCoverCapacity_shouldDoScalingForFirstOnly() Assert.assertEquals( NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED, strategy.apply(state)); - verify(fleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(2)); - verify(fleetCloud2, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(2)); + verify(ec2FleetCloud2, never()).provision(any(Cloud.CloudState.class), anyInt()); } @Test @@ -183,15 +183,15 @@ public void givenEC2Clouds_shouldDoScalingAndReduceForNextOne() { when(snapshot.getQueueLength()).thenReturn(5); when(state.getLabel()).thenReturn(label); - final FleetCloud fleetCloud1 = mock(FleetCloud.class); - clouds.add(fleetCloud1); - final FleetCloud fleetCloud2 = mock(FleetCloud.class); - clouds.add(fleetCloud2); - when(fleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud1.isNoDelayProvision()).thenReturn(true); - when(fleetCloud2.isNoDelayProvision()).thenReturn(true); - when(fleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList( + final EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud1); + final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud2); + when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true); + when(ec2FleetCloud2.isNoDelayProvision()).thenReturn(true); + when(ec2FleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList( new NodeProvisioner.PlannedNode("", new CompletableFuture<>(), 1), new NodeProvisioner.PlannedNode("", new CompletableFuture<>(), 1) )); @@ -199,8 +199,8 @@ public void givenEC2Clouds_shouldDoScalingAndReduceForNextOne() { Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); - verify(fleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(5)); - verify(fleetCloud2, times(1)).provision(any(Cloud.CloudState.class), eq(3)); + verify(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(5)); + verify(ec2FleetCloud2, times(1)).provision(any(Cloud.CloudState.class), eq(3)); } @Test @@ -208,17 +208,17 @@ public void givenEC2Clouds_shouldReduceAsAmountOfExecutors() { when(snapshot.getQueueLength()).thenReturn(2); when(state.getLabel()).thenReturn(label); - final FleetCloud fleetCloud1 = mock(FleetCloud.class); - clouds.add(fleetCloud1); - when(fleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud1.isNoDelayProvision()).thenReturn(true); + final EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud1); + when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true); final NodeProvisioner.PlannedNode plannedNode = new NodeProvisioner.PlannedNode("", new CompletableFuture<>(), 2); - when(fleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode)); + when(ec2FleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode)); // then final NodeProvisioner.StrategyDecision decision = strategy.apply(state); // when Assert.assertEquals(NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED, decision); - verify(fleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(2)); + verify(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(2)); } @Test @@ -228,25 +228,25 @@ public void givenPlannedCapacity_shouldComputeExcessWorkloadCorrectly() { when(state.getPlannedCapacitySnapshot()).thenReturn(3); when(state.getLabel()).thenReturn(label); - final FleetCloud fleetCloud1 = mock(FleetCloud.class); - clouds.add(fleetCloud1); - when(fleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud1.isNoDelayProvision()).thenReturn(true); + final EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud1); + when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true); final NodeProvisioner.PlannedNode plannedNode1 = new NodeProvisioner.PlannedNode("fc1-0", new CompletableFuture<>(), 2); - when(fleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode1)); + when(ec2FleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode1)); - final FleetCloud fleetCloud2 = mock(FleetCloud.class); - clouds.add(fleetCloud2); - when(fleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(fleetCloud2.isNoDelayProvision()).thenReturn(true); + final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class); + clouds.add(ec2FleetCloud2); + when(ec2FleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(ec2FleetCloud2.isNoDelayProvision()).thenReturn(true); final NodeProvisioner.PlannedNode plannedNode2 = new NodeProvisioner.PlannedNode("fc2-0", new CompletableFuture<>(), 1); - when(fleetCloud2.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode2)); + when(ec2FleetCloud2.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode2)); final NodeProvisioner.StrategyDecision decision = strategy.apply(state); Assert.assertEquals(NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED, decision); - verify(fleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(3)); - verify(fleetCloud2, times(1)).provision(any(Cloud.CloudState.class), eq(1)); + verify(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(3)); + verify(ec2FleetCloud2, times(1)).provision(any(Cloud.CloudState.class), eq(1)); } } diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java index 9abd9606..25322507 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java @@ -1,8 +1,8 @@ package com.amazon.jenkins.ec2fleet; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.ActiveInstance; import com.amazonaws.services.ec2.model.DescribeInstancesRequest; @@ -49,7 +49,7 @@ public class ProvisionIntegrationTest extends IntegrationTest { - private final FleetCloud.ExecutorScaler noScaling = new FleetCloud.NoScaler(); + private final EC2FleetCloud.ExecutorScaler noScaling = new EC2FleetCloud.NoScaler(); @BeforeClass public static void beforeClass() { @@ -61,13 +61,13 @@ public void dont_provide_any_planned_if_empty_and_reached_max_capacity() throws ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); - when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); + when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 0, 0, 1, true, false, "-1", false, 0, 0, @@ -99,9 +99,9 @@ public void should_add_planned_if_capacity_required_but_not_described_yet() thro ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - mockFleetApi(); + mockEc2FleetApi(); - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -131,12 +131,12 @@ public void should_keep_planned_node_until_node_will_not_be_online_so_jenkins_wi ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); - when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); + when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud cloud = spy(new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = spy(new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 300, 15, @@ -144,7 +144,7 @@ public void should_keep_planned_node_until_node_will_not_be_online_so_jenkins_wi j.jenkins.clouds.add(cloud); - mockFleetApiToSpotFleet(InstanceStateName.Running); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); List rs = enqueTask(1); @@ -165,19 +165,19 @@ public void should_not_keep_planned_node_if_configured_so_jenkins_will_overprovi ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); - when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); + when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - final FleetCloud cloud = spy(new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud cloud = spy(new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, 10, false, noScaling)); j.jenkins.clouds.add(cloud); - mockFleetApiToSpotFleet(InstanceStateName.Running); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); enqueTask(1); @@ -192,13 +192,13 @@ public void run() { @Test public void should_not_allow_jenkins_to_provision_if_address_not_available() throws Exception { - mockFleetApiToSpotFleet(InstanceStateName.Running); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - FleetCloud cloud = spy(new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = spy(new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, @@ -254,19 +254,19 @@ public void should_not_convert_planned_to_node_if_state_is_not_running_and_check ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); - when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); + when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, 2, false, noScaling); j.jenkins.clouds.add(cloud); - mockFleetApiToSpotFleet(InstanceStateName.Pending); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Pending); final List rs = enqueTask(1); @@ -291,19 +291,19 @@ public void should_successfully_create_nodes() throws Exception { ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); - when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); + when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 2, 0, 1, true, false, "-1", false, 0, 0, 2, false, noScaling); j.jenkins.clouds.add(cloud); - mockFleetApiToSpotFleet(InstanceStateName.Running); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); final List rs = enqueTask(2); @@ -324,10 +324,10 @@ public void run() { @Test public void should_continue_update_after_termination() throws IOException { - mockFleetApiToSpotFleet(InstanceStateName.Running, 5); + mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running, 5); final ComputerConnector computerConnector = new LocalComputerConnector(j); - final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", + final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 1, 0, 5, 0, 1, true, false, "-1", false, 0, 0, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java index fb22746c..265efe89 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java @@ -20,7 +20,7 @@ @Ignore public class ProvisionPerformanceTest extends IntegrationTest { - private final FleetCloud.ExecutorScaler noScaling = new FleetCloud.NoScaler(); + private final EC2FleetCloud.ExecutorScaler noScaling = new EC2FleetCloud.NoScaler(); @BeforeClass public static void beforeClass() { @@ -38,10 +38,10 @@ public void spikeLoadWorkers20Tasks60() throws Exception { } private void test(int workers, int maxTasks) throws IOException, InterruptedException { - mockFleetApiToSpotFleetWithDelay(InstanceStateName.Running, 500); + mockEc2FleetApiToEc2SpotFleetWithDelay(InstanceStateName.Running, 500); final ComputerConnector computerConnector = new LocalComputerConnector(j); - final FleetCloudWithMeter cloud = new FleetCloudWithMeter(null, "credId", null, "region", + final EC2FleetCloudWithMeter cloud = new EC2FleetCloudWithMeter(null, "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 1, 0, workers, 0, 1, true, false, false, 0, 0, 2, false, noScaling); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java index 3c4b38b2..f4baeeb8 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java @@ -71,14 +71,14 @@ public static void beforeClass() { private List credentialLines; private String privateKeyName; private AWSCredentialsProvider awsCredentialsProvider; - private FleetCloud.ExecutorScaler noScaling; + private EC2FleetCloud.ExecutorScaler noScaling; @Before public void before() throws IOException { credentialLines = FileUtils.readLines(new File("credentials.txt")); privateKeyName = getPrivateKeyName(credentialLines); awsCredentialsProvider = getAwsCredentialsProvider(credentialLines); - noScaling = new FleetCloud.NoScaler(); + noScaling = new EC2FleetCloud.NoScaler(); } @Ignore("for manual run as you need to provide real AWS credentials") @@ -131,7 +131,7 @@ public void run() { final SSHConnector computerConnector = new SSHConnector( 22, sshCredentialId, null, null, null, null, null, null, null, new NonVerifyingKeyVerificationStrategy()); - final FleetCloud cloud = new FleetCloud( + final EC2FleetCloud cloud = new EC2FleetCloud( "TestCloud", credentialId, null, null, null, autoScalingGroupName, "momo", null, computerConnector, false, false, @@ -183,7 +183,7 @@ public void givenEc2SpotFleet_shouldScaleUpExecuteTaskAndScaleDown() throws Exce final SSHConnector computerConnector = new SSHConnector( 22, sshCredentialId, null, null, null, null, null, null, null, new NonVerifyingKeyVerificationStrategy()); - final FleetCloud cloud = new FleetCloud( + final EC2FleetCloud cloud = new EC2FleetCloud( "TestCloud", credentialId, null, null, null, requestSpotFleetResult.getSpotFleetRequestId(), "momo", null, computerConnector, false, false, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java index f5756267..e1bdb53f 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/UiIntegrationTest.java @@ -1,8 +1,8 @@ package com.amazon.jenkins.ec2fleet; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -import com.amazon.jenkins.ec2fleet.fleet.Fleet; -import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; +import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.gargoylesoftware.htmlunit.html.DomElement; @@ -54,17 +54,17 @@ public class UiIntegrationTest { @Rule public JenkinsRule j = new JenkinsRule(); - private final FleetCloud.ExecutorScaler noScaling = new FleetCloud.NoScaler(); + private final EC2FleetCloud.ExecutorScaler noScaling = new EC2FleetCloud.NoScaler(); @Before public void before() { - final Fleet fleet = mock(Fleet.class); - Fleets.setGet(fleet); + final EC2Fleet ec2Fleet = mock(EC2Fleet.class); + EC2Fleets.setGet(ec2Fleet); final EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); final AmazonEC2 amazonEC2 = mock(AmazonEC2.class); - when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) + when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) .thenReturn(new FleetStateStats("", 2, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-1", "i-2")), Collections.emptyMap())); when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); } @@ -78,14 +78,14 @@ public void shouldFindThePluginByShortName() { @Test public void shouldShowNodeConfigurationPage() throws Exception { final String nodeName = "node-name"; - FleetCloud cloud = new FleetCloud("test-cloud", null, null, null, null, null, + EC2FleetCloud cloud = new EC2FleetCloud("test-cloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); j.jenkins.clouds.add(cloud); - j.jenkins.addNode(new FleetNode(nodeName, "", "", 1, + j.jenkins.addNode(new EC2FleetNode(nodeName, "", "", 1, Node.Mode.EXCLUSIVE, "label", new ArrayList>(), cloud.name, j.createComputerLauncher(null), -1)); @@ -96,14 +96,14 @@ public void shouldShowNodeConfigurationPage() throws Exception { @Test public void shouldReplaceCloudForNodesAfterConfigurationSave() throws Exception { - FleetCloud cloud = new FleetCloud("test-cloud", null, null, null, null, "", + EC2FleetCloud cloud = new EC2FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); j.jenkins.clouds.add(cloud); - j.jenkins.addNode(new FleetNode("mock", "", "", 1, + j.jenkins.addNode(new EC2FleetNode("mock", "", "", 1, Node.Mode.EXCLUSIVE, "", new ArrayList>(), cloud.name, j.createComputerLauncher(null), -1)); @@ -117,12 +117,12 @@ public void shouldReplaceCloudForNodesAfterConfigurationSave() throws Exception final Cloud newCloud = j.jenkins.clouds.get(0); assertNotNull(newCloud); assertNotSame(cloud, newCloud); - assertSame(newCloud, ((FleetNode) j.jenkins.getNode("mock")).getCloud()); + assertSame(newCloud, ((EC2FleetNode) j.jenkins.getNode("mock")).getCloud()); } @Test public void shouldShowInConfigurationClouds() throws IOException, SAXException { - Cloud cloud = new FleetCloud("TestCloud", null, null, null, null, null, + Cloud cloud = new EC2FleetCloud("TestCloud", null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -136,14 +136,14 @@ public void shouldShowInConfigurationClouds() throws IOException, SAXException { @Test public void shouldShowMultipleClouds() throws IOException, SAXException { - Cloud cloud1 = new FleetCloud("a", null, null, null, null, + Cloud cloud1 = new EC2FleetCloud("a", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); j.jenkins.clouds.add(cloud1); - Cloud cloud2 = new FleetCloud("b", null, null, null, null, + Cloud cloud2 = new EC2FleetCloud("b", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -160,14 +160,14 @@ public void shouldShowMultipleClouds() throws IOException, SAXException { @Test public void shouldShowMultipleCloudsWithDefaultName() throws IOException, SAXException { - Cloud cloud1 = new FleetCloud("TestCloud1", null, null, null, null, + Cloud cloud1 = new EC2FleetCloud("TestCloud1", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); j.jenkins.clouds.add(cloud1); - Cloud cloud2 = new FleetCloud("TestCloud2", null, null, null, null, + Cloud cloud2 = new EC2FleetCloud("TestCloud2", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -184,14 +184,14 @@ public void shouldShowMultipleCloudsWithDefaultName() throws IOException, SAXExc @Test public void shouldUpdateProperCloudWhenMultiple() throws Exception { - FleetCloud cloud1 = new FleetCloud("TestCloud1", null, null, null, null, + EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud1", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); j.jenkins.clouds.add(cloud1); - FleetCloud cloud2 = new FleetCloud("TestCloud2", null, null, null, null, + EC2FleetCloud cloud2 = new EC2FleetCloud("TestCloud2", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -205,12 +205,12 @@ public void shouldUpdateProperCloudWhenMultiple() throws Exception { HtmlFormUtil.submit(form); - assertEquals("new-label", ((FleetCloud)j.jenkins.clouds.get(0)).getLabelString()); - assertEquals("label", ((FleetCloud)j.jenkins.clouds.get(1)).getLabelString()); } + assertEquals("new-label", ((EC2FleetCloud)j.jenkins.clouds.get(0)).getLabelString()); + assertEquals("label", ((EC2FleetCloud)j.jenkins.clouds.get(1)).getLabelString()); } @Test public void shouldContainRegionValueInRegionLabel() throws IOException, SAXException { - FleetCloud cloud1 = new FleetCloud("TestCloud", "uh", null, null, null, + EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud", "uh", null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -232,7 +232,7 @@ public void shouldContainRegionValueInRegionLabel() throws IOException, SAXExcep public void shouldHaveRegionCodeAndRegionDescriptionInRegionLabel() throws IOException, SAXException { final String regionName = "us-east-1"; final String displayName = "us-east-1 US East (N. Virginia)"; - FleetCloud cloud1 = new FleetCloud("TestCloud", "uh", null, null, null, + EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud", "uh", null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -260,14 +260,14 @@ public void shouldHaveRegionCodeAndRegionDescriptionInRegionLabel() throws IOExc // Note: multiple clouds with same name can be created via JCasC only. @Test public void shouldGetFirstWhenMultipleCloudWithSameName() { - FleetCloud cloud1 = new FleetCloud("TestCloud", null, null, null, null, + EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); j.jenkins.clouds.add(cloud1); - FleetCloud cloud2 = new FleetCloud("TestCloud", null, null, null, null, + EC2FleetCloud cloud2 = new EC2FleetCloud("TestCloud", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -279,14 +279,14 @@ public void shouldGetFirstWhenMultipleCloudWithSameName() { @Test public void shouldGetProperWhenMultipleWithDiffName() { - FleetCloud cloud1 = new FleetCloud("a", null, null, null, null, + EC2FleetCloud cloud1 = new EC2FleetCloud("a", null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling); j.jenkins.clouds.add(cloud1); - FleetCloud cloud2 = new FleetCloud("b", null, null, null, null, + EC2FleetCloud cloud2 = new EC2FleetCloud("b", null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -299,7 +299,7 @@ public void shouldGetProperWhenMultipleWithDiffName() { @Test public void verifyCloudNameReadOnlyAfterCloudCreated() throws Exception { - FleetCloud cloud = new FleetCloud("test-cloud", null, null, null, null, "", + EC2FleetCloud cloud = new EC2FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, @@ -314,13 +314,13 @@ public void verifyCloudNameReadOnlyAfterCloudCreated() throws Exception { @Test public void verifyExistingDuplicateCloudNamesEditable() throws Exception { - j.jenkins.clouds.add(new FleetCloud("test-cloud", null, null, null, null, "", + j.jenkins.clouds.add(new EC2FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, 10, false, noScaling)); - j.jenkins.clouds.add(new FleetCloud("test-cloud", null, null, null, null, "", + j.jenkins.clouds.add(new EC2FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2FleetTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2EC2FleetTest.java similarity index 90% rename from src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2FleetTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2EC2FleetTest.java index 0e99128a..37eabf8e 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2FleetTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2EC2FleetTest.java @@ -22,7 +22,7 @@ import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) -public class EC2FleetTest { +public class EC2EC2FleetTest { @Mock private AmazonEC2 ec2; @@ -58,7 +58,7 @@ public void getState_failIfNoFleet() { when(ec2.describeFleets(any(DescribeFleetsRequest.class))) .thenReturn(new DescribeFleetsResult()); - new EC2Fleet().getState("cred", "region", "", "f"); + new EC2EC2Fleet().getState("cred", "region", "", "f"); } @Test @@ -72,7 +72,7 @@ public void getState_returnFleetInfo() { new TargetCapacitySpecification() .withTotalTargetCapacity(12)))); - FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f-id"); + FleetStateStats stats = new EC2EC2Fleet().getState("cred", "region", "", "f-id"); Assert.assertEquals("f-id", stats.getFleetId()); Assert.assertEquals(FleetStateStats.State.active(), stats.getState()); @@ -81,7 +81,7 @@ public void getState_returnFleetInfo() { @Test public void getState_returnEmptyIfNoInstancesForFleet() { - FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2EC2Fleet().getState("cred", "region", "", "f"); Assert.assertEquals(Collections.emptySet(), stats.getInstances()); Assert.assertEquals(0, stats.getNumActive()); @@ -95,7 +95,7 @@ public void getState_returnAllDescribedInstancesForFleet() { new ActiveInstance().withInstanceId("i-1"), new ActiveInstance().withInstanceId("i-2"))); - FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2EC2Fleet().getState("cred", "region", "", "f"); Assert.assertEquals(new HashSet<>(Arrays.asList("i-1", "i-2")), stats.getInstances()); Assert.assertEquals(2, stats.getNumActive()); @@ -114,7 +114,7 @@ public void getState_returnAllPagesDescribedInstancesForFleet() { .thenReturn(new DescribeFleetInstancesResult() .withActiveInstances(new ActiveInstance().withInstanceId("i-2"))); - FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2EC2Fleet().getState("cred", "region", "", "f"); Assert.assertEquals(new HashSet<>(Arrays.asList("i-1", "i-2")), stats.getInstances()); Assert.assertEquals(2, stats.getNumActive()); @@ -126,7 +126,7 @@ public void getState_returnAllPagesDescribedInstancesForFleet() { @Test public void getState_returnEmptyInstanceTypeWeightsIfNoInformation() { - FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2EC2Fleet().getState("cred", "region", "", "f"); Assert.assertEquals(Collections.emptyMap(), stats.getInstanceTypeWeights()); } @@ -144,7 +144,7 @@ public void getState_returnInstanceTypeWeightsFromLaunchSpecification() { new FleetLaunchTemplateOverrides().withInstanceType("t1").withWeightedCapacity(0.1), new FleetLaunchTemplateOverrides().withInstanceType("t2").withWeightedCapacity(12.0))))); - FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2EC2Fleet().getState("cred", "region", "", "f"); Map expected = new HashMap<>(); expected.put("t1", 0.1); @@ -165,7 +165,7 @@ public void getState_returnInstanceTypeWeightsForLaunchSpecificationIfItHasIt() new FleetLaunchTemplateOverrides().withInstanceType("t1"), new FleetLaunchTemplateOverrides().withWeightedCapacity(12.0))))); - FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2EC2Fleet().getState("cred", "region", "", "f"); Assert.assertEquals(Collections.emptyMap(), stats.getInstanceTypeWeights()); } @@ -177,7 +177,7 @@ public void getStateBatch_withNoFleetIdsAndNoFleets_returnsAnEmptyMap() { Collection fleetIds = new ArrayList<>(); - Map fleetStateStatsMap = new EC2Fleet().getStateBatch("cred", "region", "", fleetIds); + Map fleetStateStatsMap = new EC2EC2Fleet().getStateBatch("cred", "region", "", fleetIds); Assert.assertTrue("FleetStateStats Map is expected to be empty when no Fleet Ids are given", fleetStateStatsMap.isEmpty()); } @@ -191,7 +191,7 @@ public void getStateBatch_withFleetIdsAndNoFleets_returnsMapWithNoInstances() { fleetIds.add("f1"); fleetIds.add("f2"); - Map fleetStateStatsMap = new EC2Fleet().getStateBatch("cred", "region", "", fleetIds); + Map fleetStateStatsMap = new EC2EC2Fleet().getStateBatch("cred", "region", "", fleetIds); Assert.assertTrue(fleetStateStatsMap.isEmpty()); } @@ -230,7 +230,7 @@ public void getBatchState_withFleetsAndActiveInstances_returnsDescribedInstances fleetIds.add("f1"); fleetIds.add("f2"); - Map statsMap = new EC2Fleet().getStateBatch("cred", "region", "", fleetIds); + Map statsMap = new EC2EC2Fleet().getStateBatch("cred", "region", "", fleetIds); Assert.assertEquals(new HashSet<>(Arrays.asList("i-1", "i-2")), statsMap.get("f1").getInstances()); Assert.assertEquals(new HashSet<>(Collections.singletonList("i-3")), statsMap.get("f2").getInstances()); @@ -264,7 +264,7 @@ public void getBatchState_withFleets_returnsDescribedFleetStats() { fleetIds.add("f1"); fleetIds.add("f2"); - Map statsMap = new EC2Fleet().getStateBatch("cred", "region", "", fleetIds); + Map statsMap = new EC2EC2Fleet().getStateBatch("cred", "region", "", fleetIds); Assert.assertTrue(statsMap.get("f1").getState().isActive()); Assert.assertTrue(statsMap.get("f2").getState().isModifying()); @@ -288,7 +288,7 @@ public void describe_whenAllFleetsEnabled_shouldIncludeAllFleetsInAllStates() { .withType(FleetType.Request))); // when ListBoxModel model = new ListBoxModel(); - new EC2Fleet().describe("cred", "region", "", model, "selected", true); + new EC2EC2Fleet().describe("cred", "region", "", model, "selected", true); // then Assert.assertEquals( "[EC2 Fleet - f1 (active) (maintain)=f1, EC2 Fleet - f2 (modifying) (request)=f2]", @@ -310,7 +310,7 @@ public void describe_whenAllFleetsDisabled_shouldSkipNonMaintain() { .withType(FleetType.Request))); // when ListBoxModel model = new ListBoxModel(); - new EC2Fleet().describe("cred", "region", "", model, "selected", false); + new EC2EC2Fleet().describe("cred", "region", "", model, "selected", false); // then Assert.assertEquals( "[EC2 Fleet - f1 (active) (maintain)=f1]", @@ -340,7 +340,7 @@ public void describe_whenAllFleetsDisabled_shouldSkipNonCancelledOrFailed() { .withType(FleetType.Maintain))); // when ListBoxModel model = new ListBoxModel(); - new EC2Fleet().describe("cred", "region", "", model, "selected", false); + new EC2EC2Fleet().describe("cred", "region", "", model, "selected", false); // then Assert.assertEquals( "[EC2 Fleet - f1 (active) (maintain)=f1]", @@ -366,7 +366,7 @@ public void describe_whenAllFleetsDisabled_shouldIncludeSubmittedModifiedActive( .withType(FleetType.Maintain))); // when ListBoxModel model = new ListBoxModel(); - new EC2Fleet().describe("cred", "region", "", model, "selected", false); + new EC2EC2Fleet().describe("cred", "region", "", model, "selected", false); // then Assert.assertEquals( "[EC2 Fleet - f1 (active) (maintain)=f1, EC2 Fleet - f2 (submitted) (maintain)=f2, EC2 Fleet - f3 (modifying) (maintain)=f3]", @@ -374,17 +374,17 @@ public void describe_whenAllFleetsDisabled_shouldIncludeSubmittedModifiedActive( } @Test - public void isECFleet_withFleetId_returnsTrue() { + public void isEC2EC2Fleet_withFleetId_returnsTrue() { String fleetId = "fleet-123456"; - boolean isECFleet = Fleets.isEC2Fleet(fleetId); + boolean isEC2EC2Fleet = EC2Fleets.isEC2EC2Fleet(fleetId); - Assert.assertTrue(isECFleet); + Assert.assertTrue(isEC2EC2Fleet); } @Test - public void isECFleet_withNonFleetId_returnsFalse() { + public void isEC2EC2Fleet_withNonFleetId_returnsFalse() { String fleetId = "sfr-123456"; - boolean isECFleet = Fleets.isEC2Fleet(fleetId); + boolean isEC2EC2Fleet = EC2Fleets.isEC2EC2Fleet(fleetId); - Assert.assertFalse(isECFleet); + Assert.assertFalse(isEC2EC2Fleet); } } \ No newline at end of file diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleetTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleetTest.java similarity index 92% rename from src/test/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleetTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleetTest.java index 14c6b189..1451e262 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleetTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleetTest.java @@ -35,7 +35,7 @@ import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) -public class SpotFleetTest { +public class EC2SpotFleetTest { @Mock private AmazonEC2 ec2; @@ -71,7 +71,7 @@ public void getState_failIfNoFleet() { when(ec2.describeSpotFleetRequests(any(DescribeSpotFleetRequestsRequest.class))) .thenReturn(new DescribeSpotFleetRequestsResult()); - new SpotFleet().getState("cred", "region", "", "f"); + new EC2SpotFleet().getState("cred", "region", "", "f"); } @Test @@ -85,7 +85,7 @@ public void getState_returnFleetInfo() { new SpotFleetRequestConfigData() .withTargetCapacity(12)))); - FleetStateStats stats = new SpotFleet().getState("cred", "region", "", "f-id"); + FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f-id"); Assert.assertEquals("f-id", stats.getFleetId()); Assert.assertEquals(FleetStateStats.State.active(), stats.getState()); @@ -94,7 +94,7 @@ public void getState_returnFleetInfo() { @Test public void getState_returnEmptyIfNoInstancesForFleet() { - FleetStateStats stats = new SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f"); Assert.assertEquals(Collections.emptySet(), stats.getInstances()); Assert.assertEquals(0, stats.getNumActive()); @@ -108,7 +108,7 @@ public void getState_returnAllDescribedInstancesForFleet() { new ActiveInstance().withInstanceId("i-1"), new ActiveInstance().withInstanceId("i-2"))); - FleetStateStats stats = new SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f"); Assert.assertEquals(new HashSet<>(Arrays.asList("i-1", "i-2")), stats.getInstances()); Assert.assertEquals(2, stats.getNumActive()); @@ -125,7 +125,7 @@ public void getState_returnAllPagesDescribedInstancesForFleet() { .thenReturn(new DescribeSpotFleetInstancesResult() .withActiveInstances(new ActiveInstance().withInstanceId("i-2"))); - FleetStateStats stats = new SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f"); Assert.assertEquals(new HashSet<>(Arrays.asList("i-1", "i-2")), stats.getInstances()); Assert.assertEquals(2, stats.getNumActive()); @@ -137,7 +137,7 @@ public void getState_returnAllPagesDescribedInstancesForFleet() { @Test public void getState_returnEmptyInstanceTypeWeightsIfNoInformation() { - FleetStateStats stats = new SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f"); Assert.assertEquals(Collections.emptyMap(), stats.getInstanceTypeWeights()); } @@ -154,7 +154,7 @@ public void getState_returnInstanceTypeWeightsFromLaunchSpecification() { new SpotFleetLaunchSpecification().withInstanceType("t1").withWeightedCapacity(0.1), new SpotFleetLaunchSpecification().withInstanceType("t2").withWeightedCapacity(12.0))))); - FleetStateStats stats = new SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f"); Map expected = new HashMap<>(); expected.put("t1", 0.1); @@ -174,7 +174,7 @@ public void getState_returnInstanceTypeWeightsForLaunchSpecificationIfItHasIt() new SpotFleetLaunchSpecification().withInstanceType("t1"), new SpotFleetLaunchSpecification().withWeightedCapacity(12.0))))); - FleetStateStats stats = new SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f"); Assert.assertEquals(Collections.emptyMap(), stats.getInstanceTypeWeights()); } @@ -197,7 +197,7 @@ public void describe_whenAllFleetsEnabled_shouldIncludeAllFleetsInAllStates() { )); // when ListBoxModel model = new ListBoxModel(); - new SpotFleet().describe("cred", "region", "", model, "selected", true); + new EC2SpotFleet().describe("cred", "region", "", model, "selected", true); // then Assert.assertEquals( "[EC2 Spot Fleet - f1 (active) (maintain)=f1, EC2 Spot Fleet - f2 (modifying) (request)=f2]", @@ -222,7 +222,7 @@ public void describe_whenAllFleetsDisabled_shouldSkipNonMaintain() { )); // when ListBoxModel model = new ListBoxModel(); - new SpotFleet().describe("cred", "region", "", model, "selected", false); + new EC2SpotFleet().describe("cred", "region", "", model, "selected", false); // then Assert.assertEquals( "[EC2 Spot Fleet - f1 (active) (maintain)=f1]", @@ -257,7 +257,7 @@ public void describe_whenAllFleetsDisabled_shouldSkipNonCancelledOrFailed() { )); // when ListBoxModel model = new ListBoxModel(); - new SpotFleet().describe("cred", "region", "", model, "selected", false); + new EC2SpotFleet().describe("cred", "region", "", model, "selected", false); // then Assert.assertEquals( "[EC2 Spot Fleet - f1 (active) (maintain)=f1]", @@ -287,7 +287,7 @@ public void describe_whenAllFleetsDisabled_shouldIncludeSubmittedModifiedActive( )); // when ListBoxModel model = new ListBoxModel(); - new SpotFleet().describe("cred", "region", "", model, "selected", false); + new EC2SpotFleet().describe("cred", "region", "", model, "selected", false); // then Assert.assertEquals( "[EC2 Spot Fleet - f1 (active) (maintain)=f1, EC2 Spot Fleet - f2 (submitted) (maintain)=f2, EC2 Spot Fleet - f3 (modifying) (maintain)=f3]", diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/empty-name-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/empty-name-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/empty-name-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/empty-name-configuration-as-code.yml diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/max-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/max-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/max-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/max-configuration-as-code.yml diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/min-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/min-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/min-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/min-configuration-as-code.yml diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/name-required-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/name-required-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/name-required-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/name-required-configuration-as-code.yml diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/empty-name-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/empty-name-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/empty-name-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/empty-name-configuration-as-code.yml diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/max-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/max-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/max-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/max-configuration-as-code.yml diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/min-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/min-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/min-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/min-configuration-as-code.yml diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/name-required-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/name-required-configuration-as-code.yml similarity index 100% rename from src/test/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/name-required-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/name-required-configuration-as-code.yml