You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2013/10/15 16:56:54 UTC

svn commit: r1532372 - in /ace/trunk: org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/ org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/

Author: marrs
Date: Tue Oct 15 14:56:53 2013
New Revision: 1532372

URL: http://svn.apache.org/r1532372
Log:
ACE-373 Implementation now makes sure it always selects the latest version of a resource processor, and that this triggers a change. Extended an existing test to also validate this behaviour.

Modified:
    ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/TemplateProcessorTest.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java

Modified: ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/TemplateProcessorTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/TemplateProcessorTest.java?rev=1532372&r1=1532371&r2=1532372&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/TemplateProcessorTest.java (original)
+++ ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/TemplateProcessorTest.java Tue Oct 15 14:56:53 2013
@@ -188,6 +188,7 @@ public class TemplateProcessorTest exten
         attr.put(ArtifactObject.KEY_URL, "http://myprocessor");
         attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
         attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
+        attr.put(BundleHelper.KEY_VERSION, "1.0.0");
         attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);
 
         ArtifactObject b2 = m_artifactRepository.create(attr, tags);
@@ -221,6 +222,78 @@ public class TemplateProcessorTest exten
         assertEquals(a2.getURL(), artifact2.getUrl());
         assertEquals("my.processor.pid", artifact2.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
         assertEquals(a2.getResourceId(), artifact2.getDirective(DeploymentArtifact.DIRECTIVE_KEY_RESOURCE_ID));
+        
+        // Now, add a new version of the processor (ACE-373)
+        assertFalse("There should be no changes.", sgo.needsApprove());
+
+        attr = new HashMap<String, String>();
+        attr.put(ArtifactObject.KEY_URL, "http://myprocessor/v2");
+        attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
+        attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
+        attr.put(BundleHelper.KEY_VERSION, "2.0.0");
+        attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);
+
+        ArtifactObject b3 = m_artifactRepository.create(attr, tags);
+
+        assertTrue("By adding a resource processor, we should have triggered a change that needs to be approved.", sgo.needsApprove());
+
+        sgo.approve();
+
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
+                return null;
+            }
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
+
+        dep = m_deploymentVersionRepository.getMostRecentDeploymentVersion(sgo.getID());
+
+        toDeploy = dep.getDeploymentArtifacts();
+
+        assertEquals("We expect to find four artifacts to deploy;", 4, toDeploy.length);
+        boolean foundBundle = false;
+        boolean foundProcessor = false;
+        boolean foundArtifact1 = false;
+        boolean foundArtifact2 = false;
+        for (DeploymentArtifact a : toDeploy) {
+            String url = a.getUrl();
+            if (url.equals(b1.getURL())) {
+                foundBundle = true;
+            }
+            else if (url.equals(b3.getURL())) {
+                assertEquals("true", a.getDirective(DeploymentArtifact.DIRECTIVE_ISCUSTOMIZER));
+                foundProcessor = true;
+            }
+            else if (url.equals(a1.getURL())) {
+                assertEquals("my.processor.pid", a.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
+                foundArtifact1 = true;
+            }
+            else if (url.equals(a2.getURL())) {
+                assertEquals("my.processor.pid", a.getDirective(DeploymentArtifact.DIRECTIVE_KEY_PROCESSORID));
+                assertEquals(a2.getResourceId(), a.getDirective(DeploymentArtifact.DIRECTIVE_KEY_RESOURCE_ID));
+                foundArtifact2 = true;
+            }
+        }
+        assertTrue("Could not find bundle in deployment", foundBundle);
+        assertTrue("Could not find processor in deployment", foundProcessor);
+        assertTrue("Could not find artifact 1 in deployment", foundArtifact1);
+        assertTrue("Could not find artifact 2 in deployment", foundArtifact2);
+
+        // Now, let's add a new resource processor that is *older* than the one we already have.
+        // Nothing should change.
+
+        assertFalse("There should be no changes.", sgo.needsApprove());
+
+        attr = new HashMap<String, String>();
+        attr.put(ArtifactObject.KEY_URL, "http://myprocessor/v1.5");
+        attr.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, "my.processor.pid");
+        attr.put(BundleHelper.KEY_SYMBOLICNAME, "my.processor.bundle");
+        attr.put(BundleHelper.KEY_VERSION, "1.5.0");
+        attr.put(ArtifactHelper.KEY_MIMETYPE, BundleHelper.MIMETYPE);
+
+        m_artifactRepository.create(attr, tags);
+
+        assertFalse("By adding an older resource processor, we should not have triggered a change.", sgo.needsApprove());
 
         cleanUp();
 

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java?rev=1532372&r1=1532371&r2=1532372&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java (original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java Tue Oct 15 14:56:53 2013
@@ -549,10 +549,7 @@ public class StatefulTargetRepositoryImp
         }
 
         // Find all processors
-        Map<String, ArtifactObject> allProcessors = new HashMap<String, ArtifactObject>();
-        for (ArtifactObject bundle : m_artifactRepository.getResourceProcessors()) {
-            allProcessors.put(m_bundleHelper.getResourceProcessorPIDs(bundle), bundle);
-        }
+        Map<String, ArtifactObject> allProcessors = getAllProcessors();
 
         // Determine all resource processors we need
         for (String processor : artifacts.values()) {
@@ -609,6 +606,35 @@ public class StatefulTargetRepositoryImp
         return result.toArray(new DeploymentArtifact[result.size()]);
     }
 
+    /**
+     * Returns a map of all resource processors that are available. If there are multiple versions
+     * of a specific processor, it will only return the latest version.
+     * 
+     * @return a map of all resource processors, indexed by processor ID
+     */
+    private Map<String, ArtifactObject> getAllProcessors() {
+        Map<String, ArtifactObject> allProcessors = new HashMap<String, ArtifactObject>();
+        for (ArtifactObject processorBundle : m_artifactRepository.getResourceProcessors()) {
+            String pid = m_bundleHelper.getResourceProcessorPIDs(processorBundle);
+            ArtifactObject existingProcessorBundle = allProcessors.get(pid);
+            if (existingProcessorBundle == null) {
+                allProcessors.put(pid, processorBundle);
+            }
+            else {
+                // if there are multiple versions of a resource processor, we explicitly want to always
+                // return the latest version of a resource processor...
+                String existingVersionString = existingProcessorBundle.getAttribute(BundleHelper.KEY_VERSION);
+                String newVersionString = processorBundle.getAttribute(BundleHelper.KEY_VERSION);
+                Version existingVersion = existingVersionString == null ? Version.emptyVersion : Version.parseVersion(existingVersionString);
+                Version newVersion = newVersionString == null ? Version.emptyVersion : Version.parseVersion(newVersionString);
+                if (existingVersion.compareTo(newVersion) < 0) {
+                    allProcessors.put(pid, processorBundle);
+                }
+            }
+        }
+        return allProcessors;
+    }
+
     private String getRepositoryPath(ArtifactObject artifact,
         Map<ArtifactObject, Map<FeatureObject, List<DistributionObject>>> path) {
         StringBuilder builder = new StringBuilder();
@@ -635,11 +661,7 @@ public class StatefulTargetRepositoryImp
         List<ArtifactObject> result = new ArrayList<ArtifactObject>();
         TargetObject to = getTargetObject(targetID);
 
-        Map<String, ArtifactObject> allProcessors = new HashMap<String, ArtifactObject>();
-        for (ArtifactObject bundle : m_artifactRepository.getResourceProcessors()) {
-            allProcessors.put(m_bundleHelper.getResourceProcessorPIDs(bundle), bundle);
-        }
-
+        Map<String, ArtifactObject> allProcessors = getAllProcessors();
         if (to != null) {
             for (DistributionObject distribution : to.getDistributions()) {
                 for (FeatureObject feature : distribution.getFeatures()) {