| 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 | import java.util.Set; | 
| 26 |   | 
| 27 | import org.jclouds.compute.domain.NodeMetadata; | 
| 28 | import org.jclouds.compute.domain.Template; | 
| 29 |   | 
| 30 | /** | 
| 31 |  *  | 
| 32 |  * @author Adrian Cole | 
| 33 |  */ | 
| 34 | public class RunNodesException extends Exception { | 
| 35 |   | 
| 36 |    /** The serialVersionUID */ | 
| 37 |    private static final long serialVersionUID = -2272965726680821281L; | 
| 38 |    private final String tag; | 
| 39 |    private final int count; | 
| 40 |    private final Template template; | 
| 41 |    private final Set<? extends NodeMetadata> successfulNodes; | 
| 42 |    private final Map<? extends NodeMetadata, ? extends Throwable> failedNodes; | 
| 43 |    private final Map<?, Exception> executionExceptions; | 
| 44 |   | 
| 45 |    public RunNodesException(String tag, int count, Template template, | 
| 46 |             Set<? extends NodeMetadata> successfulNodes, Map<?, Exception> executionExceptions, | 
| 47 |             Map<? extends NodeMetadata, ? extends Throwable> failedNodes) { | 
| 48 |       super( | 
| 49 |                String | 
| 50 |                         .format( | 
| 51 |                                  "error running %d node%s tag(%s) location(%s) image(%s) size(%s) options(%s)%n%s%n%s", | 
| 52 |                                  count, count > 1 ? "s" : "", tag, template.getLocation().getId(), | 
| 53 |                                  template.getImage().getProviderId(), template.getHardware() | 
| 54 |                                           .getProviderId(), template.getOptions(), | 
| 55 |                                  createExecutionErrorMessage(executionExceptions), | 
| 56 |                                  createNodeErrorMessage(failedNodes))); | 
| 57 |       this.tag = tag; | 
| 58 |       this.count = count; | 
| 59 |       this.template = template; | 
| 60 |       this.successfulNodes = successfulNodes; | 
| 61 |       this.failedNodes = failedNodes; | 
| 62 |       this.executionExceptions = executionExceptions; | 
| 63 |    } | 
| 64 |   | 
| 65 |    /** | 
| 66 |     *  | 
| 67 |     * @return Nodes that performed startup without error | 
| 68 |     */ | 
| 69 |    public Set<? extends NodeMetadata> getSuccessfulNodes() { | 
| 70 |       return successfulNodes; | 
| 71 |    } | 
| 72 |   | 
| 73 |    /** | 
| 74 |     *  | 
| 75 |     * @return Nodes that performed startup without error, but incurred problems applying options | 
| 76 |     */ | 
| 77 |    public Map<?, ? extends Throwable> getExecutionErrors() { | 
| 78 |       return executionExceptions; | 
| 79 |    } | 
| 80 |   | 
| 81 |    /** | 
| 82 |     *  | 
| 83 |     * @return Nodes that performed startup without error, but incurred problems applying options | 
| 84 |     */ | 
| 85 |    public Map<? extends NodeMetadata, ? extends Throwable> getNodeErrors() { | 
| 86 |       return failedNodes; | 
| 87 |    } | 
| 88 |   | 
| 89 |    public String getTag() { | 
| 90 |       return tag; | 
| 91 |    } | 
| 92 |   | 
| 93 |    public int getCount() { | 
| 94 |       return count; | 
| 95 |    } | 
| 96 |   | 
| 97 |    public Template getTemplate() { | 
| 98 |       return template; | 
| 99 |    } | 
| 100 |   | 
| 101 | } |