From 9aaaac176b1b76888809ff18ec9a17449ec5353d Mon Sep 17 00:00:00 2001 From: Gavin Burris <66969321+GavinBurris42@users.noreply.github.com> Date: Thu, 2 Nov 2023 01:38:12 -0500 Subject: [PATCH] Add support for fleets created through the CreateFleet API (#410) * Added support for the CreateFleet API * Fixed EC2CreateFleet usage of launch template overrides for retreiving instance type and weight capacity * Rename all occurances of EC2Fleet to Fleet, and rename CreateFleet to EC2Fleet * Renaming instances of 'EC2Fleet' to 'Fleet' * Add permision checks and add missing permissions for EC2Fleets, fleets created by the CreateFleet API --------- Co-authored-by: Prathibha Datta Kumar --- README.md | 4 +- docs/CONFIGURATION-AS-CODE.md | 16 +- pom.xml | 5 + ...leetCloud.java => AbstractFleetCloud.java} | 4 +- .../amazon/jenkins/ec2fleet/CloudNames.java | 3 +- .../amazon/jenkins/ec2fleet/CloudNanny.java | 10 +- .../ec2fleet/EC2RetentionStrategy.java | 56 +-- ...=> FleetAutoResubmitComputerLauncher.java} | 18 +- .../{EC2FleetCloud.java => FleetCloud.java} | 119 +++--- ...etLabelCloud.java => FleetLabelCloud.java} | 75 ++-- ...ameters.java => FleetLabelParameters.java} | 4 +- ...belUpdater.java => FleetLabelUpdater.java} | 8 +- .../{EC2FleetNode.java => FleetNode.java} | 16 +- ...deComputer.java => FleetNodeComputer.java} | 24 +- ...neChecker.java => FleetOnlineChecker.java} | 12 +- .../jenkins/ec2fleet/FleetStateStats.java | 12 +- ...etStatusInfo.java => FleetStatusInfo.java} | 10 +- ...atusWidget.java => FleetStatusWidget.java} | 10 +- ...ter.java => FleetStatusWidgetUpdater.java} | 16 +- .../ec2fleet/NoDelayProvisionStrategy.java | 6 +- .../ec2fleet/aws/AwsPermissionChecker.java | 61 ++- .../ec2fleet/aws/CloudFormationApi.java | 4 +- .../ec2fleet/fleet/AutoScalingGroupFleet.java | 2 +- .../jenkins/ec2fleet/fleet/EC2Fleet.java | 173 +++++++- .../amazon/jenkins/ec2fleet/fleet/Fleet.java | 35 ++ .../fleet/{EC2Fleets.java => Fleets.java} | 32 +- .../{EC2SpotFleet.java => SpotFleet.java} | 2 +- .../config.jelly | 0 .../help-cloudStatusIntervalSec.html | 0 .../help-disableTaskResubmit.html | 0 .../help-endpoint.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 | 16 +- .../jenkins/ec2fleet/CloudNamesTest.java | 30 +- .../jenkins/ec2fleet/CloudNannyTest.java | 8 +- .../EC2RetentionStrategyIntegrationTest.java | 52 ++- .../ec2fleet/EC2RetentionStrategyTest.java | 6 +- ...leetAutoResubmitComputerLauncherTest.java} | 24 +- ...=> FleetCloudConfigurationAsCodeTest.java} | 29 +- ...leetCloudTest.java => FleetCloudTest.java} | 307 +++++++------- ...istory.java => FleetCloudWithHistory.java} | 4 +- ...ithMeter.java => FleetCloudWithMeter.java} | 4 +- ...va => FleetLabelCloudIntegrationTest.java} | 10 +- ...est.java => FleetLabelParametersTest.java} | 20 +- ...erTest.java => FleetNodeComputerTest.java} | 8 +- ...rTest.java => FleetOnlineCheckerTest.java} | 24 +- ...java => FleetStatusWidgetUpdaterTest.java} | 38 +- .../jenkins/ec2fleet/IntegrationTest.java | 55 +-- ...DelayProvisionStrategyPerformanceTest.java | 5 +- .../NoDelayProvisionStrategyTest.java | 130 +++--- .../ec2fleet/ProvisionIntegrationTest.java | 64 +-- .../ec2fleet/ProvisionPerformanceTest.java | 4 +- .../com/amazon/jenkins/ec2fleet/RealTest.java | 4 +- .../jenkins/ec2fleet/UiIntegrationTest.java | 56 +-- .../jenkins/ec2fleet/fleet/EC2FleetTest.java | 390 ++++++++++++++++++ ...2SpotFleetTest.java => SpotFleetTest.java} | 26 +- .../empty-name-configuration-as-code.yml | 6 +- .../max-configuration-as-code.yml | 2 +- .../min-configuration-as-code.yml | 2 +- .../name-required-configuration-as-code.yml | 2 +- 72 files changed, 1324 insertions(+), 743 deletions(-) rename src/main/java/com/amazon/jenkins/ec2fleet/{AbstractEC2FleetCloud.java => AbstractFleetCloud.java} (79%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetAutoResubmitComputerLauncher.java => FleetAutoResubmitComputerLauncher.java} (87%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetCloud.java => FleetCloud.java} (91%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetLabelCloud.java => FleetLabelCloud.java} (93%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetLabelParameters.java => FleetLabelParameters.java} (92%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetLabelUpdater.java => FleetLabelUpdater.java} (75%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetNode.java => FleetNode.java} (74%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetNodeComputer.java => FleetNodeComputer.java} (75%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetOnlineChecker.java => FleetOnlineChecker.java} (92%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetStatusInfo.java => FleetStatusInfo.java} (82%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetStatusWidget.java => FleetStatusWidget.java} (57%) rename src/main/java/com/amazon/jenkins/ec2fleet/{EC2FleetStatusWidgetUpdater.java => FleetStatusWidgetUpdater.java} (79%) create mode 100644 src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleet.java rename src/main/java/com/amazon/jenkins/ec2fleet/fleet/{EC2Fleets.java => Fleets.java} (51%) rename src/main/java/com/amazon/jenkins/ec2fleet/fleet/{EC2SpotFleet.java => SpotFleet.java} (99%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/config.jelly (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-cloudStatusIntervalSec.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-disableTaskResubmit.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-endpoint.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-fleet.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-idleMinutes.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-initOnlineTimeoutSec.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-maxTotalUses.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-minSpareSize.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-name.html (68%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-noDelayProvision.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-numExecutors.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-restrictUsage.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/help-scaleExecutorsByWeight.html (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetLabelCloud => FleetLabelCloud}/config.jelly (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetNode => FleetNode}/configure-entries.jelly (100%) rename src/main/resources/com/amazon/jenkins/ec2fleet/{EC2FleetStatusWidget => FleetStatusWidget}/index.jelly (93%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetAutoResubmitComputerLauncherTest.java => FleetAutoResubmitComputerLauncherTest.java} (89%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetCloudConfigurationAsCodeTest.java => FleetCloudConfigurationAsCodeTest.java} (80%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetCloudTest.java => FleetCloudTest.java} (85%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetCloudWithHistory.java => FleetCloudWithHistory.java} (95%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetCloudWithMeter.java => FleetCloudWithMeter.java} (95%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetLabelCloudIntegrationTest.java => FleetLabelCloudIntegrationTest.java} (88%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetLabelParametersTest.java => FleetLabelParametersTest.java} (69%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetNodeComputerTest.java => FleetNodeComputerTest.java} (87%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetOnlineCheckerTest.java => FleetOnlineCheckerTest.java} (82%) rename src/test/java/com/amazon/jenkins/ec2fleet/{EC2FleetStatusWidgetUpdaterTest.java => FleetStatusWidgetUpdaterTest.java} (68%) create mode 100644 src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2FleetTest.java rename src/test/java/com/amazon/jenkins/ec2fleet/fleet/{EC2SpotFleetTest.java => SpotFleetTest.java} (92%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/empty-name-configuration-as-code.yml (58%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/max-configuration-as-code.yml (98%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/min-configuration-as-code.yml (72%) rename src/test/resources/com/amazon/jenkins/ec2fleet/{EC2FleetCloud => FleetCloud}/name-required-configuration-as-code.yml (93%) diff --git a/README.md b/README.md index a2c949d0..53771902 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,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.EC2FleetCloud +import com.amazon.jenkins.ec2fleet.FleetCloud import jenkins.model.Jenkins // just modify this config other code just logic @@ -247,7 +247,7 @@ BasicSSHUserPrivateKey instanceCredentials = new BasicSSHUserPrivateKey( ) // 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/EC2FleetCloud.java -EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( +FleetCloud fleetCloud = new FleetCloud( "", // fleetCloudName null, awsCredentials.id, diff --git a/docs/CONFIGURATION-AS-CODE.md b/docs/CONFIGURATION-AS-CODE.md index fdc2c501..abe69d34 100644 --- a/docs/CONFIGURATION-AS-CODE.md +++ b/docs/CONFIGURATION-AS-CODE.md @@ -4,9 +4,9 @@ ## Properties -### EC2FleetCloud +### FleetCloud -[Definition](https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java#L156-L179) +[Definition](https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java#L156-L179) | Property | Type | Required | Description | |----------------------------|---------|------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------| @@ -35,20 +35,20 @@ | cloudStatusIntervalSec | int | no, default ```10``` || | noDelayProvision | boolean | no, default ```false``` || -## EC2FleetLabelCloud +## FleetLabelCloud 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/EC2FleetLabelCloud.java#L123-L145) +[Definition](https://github.com/jenkinsci/ec2-fleet-plugin/blob/master/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.java#L123-L145) ## Examples -### EC2FleetCloud (min set of properties) +### FleetCloud (min set of properties) ```yaml jenkins: clouds: - - ec2Fleet: + - eC2Fleet: name: ec2-fleet computerConnector: sshConnector: @@ -61,12 +61,12 @@ jenkins: maxSize: 10 ``` -### EC2FleetCloud (All properties) +### FleetCloud (All properties) ```yaml jenkins: clouds: - - ec2Fleet: + - eC2Fleet: name: ec2-fleet awsCredentialsId: xx computerConnector: diff --git a/pom.xml b/pom.xml index d5d5fd96..6859d78d 100644 --- a/pom.xml +++ b/pom.xml @@ -57,6 +57,11 @@ Steve Nay stevnay@amazon.com + + GavinBurris42 + Gavin Burris + ggburris@amazon.com + diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/AbstractEC2FleetCloud.java b/src/main/java/com/amazon/jenkins/ec2fleet/AbstractFleetCloud.java similarity index 79% rename from src/main/java/com/amazon/jenkins/ec2fleet/AbstractEC2FleetCloud.java rename to src/main/java/com/amazon/jenkins/ec2fleet/AbstractFleetCloud.java index 7f132c22..5c913ea8 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/AbstractEC2FleetCloud.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/AbstractFleetCloud.java @@ -2,9 +2,9 @@ import hudson.slaves.Cloud; -public abstract class AbstractEC2FleetCloud extends Cloud { +public abstract class AbstractFleetCloud extends Cloud { - protected AbstractEC2FleetCloud(String name) { + protected AbstractFleetCloud(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 307f3d52..79f4ebf9 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/CloudNames.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/CloudNames.java @@ -1,6 +1,5 @@ package com.amazon.jenkins.ec2fleet; -import hudson.slaves.Cloud; import jenkins.model.Jenkins; import org.apache.commons.lang.RandomStringUtils; @@ -26,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(EC2FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID) || proposedName.equals(EC2FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID) || usedNames.contains(proposedName)) { + if (proposedName.equals(FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID) || proposedName.equals(FleetLabelCloud.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 4af14599..b30feac8 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 EC2FleetCloud}s. + * {@link CloudNanny} is responsible for periodically running update (i.e. sync-state-with-AWS) cycles for {@link FleetCloud}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 EC2FleetCloud)) continue; - final EC2FleetCloud fleetCloud = (EC2FleetCloud) cloud; + if (!(cloud instanceof FleetCloud)) continue; + final FleetCloud fleetCloud = (FleetCloud) cloud; final AtomicInteger recurrenceCounter = getRecurrenceCounter(fleetCloud); @@ -70,7 +70,7 @@ private static List getClouds() { return Jenkins.get().clouds; } - private AtomicInteger getRecurrenceCounter(EC2FleetCloud fleetCloud) { + private AtomicInteger getRecurrenceCounter(FleetCloud 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/EC2RetentionStrategy.java b/src/main/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategy.java index 655b7273..99a88111 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 EC2FleetNodeComputer} offline, bring it back online, or even to destroy it. + * The {@link EC2RetentionStrategy} controls when to take {@link FleetNodeComputer} 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 EC2FleetNodeComputer + * @param fc FleetNodeComputer * @return delay in min before next run */ @SuppressFBWarnings( value = "BC_UNCONFIRMED_CAST", - justification = "to ignore EC2FleetNodeComputer cast") + justification = "to ignore FleetNodeComputer cast") @Override - public long check(final EC2FleetNodeComputer fc) { - final AbstractEC2FleetCloud cloud = fc.getCloud(); + public long check(final FleetNodeComputer fc) { + final AbstractFleetCloud cloud = fc.getCloud(); LOGGER.fine(String.format("Checking if node '%s' is idle ", fc.getName())); @@ -41,7 +41,7 @@ public long check(final EC2FleetNodeComputer fc) { return RE_CHECK_IN_A_MINUTE; } - // Ensure that the EC2FleetCloud cannot be mutated from under us while + // Ensure that the FleetCloud 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 EC2FleetNodeComputer 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 EC2FleetCloud object, erasing class fields containing data like instance IDs to terminate. + // A user-initiated change to cloud configuration creates a new FleetCloud 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 EC2FleetCloud && !((EC2FleetCloud) cloud).hasUnlimitedUsesForNodes() - && ((EC2FleetNode)node).getUsesRemaining() <= 0) { + } else if (cloud instanceof FleetCloud && !((FleetCloud) cloud).hasUnlimitedUsesForNodes() + && ((FleetNode)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 EC2FleetNodeComputer fc) { } @Override - public void start(EC2FleetNodeComputer c) { + public void start(FleetNodeComputer c) { LOGGER.log(Level.INFO, "Connecting to instance: " + c.getDisplayName()); c.connect(false); } - private boolean isIdleForTooLong(final AbstractEC2FleetCloud cloud, final Computer computer) { + private boolean isIdleForTooLong(final AbstractFleetCloud cloud, final Computer computer) { final int idleMinutes = cloud.getIdleMinutes(); if (idleMinutes <= 0) return false; @@ -122,25 +122,25 @@ private boolean isIdleForTooLong(final AbstractEC2FleetCloud cloud, final Comput @Override public void taskAccepted(Executor executor, Queue.Task task) { - final EC2FleetNodeComputer computer = (EC2FleetNodeComputer) executor.getOwner(); + final FleetNodeComputer computer = (FleetNodeComputer) executor.getOwner(); if (computer != null) { - final EC2FleetNode ec2FleetNode = computer.getNode(); - if (ec2FleetNode != null) { - final int maxTotalUses = ec2FleetNode.getMaxTotalUses(); + final FleetNode fleetNode = computer.getNode(); + if (fleetNode != null) { + final int maxTotalUses = fleetNode.getMaxTotalUses(); if (maxTotalUses <= -1) { // unlimited uses LOGGER.fine("maxTotalUses set to unlimited (" + maxTotalUses + ") for agent " + computer.getName()); } else { // limited uses - 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 + 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 LOGGER.info(String.format("maxTotalUses drained - suspending agent %s after current build", computer.getName())); computer.setAcceptingTasks(false); - ec2FleetNode.decrementUsesRemaining(); + fleetNode.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(), ec2FleetNode.getMaxTotalUses(), ec2FleetNode.getUsesRemaining())); + computer.getName(), fleetNode.getMaxTotalUses(), fleetNode.getUsesRemaining())); } } } @@ -170,15 +170,15 @@ private void postJobAction(final Executor executor, final Throwable throwable) { TimeUnit.MILLISECONDS.toSeconds(executor.getElapsedTime()))); } - final EC2FleetNodeComputer computer = (EC2FleetNodeComputer) executor.getOwner(); + final FleetNodeComputer computer = (FleetNodeComputer) executor.getOwner(); if (computer != null) { - final EC2FleetNode ec2FleetNode = computer.getNode(); - if (ec2FleetNode != null) { - final AbstractEC2FleetCloud cloud = ec2FleetNode.getCloud(); + final FleetNode fleetNode = computer.getNode(); + if (fleetNode != null) { + final AbstractFleetCloud cloud = fleetNode.getCloud(); if (computer.countBusy() <= 1 && !computer.isAcceptingTasks()) { - LOGGER.info("Calling scheduleToTerminate for node " + ec2FleetNode.getNodeName() + " due to exhausted maxTotalUses."); + LOGGER.info("Calling scheduleToTerminate for node " + fleetNode.getNodeName() + " due to exhausted maxTotalUses."); // Schedule instance for termination even if it breaches minSize and minSpareSize constraints - cloud.scheduleToTerminate(ec2FleetNode.getNodeName(), true, EC2AgentTerminationReason.MAX_TOTAL_USES_EXHAUSTED); + cloud.scheduleToTerminate(fleetNode.getNodeName(), true, EC2AgentTerminationReason.MAX_TOTAL_USES_EXHAUSTED); } } } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncher.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncher.java similarity index 87% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncher.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncher.java index f23d9543..9574da7b 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncher.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncher.java @@ -22,23 +22,23 @@ import java.util.logging.Logger; /** - * The {@link EC2FleetAutoResubmitComputerLauncher} is responsible for controlling: - * * how {@link EC2FleetNodeComputer}s are launched - * * how {@link EC2FleetNodeComputer}s connect to agents {@link EC2FleetNode} + * The {@link FleetAutoResubmitComputerLauncher} is responsible for controlling: + * * how {@link FleetNodeComputer}s are launched + * * how {@link FleetNodeComputer}s connect to agents {@link FleetNode} * * 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 EC2FleetCloud#isDisableTaskResubmit()} + * {@link FleetCloud#isDisableTaskResubmit()} */ @SuppressWarnings("WeakerAccess") @ThreadSafe -public class EC2FleetAutoResubmitComputerLauncher extends DelegatingComputerLauncher { +public class FleetAutoResubmitComputerLauncher extends DelegatingComputerLauncher { private static final Level LOG_LEVEL = Level.INFO; - private static final Logger LOGGER = Logger.getLogger(EC2FleetAutoResubmitComputerLauncher.class.getName()); + private static final Logger LOGGER = Logger.getLogger(FleetAutoResubmitComputerLauncher.class.getName()); /** * Delay which will be applied when job {@link Queue#scheduleInternal(Queue.Task, int, List)} @@ -46,7 +46,7 @@ public class EC2FleetAutoResubmitComputerLauncher extends DelegatingComputerLaun */ private static final int RESCHEDULE_QUIET_PERIOD_SEC = 10; - public EC2FleetAutoResubmitComputerLauncher(final ComputerLauncher launcher) { + public FleetAutoResubmitComputerLauncher(final ComputerLauncher launcher) { super(launcher); } @@ -72,14 +72,14 @@ public EC2FleetAutoResubmitComputerLauncher(final ComputerLauncher launcher) { */ @SuppressFBWarnings( value = "BC_UNCONFIRMED_CAST", - justification = "to ignore EC2FleetNodeComputer cast") + justification = "to ignore FleetNodeComputer 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 AbstractEC2FleetCloud cloud = ((EC2FleetNodeComputer) computer).getCloud(); + final AbstractFleetCloud cloud = ((FleetNodeComputer) 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/EC2FleetCloud.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java similarity index 91% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.java index f19db6a9..3fe70638 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetCloud.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.EC2Fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.Fleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.Instance; import com.amazonaws.services.ec2.model.InstanceStateName; @@ -27,6 +27,7 @@ import jenkins.model.Jenkins; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; @@ -56,19 +57,19 @@ import java.util.stream.Collectors; /** - * 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. + * 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. * * Responsibilities include: * * maintain the configuration values set by user for the Cloud. - * 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()} + * 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()} * * provide helper methods to extract certain state values * * provide helper methods to schedule termination of compute / nodes */ @SuppressWarnings({"unused", "WeakerAccess"}) -public class EC2FleetCloud extends AbstractEC2FleetCloud { +public class FleetCloud extends AbstractFleetCloud { 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"; @@ -83,13 +84,13 @@ public class EC2FleetCloud extends AbstractEC2FleetCloud { private static final int DEFAULT_MAX_TOTAL_USES = -1; private static final SimpleFormatter sf = new SimpleFormatter(); - private static final Logger LOGGER = Logger.getLogger(EC2FleetCloud.class.getName()); + private static final Logger LOGGER = Logger.getLogger(FleetCloud.class.getName()); private static final ScheduledExecutorService EXECUTOR = Executors.newSingleThreadScheduledExecutor(); /** - * Replaced with {@link EC2FleetCloud#awsCredentialsId} + * Replaced with {@link FleetCloud#awsCredentialsId} *

- * Plugin is using {@link EC2FleetCloud#computerConnector} for node connection credentials + * Plugin is using {@link FleetCloud#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. *

@@ -130,7 +131,7 @@ public class EC2FleetCloud extends AbstractEC2FleetCloud { private final Integer maxTotalUses; /** - * @see EC2FleetAutoResubmitComputerLauncher + * @see FleetAutoResubmitComputerLauncher */ private final boolean disableTaskResubmit; @@ -140,9 +141,9 @@ public class EC2FleetCloud extends AbstractEC2FleetCloud { private final boolean noDelayProvision; /** - * {@link EC2FleetCloud#update()} updating this field, this is one thread + * {@link FleetCloud#update()} updating this field, this is one thread * related to {@link CloudNanny}. At the same time {@link EC2RetentionStrategy} - * call {@link EC2FleetCloud#scheduleToTerminate(String, boolean, EC2AgentTerminationReason)} to terminate instance when it is free + * call {@link FleetCloud#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, @@ -159,35 +160,35 @@ public class EC2FleetCloud extends AbstractEC2FleetCloud { private transient ArrayList> plannedNodeScheduledFutures; - // Counter to keep track of planned nodes per EC2FleetCloud, used in node's display name + // Counter to keep track of planned nodes per FleetCloud, used in node's display name private transient AtomicInteger plannedNodeCounter = new AtomicInteger(1); @DataBoundConstructor - 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 boolean scaleExecutorsByWeight, - final Integer cloudStatusIntervalSec, - final boolean noDelayProvision) { + 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 boolean scaleExecutorsByWeight, + final Integer cloudStatusIntervalSec, + final boolean noDelayProvision) { super(StringUtils.isNotBlank(name) ? name : CloudNames.generateUnique(BASE_DEFAULT_FLEET_CLOUD_ID)); init(); this.credentialsId = credentialsId; @@ -219,7 +220,7 @@ public EC2FleetCloud(@Nonnull final String name, this.noDelayProvision = noDelayProvision; if (fleet != null) { - this.stats = EC2Fleets.get(fleet).getState( + this.stats = Fleets.get(fleet).getState( getAwsCredentialsId(), region, endpoint, getFleet()); } } @@ -229,9 +230,9 @@ public boolean isNoDelayProvision() { } /** - * Deprecated.Use {@link EC2FleetCloud#awsCredentialsId} + * Deprecated.Use {@link FleetCloud#awsCredentialsId} * - * See {@link EC2FleetCloud#awsCredentialsId} documentation. Don't use fields directly to be able + * See {@link FleetCloud#awsCredentialsId} documentation. Don't use fields directly to be able * get old version of plugin and for new. * * @return credentials ID @@ -366,7 +367,7 @@ synchronized void setStats(final FleetStateStats stats) { this.stats = stats; } - // make maxTotalUses inaccessible from cloud for safety. Use {@link EC2FleetNode#maxTotalUses} and {@link EC2FleetNode#usesRemaining} instead. + // make maxTotalUses inaccessible from cloud for safety. Use {@link FleetNode#maxTotalUses} and {@link FleetNode#usesRemaining} instead. public boolean hasUnlimitedUsesForNodes() { return maxTotalUses == -1; } @@ -450,9 +451,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, EC2FleetOnlineChecker will cancel the future + // is updated or removed before it can scale. After scaling, FleetOnlineChecker will cancel the future // if something happens to the Fleet. - // TODO: refactor to consolidate logic with EC2FleetOnlineChecker + // TODO: refactor to consolidate logic with FleetOnlineChecker final ScheduledFuture scheduledFuture = EXECUTOR.schedule(() -> { if (completableFuture.isDone()) { return; @@ -478,10 +479,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 = EC2Fleets.get(fleet).getState( + FleetStateStats currentState = Fleets.get(fleet).getState( getAwsCredentialsId(), region, endpoint, getFleet()); - // Some Fleet implementations (e.g. EC2SpotFleet) reflect their state only at the end of modification + // Some Fleet implementations (e.g. SpotFleet) 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) { @@ -582,7 +583,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()) { - EC2Fleets.get(fleet).modify( + Fleets.get(fleet).modify( getAwsCredentialsId(), region, endpoint, fleet, targetCapacity, minSize, maxSize); info("Set target capacity to '%s'", targetCapacity); } @@ -628,7 +629,7 @@ public void run() { final Set jenkinsInstances = new HashSet<>(); for (final Node node : jenkins.getNodes()) { - if (node instanceof EC2FleetNode && ((EC2FleetCloud)((EC2FleetNode) node).getCloud()).getFleet().equals(fleet)) { + if (node instanceof FleetNode && ((FleetCloud)((FleetNode) node).getCloud()).getFleet().equals(fleet)) { jenkinsInstances.add(node.getNodeName()); } } @@ -716,7 +717,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 EC2FleetCloud#update()} which is periodically called by + * Real termination will happens in {@link FleetCloud#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()} *

@@ -840,10 +841,10 @@ private void addNewAgent(final AmazonEC2 ec2, final Instance instance, FleetStat effectiveNumExecutors = numExecutors; } - final EC2FleetAutoResubmitComputerLauncher computerLauncher = new EC2FleetAutoResubmitComputerLauncher( + final FleetAutoResubmitComputerLauncher computerLauncher = new FleetAutoResubmitComputerLauncher( computerConnector.launch(address, TaskListener.NULL)); final Node.Mode nodeMode = restrictUsage ? Node.Mode.EXCLUSIVE : Node.Mode.NORMAL; - final EC2FleetNode node = new EC2FleetNode(instanceId, "Fleet agent for " + instanceId, + final FleetNode node = new FleetNode(instanceId, "Fleet agent for " + instanceId, effectiveFsRoot, effectiveNumExecutors, nodeMode, labelString, new ArrayList>(), this.name, computerLauncher, maxTotalUses); @@ -868,7 +869,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 - EC2FleetOnlineChecker.start(node, future, + FleetOnlineChecker.start(node, future, TimeUnit.SECONDS.toMillis(getInitOnlineTimeoutSec()), TimeUnit.SECONDS.toMillis(getInitOnlineCheckIntervalSec())); } @@ -879,14 +880,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 EC2FleetNodeComputer && !computer.isIdle()) { + if (computer instanceof FleetNodeComputer && !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(((EC2FleetCloud)((EC2FleetNodeComputer) computer).getCloud()).getFleet(), currentState.getFleetId())) { + if (!Objects.equals(((FleetCloud)((FleetNodeComputer) computer).getCloud()).getFleet(), currentState.getFleetId())) { continue; } currentBusyInstances++; @@ -927,7 +928,7 @@ public DescriptorImpl getDescriptor() { } @Extension - @SuppressWarnings("unused") + @SuppressWarnings("unused") @Symbol("eC2Fleet") public static class DescriptorImpl extends Descriptor { public DescriptorImpl() { @@ -990,8 +991,8 @@ public ListBoxModel doFillFleetItems(@QueryParameter final boolean showAllFleets final ListBoxModel model = new ListBoxModel(); model.add(0, new Option("- please select -", "", true)); try { - for (final EC2Fleet EC2Fleet : EC2Fleets.all()) { - EC2Fleet.describe( + for (final Fleet Fleet : Fleets.all()) { + Fleet.describe( awsCredentialsId, region, endpoint, model, fleet, showAllFleets); } } catch (final Exception ex) { diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.java similarity index 93% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.java index 24cf4c5e..a25265bb 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelCloud.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.EC2Fleets; -import com.amazon.jenkins.ec2fleet.fleet.EC2SpotFleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.SpotFleet; import com.amazonaws.services.cloudformation.AmazonCloudFormation; import com.amazonaws.services.cloudformation.model.StackStatus; import com.amazonaws.services.ec2.AmazonEC2; @@ -31,6 +31,7 @@ import jenkins.model.Jenkins; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; +import org.jenkinsci.Symbol; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; @@ -58,7 +59,7 @@ * @see CloudNanny */ @SuppressWarnings({"unused", "WeakerAccess"}) -public class EC2FleetLabelCloud extends AbstractEC2FleetCloud { +public class FleetLabelCloud extends AbstractFleetCloud { 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"; @@ -73,7 +74,7 @@ public class EC2FleetLabelCloud extends AbstractEC2FleetCloud { // 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(EC2FleetLabelCloud.class.getName()); + private static final Logger LOGGER = Logger.getLogger(FleetLabelCloud.class.getName()); private final String awsCredentialsId; private final String region; @@ -94,7 +95,7 @@ public class EC2FleetLabelCloud extends AbstractEC2FleetCloud { private final String ec2KeyPairName; /** - * @see EC2FleetAutoResubmitComputerLauncher + * @see FleetAutoResubmitComputerLauncher */ private final boolean disableTaskResubmit; @@ -106,25 +107,25 @@ public class EC2FleetLabelCloud extends AbstractEC2FleetCloud { private transient Map states; @DataBoundConstructor - 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 Integer minSize, - final Integer maxSize, - final Integer numExecutors, - final boolean restrictUsage, - final boolean disableTaskResubmit, - final Integer initOnlineTimeoutSec, - final Integer initOnlineCheckIntervalSec, - final Integer cloudStatusIntervalSec, - final boolean noDelayProvision, - final String ec2KeyPairName) { + 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 Integer minSize, + final Integer maxSize, + final Integer 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; @@ -282,7 +283,7 @@ public synchronized Collection provision(@Nonnull f continue; } - final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(state.getKey()); + final FleetLabelParameters parameters = new FleetLabelParameters(state.getKey()); final int maxSize = parameters.getIntOrDefault("maxSize", this.maxSize); if (cap >= maxSize) { @@ -358,7 +359,7 @@ public void update() { final Set fleetIds = new HashSet<>(); for (State state : states.values()) fleetIds.add(state.fleetId); - final Map currentStats = new EC2SpotFleet().getStateBatch( + final Map currentStats = new SpotFleet().getStateBatch( getAwsCredentialsId(), region, endpoint, fleetIds); for (State state : currentStates.values()) { // todo what if we don't find this fleet in map @@ -403,7 +404,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 - EC2Fleets.get(state.fleetId).modify( + Fleets.get(state.fleetId).modify( getAwsCredentialsId(), region, endpoint, state.fleetId, state.targetCapacity, minSize, maxSize); info("Update fleet target capacity to %s", state.targetCapacity); } @@ -454,8 +455,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 EC2FleetNode) { - final EC2FleetNode node1 = (EC2FleetNode) node; + if (node instanceof FleetNode) { + final FleetNode node1 = (FleetNode) node; // cloud and label are same if (node1.getCloud() == this && node1.getLabelString().equals(entry.getKey())) { jenkinsInstances.add(node.getNodeName()); @@ -549,7 +550,7 @@ public synchronized boolean scheduleToTerminate(final String instanceId, final b } // We can't remove instances beyond minSize unless ignoreMinConstraints is true - final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(node.getLabelString()); + final FleetLabelParameters parameters = new FleetLabelParameters(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); @@ -616,11 +617,11 @@ private void addNewAgent( effectiveNumExecutors = numExecutors; } - final EC2FleetAutoResubmitComputerLauncher computerLauncher = new EC2FleetAutoResubmitComputerLauncher( + final FleetAutoResubmitComputerLauncher computerLauncher = new FleetAutoResubmitComputerLauncher( computerConnector.launch(address, TaskListener.NULL)); final Node.Mode nodeMode = restrictUsage ? Node.Mode.EXCLUSIVE : Node.Mode.NORMAL; - //TODO: Add maxTotalUses to EC2FleetLabelCloud similar to EC2FleetCloud - final EC2FleetNode node = new EC2FleetNode(instanceId, "Fleet agent for " + instanceId, + //TODO: Add maxTotalUses to FleetLabelCloud similar to FleetCloud + final FleetNode node = new FleetNode(instanceId, "Fleet agent for " + instanceId, effectiveFsRoot, effectiveNumExecutors, nodeMode, labelString, new ArrayList>(), this.name, computerLauncher, -1); @@ -645,7 +646,7 @@ 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 - EC2FleetOnlineChecker.start(node, future, + FleetOnlineChecker.start(node, future, TimeUnit.SECONDS.toMillis(getInitOnlineTimeoutSec()), TimeUnit.SECONDS.toMillis(getInitOnlineCheckIntervalSec())); } @@ -782,12 +783,12 @@ public void run() { } @Override - public EC2FleetLabelCloud.DescriptorImpl getDescriptor() { - return (EC2FleetLabelCloud.DescriptorImpl) super.getDescriptor(); + public FleetLabelCloud.DescriptorImpl getDescriptor() { + return (FleetLabelCloud.DescriptorImpl) super.getDescriptor(); } @Extension - @SuppressWarnings("unused") + @SuppressWarnings("unused") @Symbol("eC2FleetLabel") public static class DescriptorImpl extends Descriptor { public DescriptorImpl() { diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParameters.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelParameters.java similarity index 92% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParameters.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelParameters.java index cea3e9ac..b49cbba7 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParameters.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelParameters.java @@ -5,11 +5,11 @@ import java.util.Map; @ThreadSafe -public class EC2FleetLabelParameters { +public class FleetLabelParameters { private final Map parameters; - public EC2FleetLabelParameters(final String label) { + public FleetLabelParameters(final String label) { parameters = parse(label); } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelUpdater.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelUpdater.java similarity index 75% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelUpdater.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelUpdater.java index 6ad5f087..0a636f25 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelUpdater.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetLabelUpdater.java @@ -12,9 +12,9 @@ // todo make configurable @Extension @SuppressWarnings("unused") -public class EC2FleetLabelUpdater extends PeriodicWork { +public class FleetLabelUpdater extends PeriodicWork { - private static final Logger LOGGER = Logger.getLogger(EC2FleetLabelUpdater.class.getName()); + private static final Logger LOGGER = Logger.getLogger(FleetLabelUpdater.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 EC2FleetLabelCloud)) continue; - final EC2FleetLabelCloud ec2FleetLabelCloud = (EC2FleetLabelCloud) cloud; + if (!(cloud instanceof FleetLabelCloud)) continue; + final FleetLabelCloud ec2FleetLabelCloud = (FleetLabelCloud) cloud; try { ec2FleetLabelCloud.updateStacks(); } catch (Throwable t) { diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNode.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetNode.java similarity index 74% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNode.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetNode.java index 0379ee3d..81ff8c57 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNode.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetNode.java @@ -17,18 +17,18 @@ import java.util.logging.Logger; /** - * The {@link EC2FleetNode} represents an agent running on an EC2 instance, responsible for creating {@link EC2FleetNodeComputer}. + * The {@link FleetNode} represents an agent running on an EC2 instance, responsible for creating {@link FleetNodeComputer}. */ -public class EC2FleetNode extends Slave implements EphemeralNode { - private static final Logger LOGGER = Logger.getLogger(EC2FleetNode.class.getName()); +public class FleetNode extends Slave implements EphemeralNode { + private static final Logger LOGGER = Logger.getLogger(FleetNode.class.getName()); private String cloudName; private String instanceId; private final int maxTotalUses; private int usesRemaining; - 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 { + 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 { //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 EC2FleetNodeComputer(this); + return new FleetNodeComputer(this); } - public AbstractEC2FleetCloud getCloud() { - return (AbstractEC2FleetCloud) Jenkins.get().getCloud(cloudName); + public AbstractFleetCloud getCloud() { + return (AbstractFleetCloud) Jenkins.get().getCloud(cloudName); } public DescriptorImpl getDescriptor() { diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputer.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetNodeComputer.java similarity index 75% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputer.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetNodeComputer.java index ec5e3125..1e5ea772 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputer.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetNodeComputer.java @@ -11,15 +11,15 @@ import java.util.logging.Logger; /** - * The {@link EC2FleetNodeComputer} represents the running state of {@link EC2FleetNode} that holds executors. + * The {@link FleetNodeComputer} represents the running state of {@link FleetNode} that holds executors. * @see hudson.model.Computer */ @ThreadSafe -public class EC2FleetNodeComputer extends SlaveComputer { - private static final Logger LOGGER = Logger.getLogger(EC2FleetNodeComputer.class.getName()); +public class FleetNodeComputer extends SlaveComputer { + private static final Logger LOGGER = Logger.getLogger(FleetNodeComputer.class.getName()); private boolean isMarkedForDeletion; - public EC2FleetNodeComputer(final EC2FleetNode agent) { + public FleetNodeComputer(final FleetNode agent) { super(agent); this.isMarkedForDeletion = false; } @@ -29,18 +29,18 @@ public boolean isMarkedForDeletion() { } @Override - public EC2FleetNode getNode() { - return (EC2FleetNode) super.getNode(); + public FleetNode getNode() { + return (FleetNode) super.getNode(); } @CheckForNull public String getInstanceId() { - EC2FleetNode node = getNode(); + FleetNode node = getNode(); return node == null ? null : node.getInstanceId(); } - public AbstractEC2FleetCloud getCloud() { - final EC2FleetNode node = getNode(); + public AbstractFleetCloud getCloud() { + final FleetNode node = getNode(); return node == null ? null : node.getCloud(); } @@ -53,7 +53,7 @@ public AbstractEC2FleetCloud getCloud() { @Nonnull @Override public String getDisplayName() { - final EC2FleetNode node = getNode(); + final FleetNode 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 EC2FleetNode node = getNode(); + final FleetNode node = getNode(); if (node != null) { final String instanceId = node.getInstanceId(); - final AbstractEC2FleetCloud cloud = node.getCloud(); + final AbstractFleetCloud 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/EC2FleetOnlineChecker.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetOnlineChecker.java similarity index 92% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineChecker.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetOnlineChecker.java index 29ee9580..4c5702f5 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineChecker.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetOnlineChecker.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 EC2FleetCloud - * @see EC2FleetNode + * @see FleetCloud + * @see FleetNode */ @SuppressWarnings("WeakerAccess") @ThreadSafe -class EC2FleetOnlineChecker implements Runnable { +class FleetOnlineChecker implements Runnable { - private static final Logger LOGGER = Logger.getLogger(EC2FleetOnlineChecker.class.getName()); + private static final Logger LOGGER = Logger.getLogger(FleetOnlineChecker.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 EC2FleetOnlineChecker(node, future, timeout, interval)); + EXECUTOR.execute(new FleetOnlineChecker(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 EC2FleetOnlineChecker( + private FleetOnlineChecker( 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/FleetStateStats.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStateStats.java index 05e8a056..a52a3c57 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/FleetStateStats.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStateStats.java @@ -1,5 +1,7 @@ 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; @@ -10,7 +12,7 @@ import java.util.Set; /** - * @see EC2FleetCloud + * @see FleetCloud */ @SuppressWarnings({"unused"}) @ThreadSafe @@ -18,7 +20,7 @@ public final class FleetStateStats { /** * Abstract state of different implementation of - * {@link com.amazon.jenkins.ec2fleet.fleet.EC2Fleet} + * {@link Fleet} */ public static class State { @@ -52,12 +54,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 com.amazon.jenkins.ec2fleet.fleet.EC2SpotFleet} + * This is important only for {@link SpotFleet} * 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 EC2FleetCloud#update()} + * Consumed by {@link FleetCloud#update()} * * @return true or false */ @@ -67,7 +69,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 EC2FleetCloud#provision(hudson.slaves.Cloud.CloudState, int)} ()} and de-provision + * and plugin will use it for provision {@link FleetCloud#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/EC2FleetStatusInfo.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusInfo.java similarity index 82% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusInfo.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusInfo.java index 3999f79d..9397aec7 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusInfo.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusInfo.java @@ -6,16 +6,16 @@ import java.util.Objects; /** - * This consumed by jelly file EC2FleetStatusWidget/index.jelly + * This consumed by jelly file FleetStatusWidget/index.jelly * to render fleet information about all fleets, don't forget to update it * if you change fields name * - * @see EC2FleetStatusWidget + * @see FleetStatusWidget * @see CloudNanny */ @SuppressWarnings({"WeakerAccess", "unused"}) @ThreadSafe -public class EC2FleetStatusInfo extends Widget { +public class FleetStatusInfo extends Widget { private final String id; private final String state; @@ -23,7 +23,7 @@ public class EC2FleetStatusInfo extends Widget { private final int numActive; private final int numDesired; - public EC2FleetStatusInfo(String id, String state, String label, int numActive, int numDesired) { + public FleetStatusInfo(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; - EC2FleetStatusInfo that = (EC2FleetStatusInfo) o; + FleetStatusInfo that = (FleetStatusInfo) o; return numActive == that.numActive && numDesired == that.numDesired && Objects.equals(id, that.id) && diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidget.java similarity index 57% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidget.java index 315b97a0..e7908eb1 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidget.java @@ -9,20 +9,20 @@ /** * This class should be thread safe, consumed by Jenkins and updated - * by {@link EC2FleetStatusWidgetUpdater} + * by {@link FleetStatusWidgetUpdater} */ @Extension @ThreadSafe -public class EC2FleetStatusWidget extends Widget { +public class FleetStatusWidget 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/EC2FleetStatusWidgetUpdater.java b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdater.java similarity index 79% rename from src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java rename to src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdater.java index 75c863a8..f69114a7 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdater.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdater.java @@ -10,12 +10,12 @@ import java.util.List; /** - * @see EC2FleetCloud - * @see EC2FleetStatusWidget + * @see FleetCloud + * @see FleetStatusWidget */ @Extension @SuppressWarnings("unused") -public class EC2FleetStatusWidgetUpdater extends PeriodicWork { +public class FleetStatusWidgetUpdater 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 EC2FleetCloud)) continue; - final EC2FleetCloud fleetCloud = (EC2FleetCloud) cloud; + if (!(cloud instanceof FleetCloud)) continue; + final FleetCloud fleetCloud = (FleetCloud) 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 EC2FleetStatusInfo( + info.add(new FleetStatusInfo( fleetCloud.getFleet(), stats.getState().getDetailed(), fleetCloud.getLabelString(), stats.getNumActive(), stats.getNumDesired())); } for (final Widget w : getWidgets()) { - if (w instanceof EC2FleetStatusWidget) ((EC2FleetStatusWidget) w).setStatusList(info); + if (w instanceof FleetStatusWidget) ((FleetStatusWidget) w).setStatusList(info); } } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategy.java b/src/main/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategy.java index 4da41b24..d059d478 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 EC2FleetCloud)) { - LOGGER.log(Level.FINE, "label [{0}]: cloud {1} is not an EC2FleetCloud, continuing...", + if (!(c instanceof FleetCloud)) { + LOGGER.log(Level.FINE, "label [{0}]: cloud {1} is not an FleetCloud, continuing...", new Object[]{label, c.getDisplayName()}); continue; } @@ -63,7 +63,7 @@ public NodeProvisioner.StrategyDecision apply(final NodeProvisioner.StrategyStat continue; } - if (!((EC2FleetCloud) c).isNoDelayProvision()) { + if (!((FleetCloud) 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 f5592621..92c94488 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/aws/AwsPermissionChecker.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/aws/AwsPermissionChecker.java @@ -2,17 +2,11 @@ import com.amazon.jenkins.ec2fleet.Registry; import com.amazon.jenkins.ec2fleet.fleet.AutoScalingGroupFleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; import com.amazonaws.services.autoscaling.AmazonAutoScalingClient; import com.amazonaws.services.autoscaling.model.AmazonAutoScalingException; import com.amazonaws.services.ec2.AmazonEC2; -import com.amazonaws.services.ec2.model.CreateTagsRequest; -import com.amazonaws.services.ec2.model.DescribeInstancesRequest; -import com.amazonaws.services.ec2.model.DescribeSpotFleetInstancesRequest; -import com.amazonaws.services.ec2.model.DescribeSpotFleetRequestsRequest; -import com.amazonaws.services.ec2.model.DryRunResult; -import com.amazonaws.services.ec2.model.ModifySpotFleetRequestRequest; -import com.amazonaws.services.ec2.model.Tag; +import com.amazonaws.services.ec2.model.*; import org.apache.commons.lang.StringUtils; import java.util.ArrayList; @@ -38,6 +32,9 @@ public enum FleetAPI { ModifySpotFleetRequest, DescribeSpotFleetRequests, DescribeAutoScalingGroups, + DescribeEC2FleetRequests, + DescribeEC2FleetInstances, + ModifyEC2FleetRequest, TerminateInstances, // TODO: Dry-run throws invalid instanceID first then AuthZ error. We need to find a better way to test UpdateAutoScalingGroup; // TODO: There is no dry-run for AutoScalingClient }; @@ -45,10 +42,13 @@ public enum FleetAPI { 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 permissions for both + 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(getMissingPermissionsForASG()); - } else if(EC2Fleets.isEC2Fleet(fleet)) { + } else if(Fleets.isSpotFleet(fleet)) { + missingPermissions.addAll(getMissingPermissionsForSpotFleet(ec2Client, fleet)); + } else if(Fleets.isEC2Fleet(fleet)) { missingPermissions.addAll(getMissingPermissionsForEC2Fleet(ec2Client, fleet)); } else { missingPermissions.addAll(getMissingPermissionsForASG()); @@ -56,18 +56,18 @@ public List getMissingPermissions(final String fleet) { return missingPermissions; } - private List getMissingPermissionsForEC2Fleet(final AmazonEC2 ec2Client, final String fleet) { - final List missingEC2FleetPermissions = new ArrayList<>(); + private List getMissingPermissionsForSpotFleet(final AmazonEC2 ec2Client, final String fleet) { + final List missingFleetPermissions = new ArrayList<>(); if(!hasDescribeSpotFleetRequestsPermission(ec2Client, fleet)) { - missingEC2FleetPermissions.add(FleetAPI.DescribeSpotFleetRequests.name()); + missingFleetPermissions.add(FleetAPI.DescribeSpotFleetRequests.name()); } if(!hasDescribeSpotFleetInstancesPermission(ec2Client, fleet)) { - missingEC2FleetPermissions.add(FleetAPI.DescribeSpotFleetInstances.name()); + missingFleetPermissions.add(FleetAPI.DescribeSpotFleetInstances.name()); } if(!hasModifySpotFleetRequestPermission(ec2Client, fleet)) { - missingEC2FleetPermissions.add(FleetAPI.ModifySpotFleetRequest.name()); + missingFleetPermissions.add(FleetAPI.ModifySpotFleetRequest.name()); } - return missingEC2FleetPermissions; + return missingFleetPermissions; } private List getMissingCommonPermissions(final AmazonEC2 ec2Client) { @@ -90,6 +90,35 @@ private List getMissingPermissionsForASG() { return missingAsgPermissions; } + private List getMissingPermissionsForEC2Fleet(final AmazonEC2 ec2Client, final String fleet) { + final List missingFleetPermissions = new ArrayList<>(); + if(!hasDescribeEC2FleetRequestsPermission(ec2Client, fleet)) { + missingFleetPermissions.add(FleetAPI.DescribeEC2FleetRequests.name()); + } + if(!hasDescribeEC2FleetInstancesPermission(ec2Client, fleet)) { + missingFleetPermissions.add(FleetAPI.DescribeEC2FleetInstances.name()); + } + if(!hasModifyEC2FleetRequestPermission(ec2Client, fleet)) { + missingFleetPermissions.add(FleetAPI.ModifyEC2FleetRequest.name()); + } + return missingFleetPermissions; + } + + private boolean hasModifyEC2FleetRequestPermission(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) { + 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) { + final DryRunResult dryRunResult = ec2Client.dryRun(new DescribeFleetsRequest().withFleetIds(fleet)); + return dryRunResult.getDryRunResponse().getStatusCode() != UNAUTHORIZED_STATUS_CODE; + } + private boolean hasModifySpotFleetRequestPermission(final AmazonEC2 ec2Client, final String fleet) { final DryRunResult dryRunResult = ec2Client.dryRun(new ModifySpotFleetRequestRequest().withSpotFleetRequestId(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 3c083273..e2cfb342 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.EC2FleetLabelParameters; +import com.amazon.jenkins.ec2fleet.FleetLabelParameters; 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 EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(parametersString); + final FleetLabelParameters parameters = new FleetLabelParameters(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 50f5b456..4ce111a3 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 EC2Fleet { +public class AutoScalingGroupFleet implements Fleet { @Override public void describe( 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 7fea983d..c7851998 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleet.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleet.java @@ -1,34 +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.Collection; -import java.util.Map; +import java.util.*; -/** - * Hide details of access to EC2 Fleet depending on implementation like EC2 Fleet based on EC2 Spot Fleet - * or Auto Scaling Group. - * - * @see EC2SpotFleet - * @see AutoScalingGroupFleet - */ -public interface EC2Fleet { +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); + } - void describe( - final String awsCredentialsId, final String regionName, final String endpoint, - final ListBoxModel model, final String selectedId, final boolean showAll); + private static boolean isActiveAndMaintain(final FleetData fleetData) { + return FleetType.Maintain.toString().equals(fleetData.getType()) && isActive(fleetData); + } - void modify( - final String awsCredentialsId, final String regionName, final String endpoint, - final String id, final int targetCapacity, int min, int max); + 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()); + } - FleetStateStats getState( - final String awsCredentialsId, final String regionName, final String endpoint, - final String id); + private static boolean isModifying(final FleetData fleetData) { + return BatchState.Submitted.toString().equals(fleetData.getFleetState()) + || BatchState.Modifying.toString().equals(fleetData.getFleetState()); + } - Map getStateBatch( - final String awsCredentialsId, final String regionName, final String endpoint, - final Collection ids); + @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"); + 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/Fleet.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleet.java new file mode 100644 index 00000000..d8e7cd52 --- /dev/null +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleet.java @@ -0,0 +1,35 @@ +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/EC2Fleets.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleets.java similarity index 51% rename from src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleets.java rename to src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleets.java index 32fe11c0..6310413c 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2Fleets.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/Fleets.java @@ -7,41 +7,51 @@ import java.util.List; @ThreadSafe -public class EC2Fleets { +public class Fleets { private static final String EC2_SPOT_FLEET_PREFIX = "sfr-"; - private static final EC2SpotFleet EC2_SPOT_FLEET = new EC2SpotFleet(); + private static final SpotFleet EC2_SPOT_FLEET = new SpotFleet(); - private static EC2Fleet GET = null; + private static final String EC2_FLEET_PREFIX = "fleet-"; + private static final EC2Fleet EC2_FLEET = new EC2Fleet(); - private EC2Fleets() { + private static Fleet GET = null; + + private Fleets() { throw new UnsupportedOperationException("util class"); } - public static List all() { + public static List all() { return Arrays.asList( - new EC2SpotFleet(), + new SpotFleet(), + new EC2Fleet(), new AutoScalingGroupFleet() ); } - public static EC2Fleet get(final String id) { + public static Fleet get(final String id) { if (GET != null) return GET; - if (isEC2Fleet(id)) { + if (isSpotFleet(id)) { return EC2_SPOT_FLEET; + } else if(isEC2Fleet(id)) { + return EC2_FLEET; } else { return new AutoScalingGroupFleet(); } } - public static boolean isEC2Fleet(final String fleet) { + 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(EC2Fleet ec2Fleet) { - GET = ec2Fleet; + public static void setGet(Fleet fleet) { + GET = fleet; } } diff --git a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleet.java b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleet.java similarity index 99% rename from src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleet.java rename to src/main/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleet.java index ada18da2..c839d848 100644 --- a/src/main/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleet.java +++ b/src/main/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleet.java @@ -31,7 +31,7 @@ * https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-requests.html#spot-fleet-states */ @ThreadSafe -public class EC2SpotFleet implements EC2Fleet { +public class SpotFleet implements Fleet { @Override public void describe( diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/config.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/config.jelly similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/config.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/config.jelly diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-cloudStatusIntervalSec.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-cloudStatusIntervalSec.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-cloudStatusIntervalSec.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-cloudStatusIntervalSec.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-disableTaskResubmit.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-disableTaskResubmit.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-disableTaskResubmit.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-disableTaskResubmit.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-endpoint.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-endpoint.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-endpoint.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-endpoint.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-fleet.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-fleet.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-fleet.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-fleet.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-idleMinutes.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-idleMinutes.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-idleMinutes.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-idleMinutes.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-initOnlineTimeoutSec.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-initOnlineTimeoutSec.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-initOnlineTimeoutSec.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-initOnlineTimeoutSec.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-maxTotalUses.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-maxTotalUses.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-maxTotalUses.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-maxTotalUses.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-minSpareSize.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-minSpareSize.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-minSpareSize.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-minSpareSize.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-name.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-name.html similarity index 68% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-name.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-name.html index 5d0a195f..5f49dbdf 100644 --- a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-name.html +++ b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-name.html @@ -1,5 +1,5 @@

- 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. + 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.

Could be used in Groovy as cloud identifier. diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-noDelayProvision.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-noDelayProvision.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-noDelayProvision.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-noDelayProvision.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-numExecutors.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-numExecutors.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-numExecutors.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-numExecutors.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-restrictUsage.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-restrictUsage.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-restrictUsage.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-restrictUsage.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-scaleExecutorsByWeight.html b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-scaleExecutorsByWeight.html similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/help-scaleExecutorsByWeight.html rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetCloud/help-scaleExecutorsByWeight.html diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/config.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/config.jelly similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloud/config.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetLabelCloud/config.jelly diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetNode/configure-entries.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetNode/configure-entries.jelly similarity index 100% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetNode/configure-entries.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetNode/configure-entries.jelly diff --git a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget/index.jelly b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetStatusWidget/index.jelly similarity index 93% rename from src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget/index.jelly rename to src/main/resources/com/amazon/jenkins/ec2fleet/FleetStatusWidget/index.jelly index f08b6281..0875b072 100644 --- a/src/main/resources/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidget/index.jelly +++ b/src/main/resources/com/amazon/jenkins/ec2fleet/FleetStatusWidget/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 5c92f6fc..73c4141b 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.EC2Fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.Fleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.DescribeInstancesRequest; import com.amazonaws.services.ec2.model.DescribeInstancesResult; @@ -45,14 +45,14 @@ public class AutoResubmitIntegrationTest extends IntegrationTest { @Before public void before() { - EC2Fleet ec2Fleet = mock(EC2Fleet.class); + Fleet fleet = mock(Fleet.class); - EC2Fleets.setGet(ec2Fleet); + Fleets.setGet(fleet); EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); - when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())).thenReturn( + when(fleet.getState(anyString(), anyString(), nullable(String.class), anyString())).thenReturn( new FleetStateStats("", 1, FleetStateStats.State.active(), Collections.singleton("i-1"), Collections.emptyMap())); @@ -73,7 +73,7 @@ public void before() { @Test public void should_successfully_resubmit_freestyle_task() throws Exception { - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, 0, 0, false, @@ -109,7 +109,7 @@ public void should_successfully_resubmit_freestyle_task() throws Exception { @Test public void should_successfully_resubmit_parametrized_task() throws Exception { - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, 0, 0, false, @@ -165,7 +165,7 @@ public void should_successfully_resubmit_parametrized_task() throws Exception { @Test public void should_not_resubmit_if_disabled() throws Exception { - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 0, 0, 10, 0, 1, false, true, "-1", true, 0, 0, false, 10, false); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java index ace23484..b3c4d845 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/CloudNamesTest.java @@ -11,7 +11,7 @@ public class CloudNamesTest { @Test public void isUnique_true() { - j.jenkins.clouds.add(new EC2FleetCloud("SomeDefaultName", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("SomeDefaultName", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -22,7 +22,7 @@ public void isUnique_true() { @Test public void isUnique_false() { - j.jenkins.clouds.add(new EC2FleetCloud("SomeDefaultName", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("SomeDefaultName", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -33,13 +33,13 @@ public void isUnique_false() { @Test public void isDuplicated_false() { - j.jenkins.clouds.add(new EC2FleetCloud("TestCloud", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("TestCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false)); - j.jenkins.clouds.add(new EC2FleetCloud("TestCloud2", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("TestCloud2", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -50,13 +50,13 @@ public void isDuplicated_false() { @Test public void isDuplicated_true() { - j.jenkins.clouds.add(new EC2FleetCloud("TestCloud", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("TestCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false)); - j.jenkins.clouds.add(new EC2FleetCloud("TestCloud", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("TestCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -72,7 +72,7 @@ public void generateUnique_noSuffix() { @Test public void generateUnique_addsSuffixOnlyWhenNeeded() { - j.jenkins.clouds.add(new EC2FleetCloud("UniqueCloud-1", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("UniqueCloud-1", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -83,12 +83,12 @@ public void generateUnique_addsSuffixOnlyWhenNeeded() { @Test public void generateUnique_addsSuffixCorrectly() { - j.jenkins.clouds.add(new EC2FleetCloud("UniqueCloud", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("UniqueCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false)); - j.jenkins.clouds.add(new EC2FleetCloud("UniqueCloud-1", null, null, null, null, null, + j.jenkins.clouds.add(new FleetCloud("UniqueCloud-1", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -101,31 +101,31 @@ public void generateUnique_addsSuffixCorrectly() { @Test public void generateUnique_emptyStringInConstructor() { - EC2FleetCloud fleetCloud = new EC2FleetCloud("", null, null, null, null, null, + FleetCloud fleetCloud = new FleetCloud("", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); - EC2FleetLabelCloud fleetLabelCloud = new EC2FleetLabelCloud("", null, null, + FleetLabelCloud fleetLabelCloud = new FleetLabelCloud("", 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(EC2FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); + Assert.assertTrue(fleetCloud.name.startsWith(FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); Assert.assertEquals(("FleetLabelCloud".length() + CloudNames.SUFFIX_LENGTH + 1), fleetLabelCloud.name.length()); - Assert.assertTrue(fleetLabelCloud.name.startsWith(EC2FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); + Assert.assertTrue(fleetLabelCloud.name.startsWith(FleetLabelCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); } @Test public void generateUnique_nonEmptyStringInConstructor() { - EC2FleetCloud fleetCloud = new EC2FleetCloud("UniqueCloud", null, null, null, null, null, + FleetCloud fleetCloud = new FleetCloud("UniqueCloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); - EC2FleetLabelCloud fleetLabelCloud = new EC2FleetLabelCloud("UniqueLabelCloud", null, null, + FleetLabelCloud fleetLabelCloud = new FleetLabelCloud("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 fb4075cf..22cf2c62 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 EC2FleetCloud cloud1; + private FleetCloud cloud1; @Mock - private EC2FleetCloud cloud2; + private FleetCloud 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 shouldIgnoreNonEC2FleetClouds() { + public void shouldIgnoreNonFleetClouds() { clouds.add(cloud1); Cloud nonEc2FleetCloud = mock(Cloud.class); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java index 01a1843e..e4b218f8 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyIntegrationTest.java @@ -1,13 +1,11 @@ package com.amazon.jenkins.ec2fleet; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.Fleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; 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; @@ -43,13 +41,13 @@ public class EC2RetentionStrategyIntegrationTest extends IntegrationTest { @Before public void before() { - final EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); final EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); amazonEC2 = mock(AmazonEC2.class); - when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) + 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())); when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); @@ -72,7 +70,7 @@ public void before() { @Test public void shouldTerminateNodeMarkedForDeletion() throws Exception { - final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 0, 0, 1, false, true, "-1", false, 0, 0, false, 999, false); // Set initial jenkins nodes @@ -81,8 +79,8 @@ public void shouldTerminateNodeMarkedForDeletion() throws Exception { assertAtLeastOneNode(); - EC2FleetNode node = (EC2FleetNode) j.jenkins.getNode("i-1"); - EC2FleetNodeComputer c = (EC2FleetNodeComputer) node.toComputer(); + FleetNode node = (FleetNode) j.jenkins.getNode("i-1"); + FleetNodeComputer c = (FleetNodeComputer) node.toComputer(); c.doDoDelete(); // mark node for termination node.getRetentionStrategy().check(c); @@ -96,7 +94,7 @@ public void shouldTerminateNodeMarkedForDeletion() throws Exception { @Test public void shouldTerminateExcessCapacity() throws Exception { - final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 0, 0, 1, false, true, "-1", false, 0, 0, false, 999, false); // Set initial jenkins nodes @@ -111,8 +109,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 EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { - EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); + if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { + FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -135,14 +133,14 @@ public void shouldNotTerminateExcessCapacityWhenNodeIsBusy() throws Exception { List rs = enqueTask(10, 90); triggerSuggestReviewNow(); - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 2, 2, 0, 1, false, true, "-1", false, 0, 0, false, 999, false); j.jenkins.clouds.add(cloud); cloud.update(); assertAtLeastOneNode(); - cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 0, 0, 1, false, true, "-1", false, 0, 0, false, 99, false); j.jenkins.clouds.clear(); @@ -154,8 +152,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 EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { - EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); + if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { + FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -167,7 +165,7 @@ public void shouldNotTerminateExcessCapacityWhenNodeIsBusy() throws Exception { @Test public void shouldTerminateIdleNodesAfterIdleTimeout() throws Exception { - final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 2, 0, 1, false, true, "-1", false, 0, 0, false, 99, false); j.jenkins.clouds.add(cloud); @@ -181,8 +179,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 EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { - EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); + if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { + FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -198,7 +196,7 @@ public void shouldTerminateIdleNodesAfterIdleTimeout() throws Exception { @Test public void shouldNotTerminateBelowMinSize() throws Exception { - final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 2, 5, 0, 1, false, true, "-1", false, 0, 0, false, 30, false); j.jenkins.clouds.add(cloud); @@ -210,8 +208,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 EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { - EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); + if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { + FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -222,7 +220,7 @@ public void shouldNotTerminateBelowMinSize() throws Exception { @Test public void shouldNotTerminateBelowMinSpareSize() throws Exception { - final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, new LocalComputerConnector(j), false, false, 1, 0, 5, 2, 1, false, true, "-1", false, 0, 0, false, 30, false); j.jenkins.clouds.add(cloud); @@ -234,8 +232,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 EC2FleetNode && ((EC2FleetNode) node).getCloud() == cloud) { - EC2FleetNodeComputer computer = (EC2FleetNodeComputer) ((EC2FleetNode) node).getComputer(); + if (node instanceof FleetNode && ((FleetNode) node).getCloud() == cloud) { + FleetNodeComputer computer = (FleetNodeComputer) ((FleetNode) node).getComputer(); new EC2RetentionStrategy().check(computer); } } @@ -251,7 +249,7 @@ public void shouldTerminateWhenMaxTotalUsesIsExhausted() throws Exception { final int maxTotalUses = 2; final int taskSleepTime = 1; - EC2FleetCloud cloud = spy(new EC2FleetCloud("testCloud", "credId", null, "region", + FleetCloud cloud = spy(new FleetCloud("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, false, 10, false)); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/EC2RetentionStrategyTest.java index 24e3b408..947078d3 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 EC2FleetCloud cloud; + private FleetCloud cloud; @Mock - private EC2FleetNodeComputer computer; + private FleetNodeComputer computer; @Mock - private EC2FleetNode node; + private FleetNode node; @Mock private Queue.Task task; diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncherTest.java similarity index 89% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncherTest.java index 06974bf6..0389aefb 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetAutoResubmitComputerLauncherTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetAutoResubmitComputerLauncherTest.java @@ -36,7 +36,7 @@ @SuppressWarnings("ArraysAsListWithZeroOrOneArgument") @RunWith(PowerMockRunner.class) @PrepareForTest({Jenkins.class, Queue.class, WorkflowJob.class, WorkflowRun.class}) -public class EC2FleetAutoResubmitComputerLauncherTest { +public class FleetAutoResubmitComputerLauncherTest { @Mock private ComputerLauncher baseComputerLauncher; @@ -62,7 +62,7 @@ public class EC2FleetAutoResubmitComputerLauncherTest { private Slave agent; @Mock - private EC2FleetNodeComputer computer; + private FleetNodeComputer computer; @Mock private Jenkins jenkins; @@ -83,10 +83,10 @@ public class EC2FleetAutoResubmitComputerLauncherTest { private Queue.Task task2; @Mock - private EC2FleetNode fleetNode; + private FleetNode fleetNode; @Mock - private EC2FleetCloud cloud; + private FleetCloud 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 EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(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 EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(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 EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(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 EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(baseComputerLauncher) .afterDisconnect(computer, taskListener); verifyZeroInteractions(queue); } @Test public void taskCompleted_should_resubmit_task_for_all_executors() { - new EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(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 EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(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 EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(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 EC2FleetAutoResubmitComputerLauncher(baseComputerLauncher) + new FleetAutoResubmitComputerLauncher(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/EC2FleetCloudConfigurationAsCodeTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudConfigurationAsCodeTest.java similarity index 80% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudConfigurationAsCodeTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudConfigurationAsCodeTest.java index 2d0dbc23..23d2c0b7 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudConfigurationAsCodeTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudConfigurationAsCodeTest.java @@ -1,10 +1,9 @@ package com.amazon.jenkins.ec2fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.Fleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; 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; @@ -24,32 +23,32 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -public class EC2FleetCloudConfigurationAsCodeTest { +public class FleetCloudConfigurationAsCodeTest { @Rule public JenkinsRule jenkinsRule = new JenkinsConfiguredWithCodeRule(); @Before public void before() { - final EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); - when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) + final Fleet fleet = mock(Fleet.class); + Fleets.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 = "EC2FleetCloud/name-required-configuration-as-code.yml", + value = "FleetCloud/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("EC2FleetCloud/min-configuration-as-code.yml") + @ConfiguredWithCode("FleetCloud/min-configuration-as-code.yml") public void shouldCreateCloudFromMinConfiguration() { assertEquals(jenkinsRule.jenkins.clouds.size(), 1); - EC2FleetCloud cloud = (EC2FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); + FleetCloud cloud = (FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); assertEquals("ec2-fleet", cloud.name); assertEquals(cloud.getRegion(), null); @@ -74,10 +73,10 @@ public void shouldCreateCloudFromMinConfiguration() { } @Test - @ConfiguredWithCode("EC2FleetCloud/max-configuration-as-code.yml") + @ConfiguredWithCode("FleetCloud/max-configuration-as-code.yml") public void shouldCreateCloudFromMaxConfiguration() { assertEquals(jenkinsRule.jenkins.clouds.size(), 1); - EC2FleetCloud cloud = (EC2FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); + FleetCloud cloud = (FleetCloud) jenkinsRule.jenkins.clouds.getByName("ec2-fleet"); assertEquals("ec2-fleet", cloud.name); assertEquals(cloud.getRegion(), "us-east-2"); @@ -106,13 +105,13 @@ public void shouldCreateCloudFromMaxConfiguration() { } @Test - @ConfiguredWithCode("EC2FleetCloud/empty-name-configuration-as-code.yml") + @ConfiguredWithCode("FleetCloud/empty-name-configuration-as-code.yml") public void configurationWithEmptyName_shouldUseDefault() { assertEquals(jenkinsRule.jenkins.clouds.size(), 3); - for (EC2FleetCloud cloud : jenkinsRule.jenkins.clouds.getAll(EC2FleetCloud.class)){ + for (FleetCloud cloud : jenkinsRule.jenkins.clouds.getAll(FleetCloud.class)){ - assertTrue(cloud.name.startsWith(EC2FleetCloud.BASE_DEFAULT_FLEET_CLOUD_ID)); + assertTrue(cloud.name.startsWith(FleetCloud.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/EC2FleetCloudTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudTest.java similarity index 85% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudTest.java index 623582e7..5a32df6f 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudTest.java @@ -1,12 +1,11 @@ package com.amazon.jenkins.ec2fleet; import com.amazon.jenkins.ec2fleet.aws.EC2Api; -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.fleet.*; +import com.amazon.jenkins.ec2fleet.fleet.SpotFleet; 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; @@ -79,9 +78,9 @@ @SuppressWarnings("unchecked") @RunWith(PowerMockRunner.class) -@PrepareForTest({Jenkins.class, EC2FleetCloud.class, EC2FleetCloud.DescriptorImpl.class, - LabelFinder.class, FleetStateStats.class, EC2Fleets.class, EC2FleetNodeComputer.class}) -public class EC2FleetCloudTest { +@PrepareForTest({Jenkins.class, FleetCloud.class, FleetCloud.DescriptorImpl.class, + LabelFinder.class, FleetStateStats.class, Fleets.class, FleetNodeComputer.class}) +public class FleetCloudTest { private SpotFleetRequestConfig spotFleetRequestConfig1; private SpotFleetRequestConfig spotFleetRequestConfig2; @@ -96,7 +95,7 @@ public class EC2FleetCloudTest { private Jenkins jenkins; @Mock - private EC2Fleet ec2Fleet; + private Fleet fleet; @Mock private EC2Api ec2Api; @@ -105,10 +104,10 @@ public class EC2FleetCloudTest { private AmazonEC2 amazonEC2; @Mock - private EC2FleetNodeComputer idleComputer; + private FleetNodeComputer idleComputer; @Mock - private EC2FleetNodeComputer busyComputer; + private FleetNodeComputer busyComputer; @Before public void before() { @@ -139,8 +138,8 @@ public void before() { Registry.setEc2Api(ec2Api); - PowerMockito.mockStatic(EC2Fleets.class); - when(EC2Fleets.get(anyString())).thenReturn(ec2Fleet); + PowerMockito.mockStatic(Fleets.class); + when(Fleets.get(anyString())).thenReturn(fleet); PowerMockito.mockStatic(FleetStateStats.class); PowerMockito.mockStatic(LabelFinder.class); @@ -159,7 +158,7 @@ public void after() { @Test public void canProvision_fleetIsNull(){ - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", null, "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -172,7 +171,7 @@ public void canProvision_fleetIsNull(){ @Test public void canProvision_restrictUsageLabelIsNull(){ - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, true, "-1", false, 0, 0, false, @@ -185,7 +184,7 @@ public void canProvision_restrictUsageLabelIsNull(){ @Test public void canProvision_LabelNotInLabelString(){ - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -198,7 +197,7 @@ public void canProvision_LabelNotInLabelString(){ @Test public void canProvision_LabelInLabelString(){ - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "label1 momo", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -218,11 +217,11 @@ public void provision_shouldProvisionNoneWhenMaxReached() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -244,11 +243,11 @@ public void provision_shouldProvisionNoneWhenMaxReachedAndNumExecutorsMoreOne() // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 8, 0, 3, true, false, "-1", false, 0, 0, false, @@ -270,11 +269,11 @@ public void provision_shouldProvisionNoneWhenMaxReachedAndNumExecutorsMoreOne1() // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 8, 0, 3, true, false, "-1", false, 0, 0, false, @@ -296,11 +295,11 @@ public void provision_shouldProvisionNoneWhenExceedMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 9, 0, 1, true, false, "-1", false, 0, 0, false, @@ -322,11 +321,11 @@ public void provision_shouldProvisionIfBelowMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -348,11 +347,11 @@ public void provision_shouldProvisionNoMoreMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -374,11 +373,11 @@ public void provision_shouldProvisionNoMoreMaxWhenMultipleCallBeforeUpdate() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -405,10 +404,10 @@ public void provision_shouldProvisionNoneIfNotYetUpdated() { when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); // Don't set the status - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(null); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, 0, false, @@ -428,10 +427,10 @@ public void scheduleToTerminate_shouldNotRemoveIfStatsNotUpdated() { when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); // Don't set the status - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(null); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, 0, false, @@ -449,11 +448,11 @@ public void scheduleToTerminate_notRemoveIfBelowMin() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, false, @@ -474,11 +473,11 @@ public void scheduleToTerminate_notRemoveIfEqualMin() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, false, @@ -499,12 +498,12 @@ public void scheduleToTerminate_notRemoveIfEqualMinSpare() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); when(jenkins.getComputers()).thenReturn(new Computer[0]); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 5, 1, 1, true, false, "-1", false, 0, 0, false, @@ -525,11 +524,11 @@ public void scheduleToTerminate_remove() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, false, @@ -551,11 +550,11 @@ public void scheduleToTerminate_upToZeroNodes() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, 0, false, @@ -582,11 +581,11 @@ public void scheduleToTerminate_removeNoMoreMinIfCalledMultipleBeforeUpdate() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 1, 1, 0, 1, true, false, "-1", false, 0, 0, false, @@ -615,11 +614,11 @@ public void update_shouldDoNothingIfNoTerminationOrProvisionAndFleetIsEmpty() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 1, 0, 1, true, false, "-1", false, 0, @@ -639,11 +638,11 @@ public void update_shouldIncreaseTargetCapacityWhenProvisioned() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -658,7 +657,7 @@ public void update_shouldIncreaseTargetCapacityWhenProvisioned() { fleetCloud.update(); // then - verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); + verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); } @Test @@ -668,10 +667,10 @@ public void update_shouldResetTerminateAndProvision() { final FleetStateStats currentState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(currentState); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -686,7 +685,7 @@ public void update_shouldResetTerminateAndProvision() { fleetCloud.update(); // then - verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(6), eq(0), eq(10)); + verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(6), eq(0), eq(10)); assertEquals(0, fleetCloud.getInstanceIdsToTerminate().size()); assertEquals(0, fleetCloud.getToAdd()); } @@ -696,11 +695,11 @@ public void update_shouldNotIncreaseMoreThenMax() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -717,7 +716,7 @@ public void update_shouldNotIncreaseMoreThenMax() { fleetCloud.update(); // then - verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(0), eq(0), eq(10)); + verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(0), eq(0), eq(10)); assertEquals(0, fleetCloud.getInstanceIdsToTerminate().size()); assertEquals(0, fleetCloud.getToAdd()); } @@ -727,11 +726,11 @@ public void update_shouldNotCountScheduledToTerminateWhenScaleUp() { // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -747,7 +746,7 @@ public void update_shouldNotCountScheduledToTerminateWhenScaleUp() { fleetCloud.update(); // then - verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(5), eq(0), eq(10)); + verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(5), eq(0), eq(10)); assertEquals(0, fleetCloud.getInstanceIdsToTerminate().size()); assertEquals(0, fleetCloud.getToAdd()); } @@ -757,11 +756,11 @@ public void update_shouldDecreaseTargetCapacityAndTerminateInstancesIfScheduled( // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 4, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, null, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, @@ -777,7 +776,7 @@ public void update_shouldDecreaseTargetCapacityAndTerminateInstancesIfScheduled( fleetCloud.update(); // then - verify(ec2Fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); + verify(fleet).modify(anyString(), anyString(), anyString(), eq("fleetId"), eq(2), eq(0), eq(10)); verify(ec2Api).terminateInstances(amazonEC2, new HashSet<>(Arrays.asList("i-1", "i-2"))); } @@ -796,13 +795,13 @@ public void update_shouldAddNodeIfAnyNewDescribed() throws IOException { when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, @@ -838,13 +837,13 @@ public void update_shouldTagNewNodesBeforeAdding() throws IOException { when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), new HashSet<>(Arrays.asList("i-0", "i-1")), Collections.emptyMap())); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 2, 0, 1, false, false, "-1", false, @@ -874,13 +873,13 @@ public void update_shouldTagNewNodesBeforeAddingWithFleetName() throws IOExcepti when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("my-fleet", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("my-fleet", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, @@ -915,13 +914,13 @@ public void update_givenFailedTaggingShouldIgnoreExceptionAndAddNode() throws IO when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, false, "-1", false, @@ -944,7 +943,7 @@ public void update_shouldAddNodeIfAnyNewDescribed_restrictUsage() throws IOExcep // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap())); @@ -959,7 +958,7 @@ public void update_shouldAddNodeIfAnyNewDescribed_restrictUsage() throws IOExcep mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -997,14 +996,14 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightProvidedButNotEnabled when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.singletonMap(instanceType, 1.1))); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1032,12 +1031,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(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, @@ -1054,7 +1053,7 @@ public void update_givenManuallyUpdatedFleetShouldCorrectLocalTargetCapacityToKe // then // should reset list to empty - verify(ec2Fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); + verify(fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); Assert.assertEquals(0, fleetCloud.getPlannedNodesCache().size()); } @@ -1069,12 +1068,12 @@ public void update_shouldTrimPlannedNodesIfExceedTargetCapacity() throws IOExcep final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, @@ -1117,12 +1116,12 @@ public void update_shouldTrimPlannedNodesBasedOnUpdatedTargetCapacityIfProvision final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - final EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0, 1, false, true, "-1", false, @@ -1140,7 +1139,7 @@ public Object answer(InvocationOnMock invocation) { fleetCloud.provision(new Cloud.CloudState(null, 0), 1); return null; } - }).when(ec2Fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); + }).when(fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); // when fleetCloud.update(); @@ -1169,12 +1168,12 @@ public void update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd() throws IO final FleetStateStats initState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, 0,1, false, true, "-1", false, @@ -1193,7 +1192,7 @@ public void update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd() throws IO } /** - * See {@link EC2FleetCloudTest#update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd()} + * See {@link FleetCloudTest#update_shouldUpdateStateWithFleetTargetCapacityPlusToAdd()} */ @Test public void update_shouldUpdateStateWithFleetTargetCapacityMinusToTerminate() throws IOException { @@ -1215,12 +1214,12 @@ public void update_shouldUpdateStateWithFleetTargetCapacityMinusToTerminate() th final FleetStateStats initState = new FleetStateStats("fleetId", 5, FleetStateStats.State.active(), Collections.singleton("i-0"), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10,0, 1, false, true, "-1", false, @@ -1250,12 +1249,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(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.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(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 2, 0, 1, false, false, "-1", false, @@ -1296,10 +1295,10 @@ public void update_shouldUpdateStateWithMinSpare() throws IOException { final FleetStateStats initState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap()); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(initState); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 10, minSpareSize, 1, false, true, "-1", false, @@ -1333,14 +1332,14 @@ public void update_shouldAddNodeWithScaledNumExecutors_whenWeightPresentAndEnabl when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 2.0))); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1375,14 +1374,14 @@ public void update_shouldAddNodeWithNumExecutors_whenWeightPresentAndEnabledButF when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap("diff-t", 2.0))); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1417,14 +1416,14 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 1.44))); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1459,20 +1458,20 @@ public void update_shouldAddNodeWithRoundToLowScaledNumExecutors_whenWeightPrese when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, 1.5))); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, 0, 0, true, 10, false); - ArgumentCaptor nodeCaptor = ArgumentCaptor.forClass(EC2FleetNode.class); + ArgumentCaptor nodeCaptor = ArgumentCaptor.forClass(FleetNode.class); doNothing().when(jenkins).addNode(nodeCaptor.capture()); // when @@ -1501,15 +1500,15 @@ public void update_shouldAddNodeWithScaledToOneNumExecutors_whenWeightPresentBut when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.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(ec2Fleet) + PowerMockito.doThrow(new UnsupportedOperationException("Test exception")).when(fleet) .modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1547,14 +1546,14 @@ public void update_givenFailedModifyShouldNotUpdateToAddToDelete() throws IOExce when(ec2Api.describeInstances(any(AmazonEC2.class), any(Set.class))).thenReturn( instanceIdMap); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), Collections.singleton(instanceId), Collections.singletonMap(instanceType, .1))); mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1593,7 +1592,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti FleetStateStats.State.modifying(""), Collections.singleton(instanceId), Collections.singletonMap(instanceType, .1)); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn(stats); + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn(stats); final FleetStateStats initialState = new FleetStateStats("fleetId", 0, FleetStateStats.State.active(), @@ -1602,7 +1601,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti mockNodeCreatingPart(); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1617,7 +1616,7 @@ public void update_givenFleetInModifyingShouldNotDoAnyUpdates() throws IOExcepti // then Assert.assertSame(initialState, newStats); Assert.assertSame(initialState, fleetCloud.getStats()); - verify(ec2Fleet, never()).modify(any(String.class), any(String.class), any(String.class), any(String.class), anyInt(), anyInt(), anyInt()); + verify(fleet, never()).modify(any(String.class), any(String.class), any(String.class), any(String.class), anyInt(), anyInt(), anyInt()); verify(jenkins, never()).addNode(any(Node.class)); } @@ -1626,13 +1625,13 @@ public void update_scheduledFuturesExecutesAfterTimeout() throws IOException, In // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); final int timeout = 1; - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0,1, true, false, "-1", false, timeout, 0, false, @@ -1657,13 +1656,13 @@ public void update_scheduledFuturesIsCancelledAfterUpdate() throws IOException, // given when(ec2Api.connect(any(String.class), any(String.class), anyString())).thenReturn(amazonEC2); - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); final int timeout = 1; - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "", "", null, null, false, false, 0, 0, 10, 0,1, true, false, "-1", false, timeout, 0, false, @@ -1686,11 +1685,11 @@ public void update_scheduledFuturesIsCancelledAfterUpdate() throws IOException, @Test public void update_shouldScaleUpToMinSize() { // given - PowerMockito.when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())) + PowerMockito.when(fleet.getState(anyString(), anyString(), anyString(), anyString())) .thenReturn(new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 1, 1, 0,1, false, true, "-1", false, @@ -1706,7 +1705,7 @@ public void update_shouldScaleUpToMinSize() { @Test public void removeScheduledFutures_success() { // given - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1727,7 +1726,7 @@ public void removeScheduledFutures_success() { @Test public void removeScheduledFutures_scheduledFutureIsEmpty() { // given - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1746,7 +1745,7 @@ public void removeScheduledFutures_scheduledFutureIsEmpty() { @Test public void removeScheduledFutures_numToRemoveIsZero() { // given - EC2FleetCloud fleetCloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud fleetCloud = new FleetCloud("TestCloud", "credId", null, "region", "", "fleetId", "", null, PowerMockito.mock(ComputerConnector.class), false, false, 0, 0, 1, 0, 1, false, true, "-1", false, @@ -1769,7 +1768,7 @@ public void descriptorImpl_doFillRegionItems_returnStaticRegionsIfApiCallFailed( AmazonEC2Client amazonEC2Client = mock(AmazonEC2Client.class); when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(amazonEC2Client); - ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r = new FleetCloud.DescriptorImpl().doFillRegionItems(""); HashSet staticRegions = new HashSet<>(RegionInfo.getRegionNames()); staticRegions.addAll(RegionUtils.getRegions().stream().map(com.amazonaws.regions.Region::getName).collect(Collectors.toSet())); @@ -1783,7 +1782,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 EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + final FormValidation formValidation = new FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); Assert.assertTrue(formValidation.getMessage().contains("Success")); } @@ -1794,7 +1793,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 EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + final FormValidation formValidation = new FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); Assert.assertThat(formValidation.getMessage(), Matchers.containsString(AwsPermissionChecker.FleetAPI.DescribeInstances.name())); } @@ -1809,7 +1808,7 @@ public void descriptorImpl_doTestConnection_missingMultiplePermissions() throws when(awsPermissionChecker.getMissingPermissions(null)).thenReturn(missingPermissions); PowerMockito.whenNew(AwsPermissionChecker.class).withAnyArguments().thenReturn(awsPermissionChecker); - final FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doTestConnection("credentials", null, null, null); + final FormValidation formValidation = new FleetCloud.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())); @@ -1821,7 +1820,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 EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r = new FleetCloud.DescriptorImpl().doFillRegionItems(""); HashSet staticRegions = new HashSet<>(RegionInfo.getRegionNames()); staticRegions.addAll(RegionUtils.getRegions().stream().map(com.amazonaws.regions.Region::getName).collect(Collectors.toSet())); @@ -1837,7 +1836,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 EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); + final ListBoxModel regionsListBoxModel = new FleetCloud.DescriptorImpl().doFillRegionItems(""); boolean isPresent = false; for (final ListBoxModel.Option item : regionsListBoxModel) { @@ -1860,7 +1859,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 EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); + final ListBoxModel regionsListBoxModel = new FleetCloud.DescriptorImpl().doFillRegionItems(""); boolean isPresent = false; for (final ListBoxModel.Option item : regionsListBoxModel) { @@ -1880,9 +1879,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 EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); - ListBoxModel r2 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); - ListBoxModel r3 = new EC2FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r1 = new FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r2 = new FleetCloud.DescriptorImpl().doFillRegionItems(""); + ListBoxModel r3 = new FleetCloud.DescriptorImpl().doFillRegionItems(""); assertEquals(r1.toString(), r2.toString()); assertEquals(r2.toString(), r3.toString()); @@ -1890,19 +1889,19 @@ public void descriptorImpl_doFillRegionItems_returnConsistOrderBetweenCalls() { @Test public void descriptorImpl_doCheckFleetName_validName() { - FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet("FleetCloud"); + FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet("FleetCloud"); assertEquals(formValidation.kind, Kind.OK); } @Test public void descriptorImpl_doCheckFleetName_invalidName() { - FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet(null); + FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet(null); assertEquals(formValidation.kind, Kind.ERROR); } @Test - public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyEC2Fleet() { - ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( + public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyFleet() { + ListBoxModel r = new FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); assertEquals(1, r.size()); @@ -1910,12 +1909,12 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfNoEmptyEC2Fleet() { } @Test - 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)); + 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)); - ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( + ListBoxModel r = new FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); assertEquals(1, r.size()); @@ -1926,14 +1925,14 @@ public void descriptorImpl_doFillFleetItems_returnFleetsProvidedByAllEC2Fleets() @Test public void descriptorImpl_doFillFleetItems_returnEmptyListIfAnyException() { - final EC2Fleet ec2SpotFleet = mock(EC2SpotFleet.class); + final Fleet ec2SpotFleet = mock(SpotFleet.class); doThrow(new RuntimeException("test")).when(ec2SpotFleet).describe( anyString(), anyString(), anyString(), any(ListBoxModel.class), anyString(), anyBoolean()); - final EC2Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); - when(EC2Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); + final Fleet autoScalingGroupFleet = mock(AutoScalingGroupFleet.class); + when(Fleets.all()).thenReturn(Arrays.asList(ec2SpotFleet, autoScalingGroupFleet)); - ListBoxModel r = new EC2FleetCloud.DescriptorImpl().doFillFleetItems( + ListBoxModel r = new FleetCloud.DescriptorImpl().doFillFleetItems( false, "", "", "", ""); assertEquals(1, r.size()); @@ -1942,20 +1941,20 @@ public void descriptorImpl_doFillFleetItems_returnEmptyListIfAnyException() { @Test public void descriptorImpl_doCheckFleet_default() { - FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet(""); + FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet(""); assertEquals(formValidation.kind, Kind.ERROR); } @Test public void descriptorImpl_doCheckFleet_nonDefault() { - FormValidation formValidation = new EC2FleetCloud.DescriptorImpl().doCheckFleet("ASG1"); + FormValidation formValidation = new FleetCloud.DescriptorImpl().doCheckFleet("ASG1"); assertEquals(formValidation.kind, Kind.OK); } @Test public void getDisplayName_returnDisplayName() { - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -1967,7 +1966,7 @@ public void getDisplayName_returnDisplayName() { @Test public void getAwsCredentialsId_returnNull_whenNoCredentialsIdOrAwsCredentialsId() { - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "TestCloud", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -1979,7 +1978,7 @@ public void getAwsCredentialsId_returnNull_whenNoCredentialsIdOrAwsCredentialsId @Test public void getAwsCredentialsId_returnValue_whenCredentialsIdPresent() { - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "TestCloud", null, "Opa", null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -1991,7 +1990,7 @@ public void getAwsCredentialsId_returnValue_whenCredentialsIdPresent() { @Test public void getAwsCredentialsId_returnValue_whenAwsCredentialsIdPresent() { - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "TestCloud", "Opa", null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -2003,7 +2002,7 @@ public void getAwsCredentialsId_returnValue_whenAwsCredentialsIdPresent() { @Test public void getAwsCredentialsId_returnAwsCredentialsId_whenAwsCredentialsIdAndCredentialsIdPresent() { - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "TestCloud", "A", "B", null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -2017,7 +2016,7 @@ public void getAwsCredentialsId_returnAwsCredentialsId_whenAwsCredentialsIdAndCr @Test public void getCloudStatusInterval_returnCloudStatusInterval() { - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -2029,7 +2028,7 @@ public void getCloudStatusInterval_returnCloudStatusInterval() { @Test public void create_numExecutorsLessThenOneShouldUpgradedToOne() { - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -2042,7 +2041,7 @@ public void create_numExecutorsLessThenOneShouldUpgradedToOne() { @Test public void hasUnlimitedUsesForNodes_shouldReturnTrueWhenUnlimited() { final int maxTotalUses = -1; - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -2055,7 +2054,7 @@ public void hasUnlimitedUsesForNodes_shouldReturnTrueWhenUnlimited() { @Test public void hasUnlimitedUsesForNodes_shouldReturnDefaultTrueForNull() { final String maxTotalUses = null; - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -2068,7 +2067,7 @@ public void hasUnlimitedUsesForNodes_shouldReturnDefaultTrueForNull() { @Test public void hasUnlimitedUsesForNodes_shouldReturnDefaultTrueForEmptyString() { final String maxTotalUses = ""; - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, @@ -2081,7 +2080,7 @@ public void hasUnlimitedUsesForNodes_shouldReturnDefaultTrueForEmptyString() { @Test public void hasUnlimitedUsesForNodes_shouldReturnFalseWhenLimited() { final int maxTotalUses = 5; - EC2FleetCloud ec2FleetCloud = new EC2FleetCloud( + FleetCloud ec2FleetCloud = new FleetCloud( "CloudName", null, null, null, null, null, null, null, null, false, false, null, 0, 1, 0, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithHistory.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithHistory.java similarity index 95% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithHistory.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithHistory.java index 54877c8a..3a9814a8 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithHistory.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithHistory.java @@ -8,11 +8,11 @@ import java.util.concurrent.CopyOnWriteArrayList; -public class EC2FleetCloudWithHistory extends EC2FleetCloud { +public class FleetCloudWithHistory extends FleetCloud { public CopyOnWriteArrayList provisionTimes = new CopyOnWriteArrayList<>(); - public EC2FleetCloudWithHistory( + public FleetCloudWithHistory( 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/EC2FleetCloudWithMeter.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithMeter.java similarity index 95% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithMeter.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithMeter.java index 18828334..184d90c6 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetCloudWithMeter.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetCloudWithMeter.java @@ -7,13 +7,13 @@ import java.util.Collection; -public class EC2FleetCloudWithMeter extends EC2FleetCloud { +public class FleetCloudWithMeter extends FleetCloud { public final Meter updateMeter = new Meter("update"); public final Meter provisionMeter = new Meter("provision"); public final Meter removeMeter = new Meter("remove"); - public EC2FleetCloudWithMeter( + public FleetCloudWithMeter( 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/EC2FleetLabelCloudIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudIntegrationTest.java similarity index 88% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudIntegrationTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudIntegrationTest.java index 4f61a3c0..d290fea7 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelCloudIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelCloudIntegrationTest.java @@ -17,7 +17,7 @@ import static org.mockito.ArgumentMatchers.any; -public class EC2FleetLabelCloudIntegrationTest extends IntegrationTest { +public class FleetLabelCloudIntegrationTest 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 { - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); + mockFleetApiToSpotFleet(InstanceStateName.Running); mockCloudFormationApi(); - EC2FleetLabelCloud cloud = new EC2FleetLabelCloud("FleetLabel", "credId", "region", + FleetLabelCloud cloud = new FleetLabelCloud("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 { - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); + mockFleetApiToSpotFleet(InstanceStateName.Running); final AmazonCloudFormation amazonCloudFormation = mockCloudFormationApi(); - EC2FleetLabelCloud cloud = new EC2FleetLabelCloud("FleetLabel", "credId", "region", + FleetLabelCloud cloud = new FleetLabelCloud("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/EC2FleetLabelParametersTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelParametersTest.java similarity index 69% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParametersTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelParametersTest.java index c49b3a0d..e249e5c3 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetLabelParametersTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetLabelParametersTest.java @@ -3,23 +3,23 @@ import org.junit.Assert; import org.junit.Test; -public class EC2FleetLabelParametersTest { +public class FleetLabelParametersTest { @Test public void parse_emptyForEmptyString() { - final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(""); + final FleetLabelParameters parameters = new FleetLabelParameters(""); Assert.assertNull(parameters.get("aa")); } @Test public void parse_emptyForNullString() { - final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters(null); + final FleetLabelParameters parameters = new FleetLabelParameters(null); Assert.assertNull(parameters.get("aa")); } @Test public void parse_forString() { - final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("a=1,b=2"); + final FleetLabelParameters parameters = new FleetLabelParameters("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 EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("aBc=1"); + final FleetLabelParameters parameters = new FleetLabelParameters("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 EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("AA_a=1,b=2"); + final FleetLabelParameters parameters = new FleetLabelParameters("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 EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("_a=1,b=2"); + final FleetLabelParameters parameters = new FleetLabelParameters("_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 EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("_"); + final FleetLabelParameters parameters = new FleetLabelParameters("_"); Assert.assertNull(parameters.get("c")); } @Test public void parse_skipParameterWithoutValue() { - final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("withoutValue,b=2"); + final FleetLabelParameters parameters = new FleetLabelParameters("withoutValue,b=2"); Assert.assertEquals("2", parameters.get("b")); Assert.assertNull(parameters.get("withoutValue")); } @Test public void parse_skipParameterWithEmptyValue() { - final EC2FleetLabelParameters parameters = new EC2FleetLabelParameters("withoutValue=,b=2"); + final FleetLabelParameters parameters = new FleetLabelParameters("withoutValue=,b=2"); Assert.assertEquals("2", parameters.get("b")); Assert.assertNull(parameters.get("withoutValue")); } diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetNodeComputerTest.java similarity index 87% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetNodeComputerTest.java index 684aaafc..23bdded5 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetNodeComputerTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetNodeComputerTest.java @@ -17,10 +17,10 @@ @RunWith(PowerMockRunner.class) @PrepareForTest({Jenkins.class, Queue.class}) -public class EC2FleetNodeComputerTest { +public class FleetNodeComputerTest { @Mock - private EC2FleetNode agent; + private FleetNode 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); - EC2FleetNodeComputer computer = spy(new EC2FleetNodeComputer(agent)); + FleetNodeComputer computer = spy(new FleetNodeComputer(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); - EC2FleetNodeComputer computer = spy(new EC2FleetNodeComputer(agent)); + FleetNodeComputer computer = spy(new FleetNodeComputer(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/EC2FleetOnlineCheckerTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetOnlineCheckerTest.java similarity index 82% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetOnlineCheckerTest.java index 25f3691e..e5ea3947 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetOnlineCheckerTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetOnlineCheckerTest.java @@ -25,13 +25,13 @@ @RunWith(PowerMockRunner.class) -@PrepareForTest({EC2FleetOnlineChecker.class, EC2FleetNode.class, Jenkins.class, Computer.class}) -public class EC2FleetOnlineCheckerTest { +@PrepareForTest({FleetOnlineChecker.class, FleetNode.class, Jenkins.class, Computer.class}) +public class FleetOnlineCheckerTest { private CompletableFuture future = new CompletableFuture<>(); @Mock - private EC2FleetNode node; + private FleetNode node; @Mock private Computer computer; @@ -41,7 +41,7 @@ public class EC2FleetOnlineCheckerTest { @Before public void before() throws Exception { - when(node.getDisplayName()).thenReturn("MockEC2FleetCloud i-1"); + when(node.getDisplayName()).thenReturn("MockFleetCloud 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(EC2FleetNode.class).withAnyArguments().thenReturn(node); + PowerMockito.whenNew(FleetNode.class).withAnyArguments().thenReturn(node); } @Test public void shouldStopImmediatelyIfFutureIsCancelled() throws InterruptedException, ExecutionException { future.cancel(true); - EC2FleetOnlineChecker.start(node, future, 0, 0); + FleetOnlineChecker.start(node, future, 0, 0); try { future.get(); Assert.fail(); @@ -68,7 +68,7 @@ public void shouldStopImmediatelyIfFutureIsCancelled() throws InterruptedExcepti @Test public void shouldStopAndFailFutureIfTimeout() { - EC2FleetOnlineChecker.start(node, future, 100, 50); + FleetOnlineChecker.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); - EC2FleetOnlineChecker.start(node, future, TimeUnit.MINUTES.toMillis(1), 0); + FleetOnlineChecker.start(node, future, TimeUnit.MINUTES.toMillis(1), 0); Assert.assertSame(node, future.get()); } @Test public void shouldFinishWithNodeWhenTimeoutIsZeroWithoutCheck() throws InterruptedException, ExecutionException { - EC2FleetOnlineChecker.start(node, future, 0, 0); + FleetOnlineChecker.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 { - EC2FleetOnlineChecker.start(node, future, 10, 0); + FleetOnlineChecker.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); - EC2FleetOnlineChecker.start(node, future, 100, 10); + FleetOnlineChecker.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); - EC2FleetOnlineChecker.start(node, future, 100, 10); + FleetOnlineChecker.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/EC2FleetStatusWidgetUpdaterTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdaterTest.java similarity index 68% rename from src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdaterTest.java index 73980aaa..a5828a64 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/EC2FleetStatusWidgetUpdaterTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/FleetStatusWidgetUpdaterTest.java @@ -23,20 +23,20 @@ import static org.mockito.Mockito.when; @RunWith(PowerMockRunner.class) -@PrepareForTest(EC2FleetStatusWidgetUpdater.class) -public class EC2FleetStatusWidgetUpdaterTest { +@PrepareForTest(FleetStatusWidgetUpdater.class) +public class FleetStatusWidgetUpdaterTest { @Mock - private EC2FleetCloud cloud1; + private FleetCloud cloud1; @Mock - private EC2FleetCloud cloud2; + private FleetCloud cloud2; @Mock - private EC2FleetStatusWidget widget1; + private FleetStatusWidget widget1; @Mock - private EC2FleetStatusWidget widget2; + private FleetStatusWidget widget2; private List widgets = new ArrayList<>(); @@ -50,9 +50,9 @@ public class EC2FleetStatusWidgetUpdaterTest { @Before public void before() throws Exception { - PowerMockito.mockStatic(EC2FleetStatusWidgetUpdater.class); - PowerMockito.when(EC2FleetStatusWidgetUpdater.class, "getClouds").thenReturn(clouds); - PowerMockito.when(EC2FleetStatusWidgetUpdater.class, "getWidgets").thenReturn(widgets); + PowerMockito.mockStatic(FleetStatusWidgetUpdater.class); + PowerMockito.when(FleetStatusWidgetUpdater.class, "getClouds").thenReturn(clouds); + PowerMockito.when(FleetStatusWidgetUpdater.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 EC2FleetStatusWidgetUpdater getMockEC2FleetStatusWidgetUpdater() { - return Whitebox.newInstance(EC2FleetStatusWidgetUpdater.class); + private FleetStatusWidgetUpdater getMockFleetStatusWidgetUpdater() { + return Whitebox.newInstance(FleetStatusWidgetUpdater.class); } @Test public void shouldDoNothingIfNoCloudsAndWidgets() { - getMockEC2FleetStatusWidgetUpdater().doRun(); + getMockFleetStatusWidgetUpdater().doRun(); } @Test @@ -77,13 +77,13 @@ public void shouldDoNothingIfNoWidgets() { clouds.add(cloud1); clouds.add(cloud2); - getMockEC2FleetStatusWidgetUpdater().doRun(); + getMockFleetStatusWidgetUpdater().doRun(); verifyZeroInteractions(widget1, widget2); } @Test - public void shouldIgnoreNonEC2FleetClouds() { + public void shouldIgnoreNonFleetClouds() { clouds.add(cloud1); Cloud nonEc2FleetCloud = mock(Cloud.class); @@ -91,7 +91,7 @@ public void shouldIgnoreNonEC2FleetClouds() { widgets.add(widget2); - getMockEC2FleetStatusWidgetUpdater().doRun(); + getMockFleetStatusWidgetUpdater().doRun(); verify(cloud1).getStats(); verifyZeroInteractions(nonEc2FleetCloud); @@ -104,11 +104,11 @@ public void shouldUpdateCloudCollectAllResultAndUpdateWidgets() { widgets.add(widget1); - getMockEC2FleetStatusWidgetUpdater().doRun(); + getMockFleetStatusWidgetUpdater().doRun(); verify(widget1).setStatusList(Arrays.asList( - 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()) + 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()) )); } @@ -122,7 +122,7 @@ public void shouldIgnoreNonEc2FleetWidgets() { widgets.add(widget1); - getMockEC2FleetStatusWidgetUpdater().doRun(); + getMockFleetStatusWidgetUpdater().doRun(); verify(widget1).setStatusList(any(List.class)); verifyZeroInteractions(nonEc2FleetWidget); diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/IntegrationTest.java index 62fd0ee8..061c78e8 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.EC2Fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; -import com.amazon.jenkins.ec2fleet.fleet.EC2SpotFleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; +import com.amazon.jenkins.ec2fleet.fleet.SpotFleet; import com.amazonaws.services.cloudformation.AmazonCloudFormation; import com.amazonaws.services.cloudformation.model.CreateStackRequest; import com.amazonaws.services.cloudformation.model.CreateStackResult; @@ -16,22 +16,7 @@ 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.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.amazonaws.services.ec2.model.*; import com.gargoylesoftware.htmlunit.html.DomElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.Functions; @@ -104,7 +89,7 @@ public void after() { // restore Registry.setEc2Api(new EC2Api()); Registry.setCloudFormationApi(new CloudFormationApi()); - EC2Fleets.setGet(null); + Fleets.setGet(null); } protected static void turnOffJenkinsTestTimout() { @@ -231,7 +216,7 @@ public void run() { }, TimeUnit.MINUTES.toMillis(3)); } - protected static void waitFirstStats(final EC2FleetCloud cloud) { + protected static void waitFirstStats(final FleetCloud cloud) { System.out.println("waiting first stats for cloud"); tryUntil(new Runnable() { @Override @@ -320,19 +305,19 @@ public T answer(InvocationOnMock invocation) throws Throwable { } - protected void mockEc2FleetApiToEc2SpotFleet(final InstanceStateName instanceStateName) { - mockEc2FleetApiToEc2SpotFleetWithDelay(instanceStateName, 0, 0); + protected void mockFleetApiToSpotFleet(final InstanceStateName instanceStateName) { + mockFleetApiToSpotFleetWithDelay(instanceStateName, 0, 0); } - protected void mockEc2FleetApiToEc2SpotFleet(final InstanceStateName instanceStateName, final int initialTargetCapacity) { - mockEc2FleetApiToEc2SpotFleetWithDelay(instanceStateName, initialTargetCapacity, 0); + protected void mockFleetApiToSpotFleet(final InstanceStateName instanceStateName, final int initialTargetCapacity) { + mockFleetApiToSpotFleetWithDelay(instanceStateName, initialTargetCapacity, 0); } - protected void mockEc2FleetApiToEc2SpotFleetWithDelay(final InstanceStateName instanceStateName, final long delayMillis) { - mockEc2FleetApiToEc2SpotFleetWithDelay(instanceStateName, 0, delayMillis); + protected void mockFleetApiToSpotFleetWithDelay(final InstanceStateName instanceStateName, final long delayMillis) { + mockFleetApiToSpotFleetWithDelay(instanceStateName, 0, delayMillis); } - protected void mockEc2FleetApiToEc2SpotFleetWithDelay(final InstanceStateName instanceStateName, final int initialTargetCapacity, final long delayMillis) { + protected void mockFleetApiToSpotFleetWithDelay(final InstanceStateName instanceStateName, final int initialTargetCapacity, final long delayMillis) { EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); @@ -369,8 +354,8 @@ public Object answer(InvocationOnMock invocationOnMock) { final AtomicInteger targetCapacity = new AtomicInteger(0); - // force to use ec2 fleet - EC2Fleets.setGet(new EC2SpotFleet()); + // force to use spot fleet + Fleets.setGet(new SpotFleet()); when(amazonEC2.modifySpotFleetRequest(any(ModifySpotFleetRequestRequest.class))) .then(AnswerWithDelay.get(new Answer() { @@ -486,7 +471,7 @@ public Object answer(InvocationOnMock invocation) { return amazonCloudFormation; } - protected void mockEc2FleetApi() { + protected void mockFleetApi() { EC2Api ec2Api = mock(EC2Api.class); Registry.setEc2Api(ec2Api); @@ -503,8 +488,8 @@ public Object answer(InvocationOnMock invocationOnMock) { final AtomicInteger targetCapacity = new AtomicInteger(0); - final EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); doAnswer(new Answer() { @Override @@ -513,9 +498,9 @@ public Object answer(InvocationOnMock invocation) throws Throwable { targetCapacity.set(argument.getTargetCapacity()); return null; } - }).when(ec2Fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); + }).when(fleet).modify(anyString(), anyString(), anyString(), anyString(), anyInt(), anyInt(), anyInt()); - when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())).thenAnswer(new Answer() { + when(fleet.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 eb2b0463..92286db6 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyPerformanceTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyPerformanceTest.java @@ -1,7 +1,6 @@ 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; @@ -49,11 +48,11 @@ private void test(final boolean noDelay) throws IOException, InterruptedExceptio final int scheduleInterval = 15; final int batchSize = 9; - mockEc2FleetApiToEc2SpotFleetWithDelay(InstanceStateName.Running, 500); + mockFleetApiToSpotFleetWithDelay(InstanceStateName.Running, 500); final ComputerConnector computerConnector = new LocalComputerConnector(j); final String label = "momo"; - final EC2FleetCloudWithHistory cloud = new EC2FleetCloudWithHistory(null, "credId", null, "region", + final FleetCloudWithHistory cloud = new FleetCloudWithHistory(null, "credId", null, "region", null, "fId", label, null, computerConnector, false, false, 1, 0, maxWorkers, 0, 1, true, false, false, 0, 0, false, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/NoDelayProvisionStrategyTest.java index 66c487c7..9fcfd26b 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 EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); - clouds.add(ec2FleetCloud); + final FleetCloud fleetCloud = mock(FleetCloud.class); + clouds.add(fleetCloud); strategy.apply(state); - verify(ec2FleetCloud, never()).canProvision(any(Cloud.CloudState.class)); + verify(fleetCloud, never()).canProvision(any(Cloud.CloudState.class)); } @Test public void givenAvailableSameAsRequiredCapacity_shouldDoNotScale() { - final EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); - clouds.add(ec2FleetCloud); + final FleetCloud fleetCloud = mock(FleetCloud.class); + clouds.add(fleetCloud); 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(ec2FleetCloud, never()).canProvision(any(Cloud.CloudState.class)); + verify(fleetCloud, 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 EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); - clouds.add(ec2FleetCloud); - when(ec2FleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(ec2FleetCloud.isNoDelayProvision()).thenReturn(false); + final FleetCloud fleetCloud = mock(FleetCloud.class); + clouds.add(fleetCloud); + when(fleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(fleetCloud.isNoDelayProvision()).thenReturn(false); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); - verify(ec2FleetCloud, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(fleetCloud, 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 EC2FleetCloud ec2FleetCloud = mock(EC2FleetCloud.class); - clouds.add(ec2FleetCloud); - when(ec2FleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(false); + final FleetCloud fleetCloud = mock(FleetCloud.class); + clouds.add(fleetCloud); + when(fleetCloud.canProvision(any(Cloud.CloudState.class))).thenReturn(false); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); - verify(ec2FleetCloud, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(fleetCloud, 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 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); + 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); Assert.assertEquals( NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES, strategy.apply(state)); ArgumentCaptor cloudStateArgCaptor = ArgumentCaptor.forClass(Cloud.CloudState.class); - verify(ec2FleetCloud1, times(1)).provision(cloudStateArgCaptor.capture(), eq(10)); + verify(fleetCloud1, times(1)).provision(cloudStateArgCaptor.capture(), eq(10)); Assert.assertEquals(label, cloudStateArgCaptor.getValue().getLabel()); Assert.assertEquals(0, cloudStateArgCaptor.getValue().getAdditionalPlannedCapacity()); - verify(ec2FleetCloud2, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(fleetCloud2, 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 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( + 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( 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(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(2)); - verify(ec2FleetCloud2, never()).provision(any(Cloud.CloudState.class), anyInt()); + verify(fleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(2)); + verify(fleetCloud2, 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 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( + 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( 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(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(5)); - verify(ec2FleetCloud2, times(1)).provision(any(Cloud.CloudState.class), eq(3)); + verify(fleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(5)); + verify(fleetCloud2, 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 EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); - clouds.add(ec2FleetCloud1); - when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true); + final FleetCloud fleetCloud1 = mock(FleetCloud.class); + clouds.add(fleetCloud1); + when(fleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(fleetCloud1.isNoDelayProvision()).thenReturn(true); final NodeProvisioner.PlannedNode plannedNode = new NodeProvisioner.PlannedNode("", new CompletableFuture<>(), 2); - when(ec2FleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode)); + when(fleetCloud1.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(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(2)); + verify(fleetCloud1, 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 EC2FleetCloud ec2FleetCloud1 = mock(EC2FleetCloud.class); - clouds.add(ec2FleetCloud1); - when(ec2FleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(ec2FleetCloud1.isNoDelayProvision()).thenReturn(true); + final FleetCloud fleetCloud1 = mock(FleetCloud.class); + clouds.add(fleetCloud1); + when(fleetCloud1.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(fleetCloud1.isNoDelayProvision()).thenReturn(true); final NodeProvisioner.PlannedNode plannedNode1 = new NodeProvisioner.PlannedNode("fc1-0", new CompletableFuture<>(), 2); - when(ec2FleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode1)); + when(fleetCloud1.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode1)); - final EC2FleetCloud ec2FleetCloud2 = mock(EC2FleetCloud.class); - clouds.add(ec2FleetCloud2); - when(ec2FleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); - when(ec2FleetCloud2.isNoDelayProvision()).thenReturn(true); + final FleetCloud fleetCloud2 = mock(FleetCloud.class); + clouds.add(fleetCloud2); + when(fleetCloud2.canProvision(any(Cloud.CloudState.class))).thenReturn(true); + when(fleetCloud2.isNoDelayProvision()).thenReturn(true); final NodeProvisioner.PlannedNode plannedNode2 = new NodeProvisioner.PlannedNode("fc2-0", new CompletableFuture<>(), 1); - when(ec2FleetCloud2.provision(any(Cloud.CloudState.class), anyInt())).thenReturn(Arrays.asList(plannedNode2)); + when(fleetCloud2.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(ec2FleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(3)); - verify(ec2FleetCloud2, times(1)).provision(any(Cloud.CloudState.class), eq(1)); + verify(fleetCloud1, times(1)).provision(any(Cloud.CloudState.class), eq(3)); + verify(fleetCloud2, 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 66094aee..46904e16 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.EC2Fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.Fleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.amazonaws.services.ec2.model.ActiveInstance; import com.amazonaws.services.ec2.model.DescribeInstancesRequest; @@ -59,13 +59,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 EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); - when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); + when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 0, 0, 1, true, false, "-1", false, 0, 0, false, @@ -97,9 +97,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); - mockEc2FleetApi(); + mockFleetApi(); - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -129,12 +129,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 EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); - when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); + when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud cloud = spy(new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = spy(new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 300, 15, false, @@ -142,7 +142,7 @@ public void should_keep_planned_node_until_node_will_not_be_online_so_jenkins_wi j.jenkins.clouds.add(cloud); - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); + mockFleetApiToSpotFleet(InstanceStateName.Running); List rs = enqueTask(1); @@ -163,19 +163,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 EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); - when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); + when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - final EC2FleetCloud cloud = spy(new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud cloud = spy(new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, 10, false)); j.jenkins.clouds.add(cloud); - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); + mockFleetApiToSpotFleet(InstanceStateName.Running); enqueTask(1); @@ -190,13 +190,13 @@ public void run() { @Test public void should_not_allow_jenkins_to_provision_if_address_not_available() throws Exception { - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); + mockFleetApiToSpotFleet(InstanceStateName.Running); ComputerLauncher computerLauncher = mock(ComputerLauncher.class); ComputerConnector computerConnector = mock(ComputerConnector.class); when(computerConnector.launch(anyString(), any(TaskListener.class))).thenReturn(computerLauncher); - EC2FleetCloud cloud = spy(new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = spy(new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, @@ -252,19 +252,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 EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); - when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); + when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 10, 0, 1, true, false, "-1", false, 0, 0, false, 2, false); j.jenkins.clouds.add(cloud); - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Pending); + mockFleetApiToSpotFleet(InstanceStateName.Pending); final List rs = enqueTask(1); @@ -289,19 +289,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 EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); - when(ec2Fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); + when(fleet.getState(anyString(), anyString(), anyString(), anyString())).thenReturn( new FleetStateStats("", 0, FleetStateStats.State.active(), Collections.emptySet(), Collections.emptyMap())); - EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 0, 0, 2, 0, 1, true, false, "-1", false, 0, 0, false, 2, false); j.jenkins.clouds.add(cloud); - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running); + mockFleetApiToSpotFleet(InstanceStateName.Running); final List rs = enqueTask(2); @@ -322,10 +322,10 @@ public void run() { @Test public void should_continue_update_after_termination() throws IOException { - mockEc2FleetApiToEc2SpotFleet(InstanceStateName.Running, 5); + mockFleetApiToSpotFleet(InstanceStateName.Running, 5); final ComputerConnector computerConnector = new LocalComputerConnector(j); - final EC2FleetCloud cloud = new EC2FleetCloud("TestCloud", "credId", null, "region", + final FleetCloud cloud = new FleetCloud("TestCloud", "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 1, 0, 5, 0, 1, true, false, "-1", false, 0, 0, false, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java index f835d804..9b1539d2 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionPerformanceTest.java @@ -36,10 +36,10 @@ public void spikeLoadWorkers20Tasks60() throws Exception { } private void test(int workers, int maxTasks) throws IOException, InterruptedException { - mockEc2FleetApiToEc2SpotFleetWithDelay(InstanceStateName.Running, 500); + mockFleetApiToSpotFleetWithDelay(InstanceStateName.Running, 500); final ComputerConnector computerConnector = new LocalComputerConnector(j); - final EC2FleetCloudWithMeter cloud = new EC2FleetCloudWithMeter(null, "credId", null, "region", + final FleetCloudWithMeter cloud = new FleetCloudWithMeter(null, "credId", null, "region", null, "fId", "momo", null, computerConnector, false, false, 1, 0, workers, 0, 1, true, false, false, 0, 0, false, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java index fcff137f..292854a0 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/RealTest.java @@ -129,7 +129,7 @@ public void run() { final SSHConnector computerConnector = new SSHConnector( 22, sshCredentialId, null, null, null, null, null, null, null, new NonVerifyingKeyVerificationStrategy()); - final EC2FleetCloud cloud = new EC2FleetCloud( + final FleetCloud cloud = new FleetCloud( "TestCloud", credentialId, null, null, null, autoScalingGroupName, "momo", null, computerConnector, false, false, @@ -181,7 +181,7 @@ public void givenEc2SpotFleet_shouldScaleUpExecuteTaskAndScaleDown() throws Exce final SSHConnector computerConnector = new SSHConnector( 22, sshCredentialId, null, null, null, null, null, null, null, new NonVerifyingKeyVerificationStrategy()); - final EC2FleetCloud cloud = new EC2FleetCloud( + final FleetCloud cloud = new FleetCloud( "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 a8741f99..caa04283 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.EC2Fleet; -import com.amazon.jenkins.ec2fleet.fleet.EC2Fleets; +import com.amazon.jenkins.ec2fleet.fleet.Fleet; +import com.amazon.jenkins.ec2fleet.fleet.Fleets; import com.amazonaws.services.ec2.AmazonEC2; import com.gargoylesoftware.htmlunit.html.DomElement; @@ -56,13 +56,13 @@ public class UiIntegrationTest { @Before public void before() { - final EC2Fleet ec2Fleet = mock(EC2Fleet.class); - EC2Fleets.setGet(ec2Fleet); + final Fleet fleet = mock(Fleet.class); + Fleets.setGet(fleet); final EC2Api ec2Api = spy(EC2Api.class); Registry.setEc2Api(ec2Api); final AmazonEC2 amazonEC2 = mock(AmazonEC2.class); - when(ec2Fleet.getState(anyString(), anyString(), nullable(String.class), anyString())) + 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())); when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); } @@ -76,14 +76,14 @@ public void shouldFindThePluginByShortName() { @Test public void shouldShowNodeConfigurationPage() throws Exception { final String nodeName = "node-name"; - EC2FleetCloud cloud = new EC2FleetCloud("test-cloud", null, null, null, null, null, + FleetCloud cloud = new FleetCloud("test-cloud", null, null, null, null, null, "test-label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); - j.jenkins.addNode(new EC2FleetNode(nodeName, "", "", 1, + j.jenkins.addNode(new FleetNode(nodeName, "", "", 1, Node.Mode.EXCLUSIVE, "label", new ArrayList>(), cloud.name, j.createComputerLauncher(null), -1)); @@ -94,14 +94,14 @@ public void shouldShowNodeConfigurationPage() throws Exception { @Test public void shouldReplaceCloudForNodesAfterConfigurationSave() throws Exception { - EC2FleetCloud cloud = new EC2FleetCloud("test-cloud", null, null, null, null, "", + FleetCloud cloud = new FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud); - j.jenkins.addNode(new EC2FleetNode("mock", "", "", 1, + j.jenkins.addNode(new FleetNode("mock", "", "", 1, Node.Mode.EXCLUSIVE, "", new ArrayList>(), cloud.name, j.createComputerLauncher(null), -1)); @@ -115,12 +115,12 @@ public void shouldReplaceCloudForNodesAfterConfigurationSave() throws Exception final Cloud newCloud = j.jenkins.clouds.get(0); assertNotNull(newCloud); assertNotSame(cloud, newCloud); - assertSame(newCloud, ((EC2FleetNode) j.jenkins.getNode("mock")).getCloud()); + assertSame(newCloud, ((FleetNode) j.jenkins.getNode("mock")).getCloud()); } @Test public void shouldShowInConfigurationClouds() throws IOException, SAXException { - Cloud cloud = new EC2FleetCloud("TestCloud", null, null, null, null, null, + Cloud cloud = new FleetCloud("TestCloud", null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -134,14 +134,14 @@ public void shouldShowInConfigurationClouds() throws IOException, SAXException { @Test public void shouldShowMultipleClouds() throws IOException, SAXException { - Cloud cloud1 = new EC2FleetCloud("a", null, null, null, null, + Cloud cloud1 = new FleetCloud("a", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud1); - Cloud cloud2 = new EC2FleetCloud("b", null, null, null, null, + Cloud cloud2 = new FleetCloud("b", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -158,14 +158,14 @@ public void shouldShowMultipleClouds() throws IOException, SAXException { @Test public void shouldShowMultipleCloudsWithDefaultName() throws IOException, SAXException { - Cloud cloud1 = new EC2FleetCloud("TestCloud1", null, null, null, null, + Cloud cloud1 = new FleetCloud("TestCloud1", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud1); - Cloud cloud2 = new EC2FleetCloud("TestCloud2", null, null, null, null, + Cloud cloud2 = new FleetCloud("TestCloud2", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -182,14 +182,14 @@ public void shouldShowMultipleCloudsWithDefaultName() throws IOException, SAXExc @Test public void shouldUpdateProperCloudWhenMultiple() throws Exception { - EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud1", null, null, null, null, + FleetCloud cloud1 = new FleetCloud("TestCloud1", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud1); - EC2FleetCloud cloud2 = new EC2FleetCloud("TestCloud2", null, null, null, null, + FleetCloud cloud2 = new FleetCloud("TestCloud2", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -203,12 +203,12 @@ public void shouldUpdateProperCloudWhenMultiple() throws Exception { HtmlFormUtil.submit(form); - assertEquals("new-label", ((EC2FleetCloud)j.jenkins.clouds.get(0)).getLabelString()); - assertEquals("label", ((EC2FleetCloud)j.jenkins.clouds.get(1)).getLabelString()); } + assertEquals("new-label", ((FleetCloud)j.jenkins.clouds.get(0)).getLabelString()); + assertEquals("label", ((FleetCloud)j.jenkins.clouds.get(1)).getLabelString()); } @Test public void shouldContainRegionValueInRegionLabel() throws IOException, SAXException { - EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud", "uh", null, null, null, + FleetCloud cloud1 = new FleetCloud("TestCloud", "uh", null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -230,7 +230,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)"; - EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud", "uh", null, null, null, + FleetCloud cloud1 = new FleetCloud("TestCloud", "uh", null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -258,14 +258,14 @@ public void shouldHaveRegionCodeAndRegionDescriptionInRegionLabel() throws IOExc // Note: multiple clouds with same name can be created via JCasC only. @Test public void shouldGetFirstWhenMultipleCloudWithSameName() { - EC2FleetCloud cloud1 = new EC2FleetCloud("TestCloud", null, null, null, null, + FleetCloud cloud1 = new FleetCloud("TestCloud", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud1); - EC2FleetCloud cloud2 = new EC2FleetCloud("TestCloud", null, null, null, null, + FleetCloud cloud2 = new FleetCloud("TestCloud", null, null, null, null, null, "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -277,14 +277,14 @@ public void shouldGetFirstWhenMultipleCloudWithSameName() { @Test public void shouldGetProperWhenMultipleWithDiffName() { - EC2FleetCloud cloud1 = new EC2FleetCloud("a", null, null, null, null, + FleetCloud cloud1 = new FleetCloud("a", null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false); j.jenkins.clouds.add(cloud1); - EC2FleetCloud cloud2 = new EC2FleetCloud("b", null, null, null, null, + FleetCloud cloud2 = new FleetCloud("b", null, null, null, null, null, null, null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -297,7 +297,7 @@ public void shouldGetProperWhenMultipleWithDiffName() { @Test public void verifyCloudNameReadOnlyAfterCloudCreated() throws Exception { - EC2FleetCloud cloud = new EC2FleetCloud("test-cloud", null, null, null, null, "", + FleetCloud cloud = new FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, @@ -312,12 +312,12 @@ public void verifyCloudNameReadOnlyAfterCloudCreated() throws Exception { @Test public void verifyExistingDuplicateCloudNamesEditable() throws Exception { - j.jenkins.clouds.add(new EC2FleetCloud("test-cloud", null, null, null, null, "", + j.jenkins.clouds.add(new FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, 10, false)); - j.jenkins.clouds.add(new EC2FleetCloud("test-cloud", null, null, null, null, "", + j.jenkins.clouds.add(new FleetCloud("test-cloud", null, null, null, null, "", "label", null, null, false, false, 0, 0, 0, 0, 0, true, false, "-1", false, 0, 0, false, diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2FleetTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2FleetTest.java new file mode 100644 index 00000000..0e99128a --- /dev/null +++ b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2FleetTest.java @@ -0,0 +1,390 @@ +package com.amazon.jenkins.ec2fleet.fleet; + +import com.amazon.jenkins.ec2fleet.aws.EC2Api; +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.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.*; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class EC2FleetTest { + + @Mock + private AmazonEC2 ec2; + + @Mock + private EC2Api ec2Api; + + @Before + public void before() { + Registry.setEc2Api(ec2Api); + + when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(ec2); + + when(ec2.describeFleetInstances(any(DescribeFleetInstancesRequest.class))) + .thenReturn(new DescribeFleetInstancesResult()); + + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult() + .withFleets( + new FleetData() + .withTargetCapacitySpecification( + new TargetCapacitySpecification() + .withTotalTargetCapacity(0)))); + } + + @After + public void after() { + Registry.setEc2Api(new EC2Api()); + } + + @Test(expected = IllegalStateException.class) + public void getState_failIfNoFleet() { + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult()); + + new EC2Fleet().getState("cred", "region", "", "f"); + } + + @Test + public void getState_returnFleetInfo() { + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult() + .withFleets( + new FleetData() + .withFleetState(String.valueOf(BatchState.Active)) + .withTargetCapacitySpecification( + new TargetCapacitySpecification() + .withTotalTargetCapacity(12)))); + + FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f-id"); + + Assert.assertEquals("f-id", stats.getFleetId()); + Assert.assertEquals(FleetStateStats.State.active(), stats.getState()); + Assert.assertEquals(12, stats.getNumDesired()); + } + + @Test + public void getState_returnEmptyIfNoInstancesForFleet() { + FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + + Assert.assertEquals(Collections.emptySet(), stats.getInstances()); + Assert.assertEquals(0, stats.getNumActive()); + } + + @Test + public void getState_returnAllDescribedInstancesForFleet() { + when(ec2.describeFleetInstances(any(DescribeFleetInstancesRequest.class))) + .thenReturn(new DescribeFleetInstancesResult() + .withActiveInstances( + new ActiveInstance().withInstanceId("i-1"), + new ActiveInstance().withInstanceId("i-2"))); + + FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + + Assert.assertEquals(new HashSet<>(Arrays.asList("i-1", "i-2")), stats.getInstances()); + Assert.assertEquals(2, stats.getNumActive()); + verify(ec2).describeFleetInstances(new DescribeFleetInstancesRequest() + .withFleetId("f")); + } + + + + @Test + public void getState_returnAllPagesDescribedInstancesForFleet() { + when(ec2.describeFleetInstances(any(DescribeFleetInstancesRequest.class))) + .thenReturn(new DescribeFleetInstancesResult() + .withNextToken("p1") + .withActiveInstances(new ActiveInstance().withInstanceId("i-1"))) + .thenReturn(new DescribeFleetInstancesResult() + .withActiveInstances(new ActiveInstance().withInstanceId("i-2"))); + + FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + + Assert.assertEquals(new HashSet<>(Arrays.asList("i-1", "i-2")), stats.getInstances()); + Assert.assertEquals(2, stats.getNumActive()); + verify(ec2).describeFleetInstances(new DescribeFleetInstancesRequest() + .withFleetId("f").withNextToken("p1")); + verify(ec2).describeFleetInstances(new DescribeFleetInstancesRequest() + .withFleetId("f")); + } + + @Test + public void getState_returnEmptyInstanceTypeWeightsIfNoInformation() { + FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + + Assert.assertEquals(Collections.emptyMap(), stats.getInstanceTypeWeights()); + } + + @Test + public void getState_returnInstanceTypeWeightsFromLaunchSpecification() { + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult() + .withFleets(new FleetData() + .withFleetState(String.valueOf(BatchState.Active)) + .withTargetCapacitySpecification(new TargetCapacitySpecification() + .withTotalTargetCapacity(1)) + .withLaunchTemplateConfigs(new FleetLaunchTemplateConfig() + .withOverrides( + new FleetLaunchTemplateOverrides().withInstanceType("t1").withWeightedCapacity(0.1), + new FleetLaunchTemplateOverrides().withInstanceType("t2").withWeightedCapacity(12.0))))); + + FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + + Map expected = new HashMap<>(); + expected.put("t1", 0.1); + expected.put("t2", 12.0); + Assert.assertEquals(expected, stats.getInstanceTypeWeights()); + } + + @Test + public void getState_returnInstanceTypeWeightsForLaunchSpecificationIfItHasIt() { + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult() + .withFleets(new FleetData() + .withFleetState(String.valueOf(BatchState.Active)) + .withTargetCapacitySpecification(new TargetCapacitySpecification() + .withTotalTargetCapacity(1)) + .withLaunchTemplateConfigs(new FleetLaunchTemplateConfig() + .withOverrides( + new FleetLaunchTemplateOverrides().withInstanceType("t1"), + new FleetLaunchTemplateOverrides().withWeightedCapacity(12.0))))); + + FleetStateStats stats = new EC2Fleet().getState("cred", "region", "", "f"); + + Assert.assertEquals(Collections.emptyMap(), stats.getInstanceTypeWeights()); + } + + @Test + public void getStateBatch_withNoFleetIdsAndNoFleets_returnsAnEmptyMap() { + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult()); + + Collection fleetIds = new ArrayList<>(); + + Map fleetStateStatsMap = new EC2Fleet().getStateBatch("cred", "region", "", fleetIds); + + Assert.assertTrue("FleetStateStats Map is expected to be empty when no Fleet Ids are given", fleetStateStatsMap.isEmpty()); + } + + @Test + public void getStateBatch_withFleetIdsAndNoFleets_returnsMapWithNoInstances() { + when(ec2.describeFleetInstances(any(DescribeFleetInstancesRequest.class))) + .thenReturn(new DescribeFleetInstancesResult()); + + Collection fleetIds = new ArrayList<>(); + fleetIds.add("f1"); + fleetIds.add("f2"); + + Map fleetStateStatsMap = new EC2Fleet().getStateBatch("cred", "region", "", fleetIds); + + Assert.assertTrue(fleetStateStatsMap.isEmpty()); + } + + @Test + public void getBatchState_withFleetsAndActiveInstances_returnsDescribedInstancesForFleets() { + when(ec2.describeFleetInstances(any(DescribeFleetInstancesRequest.class))) + .thenReturn(new DescribeFleetInstancesResult() + .withFleetId("f1") + .withActiveInstances( + new ActiveInstance().withInstanceId("i-1"), + new ActiveInstance().withInstanceId("i-2")), + new DescribeFleetInstancesResult() + .withFleetId("f2") + .withActiveInstances( + new ActiveInstance().withInstanceId("i-3") + )); + + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult() + .withFleets( + new FleetData() + .withFleetId("f1") + .withFleetState(String.valueOf(BatchState.Active)) + .withTargetCapacitySpecification( + new TargetCapacitySpecification() + .withTotalTargetCapacity(4)), + new FleetData() + .withFleetId("f2") + .withFleetState(String.valueOf(BatchState.Active)) + .withTargetCapacitySpecification( + new TargetCapacitySpecification() + .withTotalTargetCapacity(8)))); + + Collection fleetIds = new ArrayList<>(); + fleetIds.add("f1"); + fleetIds.add("f2"); + + Map statsMap = new EC2Fleet().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()); + Assert.assertEquals(2, statsMap.get("f1").getNumActive()); + Assert.assertEquals(1, statsMap.get("f2").getNumActive()); + verify(ec2).describeFleetInstances(new DescribeFleetInstancesRequest() + .withFleetId("f1")); + verify(ec2).describeFleetInstances(new DescribeFleetInstancesRequest() + .withFleetId("f2")); + } + + @Test + public void getBatchState_withFleets_returnsDescribedFleetStats() { + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult() + .withFleets( + new FleetData() + .withFleetId("f1") + .withFleetState(String.valueOf(BatchState.Active)) + .withTargetCapacitySpecification( + new TargetCapacitySpecification() + .withTotalTargetCapacity(2)), + new FleetData() + .withFleetId("f2") + .withFleetState(String.valueOf(BatchState.Modifying)) + .withTargetCapacitySpecification( + new TargetCapacitySpecification() + .withTotalTargetCapacity(6)))); + + Collection fleetIds = new ArrayList<>(); + fleetIds.add("f1"); + fleetIds.add("f2"); + + Map statsMap = new EC2Fleet().getStateBatch("cred", "region", "", fleetIds); + + Assert.assertTrue(statsMap.get("f1").getState().isActive()); + Assert.assertTrue(statsMap.get("f2").getState().isModifying()); + Assert.assertEquals(2, statsMap.get("f1").getNumDesired()); + Assert.assertEquals(6, statsMap.get("f2").getNumDesired()); + } + + + @Test + public void describe_whenAllFleetsEnabled_shouldIncludeAllFleetsInAllStates() { + // given + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult().withFleets( + new FleetData() + .withFleetId("f1") + .withFleetState(String.valueOf(BatchState.Active)) + .withType(FleetType.Maintain), + new FleetData() + .withFleetId("f2") + .withFleetState(String.valueOf(BatchState.Modifying)) + .withType(FleetType.Request))); + // when + ListBoxModel model = new ListBoxModel(); + new EC2Fleet().describe("cred", "region", "", model, "selected", true); + // then + Assert.assertEquals( + "[EC2 Fleet - f1 (active) (maintain)=f1, EC2 Fleet - f2 (modifying) (request)=f2]", + model.toString()); + } + + @Test + public void describe_whenAllFleetsDisabled_shouldSkipNonMaintain() { + // given + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult().withFleets( + new FleetData() + .withFleetId("f1") + .withFleetState(String.valueOf(BatchState.Active)) + .withType(FleetType.Maintain), + new FleetData() + .withFleetId("f2") + .withFleetState(String.valueOf(BatchState.Active)) + .withType(FleetType.Request))); + // when + ListBoxModel model = new ListBoxModel(); + new EC2Fleet().describe("cred", "region", "", model, "selected", false); + // then + Assert.assertEquals( + "[EC2 Fleet - f1 (active) (maintain)=f1]", + model.toString()); + } + + @Test + public void describe_whenAllFleetsDisabled_shouldSkipNonCancelledOrFailed() { + // given + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult().withFleets( + new FleetData() + .withFleetId("f1") + .withFleetState(String.valueOf(BatchState.Active)) + .withType(FleetType.Maintain), + new FleetData() + .withFleetId("f2") + .withFleetState(String.valueOf(BatchState.Cancelled_running)) + .withType(FleetType.Maintain), + new FleetData() + .withFleetId("f3") + .withFleetState(String.valueOf(BatchState.Cancelled_terminating)) + .withType(FleetType.Maintain), + new FleetData() + .withFleetId("f3") + .withFleetState(String.valueOf(BatchState.Failed)) + .withType(FleetType.Maintain))); + // when + ListBoxModel model = new ListBoxModel(); + new EC2Fleet().describe("cred", "region", "", model, "selected", false); + // then + Assert.assertEquals( + "[EC2 Fleet - f1 (active) (maintain)=f1]", + model.toString()); + } + + @Test + public void describe_whenAllFleetsDisabled_shouldIncludeSubmittedModifiedActive() { + // given + when(ec2.describeFleets(any(DescribeFleetsRequest.class))) + .thenReturn(new DescribeFleetsResult().withFleets( + new FleetData() + .withFleetId("f1") + .withFleetState(String.valueOf(BatchState.Active)) + .withType(FleetType.Maintain), + new FleetData() + .withFleetId("f2") + .withFleetState(String.valueOf(BatchState.Submitted)) + .withType(FleetType.Maintain), + new FleetData() + .withFleetId("f3") + .withFleetState(String.valueOf(BatchState.Modifying)) + .withType(FleetType.Maintain))); + // when + ListBoxModel model = new ListBoxModel(); + new EC2Fleet().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]", + model.toString()); + } + + @Test + public void isECFleet_withFleetId_returnsTrue() { + String fleetId = "fleet-123456"; + boolean isECFleet = Fleets.isEC2Fleet(fleetId); + + Assert.assertTrue(isECFleet); + } + @Test + public void isECFleet_withNonFleetId_returnsFalse() { + String fleetId = "sfr-123456"; + boolean isECFleet = Fleets.isEC2Fleet(fleetId); + + Assert.assertFalse(isECFleet); + } +} \ No newline at end of file diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleetTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleetTest.java similarity index 92% rename from src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleetTest.java rename to src/test/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleetTest.java index 1451e262..14c6b189 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/fleet/EC2SpotFleetTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/fleet/SpotFleetTest.java @@ -35,7 +35,7 @@ import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) -public class EC2SpotFleetTest { +public class SpotFleetTest { @Mock private AmazonEC2 ec2; @@ -71,7 +71,7 @@ public void getState_failIfNoFleet() { when(ec2.describeSpotFleetRequests(any(DescribeSpotFleetRequestsRequest.class))) .thenReturn(new DescribeSpotFleetRequestsResult()); - new EC2SpotFleet().getState("cred", "region", "", "f"); + new SpotFleet().getState("cred", "region", "", "f"); } @Test @@ -85,7 +85,7 @@ public void getState_returnFleetInfo() { new SpotFleetRequestConfigData() .withTargetCapacity(12)))); - FleetStateStats stats = new EC2SpotFleet().getState("cred", "region", "", "f-id"); + FleetStateStats stats = new SpotFleet().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 EC2SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new SpotFleet().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 EC2SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new SpotFleet().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 EC2SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new SpotFleet().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 EC2SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new SpotFleet().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 EC2SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new SpotFleet().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 EC2SpotFleet().getState("cred", "region", "", "f"); + FleetStateStats stats = new SpotFleet().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 EC2SpotFleet().describe("cred", "region", "", model, "selected", true); + new SpotFleet().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 EC2SpotFleet().describe("cred", "region", "", model, "selected", false); + new SpotFleet().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 EC2SpotFleet().describe("cred", "region", "", model, "selected", false); + new SpotFleet().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 EC2SpotFleet().describe("cred", "region", "", model, "selected", false); + new SpotFleet().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/EC2FleetCloud/empty-name-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/empty-name-configuration-as-code.yml similarity index 58% rename from src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/empty-name-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/empty-name-configuration-as-code.yml index 2f8012c2..3ba750ba 100644 --- a/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/empty-name-configuration-as-code.yml +++ b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/empty-name-configuration-as-code.yml @@ -1,8 +1,8 @@ jenkins: clouds: - - ec2Fleet: + - eC2Fleet: name: "" - - ec2Fleet: + - eC2Fleet: name: "" - - ec2Fleet: + - eC2Fleet: name: "" \ No newline at end of file diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/max-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/max-configuration-as-code.yml similarity index 98% rename from src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/max-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/max-configuration-as-code.yml index 92b9e0ae..e8a6cc3d 100644 --- a/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/max-configuration-as-code.yml +++ b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/max-configuration-as-code.yml @@ -1,6 +1,6 @@ jenkins: clouds: - - ec2Fleet: + - eC2Fleet: name: ec2-fleet awsCredentialsId: xx computerConnector: diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/min-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/min-configuration-as-code.yml similarity index 72% rename from src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/min-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/min-configuration-as-code.yml index 1770a815..7969099f 100644 --- a/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/min-configuration-as-code.yml +++ b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/min-configuration-as-code.yml @@ -1,4 +1,4 @@ jenkins: clouds: - - ec2Fleet: + - eC2Fleet: name: ec2-fleet \ No newline at end of file diff --git a/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/name-required-configuration-as-code.yml b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/name-required-configuration-as-code.yml similarity index 93% rename from src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/name-required-configuration-as-code.yml rename to src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/name-required-configuration-as-code.yml index 364e07f0..beaef969 100644 --- a/src/test/resources/com/amazon/jenkins/ec2fleet/EC2FleetCloud/name-required-configuration-as-code.yml +++ b/src/test/resources/com/amazon/jenkins/ec2fleet/FleetCloud/name-required-configuration-as-code.yml @@ -1,6 +1,6 @@ jenkins: clouds: - - ec2Fleet: + - eC2Fleet: awsCredentialsId: xx region: us-east-2 fleet: my-fleet