You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2015/12/04 13:48:50 UTC
[4/7] incubator-brooklyn git commit: Adds WinRmException
Adds WinRmException
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/1984eaf5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/1984eaf5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/1984eaf5
Branch: refs/heads/master
Commit: 1984eaf5836e1ad70394da766d6ba10b787ffb97
Parents: d343b5a
Author: Aled Sage <al...@gmail.com>
Authored: Fri Dec 4 12:01:00 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Dec 4 12:01:00 2015 +0000
----------------------------------------------------------------------
.../core/internal/winrm/WinRmException.java | 32 ++++++++++++++++++++
.../internal/winrm/pywinrm/Winrm4jTool.java | 19 ++++++++++--
2 files changed, 49 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1984eaf5/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/WinRmException.java
----------------------------------------------------------------------
diff --git a/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/WinRmException.java b/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/WinRmException.java
new file mode 100644
index 0000000..9be92b4
--- /dev/null
+++ b/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/WinRmException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.util.core.internal.winrm;
+
+public class WinRmException extends RuntimeException {
+
+ private static final long serialVersionUID = -5690230838066860965L;
+
+ public WinRmException(String msg) {
+ super(msg);
+ }
+
+ public WinRmException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1984eaf5/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/pywinrm/Winrm4jTool.java
----------------------------------------------------------------------
diff --git a/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/pywinrm/Winrm4jTool.java b/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/pywinrm/Winrm4jTool.java
index e1f313d..0bdfa14 100644
--- a/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/pywinrm/Winrm4jTool.java
+++ b/software/winrm/src/main/java/org/apache/brooklyn/util/core/internal/winrm/pywinrm/Winrm4jTool.java
@@ -30,6 +30,7 @@ import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.config.Sanitizer;
import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.internal.winrm.WinRmException;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.time.Duration;
import org.apache.brooklyn.util.time.Time;
@@ -123,7 +124,7 @@ public class Winrm4jTool implements org.apache.brooklyn.util.core.internal.winrm
return new org.apache.brooklyn.util.core.internal.winrm.WinRmToolResponse("", "", 0);
} catch (java.io.IOException e) {
- throw Exceptions.propagate(e);
+ throw propagate(e, "Failed copying to server at "+destination);
}
}
@@ -173,7 +174,7 @@ public class Winrm4jTool implements org.apache.brooklyn.util.core.internal.winrm
exceptions.add(e);
}
}
- throw Exceptions.propagate("failed to execute command", exceptions);
+ throw propagate(Exceptions.create("failed to execute command", exceptions), "");
}
private io.cloudsoft.winrm4j.winrm.WinRmTool connect() {
@@ -191,4 +192,18 @@ public class Winrm4jTool implements org.apache.brooklyn.util.core.internal.winrm
private org.apache.brooklyn.util.core.internal.winrm.WinRmToolResponse wrap(io.cloudsoft.winrm4j.winrm.WinRmToolResponse resp) {
return new org.apache.brooklyn.util.core.internal.winrm.WinRmToolResponse(resp.getStdOut(), resp.getStdErr(), resp.getStatusCode());
}
+
+ @Override
+ public String toString() {
+ return String.format("%s@%s:%d", user, host, port);
+ }
+
+ /**
+ * @throws WinRmException If the given {@code e} is not fatal (e.g. not an {@link Error} or {@link InterruptedException},
+ * then wraps it in a {@link WinRmException}.
+ */
+ protected WinRmException propagate(Exception e, String message) throws WinRmException {
+ Exceptions.propagateIfFatal(e);
+ throw new WinRmException("(" + toString() + ") " + message + ": " + e.getMessage(), e);
+ }
}