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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2010, InfraDNA, 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.slaves;
25
26 import hudson.model.Descriptor.FormException;
27 import jenkins.model.Jenkins;
28 import hudson.model.Slave;
29 import hudson.model.TaskListener;
30 import hudson.util.StreamTaskListener;
31
32 import java.io.IOException;
33 import java.nio.charset.Charset;
34 import java.util.List;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37
38 /**
39 * Partial implementation of {@link Slave} to be used by {@link AbstractCloudImpl}.
40 * You may want to implement {@link EphemeralNode} too.
41 * @author Kohsuke Kawaguchi
42 * @since 1.382
43 */
44 public abstract class AbstractCloudSlave extends Slave {
45 public AbstractCloudSlave(String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException {
46 super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);
47 }
48
49 public AbstractCloudSlave(String name, String nodeDescription, String remoteFS, int numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException {
50 super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);
51 }
52
53 @Override
54 public abstract AbstractCloudComputer createComputer();
55
56 /**
57 * Releases and removes this slave.
58 */
59 public void terminate() throws InterruptedException, IOException {
60 try {
61 // TODO: send the output to somewhere real
62 _terminate(new StreamTaskListener(System.out, Charset.defaultCharset()));
63 } finally {
64 try {
65 Jenkins.getInstance().removeNode(this);
66 } catch (IOException e) {
67 LOGGER.log(Level.WARNING, "Failed to remove "+name,e);
68 }
69 }
70 }
71
72 /**
73 * Performs the removal of the underlying resource from the cloud.
74 */
75 protected abstract void _terminate(TaskListener listener) throws IOException, InterruptedException;
76
77 private static final Logger LOGGER = Logger.getLogger(AbstractCloudSlave.class.getName());
78 }
79