Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading the minimum required Jenkins version. #368

Merged
merged 2 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<properties>
<revision>2.5.3</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.249.3</jenkins.version>
<jenkins.version>2.277.2</jenkins.version>
<java.level>8</java.level>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<aws-sdk.version>1.12.101-300.vc09c7be9cb57</aws-sdk.version>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amazon/jenkins/ec2fleet/CloudNanny.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected void doRun() {
* @return basic java list
*/
private static List<Cloud> getClouds() {
return Jenkins.getActiveInstance().clouds;
return Jenkins.get().clouds;
}

private AtomicInteger getRecurrenceCounter(EC2FleetCloud fleetCloud) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void afterDisconnect(final SlaveComputer computer, final TaskListener lis
actions.addAll(failedBuild.getActions(ParametersAction.class));
}
if (executable instanceof Actionable) {
actions.addAll(((Actionable) executable).getActions());
actions.addAll(((Actionable) executable).getAllActions());
}
LOGGER.log(LOG_LEVEL, "RETRIGGERING: " + task + " - WITH ACTIONS: " + actions);
Queue.getInstance().schedule2(task, RESCHEDULE_QUIET_PERIOD_SEC, actions);
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -391,7 +392,7 @@ public synchronized boolean hasExcessCapacity() {
}

@Override
public synchronized Collection<NodeProvisioner.PlannedNode> provision(final Label label, final int excessWorkload) {
public synchronized Collection<NodeProvisioner.PlannedNode> provision(@Nonnull final Cloud.CloudState cloudState, final int excessWorkload) {
fine("excessWorkload %s", excessWorkload);

if (stats == null) {
Expand Down Expand Up @@ -726,7 +727,8 @@ public synchronized boolean scheduleToTerminate(final String instanceId, final b
}

@Override
public boolean canProvision(final Label label) {
public boolean canProvision(final Cloud.CloudState cloudState) {
final Label label = cloudState.getLabel();
fine("CanProvision called on fleet: \"" + this.labelString + "\" wanting: \"" + (label == null ? "(unspecified)" : label.getName()) + "\".");
if (fleet == null) {
fine("Fleet/ASG for cloud is null, returning false");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -292,9 +293,10 @@ public synchronized boolean hasExcessCapacity() {
// }

@Override
public synchronized Collection<NodeProvisioner.PlannedNode> provision(final Label label, int excessWorkload) {
public synchronized Collection<NodeProvisioner.PlannedNode> provision(@Nonnull final Cloud.CloudState cloudState, int excessWorkload) {
info("excessWorkload %s", excessWorkload);

final Label label = cloudState.getLabel();
List<NodeProvisioner.PlannedNode> r = new ArrayList<>();

for (Map.Entry<String, State> state : states.entrySet()) {
Expand Down Expand Up @@ -421,7 +423,7 @@ public void update() {
}

private void updateByState(final Map<String, State> states) {
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();

final AmazonEC2 ec2 = Registry.getEc2Api().connect(getAwsCredentialsId(), region, endpoint);

Expand Down Expand Up @@ -563,7 +565,7 @@ public void run() {
public synchronized boolean scheduleToTerminate(final String instanceId, boolean force) {
info("Attempting to terminate instance: %s", instanceId);

final Node node = Jenkins.getActiveInstance().getNode(instanceId);
final Node node = Jenkins.get().getNode(instanceId);
if (node == null) return false;

final State state = states.get(node.getLabelString());
Expand All @@ -586,7 +588,8 @@ public synchronized boolean scheduleToTerminate(final String instanceId, boolean

// sync as we are using modifyable state
@Override
public synchronized boolean canProvision(final Label label) {
public synchronized boolean canProvision(final Cloud.CloudState cloudState) {
final Label label = cloudState.getLabel();
for (String labelString : states.keySet()) {
final boolean r = label == null || Label.parse(labelString).containsAll(label.listAtoms());
fine("CanProvision called on fleet: \"" + labelString + "\" wanting: \"" + (label == null ? "(unspecified)" : label.getName()) + "\". Returning " + r + ".");
Expand Down Expand Up @@ -713,14 +716,14 @@ public void updateStacks() {
// ec2KeyPairName = result.getKeyPair().getKeyName();
// }

final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
final CloudFormationApi cloudFormationApi = Registry.getCloudFormationApi();
final AmazonCloudFormation client = cloudFormationApi.connect(awsCredentialsId, region, endpoint);
final Map<String, CloudFormationApi.StackInfo> allStacks = cloudFormationApi.describe(client, name);

// labels
final Set<String> labels = new HashSet<>();
for (final Item item : Jenkins.getActiveInstance().getAllItems()) {
for (final Item item : Jenkins.get().getAllItems()) {
if (!(item instanceof AbstractProject)) continue;
final AbstractProject abstractProject = (AbstractProject) item;
// assinged label could be null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public long getRecurrencePeriod() {

@Override
protected void doRun() {
for (Cloud cloud : Jenkins.getActiveInstance().clouds) {
for (Cloud cloud : Jenkins.get().clouds) {
if (!(cloud instanceof EC2FleetLabelCloud)) continue;
final EC2FleetLabelCloud ec2FleetLabelCloud = (EC2FleetLabelCloud) cloud;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void doRun() {
* @return widgets
*/
private static List<Widget> getWidgets() {
return Jenkins.getActiveInstance().getWidgets();
return Jenkins.get().getWidgets();
}

/**
Expand All @@ -64,7 +64,7 @@ private static List<Widget> getWidgets() {
* @return basic java list
*/
private static List<Cloud> getClouds() {
return Jenkins.getActiveInstance().clouds;
return Jenkins.get().clouds;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.amazon.jenkins.ec2fleet;

import com.amazonaws.services.ec2.model.BatchState;
import hudson.model.Label;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -68,7 +67,7 @@ public boolean isModifying() {

/**
* Fleet is good to be used for plugin, it will be shown on UI as option to use
* and plugin will use it for provision {@link EC2FleetCloud#provision(Label, int)} ()} and de-provision
* and plugin will use it for provision {@link EC2FleetCloud#provision(hudson.slaves.Cloud.CloudState, int)} ()} and de-provision
* otherwise activity will be ignored until state will not be updated.
*
* @return true or false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import jenkins.model.Jenkins;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -55,7 +54,9 @@ public NodeProvisioner.StrategyDecision apply(final NodeProvisioner.StrategyStat
new Object[]{label, cloud.getDisplayName()});
continue;
}
if (!cloud.canProvision(label)) {

Cloud.CloudState cloudState = new Cloud.CloudState(label, strategyState.getAdditionalPlannedCapacity());
if (!cloud.canProvision(cloudState)) {
LOGGER.log(Level.INFO, "label [{0}]: cloud {1} can not provision for this label, continuing...",
new Object[]{label, cloud.getDisplayName()});
continue;
Expand All @@ -70,7 +71,7 @@ public NodeProvisioner.StrategyDecision apply(final NodeProvisioner.StrategyStat

LOGGER.log(Level.INFO, "label [{0}]: cloud {1} can provision for this label",
new Object[]{label, cloud.getDisplayName()});
final Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(label, currentDemand);
final Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(cloudState, currentDemand);
for (NodeProvisioner.PlannedNode plannedNode : plannedNodes) {
currentDemand -= plannedNode.numExecutors;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/amazon/jenkins/ec2fleet/utils/AWSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static ClientConfiguration getClientConfiguration(final String endpoint)
.withRetryPolicy(PredefinedRetryPolicies.getDefaultRetryPolicyWithCustomMaxRetries(MAX_ERROR_RETRY));
clientConfiguration.setUserAgentPrefix(USER_AGENT_PREFIX);

final ProxyConfiguration proxyConfig = Jenkins.getActiveInstance().proxy;
final ProxyConfiguration proxyConfig = Jenkins.get().proxy;
if (proxyConfig != null) {
Proxy proxy;
try {
Expand All @@ -46,7 +46,7 @@ public static ClientConfiguration getClientConfiguration(final String endpoint)
clientConfiguration.setProxyPort(address.getPort());
if (null != proxyConfig.getUserName()) {
clientConfiguration.setProxyUsername(proxyConfig.getUserName());
clientConfiguration.setProxyPassword(proxyConfig.getPassword());
clientConfiguration.setProxyPassword(proxyConfig.getSecretPassword().getPlainText());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public class EC2FleetCloudAwareUtils {
private static final Logger LOGGER = Logger.getLogger(EC2FleetCloudAwareUtils.class.getName());

public static void reassign(final @Nonnull String id, @Nonnull final AbstractEC2FleetCloud cloud) {
if (Jenkins.getActiveInstance() != null ) {
if (Jenkins.getActiveInstance().getComputers() != null) {
for (final Computer computer : Jenkins.getActiveInstance().getComputers()) {
if (Jenkins.get() != null ) {
if (Jenkins.get().getComputers() != null) {
for (final Computer computer : Jenkins.get().getComputers()) {
LOGGER.info("Trying to reassign Jenkins computer:" + computer.getDisplayName());
checkAndReassign(id, cloud, computer);
}
}

if (Jenkins.getActiveInstance().getNodes() != null) {
for (final Node node : Jenkins.getActiveInstance().getNodes()) {
if (Jenkins.get().getNodes() != null) {
for (final Node node : Jenkins.get().getNodes()) {
LOGGER.info("Trying to reassign Jenkins node:" + node.getDisplayName());
checkAndReassign(id, cloud, node);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class JenkinsUtils {

public static void removeNode(final String instanceId) {
final Jenkins jenkins = Jenkins.getActiveInstance();
final Jenkins jenkins = Jenkins.get();
// If this node is dying, remove it from Jenkins
final Node n = jenkins.getNode(instanceId);
if (n != null) {
Expand Down
Loading