View Javadoc

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;
20  
21  import static org.jclouds.compute.util.ComputeServiceUtils.createExecutionErrorMessage;
22  import static org.jclouds.compute.util.ComputeServiceUtils.createNodeErrorMessage;
23  
24  import java.util.Map;
25  
26  import javax.annotation.Nullable;
27  
28  import org.jclouds.compute.domain.ExecResponse;
29  import org.jclouds.compute.domain.NodeMetadata;
30  import org.jclouds.compute.options.RunScriptOptions;
31  import org.jclouds.scriptbuilder.domain.Statement;
32  
33  /**
34   * 
35   * @author Adrian Cole
36   */
37  public class RunScriptOnNodesException extends Exception {
38  
39     /** The serialVersionUID */
40     private static final long serialVersionUID = -2272965726680821281L;
41     private final Statement runScript;
42     private final RunScriptOptions options;
43     private final Map<NodeMetadata, ExecResponse> successfulNodes;
44     private final Map<? extends NodeMetadata, ? extends Throwable> failedNodes;
45     private final Map<?, Exception> executionExceptions;
46  
47     public RunScriptOnNodesException(Statement runScript, @Nullable RunScriptOptions options,
48              Map<NodeMetadata, ExecResponse> successfulNodes, Map<?, Exception> executionExceptions,
49              Map<? extends NodeMetadata, ? extends Throwable> failedNodes) {
50        super(String.format("error runScript on filtered nodes options(%s)%n%s%n%s", options,
51                 createExecutionErrorMessage(executionExceptions), createNodeErrorMessage(failedNodes)));
52        this.runScript = runScript;
53        this.options = options;
54        this.successfulNodes = successfulNodes;
55        this.failedNodes = failedNodes;
56        this.executionExceptions = executionExceptions;
57     }
58  
59     /**
60      * @return Nodes that performed ssh without error
61      */
62     public Map<NodeMetadata, ExecResponse> getSuccessfulNodes() {
63        return successfulNodes;
64     }
65  
66     /**
67      * 
68      * @return Nodes that performed startup without error, but incurred problems applying options
69      */
70     public Map<?, ? extends Throwable> getExecutionErrors() {
71        return executionExceptions;
72     }
73  
74     /**
75      * 
76      * @return Nodes that performed startup without error, but incurred problems applying options
77      */
78     public Map<? extends NodeMetadata, ? extends Throwable> getNodeErrors() {
79        return failedNodes;
80     }
81  
82     public Statement getRunScript() {
83        return runScript;
84     }
85  
86     public RunScriptOptions getOptions() {
87        return options;
88     }
89  
90  }