ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1491702 [5/6] - in /ace/sandbox/bramk: cnf/localrepo/ cnf/localrepo/org.apache.ace.log.api/ cnf/localrepo/org.apache.ace.log.target.store.impl/ cnf/localrepo/org.apache.ace.log.target/ cnf/localrepo/org.apache.ace.range.api/ cnf/localrepo/...
Date Tue, 11 Jun 2013 07:56:27 GMT
Added: ace/sandbox/bramk/org.apache.ace.agent/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/.settings/org.eclipse.jdt.core.prefs?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/.settings/org.eclipse.jdt.core.prefs (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/.settings/org.eclipse.jdt.core.prefs Tue Jun 11 07:56:25 2013
@@ -0,0 +1,77 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.6

Added: ace/sandbox/bramk/org.apache.ace.agent/README
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/README?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/README (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/README Tue Jun 11 07:56:25 2013
@@ -0,0 +1,18 @@
+ACE Management Agent 
+
+@see ACE-347
+
+Notes:
+
+* Switched to factory SPI approach for pluggability/extensions.
+* Removed export package atributes / cleaned up bundle contents.
+* Assembled most target specific business logic code in project.
+* Supports configuration through single (multi-agent) configuration.
+ 
+ TODOs:
+ 
+ * Cleanup assembled code and parent projects
+ * More config options
+ * More (i)testing
+ * Create run-agent project
+ * Replace ace executor with a executorservice?
\ No newline at end of file

Added: ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/bnd.bnd Tue Jun 11 07:56:25 2013
@@ -0,0 +1,78 @@
+Bundle-Activator: org.apache.ace.agent.impl.Activator
+Bundle-Version: 1.0.0
+
+-buildpath: osgi.core,\
+	osgi.cmpn,\
+	org.apache.felix.dependencymanager,\
+	org.apache.felix.deploymentadmin,\
+	org.apache.ace.log.target;version=latest,\
+	org.apache.ace.log.target.store.impl;version=latest,\
+	org.apache.ace.range.api;version=latest,\
+	org.apache.ace.log.api;version=latest,\
+	org.apache.commons.codec
+
+-sources false
+
+#
+# Embedding all required api and implementation packages to ensure that the
+# Management Agent can run in any plain vanilla framework.
+#	
+Private-Package: org.apache.ace.agent.eventlogging,\
+	org.apache.ace.agent,\
+	org.apache.ace.agent.versions,\
+	org.apache.ace.log.util,\
+	org.apache.ace.log,\
+	org.apache.ace.log.target.store,\
+	org.apache.ace.agent.spi,\
+	org.apache.ace.agent.impl,\
+	org.apache.ace.agent.connection,\
+	org.apache.ace.agent.download,\
+	org.apache.ace.agent.update,\
+	org.apache.ace.agent.logging,\
+	org.apache.ace.agent.deployment,\
+	org.apache.ace.agent.discovery,\
+	org.apache.ace.range,\
+	org.apache.ace.agent.identification,\
+	org.apache.felix.dm,\
+	org.apache.felix.dm.impl,\
+	org.apache.felix.dm.impl.dependencies,\
+	org.apache.felix.dm.impl.index,\
+	org.apache.felix.dm.impl.metatype,\
+	org.apache.felix.dm.tracker,\
+	org.apache.felix.deploymentadmin;-split-package:=first,\
+	org.apache.felix.deploymentadmin.spi;-split-package:=first,\
+	org.osgi.util.tracker;-split-package:=first,\
+	org.apache.commons.codec;-split-package:=first,\
+	org.apache.commons.codec.binary;-split-package:=first
+	
+# 
+# Exporting deploymentadmin and (some) compendium services so resource processors 
+# can wire up to the management agent. As bnd will generate the appropriate imports
+# this should not lead to any conflicts with deployment packages.
+#
+# We could consider exposing all compendium packages by default in this way?
+#
+Export-Package: org.osgi.service.deploymentadmin;version=1.0;-split-package:=first,\
+	org.osgi.service.deploymentadmin.spi;version=1.0;-split-package:=first,\
+	org.osgi.service.cm;version=1.3;-split-package:=first,\
+	org.osgi.service.event;version=1.2;-split-package:=first,\
+	org.osgi.service.log;version=1.3;-split-package:=first,\
+	org.osgi.service.metatype;-split-package:=first,\
+	org.apache.ace.agent,\
+	org.apache.ace.agent.spi,\
+	org.apache.felix.dm
+    
+# 
+# Make sure the apropriate imports are generated for the exported packages.
+#
+Import-Package: !org.apache.felix.shell,\
+	!org.eclipse.osgi.framework.console,\
+	*
+		
+Bundle-Name: Apache ACE Agent
+Bundle-Description: Implementation of the Apache ACE Agent
+-runfw: org.apache.felix.framework;version='[4.0.3,4.0.3]'
+-runee: JavaSE-1.6
+-runbundles: org.apache.felix.gogo.command,\
+	org.apache.felix.gogo.runtime,\
+	org.apache.felix.gogo.shell
\ No newline at end of file

Added: ace/sandbox/bramk/org.apache.ace.agent/build.xml
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/build.xml?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/build.xml (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/build.xml Tue Jun 11 07:56:25 2013
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="project" default="build"> 
+	<import file="../cnf/build.xml"/>
+</project>

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Agent.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Agent.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Agent.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Agent.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,28 @@
+/*
+ * 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.ace.agent;
+
+/**
+ * TODO implement or remove? The question is whether we want to expose a single API to the rest of the environment to
+ * allow client bundles to do deploy/log stuff.
+ * 
+ */
+public interface Agent {
+
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentFactory.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentFactory.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/AgentFactory.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,30 @@
+/*
+ * 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.ace.agent;
+
+import java.util.Map;
+
+/**
+ * Service interface for configuring the management agent.
+ *
+ */
+public interface AgentFactory {
+
+    void updated(Map<String, String> configuration) throws Exception;
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Constants.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Constants.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Constants.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Constants.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,57 @@
+/*
+ * 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.ace.agent;
+
+/**
+ * Compile time constants for the bundle. Only located in the API package for development time visibility.
+ * 
+ */
+public interface Constants {
+
+    /**
+     * Configuration key for the list of agents.
+     */
+    String CONFIG_AGENTS_KEY = "agents";
+
+    /**
+     * Configuration key for the agent.
+     */
+    String CONFIG_AGENT_KEY = "agent";
+
+    /**
+     * Configuration key for the serverurl.
+     */
+    String CONFIG_SERVERURL_KEY = "serverurl";
+
+    /**
+     * Configuration key for the syncinterval.
+     */
+    String CONFIG_SYNCINTERVAL_KEY = "syncinterval";
+
+    /**
+     * Configuration key for the console loglevel.
+     */
+    String CONFIG_LOGLEVEL_KEY = "loglevel";
+
+    /**
+     * Configuration key for the list of component factories.
+     */
+    String CONFIG_FACTORIES_KEY = "system.factories";
+
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandler.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandler.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandler.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandler.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,228 @@
+/*
+ * 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.ace.agent.connection;
+
+import java.io.Closeable;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.util.Map;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ConnectionHandler;
+import org.apache.commons.codec.binary.Base64;
+
+public class DefaultConnectionHandler implements ConnectionHandler {
+
+    public enum AuthType {
+        NONE,
+        BASIC,
+        CLIENT_CERT;
+    }
+
+    public static class UrlCredentials {
+
+        private final AuthType m_type;
+        private final Object[] m_credentials;
+
+        public UrlCredentials(AuthType type, Object... credentials) {
+            m_type = type;
+            m_credentials = (credentials == null) ? new Object[0] : credentials.clone();
+        }
+
+        public Object[] getCredentials() {
+            return m_credentials.clone();
+        }
+
+        public AuthType getType() {
+            return m_type;
+        }
+    }
+
+    public static final String PROP_AUTHTYPE = "authType";
+    public static final String PROP_AUTHUSER = "authUser";
+    public static final String PROP_AUTHPASS = "authPass";
+    public static final String PROP_AUTHKEYFILE = "authKeyFile";
+    public static final String PROP_AUTHKEYPASS = "authKeyPass";
+    public static final String PROP_AUTHTRUSTFILE = "authTrustFile";
+    public static final String PROP_AUTHTRUSTPASS = "authTrustPass";
+
+    private static final String HTTP_HEADER_AUTHORIZATION = "Authorization";
+
+    private volatile UrlCredentials m_credentials;
+    protected volatile AgentContext m_context;
+
+
+    public void start() throws Exception {
+        m_credentials = getCredentials(m_context.getConfig());
+    }
+
+    @Override
+    public void sync() throws Exception {
+        // TODO cleanups
+    }
+
+    @Override
+    public HttpURLConnection getConnection(URL url) throws Exception {
+        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+        if (AuthType.BASIC.equals(m_credentials.getType())) {
+            applyBasicAuthentication(connection, m_credentials.getCredentials());
+        }
+        else if (AuthType.CLIENT_CERT.equals(m_credentials.getType())) {
+            applyClientCertificate(connection, m_credentials.getCredentials());
+        }
+        return connection;
+    }
+
+    public UrlCredentials getCredentials(Map<String, String> properties) throws IllegalArgumentException {
+        DefaultConnectionHandler.AuthType type = null;
+        Object[] creds = null;
+
+        String authType = getStringProperty(properties, PROP_AUTHTYPE);
+        try {
+            type = DefaultConnectionHandler.AuthType.valueOf(authType.toUpperCase());
+        }
+        catch (Exception e) {
+            throw new IllegalArgumentException("Unsupported authentication type: " + authType);
+        }
+
+        if (AuthType.NONE.equals(type)) {
+            creds = new Object[0];
+        }
+        else if (AuthType.BASIC.equals(type)) {
+            String userName = getStringProperty(properties, PROP_AUTHUSER);
+            String password = getStringProperty(properties, PROP_AUTHPASS);
+            creds = new Object[] { userName, password };
+        }
+        else if (DefaultConnectionHandler.AuthType.CLIENT_CERT.equals(type)) {
+            String keystoreFile = getStringProperty(properties, PROP_AUTHKEYFILE);
+            String keystorePass = getStringProperty(properties, PROP_AUTHKEYPASS);
+            String truststoreFile = getStringProperty(properties, PROP_AUTHTRUSTFILE);
+            String truststorePass = getStringProperty(properties, PROP_AUTHTRUSTPASS);
+            try {
+                KeyManager[] keyManagers = getKeyManagerFactory(keystoreFile, keystorePass);
+                TrustManager[] trustManagers = getTrustManagerFactory(truststoreFile, truststorePass);
+                SSLContext context = SSLContext.getInstance("TLS");
+                context.init(keyManagers, trustManagers, new SecureRandom());
+                creds = new Object[] { context };
+            }
+            catch (Exception e) {
+                throw new IllegalArgumentException("Failed to load keystore!", e);
+            }
+        }
+        return new UrlCredentials(type, creds);
+    }
+
+    private String getStringProperty(Map<String, String> properties, String property) throws IllegalArgumentException {
+        String value = properties.get(property);
+        if (value == null || value.equals("")) {
+            throw new IllegalArgumentException("Missing configuration value: " + property);
+        }
+        return value;
+    }
+
+    private static KeyManager[] getKeyManagerFactory(String keystoreFile, String storePass) throws IOException, GeneralSecurityException {
+        InputStream keyInput = null;
+        try {
+            KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+            keyInput = new FileInputStream(keystoreFile);
+            keyStore.load(keyInput, storePass.toCharArray());
+            keyManagerFactory.init(keyStore, storePass.toCharArray());
+            return keyManagerFactory.getKeyManagers();
+        }
+        finally {
+            closeSafely(keyInput);
+        }
+    }
+
+    private static TrustManager[] getTrustManagerFactory(String truststoreFile, String storePass) throws IOException, GeneralSecurityException {
+        InputStream trustInput = null;
+        try {
+            TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+            trustInput = new FileInputStream(truststoreFile);
+            trustStore.load(trustInput, storePass.toCharArray());
+            trustManagerFactory.init(trustStore);
+            return trustManagerFactory.getTrustManagers();
+        }
+        finally {
+            closeSafely(trustInput);
+        }
+    }
+
+    private static void closeSafely(Closeable resource) {
+        try {
+            if (resource != null) {
+                resource.close();
+            }
+        }
+        catch (IOException e) {
+            // Ignore; nothing we can/will do...
+        }
+    }
+
+    private final String getBasicAuthCredentials(Object[] values) {
+        if ((values == null) || values.length < 2) {
+            throw new IllegalArgumentException("Insufficient credentials passed: expected 2 values!");
+        }
+
+        StringBuilder sb = new StringBuilder();
+        if (values[0] instanceof String) {
+            sb.append((String) values[0]);
+        }
+        else if (values[0] instanceof byte[]) {
+            sb.append(new String((byte[]) values[0]));
+        }
+        sb.append(':');
+        if (values[1] instanceof String) {
+            sb.append((String) values[1]);
+        }
+        else if (values[1] instanceof byte[]) {
+            sb.append(new String((byte[]) values[1]));
+        }
+
+        return "Basic " + new String(Base64.encodeBase64(sb.toString().getBytes()));
+    }
+
+    private void applyBasicAuthentication(URLConnection conn, Object[] values) {
+        if (conn instanceof HttpURLConnection) {
+            conn.setRequestProperty(HTTP_HEADER_AUTHORIZATION, getBasicAuthCredentials(values));
+        }
+    }
+
+    private void applyClientCertificate(URLConnection conn, Object[] values) {
+        if (conn instanceof HttpsURLConnection) {
+            ((HttpsURLConnection) conn).setSSLSocketFactory(((SSLContext) values[0]).getSocketFactory());
+        }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandlerFactory.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandlerFactory.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandlerFactory.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,43 @@
+/*
+ * 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.ace.agent.connection;
+
+import java.util.Map;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ComponentFactory;
+import org.apache.ace.agent.spi.ConnectionHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * 
+ */
+public class DefaultConnectionHandlerFactory implements ComponentFactory {
+
+    @Override
+    public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
+
+        return manager.createAdapterService(AgentContext.class, null)
+            .setInterface(ConnectionHandler.class.getName(), null)
+            .setImplementation(DefaultConnectionHandler.class);
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandler.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandler.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandler.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandler.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,82 @@
+/*
+ * 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.ace.agent.deployment;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.DeploymentHandler;
+import org.apache.ace.agent.spi.IdentificationHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Version;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.deploymentadmin.DeploymentPackage;
+
+public class DefaultDeploymentHandler implements DeploymentHandler {
+
+    protected volatile DependencyManager m_manager;
+    protected volatile Component m_component;
+    protected volatile AgentContext m_context;
+
+    private volatile DeploymentAdmin m_deploymentAdmin;
+    private volatile IdentificationHandler m_identification;
+
+    public void init() throws Exception {
+        m_component
+            .add(m_manager.createServiceDependency()
+                .setService(IdentificationHandler.class, "(agent=" + m_context.getAgentId() + ")")
+                .setRequired(true));
+    }
+
+    @Override
+    public void sync() throws Exception {
+        // TODO Auto-generated method stub
+    }
+
+    @Override
+    public SortedSet<Version> getVersions() {
+        DeploymentPackage[] installedPackages = m_deploymentAdmin.listDeploymentPackages();
+        SortedSet<Version> versions = new TreeSet<Version>();
+        for (int i = 0; i < installedPackages.length; i++) {
+            if (installedPackages[i].getName().equals(m_identification.getIdentification())) {
+                versions.add(installedPackages[i].getVersion());
+            }
+        }
+        return versions;
+    }
+
+    @Override
+    public void installPackage(File file) throws Exception {
+        InputStream inputStream = null;
+        try {
+            inputStream = new FileInputStream(file);
+            m_deploymentAdmin.installDeploymentPackage(inputStream);
+        }
+        finally {
+            if (inputStream != null) {
+                inputStream.close();
+            }
+        }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandlerFactory.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandlerFactory.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandlerFactory.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,45 @@
+/*
+ * 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.ace.agent.deployment;
+
+import java.util.Map;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ComponentFactory;
+import org.apache.ace.agent.spi.DeploymentHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.log.LogService;
+
+/**
+ * 
+ */
+public class DefaultDeploymentHandlerFactory implements ComponentFactory {
+
+    @Override
+    public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
+
+        return manager.createAdapterService(AgentContext.class, null)
+            .setInterface(DeploymentHandler.class.getName(), null)
+            .setImplementation(DefaultDeploymentHandler.class)
+            .add(manager.createServiceDependency().setService(DeploymentAdmin.class).setRequired(true));
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandler.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandler.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandler.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandler.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,49 @@
+/*
+ * 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.ace.agent.discovery;
+
+import java.net.URL;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.DiscoveryHandler;
+
+public class DefaultDiscoveryHandler implements DiscoveryHandler {
+
+    public static final String DISCOVERY_PROPERTY_VALUE = "serverurl";
+
+    private volatile AgentContext m_context;
+    private volatile URL m_url;
+
+    public void start() throws Exception {
+        final String urlStr = (String) m_context.getConfig().get(DISCOVERY_PROPERTY_VALUE);
+        if (urlStr == null || urlStr.equals("")) {
+            throw new IllegalArgumentException("Missing a valid discovery value");
+        }
+        m_url = new URL(urlStr);
+    }
+
+    @Override
+    public void sync() throws Exception {
+    }
+
+    @Override
+    public URL getServerURL() {
+        return m_url;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandlerFactory.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandlerFactory.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandlerFactory.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,43 @@
+/*
+ * 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.ace.agent.discovery;
+
+import java.util.Map;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ComponentFactory;
+import org.apache.ace.agent.spi.DiscoveryHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * 
+ */
+public class DefaultDiscoveryHandlerFactory implements ComponentFactory {
+
+    @Override
+    public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
+
+        return manager.createAdapterService(AgentContext.class, null)
+            .setInterface(DiscoveryHandler.class.getName(), null)
+            .setImplementation(DefaultDiscoveryHandler.class);
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandler.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandler.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandler.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandler.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,152 @@
+/*
+ * 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.ace.agent.download;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ConnectionHandler;
+import org.apache.ace.agent.spi.DiscoveryHandler;
+import org.apache.ace.agent.spi.DownloadHandler;
+import org.apache.ace.agent.spi.IdentificationHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Version;
+
+public class DefaultDownloadHandler implements DownloadHandler {
+
+    private volatile DependencyManager m_manager;
+    private volatile Component m_component;
+    private volatile AgentContext m_context;
+
+    private volatile IdentificationHandler m_indentification;
+    private volatile DiscoveryHandler m_discovery;
+    private volatile ConnectionHandler m_connection;
+
+    private volatile File m_workDir;
+
+    public void init() throws Exception {
+        m_component
+            .add(m_manager.createServiceDependency()
+                .setService(IdentificationHandler.class, "(agent=" + m_context.getAgentId() + ")")
+                .setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(DiscoveryHandler.class, "(agent=" + m_context.getAgentId() + ")")
+                .setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(ConnectionHandler.class, "(agent=" + m_context.getAgentId() + ")")
+                .setRequired(true)
+            );
+
+    }
+
+    public void start() throws Exception {
+        File downloadDir = new File(m_context.getWorkDir(), "downloads");
+        if (!downloadDir.exists() && !downloadDir.mkdir()) {
+            throw new IllegalStateException("Unable to access agentDownloadDir " + downloadDir.getAbsolutePath());
+        }
+        m_workDir = downloadDir;
+    }
+
+    @Override
+    public void sync() throws Exception {
+        // TODO cleanups
+    }
+
+    @Override
+    public File downloadPackage(Version from, Version to) throws Exception {
+        URL url = getUpdatePackageURL(from, to);
+        File file = getUpdatePackageFile(from, to);
+        return downloadFile(url, file);
+    }
+
+    private File getUpdatePackageFile(Version fromVersion, Version toVersion) {
+        File downloadDir = m_workDir;
+        if (!downloadDir.exists() && !downloadDir.mkdir()) {
+            throw new IllegalStateException("Unable to access download dir " + downloadDir.getAbsolutePath());
+        }
+        if (fromVersion != null && !fromVersion.equals(Version.emptyVersion)) {
+            return new File(downloadDir, m_indentification.getIdentification() + "_" + fromVersion + "_" + toVersion);
+        }
+        else {
+            return new File(downloadDir, m_indentification.getIdentification() + "_" + toVersion);
+        }
+    }
+
+    private URL getUpdatePackageURL(Version from, Version to) throws IllegalArgumentException {
+        try {
+            if (from != null && !from.equals(Version.emptyVersion)) {
+                return new URL(m_discovery.getServerURL(), "deployment/" + m_indentification.getIdentification() + "/versions/" + to.toString() + "?current=" + from);
+            }
+            else {
+                return new URL(m_discovery.getServerURL(), "deployment/" + m_indentification.getIdentification() + "/versions/" + to.toString());
+            }
+        }
+        catch (MalformedURLException e) {
+            throw new IllegalArgumentException("Invalid parameters for url", e);
+        }
+    }
+
+    private File downloadFile(URL source, File target) throws Exception {
+
+        BufferedInputStream inputstream = null;
+        BufferedOutputStream outputstream = null;
+        URLConnection connection = null;
+        try {
+            connection = m_connection.getConnection(source);
+            inputstream = new BufferedInputStream(connection.getInputStream());
+            outputstream = new BufferedOutputStream(new FileOutputStream(target));
+            byte data[] = new byte[1024];
+            int read;
+            while ((read = inputstream.read(data, 0, 1024)) >= 0) {
+                if (Thread.currentThread().isInterrupted()) {
+                    throw new InterruptedException();
+                }
+                outputstream.write(data, 0, read);
+            }
+            outputstream.flush();
+            return target;
+        }
+        catch (Exception e) {
+            if (target != null && target.exists()) {
+                target.delete();
+            }
+            e.printStackTrace();
+            throw e;
+        }
+        finally {
+            if (inputstream != null) {
+                inputstream.close();
+            }
+            if (outputstream != null) {
+                outputstream.close();
+            }
+            if (connection != null && (connection instanceof HttpURLConnection)) {
+                ((HttpURLConnection) connection).disconnect();
+            }
+        }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandlerFactory.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandlerFactory.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandlerFactory.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.ace.agent.download;
+
+import java.util.Map;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ComponentFactory;
+import org.apache.ace.agent.spi.DownloadHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ */
+public class DefaultDownloadHandlerFactory implements ComponentFactory {
+
+    @Override
+    public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
+
+        return manager.createAdapterService(AgentContext.class, null)
+            .setInterface(DownloadHandler.class.getName(), null)
+            .setImplementation(DefaultDownloadHandler.class);
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/DefaultEventLoggerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/DefaultEventLoggerFactory.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/DefaultEventLoggerFactory.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/DefaultEventLoggerFactory.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,41 @@
+/*
+ * 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.ace.agent.eventlogging;
+
+import java.util.Map;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ComponentFactory;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * 
+ */
+public class DefaultEventLoggerFactory implements ComponentFactory {
+
+    @Override
+    public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
+        
+        return manager.createAdapterService(AgentContext.class, null)
+            .setImplementation(EventLoggerImpl.class);
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/EventLoggerImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/EventLoggerImpl.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/EventLoggerImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/EventLoggerImpl.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,287 @@
+/*
+ * 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.ace.agent.eventlogging;
+
+import static org.apache.ace.log.AuditEvent.BUNDLE_BASE;
+import static org.apache.ace.log.AuditEvent.BUNDLE_INSTALLED;
+import static org.apache.ace.log.AuditEvent.BUNDLE_RESOLVED;
+import static org.apache.ace.log.AuditEvent.BUNDLE_STARTED;
+import static org.apache.ace.log.AuditEvent.BUNDLE_STARTING;
+import static org.apache.ace.log.AuditEvent.BUNDLE_STOPPED;
+import static org.apache.ace.log.AuditEvent.BUNDLE_STOPPING;
+import static org.apache.ace.log.AuditEvent.BUNDLE_UNINSTALLED;
+import static org.apache.ace.log.AuditEvent.BUNDLE_UNRESOLVED;
+import static org.apache.ace.log.AuditEvent.BUNDLE_UPDATED;
+import static org.apache.ace.log.AuditEvent.DEPLOYMENTADMIN_BASE;
+import static org.apache.ace.log.AuditEvent.DEPLOYMENTADMIN_COMPLETE;
+import static org.apache.ace.log.AuditEvent.DEPLOYMENTADMIN_INSTALL;
+import static org.apache.ace.log.AuditEvent.DEPLOYMENTADMIN_UNINSTALL;
+import static org.apache.ace.log.AuditEvent.DEPLOYMENTCONTROL_INSTALL;
+import static org.apache.ace.log.AuditEvent.FRAMEWORK_BASE;
+import static org.apache.ace.log.AuditEvent.FRAMEWORK_ERROR;
+import static org.apache.ace.log.AuditEvent.FRAMEWORK_INFO;
+import static org.apache.ace.log.AuditEvent.FRAMEWORK_REFRESH;
+import static org.apache.ace.log.AuditEvent.FRAMEWORK_STARTED;
+import static org.apache.ace.log.AuditEvent.FRAMEWORK_STARTLEVEL;
+import static org.apache.ace.log.AuditEvent.FRAMEWORK_WARNING;
+import static org.apache.ace.log.AuditEvent.KEY_ID;
+import static org.apache.ace.log.AuditEvent.KEY_LOCATION;
+import static org.apache.ace.log.AuditEvent.KEY_MSG;
+import static org.apache.ace.log.AuditEvent.KEY_NAME;
+import static org.apache.ace.log.AuditEvent.KEY_SUCCESS;
+import static org.apache.ace.log.AuditEvent.KEY_TYPE;
+import static org.apache.ace.log.AuditEvent.KEY_VERSION;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.LoggingHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.deploymentadmin.DeploymentPackage;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+/**
+ * Service component that listens for events and logs them to the autitlog.
+ * 
+ */
+public class EventLoggerImpl implements BundleListener, FrameworkListener, EventHandler {
+
+    public static final String[] TOPICS_INTEREST = new String[] { "org/osgi/service/deployment/*", "org/apache/ace/deployment/*" };
+
+    public static final String TOPIC_INSTALL = "org/osgi/service/deployment/INSTALL";
+    public static final String TOPIC_UNINSTALL = "org/osgi/service/deployment/UNINSTALL";
+    public static final String TOPIC_COMPLETE = "org/osgi/service/deployment/COMPLETE";
+    public static final String TOPIC_DEPLOYMENTPACKAGE_INSTALL = "org/apache/ace/deployment/INSTALL";
+
+    private volatile DependencyManager m_manager;
+    private volatile Component m_component;
+    private volatile BundleContext m_context;
+    private volatile AgentContext m_agent;
+
+    private volatile LoggingHandler m_logging;
+
+    public void init() throws Exception {
+
+        m_component
+            .add(m_manager.createServiceDependency()
+                .setService(LoggingHandler.class, "(agent=" + m_agent.getAgentId() + ")")
+                .setRequired(true)
+            );
+    }
+
+    public void start() throws Exception {
+        m_context.addFrameworkListener(this);
+        m_context.addBundleListener(this);
+    }
+
+    public void stop() throws Exception {
+        m_context.removeFrameworkListener(this);
+        m_context.removeBundleListener(this);
+    }
+
+    @Override
+    public void handleEvent(Event event) {
+        int eventType = DEPLOYMENTADMIN_BASE;
+        Dictionary<String, String> props = new Hashtable<String, String>();
+
+        String topic = event.getTopic();
+
+        if (topic.equals(TOPIC_DEPLOYMENTPACKAGE_INSTALL)) {
+            String url = (String) event.getProperty("deploymentpackage.url");
+            String version = (String) event.getProperty("deploymentpackage.version");
+            eventType = DEPLOYMENTCONTROL_INSTALL;
+            props.put(KEY_VERSION, version);
+            props.put(KEY_NAME, url);
+        }
+        else if (topic.equals(TOPIC_INSTALL)) {
+            String deplPackName = (String) event.getProperty("deploymentpackage.name");
+            eventType = DEPLOYMENTADMIN_INSTALL;
+            props.put(KEY_NAME, deplPackName);
+        }
+
+        else if (topic.equals(TOPIC_UNINSTALL)) {
+            String deplPackName = (String) event.getProperty("deploymentpackage.name");
+            eventType = DEPLOYMENTADMIN_UNINSTALL;
+            props.put(KEY_NAME, deplPackName);
+        }
+        else if (topic.equals(TOPIC_COMPLETE)) {
+            String deplPackName = (String) event.getProperty("deploymentpackage.name");
+            // to retrieve the version, DeploymentAdmin has to be used
+            ServiceReference ref = m_context.getServiceReference(DeploymentAdmin.class.getName());
+            if (ref != null) {
+                DeploymentAdmin deplAdmin = (DeploymentAdmin) m_context.getService(ref);
+                if (deplAdmin != null) {
+                    DeploymentPackage dp = deplAdmin.getDeploymentPackage(deplPackName);
+                    if (dp != null) {
+                        Version version = dp.getVersion();
+                        if (version != null) {
+                            props.put(KEY_VERSION, version.toString());
+                        }
+                    }
+                    // after use, release the service as is it not needed anymore
+                    m_context.ungetService(ref);
+                }
+            }
+            eventType = DEPLOYMENTADMIN_COMPLETE;
+            props.put(KEY_NAME, deplPackName);
+            Boolean success = (Boolean) event.getProperty("successful");
+            props.put(KEY_SUCCESS, success.toString());
+        }
+        try {
+            m_logging.log("auditlog", eventType, props);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void frameworkEvent(FrameworkEvent event) {
+        int eventType = FRAMEWORK_BASE;
+        Dictionary<String, String> props = new Hashtable<String, String>();
+        Bundle bundle = event.getBundle();
+
+        if (bundle != null) {
+            props.put(KEY_ID, Long.toString(bundle.getBundleId()));
+        }
+
+        String msg = null;
+        String type = null;
+        Throwable exception = event.getThrowable();
+        if (exception != null) {
+            msg = exception.getMessage();
+            type = exception.getClass().getName();
+        }
+
+        switch (event.getType()) {
+            case FrameworkEvent.INFO:
+                eventType = FRAMEWORK_INFO;
+                if (msg != null) {
+                    props.put(KEY_MSG, msg);
+                }
+                if (type != null) {
+                    props.put(KEY_TYPE, type);
+                }
+                break;
+            case FrameworkEvent.WARNING:
+                eventType = FRAMEWORK_WARNING;
+                if (msg != null) {
+                    props.put(KEY_MSG, msg);
+                }
+                if (type != null) {
+                    props.put(KEY_TYPE, type);
+                }
+                break;
+            case FrameworkEvent.ERROR:
+                eventType = FRAMEWORK_ERROR;
+                if (msg != null) {
+                    props.put(KEY_MSG, msg);
+                }
+                if (type != null) {
+                    props.put(KEY_TYPE, type);
+                }
+                break;
+            case FrameworkEvent.PACKAGES_REFRESHED:
+                eventType = FRAMEWORK_REFRESH;
+                break;
+            case FrameworkEvent.STARTED:
+                eventType = FRAMEWORK_STARTED;
+                break;
+            case FrameworkEvent.STARTLEVEL_CHANGED:
+                eventType = FRAMEWORK_STARTLEVEL;
+                break;
+        }
+        try {
+            m_logging.log("auditlog", eventType, props);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public void bundleChanged(BundleEvent event) {
+        int eventType = BUNDLE_BASE;
+        Dictionary<String, String> props = new Hashtable<String, String>();
+        Bundle bundle = event.getBundle();
+        props.put(KEY_ID, Long.toString(bundle.getBundleId()));
+
+        switch (event.getType()) {
+            case BundleEvent.INSTALLED:
+                eventType = BUNDLE_INSTALLED;
+                if (bundle.getSymbolicName() != null) {
+                    props.put(KEY_NAME, bundle.getSymbolicName());
+                }
+                String version = (String) bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+                if (version != null) {
+                    props.put(KEY_VERSION, version);
+                }
+                props.put(KEY_LOCATION, bundle.getLocation());
+                break;
+            case BundleEvent.RESOLVED:
+                eventType = BUNDLE_RESOLVED;
+                break;
+            case BundleEvent.STARTED:
+                eventType = BUNDLE_STARTED;
+                break;
+            case BundleEvent.STOPPED:
+                eventType = BUNDLE_STOPPED;
+                break;
+            case BundleEvent.UNRESOLVED:
+                eventType = BUNDLE_UNRESOLVED;
+                break;
+            case BundleEvent.UPDATED:
+                eventType = BUNDLE_UPDATED;
+                version = (String) bundle.getHeaders().get(Constants.BUNDLE_VERSION);
+                if (version != null) {
+                    props.put(KEY_VERSION, version);
+                }
+                props.put(KEY_LOCATION, bundle.getLocation());
+                break;
+            case BundleEvent.UNINSTALLED:
+                eventType = BUNDLE_UNINSTALLED;
+                break;
+            case BundleEvent.STARTING:
+                eventType = BUNDLE_STARTING;
+                break;
+            case BundleEvent.STOPPING:
+                eventType = BUNDLE_STOPPING;
+                break;
+        }
+        try {
+            m_logging.log("auditlog", eventType, props);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandler.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandler.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandler.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandler.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,47 @@
+/*
+ * 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.ace.agent.identification;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.IdentificationHandler;
+
+public class DefaultIdentificationHandler implements IdentificationHandler {
+
+    public static final String IDENTIFICATION_PROPERTY_VALUE = "agent";
+
+    private volatile AgentContext m_context;
+    private volatile String m_id;
+
+    public void start() throws Exception {
+        final String value = m_context.getConfig().get(IDENTIFICATION_PROPERTY_VALUE);
+        if (value == null || value.equals("")) {
+            throw new IllegalArgumentException("Missing a valid identification value");
+        }
+        m_id = value;
+    }
+
+    @Override
+    public void sync() throws Exception {
+    }
+
+    @Override
+    public String getIdentification() {
+        return m_id;
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandlerFactory.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandlerFactory.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandlerFactory.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,42 @@
+/*
+ * 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.ace.agent.identification;
+
+import java.util.Map;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ComponentFactory;
+import org.apache.ace.agent.spi.IdentificationHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * 
+ */
+public class DefaultIdentificationHandlerFactory implements ComponentFactory {
+
+    @Override
+    public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
+        return manager.createAdapterService(AgentContext.class, null)
+            .setInterface(IdentificationHandler.class.getName(), null)
+            .setImplementation(DefaultIdentificationHandler.class);
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/Activator.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.ace.agent.impl;
+
+import org.apache.ace.agent.AgentFactory;
+import org.apache.felix.deploymentadmin.DeploymentAdminImpl;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.deploymentadmin.DeploymentAdmin;
+import org.osgi.service.event.EventAdmin;
+import org.osgi.service.log.LogService;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * OSGi {@link BundleActivator} for the Apache ACE ManagementAgent.
+ * 
+ */
+public class Activator extends DependencyActivatorBase {
+
+    @Override
+    public void init(BundleContext context, DependencyManager manager) throws Exception {
+
+        final DeploymentAdmin deploymentAdmin = new DeploymentAdminImpl();
+        manager.add(createComponent()
+            .setInterface(DeploymentAdmin.class.getName(), null)
+            .setImplementation(deploymentAdmin)
+            .add(createServiceDependency()
+                .setService(PackageAdmin.class)
+                .setRequired(true))
+            .add(createServiceDependency()
+                .setService(EventAdmin.class)
+                .setRequired(false))
+            .add(createServiceDependency()
+                .setService(LogService.class)
+                .setRequired(false)));
+
+        final AgentFactoryImpl factory = new AgentFactoryImpl();
+        manager.add(createComponent()
+            .setInterface(AgentFactory.class.getName(), null)
+            .setImplementation(factory)
+            .add(createServiceDependency()
+                .setService(DeploymentAdmin.class)
+                .setRequired(true)
+                .setAutoConfig(false))
+            .add(createServiceDependency()
+                .setService(LogService.class)
+                .setRequired(false)));
+    }
+
+    @Override
+    public void destroy(BundleContext context, DependencyManager manager) throws Exception {
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,93 @@
+/*
+ * 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.ace.agent.impl;
+
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import org.apache.ace.agent.spi.AgentContext;
+import org.osgi.service.log.LogService;
+
+public class AgentContextImpl implements AgentContext {
+
+    private final DateFormat m_dateFormat = new SimpleDateFormat("MMM d HH:mm:ss");
+
+    private final String m_agentId;
+    private final File m_agentDir;
+    private final Map<String, String> m_agentConfig;
+    private final int m_consoleLogLevel;
+
+    private ScheduledExecutorService m_executor;
+    private volatile LogService m_logService;
+
+    public AgentContextImpl(String agentId, Map<String, String> agentConfig, File agentDir) {
+        m_agentId = agentId;
+        m_agentConfig = agentConfig;
+        m_agentDir = agentDir;
+        m_consoleLogLevel = agentConfig.get("loglevel") != null ? LogLevels.valueOf(agentConfig.get("loglevel")).getCode() : LogService.LOG_DEBUG;
+    }
+
+    public void start() {
+        m_executor = Executors.newScheduledThreadPool(4);
+    }
+
+    public void stop() {
+        m_executor.shutdown();
+        m_executor = null;
+    }
+
+    @Override
+    public ScheduledExecutorService getExecutor() {
+        return m_executor;
+    }
+
+    @Override
+    public File getWorkDir() {
+        return m_agentDir;
+    }
+
+    @Override
+    public String getAgentId() {
+        return m_agentId;
+    }
+
+    @Override
+    public Map<String, String> getConfig() {
+        return m_agentConfig;
+    }
+
+    @Override
+    public void log(int level, String message) {
+        if (level <= m_consoleLogLevel)
+            System.out.println(m_dateFormat.format(new Date()) + " [" + LogLevels.fromCode(level).name() + "] " + getAgentId() + ": " + message);
+        m_logService.log(level, message);
+    }
+
+    @Override
+    public void log(int level, String message, Throwable cause) {
+        if (level <= m_consoleLogLevel)
+            System.out.println(m_dateFormat.format(new Date()) + " [" + LogLevels.fromCode(level).name() + "] " + getAgentId() + ": " + message);
+        m_logService.log(level, message, cause);
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentFactoryImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentFactoryImpl.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentFactoryImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentFactoryImpl.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,175 @@
+/*
+ * 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.ace.agent.impl;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.ace.agent.Agent;
+import org.apache.ace.agent.AgentFactory;
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ComponentFactory;
+import org.apache.ace.agent.spi.ConnectionHandler;
+import org.apache.ace.agent.spi.DeploymentHandler;
+import org.apache.ace.agent.spi.DiscoveryHandler;
+import org.apache.ace.agent.spi.DownloadHandler;
+import org.apache.ace.agent.spi.IdentificationHandler;
+import org.apache.ace.agent.spi.LoggingHandler;
+import org.apache.ace.agent.spi.UpdateHandler;
+import org.apache.ace.agent.spi.VersionsHandler;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.log.LogService;
+
+/**
+ * Factory that handles configuration of management agents services. For every subsystem a {@link ComponentFactory} is
+ * used to instantiate the actual components. Factories can be specified through configuration using a
+ * <code>&lt;subsystem&gt;.factory</code> property.
+ */
+public class AgentFactoryImpl implements AgentFactory {
+
+    private final List<Component> m_components = new LinkedList<Component>();
+
+    private volatile BundleContext m_context;
+    private volatile DependencyManager m_manager;
+    private volatile LogService m_logService;
+
+    public void start() throws Exception {
+    }
+
+    public void stop() throws Exception {
+        removeComponents();
+    }
+
+    @Override
+    public void updated(Map<String, String> configuration) throws Exception {
+        try {
+            ConfigurationHelper configurationHelper = new ConfigurationHelper(configuration);
+            removeComponents();
+            createComponents(configurationHelper);
+        }
+        catch (Exception e) {
+            m_logService.log(LogService.LOG_ERROR, "Agent update failed! ", e);
+            System.err.println("Agent update failed!");
+            e.printStackTrace(System.err);
+        }
+    }
+
+    private void createComponents(ConfigurationHelper configurationHelper) throws Exception {
+        createFactoryComponents(configurationHelper);
+        createAgentComponents(configurationHelper);
+    }
+
+    private void removeComponents() {
+        for (Component component : m_components) {
+            try {
+                m_manager.remove(component);
+            }
+            catch (Exception e) {
+                m_logService.log(LogService.LOG_ERROR, "Failed to remove component: " + e.getMessage(), e);
+            }
+        }
+        m_components.clear();
+    }
+
+    private void createFactoryComponents(ConfigurationHelper configurationHelper) throws Exception {
+        ComponentFactory[] componentFactories = configurationHelper.getComponentFactories();
+        try {
+            for (ComponentFactory componentFactory : componentFactories) {
+                Component component = componentFactory.createComponent(m_context, m_manager, m_logService, configurationHelper.getComponentFactoriesConfiguration());
+                m_manager.add(component);
+            }
+        }
+        catch (Exception e) {
+            m_logService.log(LogService.LOG_ERROR, "Failed to create factory component: " + e.getMessage(), e);
+            throw e;
+
+        }
+    }
+
+    private void createAgentComponents(ConfigurationHelper configurationHelper) throws Exception {
+        for (String agentId : configurationHelper.getAgentIds()) {
+
+            Map<String, String> agentConfiguration = configurationHelper.getAgentConfiguration(agentId);
+            try {
+
+                Set<Component> components = new HashSet<Component>();
+
+                File agentDir = new File(m_context.getDataFile(""), agentId);
+                if (!agentDir.exists() && !agentDir.mkdir()) {
+                    throw new IllegalStateException("Unable to access work directory " + agentDir.getAbsolutePath());
+                }
+
+                // start context
+                AgentContext agentContext = new AgentContextImpl(agentId, agentConfiguration, agentDir);
+                Properties contextProperties = new Properties();
+                contextProperties.put("agent", agentId);
+                Component contextComponent = m_manager.createComponent()
+                    .setInterface(AgentContext.class.getName(), contextProperties)
+                    .setImplementation(agentContext)
+                    .add(m_manager.createServiceDependency()
+                        .setService(LogService.class).setRequired(false));
+                components.add(contextComponent);
+
+                // start agent
+                Agent agent = new AgentImpl(agentId);
+                Properties agentProperties = new Properties();
+                agentProperties.put("agent", agentId);
+                Component agentComponent = m_manager.createComponent()
+                    .setInterface(Agent.class.getName(), agentProperties)
+                    .setImplementation(agent)
+                    .add(m_manager.createServiceDependency()
+                        .setService(AgentContext.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(IdentificationHandler.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(DiscoveryHandler.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(LoggingHandler.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(DownloadHandler.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(DeploymentHandler.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(VersionsHandler.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(UpdateHandler.class, "(agent=" + agentId + ")").setRequired(true))
+                    .add(m_manager.createServiceDependency()
+                        .setService(ConnectionHandler.class, "(agent=" + agentId + ")").setRequired(true));
+
+                components.add(agentComponent);
+
+                m_components.addAll(components);
+                for (Component component : components) {
+                    m_manager.add(component);
+                }
+            }
+            catch (Exception e) {
+                m_logService.log(LogService.LOG_ERROR, "Failed to create agent component: " + e.getMessage(), e);
+                throw e;
+            }
+        }
+    }
+}

Added: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentImpl.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentImpl.java?rev=1491702&view=auto
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentImpl.java (added)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentImpl.java Tue Jun 11 07:56:25 2013
@@ -0,0 +1,87 @@
+/*
+ * 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.ace.agent.impl;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ace.agent.Agent;
+import org.apache.ace.agent.Constants;
+import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.spi.ConnectionHandler;
+import org.apache.ace.agent.spi.DiscoveryHandler;
+import org.apache.ace.agent.spi.DownloadHandler;
+import org.apache.ace.agent.spi.IdentificationHandler;
+import org.apache.ace.agent.spi.LoggingHandler;
+import org.apache.ace.agent.spi.UpdateHandler;
+import org.apache.ace.agent.spi.VersionsHandler;
+import org.osgi.service.log.LogService;
+
+public class AgentImpl implements Agent {
+
+    private final String m_agentId;
+
+    private volatile AgentContext m_context;
+
+    private volatile IdentificationHandler m_identification;
+    private volatile DiscoveryHandler m_discovery;
+    private volatile ConnectionHandler m_connection;
+    private volatile DownloadHandler m_download;
+    private volatile LoggingHandler m_logging;
+    private volatile VersionsHandler m_versions;
+    private volatile UpdateHandler m_update;
+
+    public AgentImpl(String agentId) {
+        m_agentId = agentId;
+    }
+
+    public void start() throws Exception {
+        int syncInterval = 30;
+        String syncIntervalConfig = m_context.getConfig().get(Constants.CONFIG_SYNCINTERVAL_KEY);
+        if (syncIntervalConfig != null && !syncIntervalConfig.trim().equals("")) {
+            syncInterval = Integer.parseInt(syncIntervalConfig.trim());
+        }
+        m_context.log(LogService.LOG_INFO, "Starting with syncinterval " + syncInterval);
+        m_context.getExecutor().scheduleAtFixedRate(new SyncTask(), 1, 5, TimeUnit.SECONDS);
+    }
+
+    public void stop() throws Exception {
+        m_context.log(LogService.LOG_INFO, "Stopping agent...");
+    }
+
+    private class SyncTask implements Runnable {
+
+        @Override
+        public void run() {
+            try {
+                m_context.log(LogService.LOG_DEBUG, "Syn starting");
+                m_identification.sync();
+                m_discovery.sync();
+                m_connection.sync();
+                m_logging.sync();
+                m_versions.sync();
+                m_download.sync();
+                m_update.sync();
+                m_context.log(LogService.LOG_DEBUG, "Sync completed!");
+            }
+            catch (Exception e) {
+                m_context.log(LogService.LOG_ERROR, "Sync exception: " + e.getMessage(), e);
+            }
+        }
+    }
+}



Mime
View raw message