File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\os\solaris\ZFSProvisioner.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.os.solaris;
25
26 import hudson.FileSystemProvisioner;
27 import hudson.FilePath;
28 import hudson.WorkspaceSnapshot;
29 import hudson.FileSystemProvisionerDescriptor;
30 import hudson.Extension;
31 import hudson.remoting.VirtualChannel;
32 import hudson.FilePath.FileCallable;
33 import hudson.model.AbstractBuild;
34 import hudson.model.TaskListener;
35 import hudson.model.AbstractProject;
36 import hudson.model.Node;
37
38 import java.io.IOException;
39 import java.io.File;
40 import java.io.Serializable;
41
42 import org.jvnet.solaris.libzfs.LibZFS;
43 import org.jvnet.solaris.libzfs.ZFSFileSystem;
44
45 /**
46 * {@link FileSystemProvisioner} for ZFS.
47 *
48 * @author Kohsuke Kawaguchi
49 */
50 public class ZFSProvisioner extends FileSystemProvisioner implements Serializable {
51 private static final LibZFS libzfs = new LibZFS();
52 private final String rootDataset;
53
54 public ZFSProvisioner(Node node) throws IOException, InterruptedException {
55 rootDataset = node.getRootPath().act(new FileCallable<String>() {
56 private static final long serialVersionUID = -2142349338699797436L;
57
58 public String invoke(File f, VirtualChannel channel) throws IOException {
59 ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f);
60 if(fs!=null) return fs.getName();
61
62 // TODO: for now, only support slaves that are already on ZFS.
63 throw new IOException("Not on ZFS");
64 }
65 });
66 }
67
68 public void prepareWorkspace(AbstractBuild<?,?> build, FilePath ws, final TaskListener listener) throws IOException, InterruptedException {
69 final String name = build.getProject().getFullName();
70
71 ws.act(new FileCallable<Void>() {
72 private static final long serialVersionUID = 2129531727963121198L;
73
74 public Void invoke(File f, VirtualChannel channel) throws IOException {
75 ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f);
76 if(fs!=null) return null; // already on ZFS
77
78 // nope. create a file system
79 String fullName = rootDataset + '/' + name;
80 listener.getLogger().println("Creating a ZFS file system "+fullName+" at "+f);
81 fs = libzfs.create(fullName, ZFSFileSystem.class);
82 fs.setMountPoint(f);
83 fs.mount();
84 return null;
85 }
86 });
87 }
88
89 public void discardWorkspace(AbstractProject<?, ?> project, FilePath ws) throws IOException, InterruptedException {
90 ws.act(new FileCallable<Void>() {
91 private static final long serialVersionUID = 1916618107019257530L;
92
93 public Void invoke(File f, VirtualChannel channel) throws IOException {
94 ZFSFileSystem fs = libzfs.getFileSystemByMountPoint(f);
95 if(fs!=null)
96 fs.destory(true);
97 return null;
98 }
99 });
100 }
101
102 /**
103 * @deprecated as of 1.350
104 */
105 public WorkspaceSnapshot snapshot(AbstractBuild<?, ?> build, FilePath ws, TaskListener listener) throws IOException, InterruptedException {
106 throw new UnsupportedOperationException();
107 }
108
109 public WorkspaceSnapshot snapshot(AbstractBuild<?, ?> build, FilePath ws, String glob, TaskListener listener) throws IOException, InterruptedException {
110 throw new UnsupportedOperationException();
111 }
112
113 @Extension
114 public static final class DescriptorImpl extends FileSystemProvisionerDescriptor {
115 public boolean discard(FilePath ws, TaskListener listener) throws IOException, InterruptedException {
116 // TODO
117 return false;
118 }
119
120 public String getDisplayName() {
121 return "ZFS";
122 }
123 }
124
125 private static final long serialVersionUID = 1L;
126 }
127