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 2011/09/23 21:59:43 UTC
svn commit: r1174985 - in /karaf/trunk:
assemblies/features/standard/src/main/feature/ management/mbeans/
management/mbeans/log/src/main/resources/OSGI-INF/ management/mbeans/obr/
management/mbeans/obr/src/ management/mbeans/obr/src/main/ management/mb...
Author: jbonofre
Date: Fri Sep 23 19:59:42 2011
New Revision: 1174985
URL: http://svn.apache.org/viewvc?rev=1174985&view=rev
Log:
[KARAF-786] Add the OBR MBean
Added:
karaf/trunk/management/mbeans/obr/
karaf/trunk/management/mbeans/obr/NOTICE
karaf/trunk/management/mbeans/obr/pom.xml
karaf/trunk/management/mbeans/obr/src/
karaf/trunk/management/mbeans/obr/src/main/
karaf/trunk/management/mbeans/obr/src/main/java/
karaf/trunk/management/mbeans/obr/src/main/java/org/
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/ObrMBean.java
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/internal/
karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/internal/ObrMBeanImpl.java
karaf/trunk/management/mbeans/obr/src/main/resources/
karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/
karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/blueprint/
karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/blueprint/obr-management.xml
karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/bundle.info
Modified:
karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml
karaf/trunk/management/mbeans/log/src/main/resources/OSGI-INF/bundle.info
karaf/trunk/management/mbeans/pom.xml
Modified: karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml?rev=1174985&r1=1174984&r2=1174985&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml (original)
+++ karaf/trunk/assemblies/features/standard/src/main/feature/feature.xml Fri Sep 23 19:59:42 2011
@@ -100,6 +100,7 @@
<bundle start-level="30">mvn:org.apache.felix/org.apache.felix.bundlerepository/${felix.bundlerepository.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.shell/org.apache.karaf.shell.obr/${project.version}</bundle>
<bundle start-level="30">mvn:org.apache.karaf.features/org.apache.karaf.features.obr/${project.version}</bundle>
+ <bundle start-level="30">mvn:org.apache.karaf.management.mbeans/org.apache.karaf.management.mbeans.obr/${project.version}</bundle>
<bundle start-level="30">mvn:org.ops4j.pax.url/pax-url-obr/${pax.url.version}</bundle>
</feature>
<feature name="org.apache.karaf.feature.standard.config" version="${project.version}">
Modified: karaf/trunk/management/mbeans/log/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/log/src/main/resources/OSGI-INF/bundle.info?rev=1174985&r1=1174984&r2=1174985&view=diff
==============================================================================
--- karaf/trunk/management/mbeans/log/src/main/resources/OSGI-INF/bundle.info (original)
+++ karaf/trunk/management/mbeans/log/src/main/resources/OSGI-INF/bundle.info Fri Sep 23 19:59:42 2011
@@ -10,6 +10,12 @@ PSIS\u001B[0m
The log mbean management bundle exposes a Log MBean that you can use with any JMX client (for instance JConsole).
The Log MBean allows you quite the same actions that you can perform using log:* commands:
+ \u001B[36mdisplay()\u001B[0m
+ \u001B[36mdisplay(logger)\u001B[0m
+ \u001B[36mget()\u001B[0m
+ \u001B[36mget(logger)\u001B[0m
+ \u001B[36mset(level)\u001B[0m
+ \u001B[36mlist(level, logger)\u001B[0m
\u001B[1mSEE ALSO\u001B[0m
\u001B[36mDiagnostic\u001B[0m and \u001B[36mRemote Management via JMX\u001B[0m for the Karaf User Guide.
Added: karaf/trunk/management/mbeans/obr/NOTICE
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/obr/NOTICE?rev=1174985&view=auto
==============================================================================
--- karaf/trunk/management/mbeans/obr/NOTICE (added)
+++ karaf/trunk/management/mbeans/obr/NOTICE Fri Sep 23 19:59:42 2011
@@ -0,0 +1,48 @@
+Apache Karaf
+Copyright 2010 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+FUSE Source (http://www.fusesource.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+Tanuki Software (http://www.tanukisoftware.com/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+JLine (http://jline.sourceforge.net).
+Licensed under the BSD License.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0
Added: karaf/trunk/management/mbeans/obr/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/obr/pom.xml?rev=1174985&view=auto
==============================================================================
--- karaf/trunk/management/mbeans/obr/pom.xml (added)
+++ karaf/trunk/management/mbeans/obr/pom.xml Fri Sep 23 19:59:42 2011
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ 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.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.management.mbeans</groupId>
+ <artifactId>mbeans</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.management.mbeans.obr</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: Management :: MBeans :: OBR</name>
+ <description>The OBR MBean bundle provides a JMX MBean which allows you to manipulate the Karaf OBR layer.</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../../etc/appended-resources/</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.bundlerepository</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.karaf.management.mbeans.obr;version=${project.version}
+ </Export-Package>
+ <Import-Package>
+ !org.apache.karaf.management.mbeans.obr,
+ javax.management,
+ javax.management.loading,
+ org.apache.karaf.management;version=${project.version},
+ *
+ </Import-Package>
+ <Private-Package>
+ org.apache.karaf.management.mbeans.obr.internal,
+ !*
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/ObrMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/ObrMBean.java?rev=1174985&view=auto
==============================================================================
--- karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/ObrMBean.java (added)
+++ karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/ObrMBean.java Fri Sep 23 19:59:42 2011
@@ -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.management.mbeans.obr;
+
+import javax.management.openmbean.TabularData;
+import java.util.List;
+
+/**
+ * OBR MBean.
+ */
+public interface ObrMBean {
+
+ List<String> listUrls() throws Exception;
+ void addUrl(String url) throws Exception;
+ void removeUrl(String url) throws Exception;
+ void refreshUrl(String url) throws Exception;
+
+ TabularData list() throws Exception;
+ void deploy(String bundle) throws Exception;
+ void deploy(String bundle, boolean start) throws Exception;
+}
Added: karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/internal/ObrMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/internal/ObrMBeanImpl.java?rev=1174985&view=auto
==============================================================================
--- karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/internal/ObrMBeanImpl.java (added)
+++ karaf/trunk/management/mbeans/obr/src/main/java/org/apache/karaf/management/mbeans/obr/internal/ObrMBeanImpl.java Fri Sep 23 19:59:42 2011
@@ -0,0 +1,187 @@
+/*
+ * 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.management.mbeans.obr.internal;
+
+import org.apache.felix.bundlerepository.*;
+import org.apache.karaf.management.mbeans.obr.ObrMBean;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.Version;
+
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+import javax.management.openmbean.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Implementation of the OBR MBean.
+ */
+public class ObrMBeanImpl extends StandardMBean implements ObrMBean {
+
+ private static final char VERSION_DELIM = ',';
+
+ private BundleContext bundleContext;
+ private RepositoryAdmin repositoryAdmin;
+
+ public ObrMBeanImpl() throws NotCompliantMBeanException {
+ super(ObrMBean.class);
+ }
+
+ public List<String> listUrls() throws Exception {
+ Repository[] repositories = repositoryAdmin.listRepositories();
+ List<String> urls = new ArrayList<String>();
+ for (int i = 0; i < repositories.length; i++) {
+ urls.add(repositories[i].getURI());
+ }
+ return urls;
+ }
+
+ public void addUrl(String url) throws Exception {
+ repositoryAdmin.addRepository(url);
+ }
+
+ public void removeUrl(String url) throws Exception {
+ repositoryAdmin.removeRepository(url);
+ }
+
+ public void refreshUrl(String url) throws Exception {
+ repositoryAdmin.addRepository(url);
+ }
+
+ public TabularData list() throws Exception {
+ CompositeType bundleType = new CompositeType("OBR Resource", "Bundle available in the OBR",
+ new String[]{ "presentationname", "symbolicname", "version" },
+ new String[]{ "Presentation Name", "Symbolic Name", "Version" },
+ new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING });
+ TabularType tableType = new TabularType("OBR Resources", "Table of all resources/bundles available in the OBR",
+ bundleType, new String[]{ "presentationname" });
+ TabularData table = new TabularDataSupport(tableType);
+
+ Resource[] resources = repositoryAdmin.discoverResources("(|(presentationname=*)(symbolicname=*))");
+ for (int i = 0; i < resources.length; i++) {
+ CompositeData data = new CompositeDataSupport(bundleType,
+ new String[]{ "presentationname", "symbolicname", "version" },
+ new Object[]{ resources[i].getPresentationName(), resources[i].getSymbolicName(), resources[i].getVersion() });
+ table.put(data);
+ }
+
+ return table;
+ }
+
+ public void deploy(String bundle) throws Exception {
+ deploy(bundle, false);
+ }
+
+ public void deploy(String bundle, boolean start) throws Exception {
+ Resolver resolver = repositoryAdmin.resolver();
+ String[] target = getTarget(bundle);
+ Resource resource = selectNewestVersion(searchRepository(repositoryAdmin, target[0], target[1]));
+ if (resource == null) {
+ throw new IllegalArgumentException("Unknown bundle " + target[0]);
+ }
+ resolver.add(resource);
+ if ((resolver.getAddedResources() != null) &&
+ (resolver.getAddedResources().length > 0)) {
+ }
+ if (resolver.resolve()) {
+ Resource[] resources = resolver.getAddedResources();
+ resources = resolver.getRequiredResources();
+ resources = resolver.getOptionalResources();
+
+ try {
+ resolver.deploy(start ? Resolver.START : 0);
+ } catch (IllegalStateException ex) {
+ throw new IllegalStateException("Can't deploy using OBR", ex);
+ }
+ }
+ }
+
+ private Resource[] searchRepository(RepositoryAdmin admin, String targetId, String targetVersion) throws InvalidSyntaxException {
+ // Try to see if the targetId is a bundle ID.
+ try {
+ Bundle bundle = getBundleContext().getBundle(Long.parseLong(targetId));
+ targetId = bundle.getSymbolicName();
+ } catch (NumberFormatException ex) {
+ // It was not a number, so ignore.
+ }
+
+ // The targetId may be a bundle name or a bundle symbolic name,
+ // so create the appropriate LDAP query.
+ StringBuffer sb = new StringBuffer("(|(presentationname=");
+ sb.append(targetId);
+ sb.append(")(symbolicname=");
+ sb.append(targetId);
+ sb.append("))");
+ if (targetVersion != null) {
+ sb.insert(0, "(&");
+ sb.append("(version=");
+ sb.append(targetVersion);
+ sb.append("))");
+ }
+ return admin.discoverResources(sb.toString());
+ }
+
+ private Resource selectNewestVersion(Resource[] resources) {
+ int idx = -1;
+ Version v = null;
+ for (int i = 0; (resources != null) && (i < resources.length); i++) {
+ if (i == 0) {
+ idx = 0;
+ v = resources[i].getVersion();
+ } else {
+ Version vtmp = resources[i].getVersion();
+ if (vtmp.compareTo(v) > 0) {
+ idx = i;
+ v = vtmp;
+ }
+ }
+ }
+ return (idx < 0) ? null : resources[idx];
+ }
+
+ private String[] getTarget(String bundle) {
+ String[] target;
+ int idx = bundle.indexOf(VERSION_DELIM);
+ if (idx > 0) {
+ target = new String[] { bundle.substring(0, idx), bundle.substring(idx+1) };
+ }
+ else
+ {
+ target = new String[] { bundle, null };
+ }
+ return target;
+ }
+
+ public BundleContext getBundleContext() {
+ return this.bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public RepositoryAdmin getRepositoryAdmin() {
+ return this.repositoryAdmin;
+ }
+
+ public void setRepositoryAdmin(RepositoryAdmin repositoryAdmin) {
+ this.repositoryAdmin = repositoryAdmin;
+ }
+
+}
Added: karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/blueprint/obr-management.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/blueprint/obr-management.xml?rev=1174985&view=auto
==============================================================================
--- karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/blueprint/obr-management.xml (added)
+++ karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/blueprint/obr-management.xml Fri Sep 23 19:59:42 2011
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <!-- Reference to the MBean Server -->
+ <reference id="mbeanServer" interface="javax.management.MBeanServer">
+ <reference-listener ref="mbeanRegistrer" bind-method="registerMBeanServer" unbind-method="unregisterMBeanServer"/>
+ </reference>
+
+ <!-- OBR MBean -->
+ <bean id="obrMBean" class="org.apache.karaf.management.mbeans.obr.internal.ObrMBeanImpl">
+ <property name="bundleContext" ref="blueprintBundleContext"/>
+ <property name="repositoryAdmin" ref="repositoryAdmin"/>
+ </bean>
+
+ <!-- MBean Registrer -->
+ <bean id="mbeanRegistrer" class="org.apache.karaf.management.MBeanRegistrer">
+ <property name="mbeans">
+ <map>
+ <entry value="org.apache.karaf:type=obr,name=${karaf.name}" key-ref="obrMBean"/>
+ </map>
+ </property>
+ </bean>
+
+ <!-- Reference to the OBR RepositoryAdmin service -->
+ <reference id="repositoryAdmin" interface="org.apache.felix.bundlerepository.RepositoryAdmin"/>
+
+</blueprint>
\ No newline at end of file
Added: karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/bundle.info?rev=1174985&view=auto
==============================================================================
--- karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/bundle.info (added)
+++ karaf/trunk/management/mbeans/obr/src/main/resources/OSGI-INF/bundle.info Fri Sep 23 19:59:42 2011
@@ -0,0 +1,24 @@
+PSIS\u001B[0m
+ ${project.name}
+
+ ${project.description}
+
+ Maven URL:
+ \u001B[33mmvn:${project.groupId}/${project.artifactId}/${project.version}\u001B[0m
+
+\u001B[1mDESCRIPTION\u001B[0m
+ The obr mbean management bundle exposes an OBR MBean that you can use with any JMX client (for instance JConsole).
+
+ The OBR MBean allows you quite the same actions that you can perform using obr:* commands:
+ \u001B[36mlistUrls()\u001B[0m
+ \u001B[36maddUrl(url)\u001B[0m
+ \u001B[36mremoveUrl(url)\u001B[0m
+ \u001B[36mrefreshUrl(url)\u001B[0m
+ \u001B[36mlist()\u001B[0m
+ \u001B[36mdeploy(bundle)\u001B[0m
+ \u001B[36mdeploy(bundle, start)\u001B[0m
+
+\u001B[1mSEE ALSO\u001B[0m
+ \u001B[36mDiagnostic\u001B[0m and \u001B[36mRemote Management via JMX\u001B[0m for the Karaf User Guide.
+
+
Modified: karaf/trunk/management/mbeans/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/management/mbeans/pom.xml?rev=1174985&r1=1174984&r2=1174985&view=diff
==============================================================================
--- karaf/trunk/management/mbeans/pom.xml (original)
+++ karaf/trunk/management/mbeans/pom.xml Fri Sep 23 19:59:42 2011
@@ -38,6 +38,7 @@
<module>dev</module>
<module>http</module>
<module>log</module>
+ <module>obr</module>
</modules>
</project>
\ No newline at end of file