Author: rr
Date: Mon Nov 23 10:31:32 2009
New Revision: 883298
URL: http://svn.apache.org/viewvc?rev=883298&view=rev
Log:
ODE-706: Contribute karaf console commands for ServiceMix 4.1 - initial work
(by Daniel Dominguez)
Added:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/org.apache.ode.commands.bnd
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeCommandsBase.java
(with props)
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeListCommand.java
(with props)
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeTerminateCommand.java
(with props)
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/blueprint/
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/blueprint/ode-commands.xml
(with props)
Modified:
ode/branches/APACHE_ODE_1.X/Rakefile
ode/branches/APACHE_ODE_1.X/jbi-karaf/bnd.bnd
ode/branches/APACHE_ODE_1.X/tasks/bnd.rake
Modified: ode/branches/APACHE_ODE_1.X/Rakefile
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/Rakefile?rev=883298&r1=883297&r2=883298&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/Rakefile (original)
+++ ode/branches/APACHE_ODE_1.X/Rakefile Mon Nov 23 10:31:32 2009
@@ -88,6 +88,12 @@
JBI = group("org.apache.servicemix.specs.jbi-api-1.0",
:under=>"org.apache.servicemix.specs", :version=>"1.1.0")
JENCKS = "org.jencks:jencks:jar:all:1.3"
JIBX = "jibx:jibx-run:jar:1.1-beta3"
+KARAF = [
+ "org.apache.felix:org.osgi.core:jar:1.4.0",
+
"org.apache.felix.karaf.shell:org.apache.felix.karaf.shell.console:jar:1.0.0",
+
group("org.apache.felix.gogo.commands","org.apache.felix.gogo.runtime",
+ :under=>"org.apache.felix.gogo", :version=>"0.2.0")
+ ]
LOG4J = "log4j:log4j:jar:1.2.13"
OPENJPA = ["org.apache.openjpa:openjpa:jar:1.3.0-SNAPSHOT",
"net.sourceforge.serp:serp:jar:1.13.1"]
@@ -536,6 +542,19 @@
cp_r _("src/test/resources"), _("target/test/resources")
end
end
+
+ desc "ODE Commmands for Karaf"
+ define "jbi-karaf-commands" do
+ compile.with projects("bpel-schemas", "jbi"), JBI, KARAF, XMLBEANS,
COMMONS.logging
+ libs = artifacts(projects("bpel-schemas", "jbi"), JBI, KARAF, XMLBEANS,
COMMONS.logging)
+ package(:bundle).tap do |bnd|
+ bnd.bnd_file = _("org.apache.ode.commands.bnd")
+ bnd.sourcepath = _("src/main/java")
+ bnd.classpath = _("target/classes") + File::PATH_SEPARATOR +
libs.join(File::PATH_SEPARATOR)
+ bnd.properties.update(BUNDLE_VERSIONS)
+ end
+ end
+
desc "ODE JBI Packaging for Karaf"
define "jbi-karaf" do
ode_libs = artifacts(projects("bpel-api", "bpel-api-jca", "bpel-compiler",
"bpel-connector", "bpel-dao",
Added:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/org.apache.ode.commands.bnd
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/org.apache.ode.commands.bnd?rev=883298&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/org.apache.ode.commands.bnd
(added)
+++ ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/org.apache.ode.commands.bnd
Mon Nov 23 10:31:32 2009
@@ -0,0 +1,10 @@
+Bundle-Name: Apache ODE Commands
+Bundle-Version: ${ode.version}
+Require-Bundle: org.apache.ode.jbi
+
+Import-Package: org.osgi.service.command,*
+Private-Package: org.apache.ode.karaf.commands;version=${ode.version}
+Include-Resource: src/main/resources
+
+-removeheaders = Include-Resource
+
Added:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeCommandsBase.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeCommandsBase.java?rev=883298&view=auto
==============================================================================
---
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeCommandsBase.java
(added)
+++
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeCommandsBase.java
Mon Nov 23 10:31:32 2009
@@ -0,0 +1,104 @@
+/*
+ * 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.ode.karaf.commands;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import javax.management.*;
+
+import org.apache.felix.karaf.shell.console.OsgiCommandSupport;
+import org.apache.ode.bpel.pmapi.*;
+import org.apache.ode.jbi.OdeContext;
+
+public abstract class OdeCommandsBase extends OsgiCommandSupport {
+
+ protected static String COMPONENT_NAME =
"org.apache.servicemix:Type=Component,Name=OdeBpelEngine,SubType=Management";
+
+ protected static final String LIST_ALL_PROCESSES = "listAllProcesses";
+ protected static final String LIST_ALL_INSTANCES = "listAllInstances";
+ protected static final String TERMINATE = "terminate";
+
+ protected MBeanServer getMBeanServer() {
+ OdeContext ode = OdeContext.getInstance();
+ if (ode != null) {
+ return ode.getContext().getMBeanServer();
+ }
+ return null;
+ }
+
+ /**
+ * Invokes an operation on the ODE MBean server
+ *
+ * @param <T>
+ * @param operationName
+ * @param args
+ * @param T
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> T invoke(final String operationName, final Object[] params,
+ final String[] signature, Class<?> T, long timeoutInSeconds)
+ throws Exception {
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ Callable<T> callable = new Callable<T>() {
+ public T call() throws Exception {
+ MBeanServer server = getMBeanServer();
+ if (server != null) {
+ return (T) server.invoke(new ObjectName(COMPONENT_NAME),
+ operationName, params, signature);
+ }
+ return null;
+ }
+ };
+ Future<T> future = executor.submit(callable);
+ executor.shutdown();
+ return future.get(timeoutInSeconds, TimeUnit.SECONDS);
+ }
+
+ protected List<TProcessInfo> getProcesses(long timeoutInSeconds)
+ throws Exception {
+ ProcessInfoListDocument result = invoke(LIST_ALL_PROCESSES, null, null,
+ ProcessInfoListDocument.class, timeoutInSeconds);
+ if (result != null) {
+ return result.getProcessInfoList().getProcessInfoList();
+ }
+ return null;
+ }
+
+ protected List<TInstanceInfo> getActiveInstances(long timeoutInSeconds)
+ throws Exception {
+ InstanceInfoListDocument instances = invoke(LIST_ALL_INSTANCES, null,
+ null, InstanceInfoListDocument.class, timeoutInSeconds);
+ if (instances != null) {
+ return instances.getInstanceInfoList().getInstanceInfoList();
+ }
+ return null;
+ }
+
+ protected void terminate(Long iid, long timeoutInSeconds) throws Exception
{
+ invoke(TERMINATE, new Long[] { iid }, new String[] { Long.class
+ .getName() }, InstanceInfoDocument.class, timeoutInSeconds);
+ }
+}
Propchange:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeCommandsBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeListCommand.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeListCommand.java?rev=883298&view=auto
==============================================================================
---
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeListCommand.java
(added)
+++
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeListCommand.java
Mon Nov 23 10:31:32 2009
@@ -0,0 +1,98 @@
+/*
+ * 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.ode.karaf.commands;
+
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.ode.bpel.pmapi.TInstanceInfo;
+import org.apache.ode.bpel.pmapi.TInstanceStatus;
+import org.apache.ode.bpel.pmapi.TProcessInfo;
+
+/**
+ * Lists the deployed process as well as the active instances
+ *
+ * @author daniel
+ */
+...@command(scope = "ode", name = "list", description = "Lists ode processes
and active instances")
+public class OdeListCommand extends OdeCommandsBase {
+
+ private static final Log __log = LogFactory.getLog(OdeListCommand.class);
+
+ private long timeoutInSeconds = 30;
+
+ @Override
+ protected Object doExecute() throws Exception {
+ try {
+ System.out.println("Existing processes");
+ System.out.println("------------------");
+ List<TProcessInfo> processes = getProcesses(timeoutInSeconds);
+ if (processes != null) {
+ Set<String> sorted = new TreeSet<String>(
+ String.CASE_INSENSITIVE_ORDER);
+ for (TProcessInfo info : processes) {
+ sorted.add(info.getDefinitionInfo().getProcessName()
+ .getLocalPart());
+ }
+ for (String s : sorted) {
+ System.out.println(s);
+ }
+ }
+ System.out.println();
+
+ System.out.println("Active instances");
+ System.out.println("----------------");
+ List<TInstanceInfo> instances =
getActiveInstances(timeoutInSeconds);
+ if (instances != null) {
+ System.out.println("[Instance Id] [Process Name ]");
+ for (TInstanceInfo info : instances) {
+ if (info.getStatus() == TInstanceStatus.ACTIVE) {
+ StringBuilder line = new StringBuilder();
+ line.append("[");
+ line.append(getNameString(info.getIid(), 11));
+ line.append("] [");
+ line.append(getNameString(info.getProcessName()
+ .getLocalPart(), 20));
+ line.append("]");
+ System.out.println(line.toString());
+ }
+ }
+ }
+ } catch (TimeoutException e) {
+ __log.error("Timed out after " + timeoutInSeconds + " seconds", e);
+ }
+
+ return null;
+ }
+
+ private String getNameString(String name, int colLength) {
+ String ret = name;
+ for (int i = 0; i < colLength - name.length(); i++) {
+ ret = ret + " ";
+ }
+ return ret;
+ }
+
+}
Propchange:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeListCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeTerminateCommand.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeTerminateCommand.java?rev=883298&view=auto
==============================================================================
---
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeTerminateCommand.java
(added)
+++
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeTerminateCommand.java
Mon Nov 23 10:31:32 2009
@@ -0,0 +1,70 @@
+/*
+ * 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.ode.karaf.commands;
+
+import java.util.List;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.felix.gogo.commands.*;
+import org.apache.ode.bpel.pmapi.TInstanceInfo;
+
+...@command(scope = "ode", name = "terminate", description = "Terminate an
active ode process instances")
+public class OdeTerminateCommand extends OdeCommandsBase {
+
+ private static final Log __log = LogFactory.getLog(OdeListCommand.class);
+
+ @Argument(name = "iids", description = "Instance ID's to terminate",
multiValued = true)
+ private static Long[] iids;
+
+ @Option(name = "-a", aliases = "--all", description = "Terminate all
active instances")
+ private boolean terminateAll;
+
+ private long timeoutInSeconds = 30;
+
+ @Override
+ protected Object doExecute() throws Exception {
+ try {
+ if (terminateAll) {
+ List<TInstanceInfo> instances =
getActiveInstances(timeoutInSeconds);
+ if (instances != null) {
+ for (TInstanceInfo instance : instances) {
+ terminate(Long.parseLong(instance.getIid()),
+ timeoutInSeconds);
+ }
+ }
+ } else {
+ if (iids == null) {
+ System.out.println("No instance ids to terminate");
+ } else {
+ for (Long iid : iids) {
+ terminate(iid, timeoutInSeconds);
+ }
+ }
+ }
+ } catch (TimeoutException e) {
+ __log.error("Timed out after " + timeoutInSeconds + " seconds", e);
+ }
+
+ return null;
+ }
+
+}
Propchange:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/java/org/apache/ode/karaf/commands/OdeTerminateCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/blueprint/ode-commands.xml
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/blueprint/ode-commands.xml?rev=883298&view=auto
==============================================================================
---
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/blueprint/ode-commands.xml
(added)
+++
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/blueprint/ode-commands.xml
Mon Nov 23 10:31:32 2009
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:shell="http://felix.apache.org/karaf/xmlns/shell/v1.0.0">
+
+ <shell:command-bundle>
+ <shell:command name="ode/list">
+ <shell:action class="org.apache.ode.karaf.commands.OdeListCommand"
/>
+ </shell:command>
+ <shell:command name="ode/terminate">
+ <shell:action
class="org.apache.ode.karaf.commands.OdeTerminateCommand" />
+ </shell:command>
+ </shell:command-bundle>
+
+</blueprint>
\ No newline at end of file
Propchange:
ode/branches/APACHE_ODE_1.X/jbi-karaf-commands/src/main/resources/OSGI-INF/blueprint/ode-commands.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: ode/branches/APACHE_ODE_1.X/jbi-karaf/bnd.bnd
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/jbi-karaf/bnd.bnd?rev=883298&r1=883297&r2=883298&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/jbi-karaf/bnd.bnd (original)
+++ ode/branches/APACHE_ODE_1.X/jbi-karaf/bnd.bnd Mon Nov 23 10:31:32 2009
@@ -2,7 +2,8 @@
Bundle-Name: Apache ODE Service Engine
Bundle-Version: ${ode.version}
-Export-Package: org.apache.ode.jbi;version=${ode.version}
+Export-Package: org.apache.ode.jbi;version=${ode.version}, \
+ org.apache.ode.bpel.pmapi;version=${ode.version}
Private-Package: org.apache.ode.jbi*;version=${ode.version}
Import-Package: \
Modified: ode/branches/APACHE_ODE_1.X/tasks/bnd.rake
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/tasks/bnd.rake?rev=883298&r1=883297&r2=883298&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/tasks/bnd.rake (original)
+++ ode/branches/APACHE_ODE_1.X/tasks/bnd.rake Mon Nov 23 10:31:32 2009
@@ -36,6 +36,9 @@
# Classpath string for building the bundle
attr_accessor :classpath
+ # Sourcepath
+ attr_accessor :sourcepath
+
# Path to bnd file
attr_accessor :bnd_file
@@ -58,7 +61,8 @@
end
project.taskdef :name=>'bnd', :classname=>'aQute.bnd.ant.BndTask',
:classpath=>Buildr.artifact(BND)
- project.bnd(:classpath=>classpath, :files=>File.expand_path(bnd_file),
:output=>name,
+ project.bnd(:classpath=>classpath, :sourcepath=>(sourcepath == nil) ?
"" : File.expand_path(sourcepath),
+ :files=>File.expand_path(bnd_file), :output=>name,
:eclipse=>false, :failok=>false, :exceptions=>true)
end
end