提交 b9f7d5a4 编写于 作者: K kohsuke

implementing a ZFS based FileSystemProvisioner as a test to see if the abstraction works.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15351 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b6c0519b
......@@ -138,8 +138,14 @@ public abstract class FileSystemProvisioner implements ExtensionPoint, Describab
/**
* When a project is deleted, this method is called to undo the effect of
* {@link #prepareWorkspace(AbstractBuild, FilePath, TaskListener)}.
*
* @param project
* Project whose workspace is being discarded.
* @param ws
* Workspace to be discarded. This workspace is on the node
* this {@link FileSystemProvisioner} is provisioned for.
*/
public abstract void discardWorkspace(AbstractProject<?,?> project) throws IOException, InterruptedException;
public abstract void discardWorkspace(AbstractProject<?,?> project, FilePath ws) throws IOException, InterruptedException;
// public abstract void moveWorkspace(AbstractProject<?,?> project, File oldWorkspace, File newWorkspace) throws IOException;
......@@ -186,7 +192,7 @@ public abstract class FileSystemProvisioner implements ExtensionPoint, Describab
public void prepareWorkspace(AbstractBuild<?, ?> build, FilePath ws, TaskListener listener) throws IOException, InterruptedException {
}
public void discardWorkspace(AbstractProject<?,?> project) throws IOException, InterruptedException {
public void discardWorkspace(AbstractProject<?,?> project, FilePath ws) throws IOException, InterruptedException {
}
/**
......
......@@ -202,11 +202,10 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
// prevent a new build while a delete operation is in progress
makeDisabled(true);
FilePath ws = getWorkspace();
if(ws!=null)
if(ws!=null) {
getScm().processWorkspaceBeforeDeletion(this, ws,getLastBuiltOn());
getLastBuiltOn().getFileSystemProvisioner().discardWorkspace(this);
getLastBuiltOn().getFileSystemProvisioner().discardWorkspace(this,ws);
}
super.performDelete();
}
......
/*
* The MIT License
*
* Copyright (c) 2004-2009, Sun Microsystems, 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.os.solaris;
import hudson.FileSystemProvisioner;
import hudson.FilePath;
import hudson.WorkspaceSnapshot;
import hudson.FileSystemProvisionerDescriptor;
import hudson.remoting.VirtualChannel;
import hudson.FilePath.FileCallable;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import hudson.model.AbstractProject;
import hudson.model.Node;
import java.io.IOException;
import java.io.File;
import java.io.Serializable;
import org.jvnet.solaris.libzfs.LibZFS;
import org.jvnet.solaris.libzfs.ZFSFileSystem;
/**
* {@link FileSystemProvisioner} for ZFS.
*
* @author Kohsuke Kawaguchi
*/
public class ZFSProvisioner extends FileSystemProvisioner implements Serializable {
private final LibZFS libzfs = new LibZFS();
private final Node node;
private final String rootDataset;
public ZFSProvisioner(Node node) throws IOException, InterruptedException {
this.node = node;
rootDataset = node.getRootPath().act(new FileCallable<String>() {
public String invoke(File f, VirtualChannel channel) throws IOException {
ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f);
if(fs!=null) return fs.getName();
// TODO: for now, only support slaves that are already on ZFS.
throw new IOException("Not on ZFS");
}
});
}
public void prepareWorkspace(AbstractBuild<?,?> build, FilePath ws, TaskListener listener) throws IOException, InterruptedException {
final String name = build.getProject().getFullName();
ws.act(new FileCallable<Void>() {
public Void invoke(File f, VirtualChannel channel) throws IOException {
ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f);
if(fs!=null) return null; // already on ZFS
// nope. create a file system
fs = libzfs.create(rootDataset+'/'+name, ZFSFileSystem.class);
fs.setMountPoint(f);
fs.mount();
return null;
}
});
}
public void discardWorkspace(AbstractProject<?,?> project, FilePath ws) throws IOException, InterruptedException {
ws.act(new FileCallable<Void>() {
public Void invoke(File f, VirtualChannel channel) throws IOException {
ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f);
if(fs!=null)
fs.destory(true);
return null;
}
});
}
public WorkspaceSnapshot snapshot(AbstractBuild<?, ?> build, FilePath ws, TaskListener listener) throws IOException, InterruptedException {
throw new UnsupportedOperationException();
}
public FileSystemProvisionerDescriptor getDescriptor() {
return null;
}
private static final long serialVersionUID = 1L;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册