You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2013/10/10 12:48:09 UTC

svn commit: r1530912 - in /sling/trunk/tooling/ide/api: OSGI-INF/ src/org/apache/sling/ide/osgi/impl/ src/org/apache/sling/ide/transport/

Author: rombert
Date: Thu Oct 10 10:48:09 2013
New Revision: 1530912

URL: http://svn.apache.org/r1530912
Log:
SLING-3097 - Track bundle deployment operations in the Sling console
view

Add a TracingOsgiClient which optionally wraps the main OsgiClient, if
the EventAdmin is not available.

The Maven deployment was not instrumented to display in the Sling
console since it opens its own console when running.

Added:
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java   (with props)
Modified:
    sling/trunk/tooling/ide/api/OSGI-INF/HttpOsgiClientFactory.xml
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClientFactory.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/CommandExecutionProperties.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/TracingCommand.java

Modified: sling/trunk/tooling/ide/api/OSGI-INF/HttpOsgiClientFactory.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/OSGI-INF/HttpOsgiClientFactory.xml?rev=1530912&r1=1530911&r2=1530912&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/OSGI-INF/HttpOsgiClientFactory.xml (original)
+++ sling/trunk/tooling/ide/api/OSGI-INF/HttpOsgiClientFactory.xml Thu Oct 10 10:48:09 2013
@@ -4,4 +4,5 @@
    <service>
       <provide interface="org.apache.sling.ide.osgi.OsgiClientFactory"/>
    </service>
+   <reference bind="bindEventAdmin" cardinality="1..1" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" policy="static" unbind="unbindEventAdmin"/>
 </scr:component>

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java?rev=1530912&r1=1530911&r2=1530912&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClient.java Thu Oct 10 10:48:09 2013
@@ -160,6 +160,12 @@ public class HttpOsgiClient implements O
             if (status != 200) {
                 throw new OsgiClientException("Method execution returned status " + status);
             }
+
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            IOUtils.copy(method.getResponseBodyAsStream(), out);
+
+            System.out.println(new String(out.toByteArray(), "UTF-8"));
+
         } catch (IOException e) {
             throw new OsgiClientException(e);
         } finally {

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClientFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClientFactory.java?rev=1530912&r1=1530911&r2=1530912&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClientFactory.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/HttpOsgiClientFactory.java Thu Oct 10 10:48:09 2013
@@ -19,9 +19,24 @@ package org.apache.sling.ide.osgi.impl;
 import org.apache.sling.ide.osgi.OsgiClient;
 import org.apache.sling.ide.osgi.OsgiClientFactory;
 import org.apache.sling.ide.transport.RepositoryInfo;
+import org.osgi.service.event.EventAdmin;
 
 public class HttpOsgiClientFactory implements OsgiClientFactory {
+
+    private EventAdmin eventAdmin;
+
     public OsgiClient createOsgiClient(RepositoryInfo repositoryInfo) {
+        if (eventAdmin != null) {
+            return new TracingOsgiClient(new HttpOsgiClient(repositoryInfo), eventAdmin);
+        }
         return new HttpOsgiClient(repositoryInfo);
     }
+
+    protected void bindEventAdmin(EventAdmin eventAdmin) {
+        this.eventAdmin = eventAdmin;
+    }
+
+    protected void unBindEventAdmin(EventAdmin eventAdmin) {
+        this.eventAdmin = null;
+    }
 }
\ No newline at end of file

Added: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java?rev=1530912&view=auto
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java (added)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java Thu Oct 10 10:48:09 2013
@@ -0,0 +1,85 @@
+/*
+ * 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.sling.ide.osgi.impl;
+
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.ide.osgi.OsgiClient;
+import org.apache.sling.ide.osgi.OsgiClientException;
+import org.apache.sling.ide.transport.CommandExecutionProperties;
+import org.osgi.framework.Version;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+
+/**
+ * The <tt>TracingOsgiClient</tt> decorates another OsgiClient instance by adding tracing operations
+ * 
+ */
+public class TracingOsgiClient implements OsgiClient {
+
+    private final OsgiClient osgiClient;
+    private final EventAdmin eventAdmin;
+    
+    public TracingOsgiClient(OsgiClient osgiClient, EventAdmin eventAdmin) {
+        this.osgiClient = osgiClient;
+        this.eventAdmin = eventAdmin;
+    }
+
+    @Override
+    public Version getBundleVersion(String bundleSymbolicName) throws OsgiClientException {
+        return osgiClient.getBundleVersion(bundleSymbolicName);
+    }
+
+    @Override
+    public void installBundle(InputStream in, String fileName) throws OsgiClientException {
+        osgiClient.installBundle(in, fileName);
+    }
+
+    @Override
+    public void installLocalBundle(String explodedBundleLocation) throws OsgiClientException {
+
+        Map<String, Object> props = new HashMap<String, Object>();
+        long start = System.currentTimeMillis();
+        props.put(CommandExecutionProperties.ACTION_TYPE, "InstallLocalBundle");
+        props.put(CommandExecutionProperties.ACTION_TARGET, explodedBundleLocation);
+        props.put(CommandExecutionProperties.TIMESTAMP_START, start);
+        try {
+            osgiClient.installLocalBundle(explodedBundleLocation);
+            props.put(CommandExecutionProperties.RESULT_TEXT, "OK");
+        } catch (Throwable t) {
+            props.put(CommandExecutionProperties.RESULT_TEXT, "FAILED");
+            props.put(CommandExecutionProperties.RESULT_THROWABLE, t);
+            if (t instanceof OsgiClientException) {
+                throw (OsgiClientException) t;
+            } else if (t instanceof Error) {
+                throw (Error) t;
+            } else if (t instanceof RuntimeException) {
+                throw (RuntimeException) t;
+            } else {
+                // should never happen
+                throw new Error(t);
+            }
+        } finally {
+            props.put(CommandExecutionProperties.TIMESTAMP_END, System.currentTimeMillis());
+            Event event = new Event(CommandExecutionProperties.REPOSITORY_TOPIC, props);
+            eventAdmin.postEvent(event);
+        }
+    }
+
+}

Propchange: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/osgi/impl/TracingOsgiClient.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/CommandExecutionProperties.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/CommandExecutionProperties.java?rev=1530912&r1=1530911&r2=1530912&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/CommandExecutionProperties.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/CommandExecutionProperties.java Thu Oct 10 10:48:09 2013
@@ -15,9 +15,12 @@
  * limitations under the License.
  */package org.apache.sling.ide.transport;
 
+import org.apache.sling.ide.osgi.OsgiClient;
+
 public final class CommandExecutionProperties {
 
-    public static final String TOPIC = Repository.class.getPackage().getName().replace('.', '/');
+    public static final String REPOSITORY_TOPIC = Repository.class.getPackage().getName().replace('.', '/');
+    public static final String OSGI_CLIENT_TOPIC = OsgiClient.class.getPackage().getName().replace('.', '/');
 
     public static final String TIMESTAMP_START = "timestamp.start";
     public static final String TIMESTAMP_END = "timestamp.end";

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/TracingCommand.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/TracingCommand.java?rev=1530912&r1=1530911&r2=1530912&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/TracingCommand.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/TracingCommand.java Thu Oct 10 10:48:09 2013
@@ -55,7 +55,7 @@ public class TracingCommand<T> implement
             props.put(CommandExecutionProperties.ACTION_TARGET, command.getPath());
             props.put(CommandExecutionProperties.TIMESTAMP_START, start);
             props.put(CommandExecutionProperties.TIMESTAMP_END, end);
-            Event event = new Event(CommandExecutionProperties.TOPIC, props);
+            Event event = new Event(CommandExecutionProperties.REPOSITORY_TOPIC, props);
             eventAdmin.postEvent(event);
         }