From 9bb26288039a2119fee89e4c660e0e101e3497c8 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sun, 20 Jul 2008 15:36:37 +0000 Subject: [PATCH] Prototyping the extension point that takes advantages of the underlying file system like ZFS. Still very much a work in progress. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10879 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/FileSystemProvisioner.java | 59 +++++++++++++++++++ .../main/java/hudson/WorkspaceSnapshot.java | 19 ++++++ 2 files changed, 78 insertions(+) create mode 100644 core/src/main/java/hudson/FileSystemProvisioner.java create mode 100644 core/src/main/java/hudson/WorkspaceSnapshot.java diff --git a/core/src/main/java/hudson/FileSystemProvisioner.java b/core/src/main/java/hudson/FileSystemProvisioner.java new file mode 100644 index 0000000000..a2132a0ef7 --- /dev/null +++ b/core/src/main/java/hudson/FileSystemProvisioner.java @@ -0,0 +1,59 @@ +package hudson; + +import hudson.matrix.MatrixBuild; +import hudson.model.AbstractBuild; +import hudson.model.AbstractProject; +import hudson.model.Computer; +import hudson.model.Job; + +import java.io.IOException; +import java.io.File; + +/** + * Prepares and provisions workspaces for {@link AbstractProject}s. + * + *

+ * + * + *

+ * STILL A WORK IN PROGRESS. SUBJECT TO CHANGE! + * + * TODO: is this per {@link Computer}? Per {@link Job}? + * + * @author Kohsuke Kawaguchi + * @since 1.235 + */ +public abstract class FileSystemProvisioner implements ExtensionPoint { + /** + * Called very early in the build (before a build places any files + * in the workspace, such as SCM checkout) to provision a workspace + * for the build. + * + *

+ * This method can prepare the underlying file system in preparation + * for the later {@link #snapshot(AbstractBuild)}. + * + * + * TODO: the method needs to be able to see the snapshot would + * be later needed. In fact, perhaps we should only call this method + * when Hudson knows that a snapshot is later needed? + */ + public abstract void prepareWorkspace(AbstractBuild build) throws IOException; + + public abstract void discardWorkspace(AbstractProject project) throws IOException; + + public abstract void moveWorkspace(AbstractProject project, File oldWorkspace, File newWorkspace) throws IOException; + + /** + * Obtains the snapshot of the workspace of the given build. + * + *

+ * The state of the build when this method is invoked depends on + * the project type. Most would call this at the end of the build, + * but for example {@link MatrixBuild} would call this after + * SCM check out so that the state of the fresh workspace + * can be then propagated to elsewhere. + */ + public abstract WorkspaceSnapshot snapshot(AbstractBuild build) throws IOException; + +} diff --git a/core/src/main/java/hudson/WorkspaceSnapshot.java b/core/src/main/java/hudson/WorkspaceSnapshot.java new file mode 100644 index 0000000000..474fe23f07 --- /dev/null +++ b/core/src/main/java/hudson/WorkspaceSnapshot.java @@ -0,0 +1,19 @@ +package hudson; + +import hudson.model.Action; + +/** + * Represents a workspace snapshot created by {@link FileSystemProvisioner}. + * + *

+ * This class encapsulates a logic to use the snapshot elsewhere. + * + *

+ * TODO: how to garbage-collect this object, especially for zfs? + * perhaps when a new build is started? + * + * @author Kohsuke Kawaguchi + */ +public abstract class WorkspaceSnapshot implements Action { + public abstract void restoreTo(FilePath dst); +}