ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1514862 - in /ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent: impl/ updater/
Date Fri, 16 Aug 2013 19:31:57 GMT
Author: marrs
Date: Fri Aug 16 19:31:56 2013
New Revision: 1514862

URL: http://svn.apache.org/r1514862
Log:
ACE-342 First 'working' version of the update. Still rough.

Modified:
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java
    ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java?rev=1514862&r1=1514861&r2=1514862&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentUpdateHandlerImpl.java
Fri Aug 16 19:31:56 2013
@@ -93,16 +93,23 @@ public class AgentUpdateHandlerImpl exte
     @Override
     public void install(InputStream stream) throws IOException {
         try {
-            InputStream currentBundleVersion = null;
+            InputStream currentBundleVersion = new ByteArrayInputStream(new byte[0]);
             Bundle bundle = m_bundleContext.installBundle("agent-updater", generateBundle());
             bundle.start();
             ServiceTracker st = new ServiceTracker(m_bundleContext, m_bundleContext.createFilter("("
+ Constants.OBJECTCLASS + "=org.apache.ace.agent.updater.Activator)"), null);
-            st.open();
-            Object service = st.waitForService(60000);
-            Method method = service.getClass().getMethod("update", InputStream.class, InputStream.class);
-            method.invoke(m_bundleContext.getBundle(), currentBundleVersion, stream);
+            st.open(true);
+            Object service = st.waitForService(3000);
+            if (service != null) {
+                Method method = service.getClass().getMethod("update", Bundle.class, InputStream.class,
InputStream.class);
+                System.out.println("Method: " + method);
+                method.invoke(service, m_bundleContext.getBundle(), currentBundleVersion,
stream);
+            }
+            else {
+                System.out.println("Error: no service!");
+            }
         }
         catch (Exception e) {
+            e.printStackTrace();
         }
     }
 
@@ -116,13 +123,14 @@ public class AgentUpdateHandlerImpl exte
             Manifest manifest = new Manifest();
             Attributes main = manifest.getMainAttributes();
             main.put(Attributes.Name.MANIFEST_VERSION, "1.0");
+            main.put(new Attributes.Name("Bundle-ManifestVersion"), "2");
             main.put(new Attributes.Name("Bundle-SymbolicName"), UPDATER_SYMBOLICNAME);
             main.put(new Attributes.Name("Bundle-Version"), UPDATER_VERSION);
+            main.put(new Attributes.Name("Import-Package"), "org.osgi.framework");
             main.put(new Attributes.Name("Bundle-Activator"), "org.apache.ace.agent.updater.Activator");
-            main.put(new Attributes.Name("Bundle-ManifestVersion"), "2");
             jos = new JarOutputStream(baos, manifest);
-            jos.putNextEntry(new JarEntry("org.apache.ace.agent.updater.Activator.class"));
-            is = getClass().getResourceAsStream("org/apache/ace/agent/updater/Activator.class");
+            jos.putNextEntry(new JarEntry("org/apache/ace/agent/updater/Activator.class"));
+            is = getClass().getResourceAsStream("/org/apache/ace/agent/updater/Activator.class");
             byte[] buffer = new byte[1024];
             int bytes;
             while ((bytes = is.read(buffer)) != -1) {

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java?rev=1514862&r1=1514861&r2=1514862&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
Fri Aug 16 19:31:56 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.ace.agent.impl;
 
+import java.util.Collections;
 import java.util.Map;
 import java.util.logging.Level;
 
@@ -37,7 +38,7 @@ public class ConfigurationHandlerImpl im
 
     @Override
     public long getSyncInterval() {
-        return 10;
+        return 3;
     }
 
     @Override
@@ -91,7 +92,7 @@ public class ConfigurationHandlerImpl im
 
     @Override
     public Map<String, String> getMap() {
-        return null;
+        return Collections.EMPTY_MAP;
     }
 
 }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java?rev=1514862&r1=1514861&r2=1514862&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java Fri
Aug 16 19:31:56 2013
@@ -26,6 +26,7 @@ import java.util.concurrent.ScheduledFut
 import java.util.concurrent.TimeUnit;
 
 import org.apache.ace.agent.AgentControl;
+import org.apache.ace.agent.AgentUpdateHandler;
 import org.apache.ace.agent.ConfigurationHandler;
 import org.apache.ace.agent.DeploymentHandler;
 import org.apache.ace.agent.RetryAfterException;
@@ -58,7 +59,8 @@ public class DefaultController implement
 
         long syncInterval = getSyncInterval();
         try {
-            runSafe();
+            runSafeAgent();
+            //runSafe();
         }
         catch (RetryAfterException e) {
             syncInterval = e.getSeconds();
@@ -81,8 +83,9 @@ public class DefaultController implement
         Version current = deploymentHandler.getInstalledVersion();
         SortedSet<Version> available = deploymentHandler.getAvailableVersions();
         Version highest = Version.emptyVersion;
-        if (available != null && !available.isEmpty())
+        if (available != null && !available.isEmpty()) {
             highest = available.last();
+        }
 
         if (highest.compareTo(current) > 1) {
             InputStream inputStream = deploymentHandler.getInputStream(highest, true);
@@ -94,6 +97,24 @@ public class DefaultController implement
             }
         }
     }
+    public void runSafeAgent() throws RetryAfterException, IOException {
+
+        AgentUpdateHandler deploymentHandler = getAgentUpdateHandler();
+
+        Version current = deploymentHandler.getInstalledVersion();
+        SortedSet<Version> available = deploymentHandler.getAvailableVersions();
+        Version highest = Version.emptyVersion;
+        if (available != null && !available.isEmpty()) {
+            highest = available.last();
+        }
+
+        System.out.println("runSafeAgent: " + current + ", latest: " + highest);
+        int val = highest.compareTo(current);
+        if (val > 0) {
+            InputStream inputStream = deploymentHandler.getInputStream(highest);
+            deploymentHandler.install(inputStream);
+        }
+    }
 
     private void reSchedule(long seconds) {
         m_future = m_executorService.schedule(this, seconds, TimeUnit.SECONDS);
@@ -112,6 +133,10 @@ public class DefaultController implement
         return m_agentControl.getDeploymentHandler();
     }
 
+    private AgentUpdateHandler getAgentUpdateHandler() {
+        return m_agentControl.getAgentUpdateHandler();
+    }
+
     private ConfigurationHandler getConfiguration() {
         return m_agentControl.getConfiguration();
     }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java?rev=1514862&r1=1514861&r2=1514862&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
Fri Aug 16 19:31:56 2013
@@ -20,6 +20,7 @@ package org.apache.ace.agent.impl;
 
 import java.io.IOException;
 import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.HashMap;
@@ -52,7 +53,12 @@ public class DiscoveryHandlerImpl implem
     public URL getServerUrl() {
         String configValue = m_agentContext.getConfigurationHandler().getMap().get(DISCOVERY_CONFIG_KEY);
         if (configValue == null || configValue.equals(""))
-            return null;
+            try {
+                return new URL("http://localhost:8080");
+            }
+            catch (MalformedURLException e) {
+                e.printStackTrace();
+            }
         if (configValue.indexOf(",") == -1) {
             return checkURL(configValue.trim());
         }

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java?rev=1514862&r1=1514861&r2=1514862&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java
(original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/IdentificationHandlerImpl.java
Fri Aug 16 19:31:56 2013
@@ -45,7 +45,7 @@ public class IdentificationHandlerImpl i
     public String getIdentification() {
         String configValue = m_agentContext.getConfigurationHandler().getMap().get(IDENTIFICATION_CONFIG_KEY);
         if (configValue == null)
-            return null;
+            return "defaultTargetID";
         configValue = configValue.trim();
         if (configValue.equals(""))
             return null;

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java?rev=1514862&r1=1514861&r2=1514862&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/UpdateHandlerBase.java Fri
Aug 16 19:31:56 2013
@@ -31,6 +31,8 @@ import java.util.TreeSet;
 import org.apache.ace.agent.AgentConstants;
 import org.apache.ace.agent.DownloadHandle;
 import org.apache.ace.agent.RetryAfterException;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.Version;
 
 public class UpdateHandlerBase {
@@ -106,23 +108,10 @@ public class UpdateHandlerBase {
     protected InputStream getInputStream(URL packageURL) throws RetryAfterException, IOException
{
         URLConnection urlConnection = null;
         InputStream inputStream = null;
-        try {
-            // TODO handle problems and retries
-            urlConnection = packageURL.openConnection();
-            inputStream = urlConnection.getInputStream();
-            return inputStream;
-        }
-        finally {
-            if (urlConnection != null && urlConnection instanceof HttpURLConnection)
-                ((HttpURLConnection) urlConnection).disconnect();
-            if (inputStream != null)
-                try {
-                    inputStream.close();
-                }
-                catch (IOException e) {
-                    e.printStackTrace();
-                }
-        }
+        // TODO handle problems and retries
+        urlConnection = getConnection(packageURL);
+        inputStream = urlConnection.getInputStream();
+        return inputStream;
     }
 
     protected DownloadHandle getDownloadHandle(URL packageURL) {

Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java?rev=1514862&r1=1514861&r2=1514862&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/updater/Activator.java Fri Aug
16 19:31:56 2013
@@ -48,13 +48,13 @@ public class Activator implements Bundle
 
     @Override
     public void stop(BundleContext context) throws Exception {
-        Thread thread;
-        synchronized (LOCK) {
-            thread = m_updaterThread;
-        }    
-        if (thread != null) {
-            thread.join(60000);
-        }
+//        Thread thread;
+//        synchronized (LOCK) {
+//            thread = m_updaterThread;
+//        }    
+//        if (thread != null) {
+//            thread.join(10000);
+//        }
     }
     
     public void update(Bundle agent, InputStream oldStream, InputStream newStream) {
@@ -71,10 +71,12 @@ public class Activator implements Bundle
     public void run() {
         // TODO First fetch both streams and store them in a file inside the bundle cache.
         try {
+            System.out.println("Updating to " + m_newStream);
             m_agent.update(m_newStream);
         }
         catch (BundleException e) {
             try {
+                System.out.println("Reverting to " + m_oldStream);
                 m_agent.update(m_oldStream);
             }
             catch (BundleException e1) {



Mime
View raw message