Skip to content

Commit

Permalink
Merge pull request #145 from npotluri-rh/additional-jdk-versions-on-c…
Browse files Browse the repository at this point in the history
…i-build

Port to Java 11 and newer Jenkins version
  • Loading branch information
olivergondza authored Mar 29, 2023
2 parents 6619c3c + 0383aaf commit a49d869
Show file tree
Hide file tree
Showing 23 changed files with 254 additions and 261 deletions.
1 change: 0 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ buildPlugin(
configurations: [
[platform: 'linux', jdk: 11],
[platform: 'linux', jdk: 17],
[platform: 'windows', jdk: 11],
])
3 changes: 2 additions & 1 deletion backend-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.nodesharing</groupId>
<artifactId>node-sharing-lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.jenkins</groupId>
Expand All @@ -40,4 +41,4 @@
</resource>
</resources>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Api() {
// PJ: Not working, during JUnit phase execution there aren't made packages...
InputStream resource = this.getClass().getClassLoader().getResourceAsStream("nodesharingbackend.properties");
if (resource == null) {
version = Jenkins.getInstance().pluginManager.whichPlugin(getClass()).getVersion();
version = Jenkins.get().pluginManager.whichPlugin(getClass()).getVersion();
} else {
Properties properties = new Properties();
properties.load(resource);
Expand All @@ -98,7 +98,7 @@ public Api() {
}

public static @Nonnull Api getInstance() {
ExtensionList<Api> list = Jenkins.getInstance().getExtensionList(Api.class);
ExtensionList<Api> list = Jenkins.get().getExtensionList(Api.class);
assert list.size() == 1;
return list.iterator().next();
}
Expand Down Expand Up @@ -189,7 +189,7 @@ public NodeStatusResponse.Status nodeStatus(@Nonnull final ExecutorJenkins jenki
*/
@RequirePOST
public void doDiscover(StaplerRequest req, StaplerResponse rsp) throws IOException {
Jenkins.getInstance().checkPermission(RestEndpoint.RESERVE);
Jenkins.get().checkPermission(RestEndpoint.RESERVE);

Pool pool = Pool.getInstance();
Collection<NodeDefinition> nodes = pool.getConfig().getNodes().values(); // Fail early when there is no config
Expand Down Expand Up @@ -240,7 +240,7 @@ public void doDiscover(StaplerRequest req, StaplerResponse rsp) throws IOExcepti
*/
@RequirePOST
public void doReportWorkload(@Nonnull final StaplerRequest req, @Nonnull final StaplerResponse rsp) throws IOException {
Jenkins.getInstance().checkPermission(RestEndpoint.RESERVE);
Jenkins.get().checkPermission(RestEndpoint.RESERVE);

Pool pool = Pool.getInstance();
final ConfigRepo.Snapshot config = pool.getConfig(); // Fail early when there is no config
Expand All @@ -264,7 +264,7 @@ public void doReportWorkload(@Nonnull final StaplerRequest req, @Nonnull final S

Queue.withLock(new Runnable() {
@Override public void run() {
Queue queue = Jenkins.getInstance().getQueue();
Queue queue = Jenkins.get().getQueue();
for (Queue.Item item : queue.getItems()) {
if (item.task instanceof ReservationTask && ((ReservationTask) item.task).getOwner().equals(executor)) {
// Cancel items executor is no longer interested in and keep those it cares for
Expand Down Expand Up @@ -297,7 +297,7 @@ private String unknownExecutor(String executorUrl, String configRepoUrl) {
*/
@RequirePOST
public void doReturnNode(@Nonnull final StaplerRequest req, @Nonnull final StaplerResponse rsp) throws IOException {
Jenkins.getInstance().checkPermission(RestEndpoint.RESERVE);
Jenkins.get().checkPermission(RestEndpoint.RESERVE);

String ocr = Pool.getInstance().getConfigRepoUrl(); // Fail early when there is no config
ReturnNodeRequest request = Entity.fromInputStream(req.getInputStream(), ReturnNodeRequest.class);
Expand All @@ -308,7 +308,7 @@ public void doReturnNode(@Nonnull final StaplerRequest req, @Nonnull final Stapl
return;
}

Jenkins jenkins = Jenkins.getInstance();
Jenkins jenkins = Jenkins.get();
Computer c = jenkins.getComputer(request.getNodeName());
if (c == null) {
LOGGER.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Dashboard extends View {
// It is quite delicate when this is invoked to fit between primary view updates hardcoded in Jenkins class itself
@Initializer(after = InitMilestone.JOB_LOADED)
public static void registerDashboard() throws IOException {
Jenkins j = Jenkins.getInstance();
Jenkins j = Jenkins.get();
Dashboard dashboard = new Dashboard();
j.addView(dashboard);
j.setPrimaryView(dashboard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private NoopChannel(ChannelBuilder settings, CommandTransport transport) throws
}

@Override
public boolean preloadJar(Callable<?, ?> classLoaderRef, Class... classesInJar) {
public boolean preloadJar(Callable<?, ?> classLoaderRef, Class<?>... classesInJar) {
throw new UnsupportedOperationException(); // $COVERAGE-IGNORE$
}

Expand Down
4 changes: 4 additions & 0 deletions backend-plugin/src/main/resources/index.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
Share machines as Jenkins agents across multiple Jenkins masters. This plugin maintains the nodes in the share pool of preconfigured machines.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

public class JCasCCompatibilityTest {

Expand Down
35 changes: 7 additions & 28 deletions jth-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
<dependency>
<groupId>org.jenkins-ci.plugins.nodesharing</groupId>
<artifactId>node-sharing-executor</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.nodesharing</groupId>
<artifactId>node-sharing-orchestrator</artifactId>
<version>${project.version}</version>
</dependency>
<dependency><!-- Transitive but required by JaCoCo to add to code coverage report -->
<groupId>org.jenkins-ci.plugins.nodesharing</groupId>
<artifactId>node-sharing-lib</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Java modules -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>

<dependency>
<groupId>com.offbytwo.jenkins</groupId>
<artifactId>jenkins-client</artifactId>
Expand All @@ -50,22 +50,19 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<version>5.1.1</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-auth</artifactId>
<version>2.6.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -74,29 +71,11 @@
<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>io.jenkins.configuration-as-code</groupId>
<artifactId>configuration-as-code-support</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>1.66</version>
</dependency>

<!-- Upper bound -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.4</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.8</version>
<version>1.81.1</version>
</dependency>
</dependencies>

Expand All @@ -106,7 +85,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<version>3.1.0</version>
<configuration>
<skip>true</skip>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import com.redhat.jenkins.nodesharing.utils.GridRule.Orchestrator;
import com.redhat.jenkins.nodesharing.utils.SlowTest;
import hudson.FilePath;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -51,13 +54,14 @@
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.regex.Pattern;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.matchesPattern;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@Category(SlowTest.class)
Expand Down Expand Up @@ -87,9 +91,10 @@ public void smoke() throws Exception {
System.out.println('.');
verifyBuildHasRun(fixture, "sol", "win");
return;
} catch (AssertionError ex) {
} catch (AssertionError|org.apache.http.conn.HttpHostConnectException ex) {
if (i == 8) {
TimeoutException tex = new TimeoutException("Build not completed in time");
dumpFixtureLogs();
TimeoutException tex = new TimeoutException("Build not completed in time by " + new Date());
tex.initCause(ex);
throw tex;
}
Expand Down Expand Up @@ -118,9 +123,10 @@ public void smokeNoEnvCredential() throws Exception {
System.out.println('.');
verifyBuildHasRun(fixture, "sol", "win");
return;
} catch (AssertionError ex) {
} catch (AssertionError|org.apache.http.conn.HttpHostConnectException ex) {
if (i == 8) {
TimeoutException tex = new TimeoutException("Build not completed in time");
dumpFixtureLogs();
TimeoutException tex = new TimeoutException("Build not completed in time by " + new Date());
tex.initCause(ex);
throw tex;
}
Expand Down Expand Up @@ -152,15 +158,15 @@ public void restartOrchestrator() throws Exception {
// Run nr. 1 - will be in building state during Orchestrator restart
FileBuildBlocker runningBlocker = new FileBuildBlocker(tmp);
BuildWithDetails running = triggerJobAndWaitUntilStarted(executorClient, "running",
job.build(runningBlocker.buildParams()));
job.build(runningBlocker.buildParams(), true));
await(10000,
() -> runningBlocker.isRunning(),
throwable -> { dumpFixtureLogs(); return "Build not running in time";
});

// Run nr. 2 - will be in queued state during Orchestrator restart
FileBuildBlocker queuedBlocker = new FileBuildBlocker(tmp);
QueueReference qr = job.build(queuedBlocker.buildParams());
QueueReference qr = job.build(queuedBlocker.buildParams(), true);
executorClient.getQueueItem(qr);

job = executorClient.getJob("running");
Expand All @@ -174,7 +180,7 @@ public void restartOrchestrator() throws Exception {
JenkinsServer orchestratorClient = o.getClient("admin", "admin");

// Wait until restarted
orchestratorClient.restart(false);
orchestratorClient.restart(true);
// Reservation verifier needs RestEndpoint#TIMEOUT * 2 to recover the state so this is going to take a while
await(60000 * 3, orchestratorClient::isRunning, throwable -> {
dumpFixtureLog(o);
Expand Down Expand Up @@ -232,15 +238,15 @@ public void changeOrchestratorUrlSmokeTest() throws Exception {
// Run nr. 1 - will be in building state during Orchestrator restart
FileBuildBlocker runningBlocker = new FileBuildBlocker(tmp);
BuildWithDetails running = triggerJobAndWaitUntilStarted(executorClient0, "running",
job.build(runningBlocker.buildParams()));
job.build(runningBlocker.buildParams(),true));
await(10000,
() -> runningBlocker.isRunning(),
throwable -> { dumpFixtureLogs(); return "Build not running in time";
});

// Run nr. 2 - will be in queued state during Orchestrator restart
FileBuildBlocker queuedBlocker = new FileBuildBlocker(tmp);
QueueReference qr = job.build(queuedBlocker.buildParams());
QueueReference qr = job.build(queuedBlocker.buildParams(), true);
executorClient0.getQueueItem(qr);

job = executorClient0.getJob("running");
Expand All @@ -264,19 +270,19 @@ public void changeOrchestratorUrlSmokeTest() throws Exception {
assertThat(config.readToString(), containsString("orchestrator.url=" + o1.getUri()));

// Make sure updated config is propagated through the grid
executorClient0.runScript("Jenkins.instance.getExtensionList(com.redhat.jenkins.nodesharingfrontend.SharedNodeCloud.ConfigRepoUpdater.class).get(0).doRun();");
executorClient0.runScript("Jenkins.instance.getExtensionList(com.redhat.jenkins.nodesharingfrontend.SharedNodeCloud.ConfigRepoUpdater.class).get(0).doRun();", true);
assertThat(executorClient0.runScript(
"com.redhat.jenkins.nodesharingfrontend.SharedNodeCloud.getAll().get(0).getLatestConfig().getOrchestratorUrl();"),
"com.redhat.jenkins.nodesharingfrontend.SharedNodeCloud.getAll().get(0).getLatestConfig().getOrchestratorUrl();", true),
equalTo("Result: " + o1.getUri() + "\n")
);
orchestratorClient1.runScript("com.redhat.jenkins.nodesharingbackend.Pool.Updater.getInstance().doRun();");
orchestratorClient1.runScript("com.redhat.jenkins.nodesharingbackend.Pool.Updater.getInstance().doRun();", true);
assertThat(orchestratorClient1.runScript(
"com.redhat.jenkins.nodesharingbackend.Pool.getInstance().getConfig().getOrchestratorUrl();"),
"com.redhat.jenkins.nodesharingbackend.Pool.getInstance().getConfig().getOrchestratorUrl();", true),
equalTo("Result: " + o1.getUri() + "\n")
);
orchestratorClient2.runScript("com.redhat.jenkins.nodesharingbackend.Pool.Updater.getInstance().doRun();");
orchestratorClient2.runScript("com.redhat.jenkins.nodesharingbackend.Pool.Updater.getInstance().doRun();", true);
assertThat(orchestratorClient2.runScript(
"com.redhat.jenkins.nodesharingbackend.Pool.getInstance().getConfig().getOrchestratorUrl();"),
"com.redhat.jenkins.nodesharingbackend.Pool.getInstance().getConfig().getOrchestratorUrl();", true),
equalTo("Result: " + o1.getUri() + "\n")
);

Expand Down Expand Up @@ -312,34 +318,34 @@ public void changeOrchestratorUrlSmokeTest() throws Exception {
Thread.sleep(1000);

String e0Log = e0.getLog().readToString();

// Executor should terminate computer twice
assertThat(e0Log, matchesPattern(
"(.+\n)+"
+ "INFO: Terminating computer solaris1.acme.com-NodeSharing-.+(.+\n)*"
+ "INFO: Terminating computer solaris1.acme.com-NodeSharing-.+(.+\n)*")
);
String msg = "Terminating computer solaris1.acme.com-NodeSharing-";
assertThat(e0Log, Matchers.stringContainsInOrder(msg, msg));

String o1Log = o1.getLog().readToString();
// Orchestrator 1 should register one release attempt before it knows that it was reserved,
// second reservation should be processed like common case
assertThat(o1Log, matchesPattern(
"(.*\n)*INFO: An attempt to return a node 'solaris1.acme.com' that is not reserved by " + e0.getUri()+"(.*\n)*"
+"INFO: Reservation of solaris1.acme.com by e0 .+ completed(.*\n)*")
);
String regex = "An attempt to return a node 'solaris1.acme.com' that is not reserved by "
+ e0.getUri();
assertThat(o1Log.split(regex)[1], matchesPattern("((\\n(.*))+)Reservation of solaris1.acme.com by e0 (.*) completed\\n"));

String o2Log = o2.getLog().readToString();
String o2LogRegex = o2Log.split("Jenkins is fully up and running")[1];
Pattern p = Pattern.compile("(?i)Reservation of solaris1.acme.com by e0 (.*) started", Pattern.DOTALL);
java.util.regex.Matcher m = p.matcher(o2LogRegex);
boolean b = m.find();

// Orchestrator 2 should register one reservation without release
assertThat(o2Log, matchesPattern(
"(.*\n)*INFO: Reservation of solaris1.acme.com by e0 .+ started(.*\n)*")
);
assertTrue(b);
// Orchestrator 2 shouldn't register two reservations
assertThat(o2Log, matchesPattern(
"(.*\n)*(?!INFO: Reservation of solaris1.acme.com by e0 .+ started(.*\n)*INFO: Reservation of solaris1.acme.com by e0 .+ started)(.*\n)*")
);
b = m.find();
org.junit.Assert.assertFalse(b);
// Orchestrator 2 shouldn't register any release attempt
assertThat(o2Log, matchesPattern(
"(.*\n)*(?!INFO: Reservation of solaris1.acme.com by e0 .+ completed)(.*\n)*")
);
p = Pattern.compile("(?i)Reservation of solaris1.acme.com by e0 (.*) completed", Pattern.DOTALL);
m = p.matcher(o2LogRegex);
b = m.find();
org.junit.Assert.assertFalse(b);
}

private BuildWithDetails buildDetails(JobWithDetails running, int i) throws IOException {
Expand Down
Loading

0 comments on commit a49d869

Please sign in to comment.