diff --git a/changelog.html b/changelog.html index faa82cc9bd6d54b83a1ce39709f87d42a79ddf1c..57cf111c6829831543fad8368c646cbe305be6b2 100644 --- a/changelog.html +++ b/changelog.html @@ -65,6 +65,10 @@ Upcoming changes
Descriptor.getId
fix in 1.610 introduced regressions affecting at least the Performance and NodeJS plugins.
(issue 28093 and issue 28110)
diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java
index 326019f0711db45c4cee80ddf93c39c05bad9792..1f9f94a72159c052463ceb39283010c1ac4e2c6f 100644
--- a/core/src/main/java/hudson/model/Computer.java
+++ b/core/src/main/java/hudson/model/Computer.java
@@ -271,14 +271,25 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
/**
* This is where the log from the remote agent goes.
* The method also creates a log directory if required.
- * @see #relocateOldLogs()
+ * @see #getLogDir(), #relocateOldLogs()
*/
- public File getLogFile() {
+ public @Nonnull File getLogFile() {
+ return new File(getLogDir(),"slave.log");
+ }
+
+ /**
+ * Directory where rotated slave logs are stored.
+ *
+ * The method also creates a log directory if required.
+ *
+ * @since 1.613
+ */
+ protected @Nonnull File getLogDir() {
File dir = new File(Jenkins.getInstance().getRootDir(),"logs/slaves/"+nodeName);
if (!dir.exists() && !dir.mkdirs()) {
LOGGER.severe("Failed to create slave log directory " + dir.getAbsolutePath());
}
- return new File(dir,"slave.log");
+ return dir;
}
/**
diff --git a/core/src/main/java/hudson/slaves/SlaveComputer.java b/core/src/main/java/hudson/slaves/SlaveComputer.java
index 4bf4bfbc391b9893a0543d17b486602eabcb293f..c62401dc767b975ae8485ae0fcb3d02c69ed37b1 100644
--- a/core/src/main/java/hudson/slaves/SlaveComputer.java
+++ b/core/src/main/java/hudson/slaves/SlaveComputer.java
@@ -655,6 +655,12 @@ public class SlaveComputer extends Computer {
super.kill();
closeChannel();
IOUtils.closeQuietly(log);
+
+ try {
+ Util.deleteRecursive(getLogDir());
+ } catch (IOException ex) {
+ logger.log(Level.WARNING, "Unable to delete slave logs", ex);
+ }
}
public RetentionStrategy getRetentionStrategy() {
diff --git a/test/src/test/java/hudson/model/ComputerTest.java b/test/src/test/java/hudson/model/ComputerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..b58b00f45e5380a80177ef0eb47d8f782f84d4da
--- /dev/null
+++ b/test/src/test/java/hudson/model/ComputerTest.java
@@ -0,0 +1,55 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package hudson.model;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+
+import jenkins.model.Jenkins;
+import hudson.slaves.DumbSlave;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.jvnet.hudson.test.JenkinsRule;
+
+public class ComputerTest {
+
+ @Rule public JenkinsRule j = new JenkinsRule();
+
+ @Test
+ public void discardLogsAfterDeletion() throws Exception {
+ DumbSlave delete = j.createOnlineSlave(Jenkins.getInstance().getLabelAtom("delete"));
+ DumbSlave keep = j.createOnlineSlave(Jenkins.getInstance().getLabelAtom("keep"));
+ File logFile = delete.toComputer().getLogFile();
+ assertTrue(logFile.exists());
+
+ Jenkins.getInstance().removeNode(delete);
+
+ assertFalse("Slave log should be deleted", logFile.exists());
+ assertFalse("Slave log directory should be deleted", logFile.getParentFile().exists());
+
+ assertTrue("Slave log should be kept", keep.toComputer().getLogFile().exists());
+ }
+}