You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2012/09/11 18:16:30 UTC
svn commit: r1383467 - in /karaf/branches/karaf-2.3.x:
management/mbeans/system/
management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/
management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/internal...
Author: jbonofre
Date: Tue Sep 11 16:16:30 2012
New Revision: 1383467
URL: http://svn.apache.org/viewvc?rev=1383467&view=rev
Log:
[KARAF-1813] Add osgi:name command and name attribute in SystemMBean
Added:
karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Name.java
Modified:
karaf/branches/karaf-2.3.x/management/mbeans/system/pom.xml
karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/SystemMBean.java
karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/internal/SystemMBeanImpl.java
karaf/branches/karaf-2.3.x/shell/osgi/pom.xml
karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Shutdown.java
karaf/branches/karaf-2.3.x/shell/osgi/src/main/resources/OSGI-INF/blueprint/shell-osgi.xml
Modified: karaf/branches/karaf-2.3.x/management/mbeans/system/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/management/mbeans/system/pom.xml?rev=1383467&r1=1383466&r2=1383467&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/management/mbeans/system/pom.xml (original)
+++ karaf/branches/karaf-2.3.x/management/mbeans/system/pom.xml Tue Sep 11 16:16:30 2012
@@ -42,6 +42,12 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.utils</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
@@ -78,6 +84,7 @@
</Import-Package>
<Private-Package>
org.apache.karaf.management.mbeans.system.internal,
+ org.apache.felix.utils*,
!*
</Private-Package>
</instructions>
Modified: karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/SystemMBean.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/SystemMBean.java?rev=1383467&r1=1383466&r2=1383467&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/SystemMBean.java (original)
+++ karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/SystemMBean.java Tue Sep 11 16:16:30 2012
@@ -21,6 +21,9 @@ package org.apache.karaf.management.mbea
*/
public interface SystemMBean {
+ String getName();
+ void setName(String name);
+
void shutdown() throws Exception;
}
Modified: karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/internal/SystemMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/internal/SystemMBeanImpl.java?rev=1383467&r1=1383466&r2=1383467&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/internal/SystemMBeanImpl.java (original)
+++ karaf/branches/karaf-2.3.x/management/mbeans/system/src/main/java/org/apache/karaf/management/mbeans/system/internal/SystemMBeanImpl.java Tue Sep 11 16:16:30 2012
@@ -16,11 +16,15 @@
*/
package org.apache.karaf.management.mbeans.system.internal;
+import org.apache.felix.utils.properties.Properties;
import org.apache.karaf.management.mbeans.system.SystemMBean;
import org.osgi.framework.BundleContext;
import javax.management.NotCompliantMBeanException;
import javax.management.StandardMBean;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
/**
* System MBean implementation.
@@ -33,6 +37,28 @@ public class SystemMBeanImpl extends Sta
super(SystemMBean.class);
}
+ public String getName() {
+ return bundleContext.getProperty("karaf.name");
+ }
+
+ public void setName(String name) {
+ try {
+ String karafBase = bundleContext.getProperty("karaf.base");
+ File etcDir = new File(karafBase, "etc");
+ File syspropsFile = new File(etcDir, "system.properties");
+ FileInputStream fis = new FileInputStream(syspropsFile);
+ Properties props = new Properties();
+ props.load(fis);
+ fis.close();
+ props.setProperty("karaf.name", name);
+ FileOutputStream fos = new FileOutputStream(syspropsFile);
+ props.store(fos, "");
+ fos.close();
+ } catch (Exception e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
public void shutdown() throws Exception {
bundleContext.getBundle(0).stop();
}
Modified: karaf/branches/karaf-2.3.x/shell/osgi/pom.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/shell/osgi/pom.xml?rev=1383467&r1=1383466&r2=1383467&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/shell/osgi/pom.xml (original)
+++ karaf/branches/karaf-2.3.x/shell/osgi/pom.xml Tue Sep 11 16:16:30 2012
@@ -116,8 +116,7 @@
</DynamicImport-Package>
<Private-Package>
org.apache.karaf.util;-split-package:=merge-first,
- org.apache.felix.utils.version,
- org.apache.felix.utils.manifest,
+ org.apache.felix.utils*,
!*
</Private-Package>
</instructions>
Added: karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Name.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Name.java?rev=1383467&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Name.java (added)
+++ karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Name.java Tue Sep 11 16:16:30 2012
@@ -0,0 +1,58 @@
+/*
+ * 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.shell.osgi;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.felix.utils.properties.Properties;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+@Command(scope = "osgi", name = "name", description = "Show or change Karaf instance name.")
+public class Name extends OsgiCommandSupport {
+
+ @Argument(name = "name", index = 0, description = "New name of the Karaf instance.", required = false, multiValued = false)
+ String name;
+
+ protected Object doExecute() throws Exception {
+ if (name == null) {
+ System.out.println(bundleContext.getProperty("karaf.name"));
+ } else {
+ try {
+ String karafBase = bundleContext.getProperty("karaf.base");
+ File etcDir = new File(karafBase, "etc");
+ File syspropsFile = new File(etcDir, "system.properties");
+ FileInputStream fis = new FileInputStream(syspropsFile);
+ Properties props = new Properties();
+ props.load(fis);
+ fis.close();
+ props.setProperty("karaf.name", name);
+ FileOutputStream fos = new FileOutputStream(syspropsFile);
+ props.store(fos, "");
+ fos.close();
+ } catch (Exception e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ System.out.println("Instance name changed to " + name + ". Restart needed for this to take effect.");
+ }
+ return null;
+ }
+
+}
Modified: karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Shutdown.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Shutdown.java?rev=1383467&r1=1383466&r2=1383467&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Shutdown.java (original)
+++ karaf/branches/karaf-2.3.x/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Shutdown.java Tue Sep 11 16:16:30 2012
@@ -28,7 +28,7 @@ import java.util.GregorianCalendar;
/**
* Command to shut down Karaf
*/
-@Command(scope = "osgi", name = "shutdown", description = "Shuts the framework down.")
+@Command(scope = "osgi", name = "shutdown", description = "Shutdown the framework down.")
public class Shutdown extends OsgiCommandSupport {
@Option(name = "-f", aliases = "--force", description = "Force the shutdown without confirmation message.", required = false, multiValued = false)
Modified: karaf/branches/karaf-2.3.x/shell/osgi/src/main/resources/OSGI-INF/blueprint/shell-osgi.xml
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/shell/osgi/src/main/resources/OSGI-INF/blueprint/shell-osgi.xml?rev=1383467&r1=1383466&r2=1383467&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/shell/osgi/src/main/resources/OSGI-INF/blueprint/shell-osgi.xml (original)
+++ karaf/branches/karaf-2.3.x/shell/osgi/src/main/resources/OSGI-INF/blueprint/shell-osgi.xml Tue Sep 11 16:16:30 2012
@@ -51,6 +51,9 @@
<command name="osgi/ls">
<action class="org.apache.karaf.shell.osgi.ListServices"/>
</command>
+ <command name="osgi/name">
+ <action class="org.apache.karaf.shell.osgi.Name"/>
+ </command>
<command name="osgi/refresh">
<action class="org.apache.karaf.shell.osgi.RefreshBundle"/>
</command>