You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ff...@apache.org on 2014/07/18 11:19:31 UTC
git commit: [KARAF-3130]add admin:change-ssh-host command (cherry
picked from commit 119e9fecb20633ea98664ccda532bb9cb2f286a1)
Repository: karaf
Updated Branches:
refs/heads/karaf-3.0.x a7bd5ddf2 -> 8a55f92a9
[KARAF-3130]add admin:change-ssh-host command
(cherry picked from commit 119e9fecb20633ea98664ccda532bb9cb2f286a1)
Conflicts:
admin/management/src/main/java/org/apache/karaf/admin/management/internal/AdminServiceMBeanImpl.java
instance/command/src/main/resources/OSGI-INF/blueprint/instance-command.xml
instance/core/src/main/java/org/apache/karaf/instance/core/Instance.java
instance/core/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/8a55f92a
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/8a55f92a
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/8a55f92a
Branch: refs/heads/karaf-3.0.x
Commit: 8a55f92a96f5fcc7d4270e7f1997e494911f410e
Parents: a7bd5dd
Author: Freeman Fang <fr...@gmail.com>
Authored: Fri Jul 18 16:10:01 2014 +0800
Committer: Freeman Fang <fr...@gmail.com>
Committed: Fri Jul 18 17:19:11 2014 +0800
----------------------------------------------------------------------
.../instance/command/ChangeSshHostCommand.java | 35 ++++++++++++++++++++
.../OSGI-INF/blueprint/instance-command.xml | 9 +++++
.../apache/karaf/instance/core/Instance.java | 3 ++
.../karaf/instance/core/InstancesMBean.java | 1 +
.../instance/core/internal/InstanceImpl.java | 6 +++-
.../core/internal/InstanceServiceImpl.java | 26 +++++++++++++++
.../core/internal/InstancesMBeanImpl.java | 8 +++++
7 files changed, 87 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/8a55f92a/instance/command/src/main/java/org/apache/karaf/instance/command/ChangeSshHostCommand.java
----------------------------------------------------------------------
diff --git a/instance/command/src/main/java/org/apache/karaf/instance/command/ChangeSshHostCommand.java b/instance/command/src/main/java/org/apache/karaf/instance/command/ChangeSshHostCommand.java
new file mode 100644
index 0000000..f65a492
--- /dev/null
+++ b/instance/command/src/main/java/org/apache/karaf/instance/command/ChangeSshHostCommand.java
@@ -0,0 +1,35 @@
+/*
+ * 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.karaf.instance.command;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+
+@Command(scope = "instance", name = "ssh-host-change", description = "Changes the secure shell host of an existing container instance.")
+public class ChangeSshHostCommand extends InstanceCommandSupport {
+
+ @Argument(index = 0, name = "name", description="The name of the container instance", required = true, multiValued = false)
+ private String instance = null;
+
+ @Argument(index = 1, name = "host", description = "The new secure shell host to set", required = true, multiValued = false)
+ private String host = "0.0.0.0";
+
+ protected Object doExecute() throws Exception {
+ getExistingInstance(instance).changeSshHost(host);
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/8a55f92a/instance/command/src/main/resources/OSGI-INF/blueprint/instance-command.xml
----------------------------------------------------------------------
diff --git a/instance/command/src/main/resources/OSGI-INF/blueprint/instance-command.xml b/instance/command/src/main/resources/OSGI-INF/blueprint/instance-command.xml
index 175b962..d3501b2 100644
--- a/instance/command/src/main/resources/OSGI-INF/blueprint/instance-command.xml
+++ b/instance/command/src/main/resources/OSGI-INF/blueprint/instance-command.xml
@@ -99,6 +99,15 @@
</completers>
</command>
<command>
+ <action class="org.apache.karaf.instance.command.ChangeSshHostCommand">
+ <property name="instanceService" ref="instanceService" />
+ </action>
+ <completers>
+ <ref component-id="stoppedInstanceCompleter" />
+ <null/>
+ </completers>
+ </command>
+ <command>
<action class="org.apache.karaf.instance.command.ChangeRmiRegistryPortCommand">
<property name="instanceService" ref="instanceService" />
</action>
http://git-wip-us.apache.org/repos/asf/karaf/blob/8a55f92a/instance/core/src/main/java/org/apache/karaf/instance/core/Instance.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/Instance.java b/instance/core/src/main/java/org/apache/karaf/instance/core/Instance.java
index 5e78bb2..b30f670 100644
--- a/instance/core/src/main/java/org/apache/karaf/instance/core/Instance.java
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/Instance.java
@@ -63,4 +63,7 @@ public interface Instance {
@Deprecated
boolean isAttached();
+
+ void changeSshHost(String host) throws Exception;
+
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/8a55f92a/instance/core/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java b/instance/core/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
index f77c936..0265091 100644
--- a/instance/core/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/InstancesMBean.java
@@ -49,6 +49,7 @@ public interface InstancesMBean {
void renameInstance(String originalName, String newName) throws MBeanException;
void renameInstance(String originalName, String newName, boolean verbose) throws MBeanException;
void cloneInstance(String name, String cloneName, int sshPort, int rmiRegistryPort, int rmiServerPort, String location, String javaOpts) throws MBeanException;
+ void changeSshHost(String name, String host) throws MBeanException;
// Attributes
TabularData getInstances() throws MBeanException;
http://git-wip-us.apache.org/repos/asf/karaf/blob/8a55f92a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
index edc4ec5..981ff9e 100644
--- a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceImpl.java
@@ -107,4 +107,8 @@ public class InstanceImpl implements Instance {
public boolean isAttached() {
return getPid() != 0;
}
-}
\ No newline at end of file
+
+ public void changeSshHost(String host) throws Exception {
+ service.changeInstanceSshHost(name, host);
+ }
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/8a55f92a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
index 7aa350e..910c527 100644
--- a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstanceServiceImpl.java
@@ -1185,4 +1185,30 @@ public class InstanceServiceImpl implements InstanceService {
return val;
}
+ public void changeInstanceSshHost(String name, String host) throws Exception {
+ setKarafHost(name, "etc/org.apache.karaf.shell.cfg", "sshHost", host);
+ }
+
+ private void setKarafHost(final String name, final String path, final String key, final String host) throws IOException {
+ execute(new Task<Object>() {
+ public Object call(State state) throws IOException {
+ InstanceState instance = state.instances.get(name);
+ if (instance == null) {
+ throw new IllegalArgumentException("Instance " + name + " not found");
+ }
+ checkPid(instance);
+ if (instance.pid != 0) {
+ throw new IllegalStateException("Instance is not stopped");
+ }
+ File f = new File(instance.loc, path);
+ FileLockUtils.execute(f, new FileLockUtils.RunnableWithProperties() {
+ public void run(org.apache.felix.utils.properties.Properties properties) throws IOException {
+ properties.put(key, host);
+ }
+ }, true);
+ return null;
+ }
+ }, true);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/8a55f92a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstancesMBeanImpl.java
----------------------------------------------------------------------
diff --git a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstancesMBeanImpl.java b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstancesMBeanImpl.java
index 7275c1e..adf6a1a 100644
--- a/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstancesMBeanImpl.java
+++ b/instance/core/src/main/java/org/apache/karaf/instance/core/internal/InstancesMBeanImpl.java
@@ -78,6 +78,14 @@ public class InstancesMBeanImpl extends StandardMBean implements InstancesMBean
}
}
+ public void changeSshHost(String name, String host) throws MBeanException {
+ try {
+ getExistingInstance(name).changeSshHost(host);
+ } catch (Exception e) {
+ throw new MBeanException(null, e.getMessage());
+ }
+ }
+
public void changeRmiRegistryPort(String name, int port) throws MBeanException {
try {
getExistingInstance(name).changeRmiRegistryPort(port);