1 | /** |
2 | * |
3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
4 | * |
5 | * ==================================================================== |
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * you may not use this file except in compliance with the License. |
8 | * You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, software |
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * See the License for the specific language governing permissions and |
16 | * limitations under the License. |
17 | * ==================================================================== |
18 | */ |
19 | package org.jclouds.compute.callables; |
20 | |
21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | |
23 | import javax.inject.Inject; |
24 | import javax.inject.Named; |
25 | |
26 | import org.jclouds.compute.domain.ExecResponse; |
27 | import org.jclouds.compute.domain.NodeMetadata; |
28 | import org.jclouds.compute.options.RunScriptOptions; |
29 | import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; |
30 | import org.jclouds.scriptbuilder.domain.Statement; |
31 | import org.jclouds.ssh.SshClient; |
32 | |
33 | import com.google.common.base.Function; |
34 | import com.google.common.base.Predicate; |
35 | import com.google.inject.assistedinject.Assisted; |
36 | |
37 | /** |
38 | * |
39 | * @author Adrian Cole |
40 | */ |
41 | public class RunScriptOnNodeAsInitScriptUsingSshAndBlockUntilComplete extends RunScriptOnNodeAsInitScriptUsingSsh { |
42 | protected final Predicate<CommandUsingClient> runScriptNotRunning; |
43 | |
44 | @Inject |
45 | public RunScriptOnNodeAsInitScriptUsingSshAndBlockUntilComplete( |
46 | @Named("SCRIPT_COMPLETE") Predicate<CommandUsingClient> runScriptNotRunning, |
47 | Function<NodeMetadata, SshClient> sshFactory, @Assisted NodeMetadata node, @Assisted Statement script, |
48 | @Assisted RunScriptOptions options) { |
49 | super(sshFactory, node, script, options); |
50 | this.runScriptNotRunning = checkNotNull(runScriptNotRunning, "runScriptNotRunning"); |
51 | } |
52 | |
53 | @Override |
54 | public ExecResponse doCall() { |
55 | ExecResponse returnVal = super.doCall(); |
56 | boolean complete = runScriptNotRunning.apply(new CommandUsingClient("./" + name + " status", ssh)); |
57 | logger.debug("<< complete(%s)", complete); |
58 | if (logger.isDebugEnabled() || returnVal.getExitCode() != 0) { |
59 | logger.debug("<< stdout from %s as %s@%s\n%s", name, ssh.getUsername(), ssh.getHostAddress(), ssh.exec( |
60 | "./" + name + " tail").getOutput()); |
61 | logger.debug("<< stderr from %s as %s@%s\n%s", name, ssh.getUsername(), ssh.getHostAddress(), ssh.exec( |
62 | "./" + name + " tailerr").getOutput()); |
63 | } |
64 | return returnVal; |
65 | } |
66 | } |