ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1492558 - in /ace/sandbox/bramk: ./ cnf/ org.apache.ace.agent.itest/ org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/ org.apache.ace.agent.launcher/ org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/ org.apache.ace....
Date Thu, 13 Jun 2013 08:12:25 GMT
Author: bramk
Date: Thu Jun 13 08:12:24 2013
New Revision: 1492558

URL: http://svn.apache.org/r1492558
Log:
[sandbox] Simplifying agent wip

Removed:
    ace/sandbox/bramk/check_staged_ace.sh
    ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/CustomAgentTest.java
Modified:
    ace/sandbox/bramk/cnf/   (props changed)
    ace/sandbox/bramk/org.apache.ace.agent/   (props changed)
    ace/sandbox/bramk/org.apache.ace.agent.itest/   (props changed)
    ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java
    ace/sandbox/bramk/org.apache.ace.agent.launcher/   (props changed)
    ace/sandbox/bramk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Constants.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandler.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandler.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandler.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandler.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/DefaultEventLoggerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentFactoryImpl.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHelper.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/agent-defaults.properties
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/logging/DefaultLoggingHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/update/DefaultUpdateHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/versions/DefaultVersionsHandlerFactory.java
    ace/sandbox/bramk/org.apache.ace.cli/   (props changed)

Propchange: ace/sandbox/bramk/cnf/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 13 08:12:24 2013
@@ -0,0 +1,6 @@
+bin
+bin_test
+generated
+store
+bundle-cache
+felix-cache

Propchange: ace/sandbox/bramk/org.apache.ace.agent/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 13 08:12:24 2013
@@ -0,0 +1,6 @@
+bin
+bin_test
+generated
+store
+bundle-cache
+felix-cache

Propchange: ace/sandbox/bramk/org.apache.ace.agent.itest/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 13 08:12:24 2013
@@ -0,0 +1,6 @@
+bin
+bin_test
+generated
+store
+bundle-cache
+felix-cache

Modified: ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java?rev=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BasicAgentTest.java Thu Jun 13 08:12:24 2013
@@ -25,9 +25,8 @@ import junit.framework.Assert;
 
 import org.apache.ace.agent.Agent;
 import org.apache.ace.agent.AgentFactory;
+import org.apache.ace.agent.Constants;
 import org.apache.ace.it.IntegrationTestBase;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 
@@ -37,84 +36,37 @@ import org.osgi.framework.ServiceReferen
  */
 public class BasicAgentTest extends IntegrationTestBase {
 
-    public void testOneAgentConfiguration() throws Exception {
+	public void testOneAgentConfiguration() throws Exception {
 
-        // agent factory should be up
-        AgentFactory agentFactory = getService(AgentFactory.class);
-        Assert.assertNotNull(agentFactory);
-
-        assertAgentDown("007");
-
-        // configure an agent
-        Map<String, String> config = new Hashtable<String, String>();
-        config.put("verbose", "true");
-        config.put("agents", "007");
-        config.put("serverurl", "http://localhost:8080");
-        config.put("logstores", "auditlog");
-        config.put("authType", "NONE");
-        agentFactory.updated(config);
-
-        try {
-            assertAgentUp("007");
-            config = new Hashtable<String, String>();
-            config.put("verbose", "true");
-            agentFactory.updated(config);
-
-            assertAgentDown("007");
-
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    public void testTwoAgentsConfiguration() throws Exception {
-
-        // agent factory should be up
-        AgentFactory agentFactory = getService(AgentFactory.class);
-        Assert.assertNotNull(agentFactory);
-
-        assertAgentDown("007");
-        assertAgentDown("009");
-
-        // configure an agent
-        Map<String, String> config = new Hashtable<String, String>();
-        config.put("verbose", "true");
-        config.put("agents", "007,009");
-        config.put("serverurl", "http://localhost:8080");
-        config.put("logstores", "auditlog");
-        config.put("authType", "NONE");
-        agentFactory.updated(config);
+		// agent factory should be up
+		AgentFactory agentFactory = getService(AgentFactory.class);
+		Assert.assertNotNull(agentFactory);
+
+		assertAgentDown("007");
+
+		// configure an agent
+		Map<String, String> config = new Hashtable<String, String>();
+		config.put("verbose", "true");
+		config.put(Constants.CONFIG_IDENTIFICATION_KEY, "007");
+		config.put(Constants.CONFIG_SERVERURL_KEY, "http://localhost:8080");
+		config.put("logstores", "auditlog");
+		config.put("authType", "NONE");
+		agentFactory.updated(config);
 
         assertAgentUp("007");
-        assertAgentUp("009");
+	}
 
-        config = new Hashtable<String, String>();
-        config.put("verbose", "true");
-        agentFactory.updated(config);
-
-        assertAgentDown("007");
-        assertAgentDown("009");
-    }
-
-    private void assertAgentUp(String agentId) throws InvalidSyntaxException {
-        String agentFilter = "(agent=" + agentId + ")";
-        ServiceReference[] references = m_bundleContext.getAllServiceReferences(Agent.class.getName(), agentFilter);
-        assertNotNull(references);
-    }
-
-    private void assertAgentDown(String agentId) throws InvalidSyntaxException {
-        String agentFilter = "(agent=" + agentId + ")";
-        ServiceReference[] references = m_bundleContext.getAllServiceReferences(Agent.class.getName(), agentFilter);
-        assertNull(references);
-    }
-
-    private void restartBundle(String bsn) throws BundleException {
-        for (Bundle bundle : m_bundleContext.getBundles()) {
-            if (bundle.getSymbolicName().equals(bsn)) {
-                bundle.stop();
-                bundle.start();
-            }
-        }
-    }
+	private void assertAgentUp(String agentId) throws InvalidSyntaxException {
+		String agentFilter = "(agent=" + agentId + ")";
+		ServiceReference[] references = m_bundleContext
+				.getAllServiceReferences(Agent.class.getName(), agentFilter);
+		assertNotNull(references);
+	}
+
+	private void assertAgentDown(String agentId) throws InvalidSyntaxException {
+		String agentFilter = "(agent=" + agentId + ")";
+		ServiceReference[] references = m_bundleContext
+				.getAllServiceReferences(Agent.class.getName(), agentFilter);
+		assertNull(references);
+	}
 }

Propchange: ace/sandbox/bramk/org.apache.ace.agent.launcher/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 13 08:12:24 2013
@@ -0,0 +1,6 @@
+bin
+bin_test
+generated
+store
+bundle-cache
+felix-cache

Modified: ace/sandbox/bramk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java?rev=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent.launcher/src/org/apache/ace/agent/launcher/Launcher.java Thu Jun 13 08:12:24 2013
@@ -19,7 +19,7 @@
 
 package org.apache.ace.agent.launcher;
 
-import static org.apache.ace.agent.Constants.CONFIG_AGENTS_KEY;
+import static org.apache.ace.agent.Constants.CONFIG_IDENTIFICATION_KEY;
 import static org.apache.ace.agent.Constants.CONFIG_LOGLEVEL_KEY;
 import static org.apache.ace.agent.Constants.CONFIG_SERVERURL_KEY;
 
@@ -100,7 +100,7 @@ public class Launcher {
 
         // overwrite with user args
         if (command.hasOption("a")) {
-            configuration.put(CONFIG_AGENTS_KEY, command.getOptionValue("a"));
+            configuration.put(CONFIG_IDENTIFICATION_KEY, command.getOptionValue("a"));
         }
         if (command.hasOption("s")) {
             configuration.put(CONFIG_SERVERURL_KEY, command.getOptionValue("s"));
@@ -115,7 +115,7 @@ public class Launcher {
         }
 
         // basic checks
-        if (!configuration.containsKey(CONFIG_AGENTS_KEY)) {
+        if (!configuration.containsKey(CONFIG_IDENTIFICATION_KEY)) {
             System.err.println("No agent specified");
             System.exit(1);
         }
@@ -173,7 +173,8 @@ public class Launcher {
      * Main execution logic of the launcher; Start a framework, install bundles and pass configuration to the
      * {@link AgentFactory}.
      * 
-     * @throws Exception on failure
+     * @throws Exception
+     *             on failure
      */
     public void run() throws Exception {
 

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Constants.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/Constants.java Thu Jun 13 08:12:24 2013
@@ -25,14 +25,14 @@ package org.apache.ace.agent;
 public interface Constants {
 
     /**
-     * Configuration key for the list of agents.
+     * Configuration key for the agent String
      */
-    String CONFIG_AGENTS_KEY = "agents";
+    String CONFIG_IDENTIFICATION_KEY = "agent";
 
     /**
-     * Configuration key for the agent.
+     * Configuration key for the discovery String[]
      */
-    String CONFIG_AGENT_KEY = "agent";
+    String CONFIG_DISCOVERY_KEY = "discovery";
 
     /**
      * Configuration key for the serverurl.

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandler.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandler.java Thu Jun 13 08:12:24 2013
@@ -18,26 +18,13 @@
  */
 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;
 
@@ -68,22 +55,12 @@ public class DefaultConnectionHandler im
         }
     }
 
-    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;
-
+    private final UrlCredentials m_credentials;
 
-    public void start() throws Exception {
-        m_credentials = getCredentials(m_context.getConfig());
+    public DefaultConnectionHandler(UrlCredentials credentials) {
+        m_credentials = credentials;
     }
 
     @Override
@@ -103,94 +80,6 @@ public class DefaultConnectionHandler im
         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!");

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/connection/DefaultConnectionHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,9 +18,26 @@
  */
 package org.apache.ace.agent.connection;
 
+import java.io.Closeable;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.GeneralSecurityException;
+import java.security.KeyStore;
+import java.security.SecureRandom;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
-import org.apache.ace.agent.spi.AgentContext;
+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.Constants;
+import org.apache.ace.agent.connection.DefaultConnectionHandler.AuthType;
+import org.apache.ace.agent.connection.DefaultConnectionHandler.UrlCredentials;
 import org.apache.ace.agent.spi.ComponentFactory;
 import org.apache.ace.agent.spi.ConnectionHandler;
 import org.apache.felix.dm.Component;
@@ -33,11 +50,114 @@ import org.osgi.service.log.LogService;
  */
 public class DefaultConnectionHandlerFactory implements ComponentFactory {
 
+    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";
+
     @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);
+        UrlCredentials credentials = getCredentials(configuration);
+        ConnectionHandler handler = new DefaultConnectionHandler(credentials);
+
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+
+        return manager.createComponent()
+            .setInterface(ConnectionHandler.class.getName(), props)
+            .setImplementation(handler);
+    }
+
+    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...
+        }
     }
 }

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandler.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandler.java Thu Jun 13 08:12:24 2013
@@ -24,31 +24,17 @@ 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

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/deployment/DefaultDeploymentHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,11 +18,14 @@
  */
 package org.apache.ace.agent.deployment;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
-import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.ComponentFactory;
 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.BundleContext;
@@ -37,9 +40,15 @@ public class DefaultDeploymentHandlerFac
     @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)
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+
+        return manager.createComponent()
+            .setInterface(DeploymentHandler.class.getName(), props)
             .setImplementation(DefaultDeploymentHandler.class)
-            .add(manager.createServiceDependency().setService(DeploymentAdmin.class).setRequired(true));
+            .add(manager.createServiceDependency().setService(DeploymentAdmin.class).setRequired(true))
+            .add(manager.createServiceDependency().setService(IdentificationHandler.class).setRequired(true));
+
     }
 }

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandler.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandler.java Thu Jun 13 08:12:24 2013
@@ -20,22 +20,14 @@ 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 final URL m_url;
 
-    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);
+    public DefaultDiscoveryHandler(URL url) {
+        m_url = url;
     }
 
     @Override

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/discovery/DefaultDiscoveryHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,9 +18,12 @@
  */
 package org.apache.ace.agent.discovery;
 
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
-import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.ComponentFactory;
 import org.apache.ace.agent.spi.DiscoveryHandler;
 import org.apache.felix.dm.Component;
@@ -33,11 +36,25 @@ import org.osgi.service.log.LogService;
  */
 public class DefaultDiscoveryHandlerFactory implements ComponentFactory {
 
+    public static final String DISCOVERY_PROPERTY_VALUE = "serverurl";
+
     @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);
+        final String urlStr = configuration.get(DISCOVERY_PROPERTY_VALUE);
+        if (urlStr == null || urlStr.equals("")) {
+            throw new IllegalArgumentException("Missing a valid discovery value");
+        }
+
+        URL url = new URL(urlStr);
+        DiscoveryHandler handler = new DefaultDiscoveryHandler(url);
+
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+
+        return manager.createComponent()
+            .setInterface(DiscoveryHandler.class.getName(), props)
+            .setImplementation(handler);
     }
 }

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandler.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandler.java Thu Jun 13 08:12:24 2013
@@ -27,53 +27,26 @@ 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)
-            );
-
-    }
+    private final File m_workDir;
 
-    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;
+    public DefaultDownloadHandler(File workDir) {
+        m_workDir = workDir;
     }
 
     @Override
     public void sync() throws Exception {
-        // TODO cleanups
     }
 
     @Override

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/download/DefaultDownloadHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,11 +18,17 @@
  */
 package org.apache.ace.agent.download;
 
+import java.io.File;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
-import org.apache.ace.agent.spi.AgentContext;
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.ComponentFactory;
+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.BundleContext;
@@ -35,8 +41,27 @@ public class DefaultDownloadHandlerFacto
     @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);
+        File downloadDir = new File(context.getDataFile(""), "downloads");
+        if (!downloadDir.exists() && !downloadDir.mkdir()) {
+            throw new IllegalStateException("Unable to access agentDownloadDir " + downloadDir.getAbsolutePath());
+        }
+
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+
+        return manager.createComponent()
+            .setInterface(DownloadHandler.class.getName(), props)
+            .setImplementation(new DefaultDownloadHandler(downloadDir))
+            .add(manager.createServiceDependency()
+                .setService(IdentificationHandler.class)
+                .setRequired(true))
+            .add(manager.createServiceDependency()
+                .setService(DiscoveryHandler.class)
+                .setRequired(true))
+            .add(manager.createServiceDependency()
+                .setService(ConnectionHandler.class)
+                .setRequired(true)
+            );
     }
 }

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/DefaultEventLoggerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/eventlogging/DefaultEventLoggerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,8 +18,11 @@
  */
 package org.apache.ace.agent.eventlogging;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.AgentContext;
 import org.apache.ace.agent.spi.ComponentFactory;
 import org.apache.felix.dm.Component;
@@ -34,7 +37,11 @@ public class DefaultEventLoggerFactory i
 
     @Override
     public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
-        
+
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+
         return manager.createAdapterService(AgentContext.class, null)
             .setImplementation(EventLoggerImpl.class);
     }

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/identification/DefaultIdentificationHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,8 +18,11 @@
  */
 package org.apache.ace.agent.identification;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.AgentContext;
 import org.apache.ace.agent.spi.ComponentFactory;
 import org.apache.ace.agent.spi.IdentificationHandler;
@@ -35,6 +38,11 @@ public class DefaultIdentificationHandle
 
     @Override
     public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
+        
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+        
         return manager.createAdapterService(AgentContext.class, null)
             .setInterface(IdentificationHandler.class.getName(), null)
             .setImplementation(DefaultIdentificationHandler.class);

Modified: 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=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentFactoryImpl.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentFactoryImpl.java Thu Jun 13 08:12:24 2013
@@ -68,7 +68,8 @@ public class AgentFactoryImpl implements
         try {
             ConfigurationHelper configurationHelper = new ConfigurationHelper(configuration);
             removeComponents();
-            createComponents(configurationHelper);
+            createFactoryComponents(configurationHelper);
+            createAgent(configurationHelper);
         }
         catch (Exception e) {
             m_logService.log(LogService.LOG_ERROR, "Agent update failed! ", e);
@@ -77,11 +78,6 @@ public class AgentFactoryImpl implements
         }
     }
 
-    private void createComponents(ConfigurationHelper configurationHelper) throws Exception {
-        createFactoryComponents(configurationHelper);
-        createAgentComponents(configurationHelper);
-    }
-
     private void removeComponents() {
         for (Component component : m_components) {
             try {
@@ -109,67 +105,60 @@ public class AgentFactoryImpl implements
         }
     }
 
-    private void createAgentComponents(ConfigurationHelper configurationHelper) throws Exception {
-        for (String agentId : configurationHelper.getAgentIds()) {
-
-            Map<String, String> agentConfiguration = configurationHelper.getAgentConfiguration(agentId);
-            try {
+    private void createAgent(ConfigurationHelper configurationHelper) throws Exception {
 
-                Set<Component> components = new HashSet<Component>();
+        String identification = configurationHelper.getIdentification();
+        Map<String, String> configuration = configurationHelper.getConfiguration();
 
-                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;
-            }
+        File agentDir = new File(m_context.getDataFile(""), identification);
+        if (!agentDir.exists() && !agentDir.mkdir()) {
+            throw new IllegalStateException("Unable to access work directory " + agentDir.getAbsolutePath());
+        }
+
+        Set<Component> components = new HashSet<Component>();
+
+        // start context
+        AgentContext agentContext = new AgentContextImpl(identification, configuration, agentDir);
+        Properties contextProperties = new Properties();
+        contextProperties.put("agent", identification);
+
+        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(identification);
+        Properties agentProperties = new Properties();
+        agentProperties.put("agent", identification);
+        Component agentComponent = m_manager.createComponent()
+            .setInterface(Agent.class.getName(), agentProperties)
+            .setImplementation(agent)
+            .add(m_manager.createServiceDependency()
+                .setService(AgentContext.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(IdentificationHandler.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(DiscoveryHandler.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(LoggingHandler.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(DownloadHandler.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(DeploymentHandler.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(VersionsHandler.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(UpdateHandler.class, "(agent=" + identification + ")").setRequired(true))
+            .add(m_manager.createServiceDependency()
+                .setService(ConnectionHandler.class, "(agent=" + identification + ")").setRequired(true));
+
+        components.add(agentComponent);
+        m_components.addAll(components);
+        for (Component component : components) {
+            m_manager.add(component);
         }
     }
 }

Modified: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHelper.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHelper.java?rev=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHelper.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHelper.java Thu Jun 13 08:12:24 2013
@@ -41,47 +41,48 @@ public class ConfigurationHelper {
     private static final String DEFAULTS_RESOURCE = "org/apache/ace/agent/impl/agent-defaults.properties";
     private final Map<String, String> m_configuration;
 
-    private final String[] m_agentIds;
-    private final Map<String, Map<String, String>> m_agentConfigurations;
+    private final String m_identification;
     private final ComponentFactory[] m_componentFactories;
 
-    public ConfigurationHelper(Map<String, String> configuration) throws Exception {
+    public ConfigurationHelper(Map<String, String> configuration)
+        throws Exception {
 
         m_configuration = loadDefaultConfiguration();
         m_configuration.putAll(configuration);
-        m_agentIds = loadAgentIds();
-        m_componentFactories = loadComponentFactories();
-        m_agentConfigurations = new HashMap<String, Map<String, String>>();
-        for (String agentId : m_agentIds) {
-            m_agentConfigurations.put(agentId, loadAgentConfiguration(agentId));
+
+        m_identification = m_configuration.get(Constants.CONFIG_IDENTIFICATION_KEY);
+        if (m_identification == null || m_identification.equals("")) {
+            throw new IllegalArgumentException(
+                "Configuration is missing a valid "
+                    + Constants.CONFIG_IDENTIFICATION_KEY + ": " + m_configuration);
         }
-    }
 
-    public String[] getAgentIds() {
-        return m_agentIds;
+        m_componentFactories = loadComponentFactories();
     }
 
-    public ComponentFactory[] getComponentFactories() throws Exception {
-        return m_componentFactories;
+    public String getIdentification() {
+        return m_identification;
     }
 
-    public Map<String, String> getComponentFactoriesConfiguration() throws Exception {
-        // FIXME should pass static config only
+    public Map<String, String> getConfiguration() {
         return m_configuration;
     }
 
-    public Map<String, String> getAgentConfiguration(String agentId) throws Exception {
-        return m_agentConfigurations.get(agentId);
+    public ComponentFactory[] getComponentFactories() throws Exception {
+        return m_componentFactories;
     }
 
-    private String[] loadAgentIds() {
-        List<String> agentList = getStringListProperty(m_configuration, Constants.CONFIG_AGENTS_KEY);
-        return agentList.toArray(new String[agentList.size()]);
+    public Map<String, String> getComponentFactoriesConfiguration()
+        throws Exception {
+        // FIXME should pass static config only
+        return m_configuration;
     }
 
     private ComponentFactory[] loadComponentFactories() throws Exception {
-        List<String> componentFactoryList = getStringListProperty(m_configuration, Constants.CONFIG_FACTORIES_KEY);
-        ComponentFactory[] componentFactories = new ComponentFactory[componentFactoryList.size()];
+        List<String> componentFactoryList = getStringListProperty(
+            m_configuration, Constants.CONFIG_FACTORIES_KEY);
+        ComponentFactory[] componentFactories = new ComponentFactory[componentFactoryList
+            .size()];
         int i = 0;
         for (String componentFactory : componentFactoryList) {
             componentFactories[i++] = loadComponentFactory(componentFactory);
@@ -89,7 +90,8 @@ public class ConfigurationHelper {
         return componentFactories;
     }
 
-    private Map<String, String> loadAgentConfiguration(String agentId) throws Exception {
+    private Map<String, String> loadAgentConfiguration(String agentId)
+        throws Exception {
 
         String agentPrefix = agentId + ".";
         Map<String, String> agentConfiguration = new HashMap<String, String>();
@@ -102,14 +104,17 @@ public class ConfigurationHelper {
         // overwrite with agent specific properties
         for (Entry<String, String> entry : m_configuration.entrySet()) {
             if (entry.getKey().startsWith(agentPrefix)) {
-                agentConfiguration.put(entry.getKey().replaceFirst(agentPrefix, ""), entry.getValue());
+                agentConfiguration.put(
+                    entry.getKey().replaceFirst(agentPrefix, ""),
+                    entry.getValue());
             }
         }
         agentConfiguration.put("agent", agentId);
         return agentConfiguration;
     }
 
-    private List<String> getStringListProperty(Map<String, String> configuration, String key) {
+    private List<String> getStringListProperty(
+        Map<String, String> configuration, String key) {
         List<String> values = new ArrayList<String>();
         String value = (String) m_configuration.get(key);
         if (value != null && !value.equals("")) {
@@ -124,7 +129,8 @@ public class ConfigurationHelper {
     private Map<String, String> loadDefaultConfiguration() throws IOException {
         Properties properties = new Properties();
         ClassLoader classloader = getClass().getClassLoader();
-        InputStream inStream = classloader.getResourceAsStream(DEFAULTS_RESOURCE);
+        InputStream inStream = classloader
+            .getResourceAsStream(DEFAULTS_RESOURCE);
         if (inStream != null) {
             try {
                 properties.load(inStream);
@@ -135,30 +141,40 @@ public class ConfigurationHelper {
         }
         Map<String, String> configuration = new HashMap<String, String>();
         for (Object key : properties.keySet()) {
-            configuration.put((String) key, (String) properties.getProperty((String) key));
+            configuration.put((String) key,
+                (String) properties.getProperty((String) key));
         }
         return configuration;
     }
 
-    private ComponentFactory loadComponentFactory(String componentFactoryName) throws Exception {
+    private ComponentFactory loadComponentFactory(String componentFactoryName)
+        throws Exception {
         try {
-            Class<?> clazz = AgentFactoryImpl.class.getClassLoader().loadClass(componentFactoryName);
+            Class<?> clazz = AgentFactoryImpl.class.getClassLoader().loadClass(
+                componentFactoryName);
             if (!ComponentFactory.class.isAssignableFrom(clazz)) {
-                throw new Exception("Factory class does not implement ComponentFactory interface: " + componentFactoryName);
+                throw new Exception(
+                    "Factory class does not implement ComponentFactory interface: "
+                        + componentFactoryName);
             }
             try {
                 Object instance = clazz.newInstance();
                 return (ComponentFactory) instance;
             }
             catch (InstantiationException e) {
-                throw new Exception("Factory class does not have a default constructor: " + componentFactoryName);
+                throw new Exception(
+                    "Factory class does not have a default constructor: "
+                        + componentFactoryName);
             }
             catch (IllegalAccessException e) {
-                throw new Exception("Factory class does not have a default constructor: " + componentFactoryName);
+                throw new Exception(
+                    "Factory class does not have a default constructor: "
+                        + componentFactoryName);
             }
         }
         catch (Exception e) {
-            throw new Exception("Factory class not found: " + componentFactoryName);
+            throw new Exception("Factory class not found: "
+                + componentFactoryName);
         }
     }
 

Modified: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/agent-defaults.properties
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/agent-defaults.properties?rev=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/agent-defaults.properties (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/impl/agent-defaults.properties Thu Jun 13 08:12:24 2013
@@ -3,6 +3,26 @@
 # Apache ACE agent defaults
 # 
 
+loglevel=INFO
+
+identification=xxx
+
+discovery=http://localhost:8080
+
+authentication=NONE
+
+deployment=default
+deployment.option=123
+
+discovery=http://localhost:8080
+discovery.strategy={RANDOM,STICKY}
+
+logging.type=default
+logging.stores=auditlog
+logging.auditlog.events=true
+
+update.type=default
+
 #
 # Component factories
 #

Modified: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/logging/DefaultLoggingHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/logging/DefaultLoggingHandlerFactory.java?rev=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/logging/DefaultLoggingHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/logging/DefaultLoggingHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,8 +18,11 @@
  */
 package org.apache.ace.agent.logging;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.AgentContext;
 import org.apache.ace.agent.spi.ComponentFactory;
 import org.apache.ace.agent.spi.LoggingHandler;
@@ -36,6 +39,10 @@ public class DefaultLoggingHandlerFactor
     @Override
     public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
 
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+        
         return manager.createAdapterService(AgentContext.class, null)
             .setInterface(LoggingHandler.class.getName(), null)
             .setImplementation(DefaultLoggingHandler.class);

Modified: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/update/DefaultUpdateHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/update/DefaultUpdateHandlerFactory.java?rev=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/update/DefaultUpdateHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/update/DefaultUpdateHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,8 +18,11 @@
  */
 package org.apache.ace.agent.update;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.AgentContext;
 import org.apache.ace.agent.spi.ComponentFactory;
 import org.apache.ace.agent.spi.UpdateHandler;
@@ -36,6 +39,10 @@ public class DefaultUpdateHandlerFactory
     @Override
     public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
 
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+        
         return manager.createAdapterService(AgentContext.class, null)
             .setInterface(UpdateHandler.class.getName(), null)
             .setImplementation(DefaultUpdateHandler.class);

Modified: ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/versions/DefaultVersionsHandlerFactory.java
URL: http://svn.apache.org/viewvc/ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/versions/DefaultVersionsHandlerFactory.java?rev=1492558&r1=1492557&r2=1492558&view=diff
==============================================================================
--- ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/versions/DefaultVersionsHandlerFactory.java (original)
+++ ace/sandbox/bramk/org.apache.ace.agent/src/org/apache/ace/agent/versions/DefaultVersionsHandlerFactory.java Thu Jun 13 08:12:24 2013
@@ -18,8 +18,11 @@
  */
 package org.apache.ace.agent.versions;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Map;
 
+import org.apache.ace.agent.Constants;
 import org.apache.ace.agent.spi.AgentContext;
 import org.apache.ace.agent.spi.ComponentFactory;
 import org.apache.ace.agent.spi.VersionsHandler;
@@ -36,6 +39,10 @@ public class DefaultVersionsHandlerFacto
     @Override
     public Component createComponent(BundleContext context, DependencyManager manager, LogService logService, Map<String, String> configuration) throws Exception {
 
+        // TODO remove when done
+        Dictionary<String, Object> props = new Hashtable<String, Object>();
+        props.put("agent", configuration.get(Constants.CONFIG_IDENTIFICATION_KEY));
+        
         return manager.createAdapterService(AgentContext.class, null)
             .setInterface(VersionsHandler.class.getName(), null)
             .setImplementation(DefaultVersionsHandler.class);

Propchange: ace/sandbox/bramk/org.apache.ace.cli/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Jun 13 08:12:24 2013
@@ -0,0 +1,6 @@
+bin
+bin_test
+generated
+store
+bundle-cache
+felix-cache



Mime
View raw message