| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 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 | } |