ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1506031 - 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/ org.apache.ace.client.repository/src/org/apache/ace/client/reposi...
Date Tue, 23 Jul 2013 13:19:05 GMT
Author: marrs
Date: Tue Jul 23 13:19:04 2013
New Revision: 1506031

URL: http://svn.apache.org/r1506031
Log:
ACE-397 Changed the implementation of approving changes, updated the tests and UI as well.

Added:
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/PreCommitMember.java
Modified:
    ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
    ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/StatefulTargetRepositoryTest.java
    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/RepositoryObject.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/Activator.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/StatefulTargetObject.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetObjectImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetRepositoryImpl.java
    ace/trunk/org.apache.ace.target.mgmt.ui/src/org/apache/ace/target/management/ui/TargetManagementExtension.java
    ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/Activator.java
    ace/trunk/run-server-allinone/server-allinone.bndrun

Modified: ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
(original)
+++ ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
Tue Jul 23 13:19:04 2013
@@ -39,6 +39,7 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.helper.bundle.BundleHelper;
 import org.apache.ace.client.repository.object.Artifact2FeatureAssociation;
 import org.apache.ace.client.repository.object.ArtifactObject;
+import org.apache.ace.client.repository.object.DeploymentVersionObject;
 import org.apache.ace.client.repository.object.Distribution2TargetAssociation;
 import org.apache.ace.client.repository.object.DistributionObject;
 import org.apache.ace.client.repository.object.Feature2DistributionAssociation;
@@ -151,6 +152,8 @@ public class RepositoryAdminTest extends
                 .setLocation(m_endpoint).setCustomer("apache").setName("deployment").setWriteable());
 
         m_repositoryAdmin.login(loginContext);
+        
+        m_repositoryAdmin.checkout();
 
         runAndWaitForEvent(new Callable<Object>() {
             public Object call() throws Exception {
@@ -184,13 +187,15 @@ public class RepositoryAdminTest extends
 
         assertTrue("Turning on the autoapprove should not automatically approve whatever
was waiting.", sgo.needsApprove());
 
-        runAndWaitForEvent(new Callable<Object>() {
-            public Object call() throws Exception {
-                sgo.approve();
+        sgo.approve();
+        
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
                 return null;
             }
-        }, false, TOPIC_STATUS_CHANGED);
-
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);        
+        
         assertFalse("We approved the new version by hand, so we should not need approval.",
sgo.needsApprove());
 
         runAndWaitForEvent(new Callable<Object>() {
@@ -202,6 +207,13 @@ public class RepositoryAdminTest extends
         }, false, ArtifactObject.TOPIC_ADDED, Artifact2FeatureAssociation.TOPIC_ADDED, TOPIC_STATUS_CHANGED,
             TOPIC_STATUS_CHANGED);
 
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
+                return null;
+            }
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);           
+        
         assertFalse("With autoapprove on, adding new deployment information should still
not need approval (at least, after the two CHANGED events).", sgo.needsApprove());
 
         runAndWaitForEvent(new Callable<Object>() {

Modified: ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/StatefulTargetRepositoryTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/StatefulTargetRepositoryTest.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/StatefulTargetRepositoryTest.java
(original)
+++ ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/StatefulTargetRepositoryTest.java
Tue Jul 23 13:19:04 2013
@@ -122,7 +122,7 @@ public class StatefulTargetRepositoryTes
 		    }
 		}, false, ArtifactObject.TOPIC_ADDED, Artifact2FeatureAssociation.TOPIC_CHANGED, TOPIC_STATUS_CHANGED);
 		
-		assertTrue("We added a new version of a bundle that is used by the target, so approval
should be necessary.", sgo.needsApprove());
+        assertTrue("We added a new version of a bundle that is used by the target, so approval
should be necessary.", sgo.needsApprove());
 		assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered,
sgo.getRegistrationState());
 		assertEquals("We expect the registration state to be Unapproved;", StoreState.Unapproved,
sgo.getStoreState());
 		assertEquals("According to the shop, this target needs 1 bundle", 1, sgo.getArtifactsFromShop().length);
@@ -131,11 +131,14 @@ public class StatefulTargetRepositoryTes
 		assertEquals("The deployment should tell use we need bundle URL 'bundle1-1';", "http://bundle1-1",
sgo.getArtifactsFromDeployment()[0].getUrl());
 		assertEquals("1", sgo.getCurrentVersion());
 		
-		final String newVersion = runAndWaitForEvent(new Callable<String>() {
-		    public String call() throws Exception {
-		        return sgo.approve();
-		    }
-		}, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
+		String newVersion = sgo.approve();
+		
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
+                return null;
+            }
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
 		
 		assertFalse("Immediately after approval, no approval is necessary.", sgo.needsApprove());
 		assertEquals("We expect the registration state to be Registered;", RegistrationState.Registered,
sgo.getRegistrationState());
@@ -708,5 +711,6 @@ public class StatefulTargetRepositoryTes
                 .setLocation(m_endpoint).setCustomer(customer).setName("deployment").setWriteable());
 
         m_repositoryAdmin.login(loginContext);
+        m_repositoryAdmin.checkout();
 	}
 }

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=1506031&r1=1506030&r2=1506031&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 Jul 23 13:19:04 2013
@@ -36,6 +36,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.Callable;
 
+import org.apache.ace.client.repository.RepositoryAdminLoginContext;
 import org.apache.ace.client.repository.helper.ArtifactHelper;
 import org.apache.ace.client.repository.helper.ArtifactPreprocessor;
 import org.apache.ace.client.repository.helper.PropertyResolver;
@@ -50,6 +51,8 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.stateful.StatefulTargetObject;
 import org.apache.ace.test.constants.TestConstants;
 import org.apache.felix.dm.Component;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.useradmin.User;
 
 /**
  * Test cases for the template processing functionality.
@@ -121,6 +124,8 @@ public class TemplateProcessorTest exten
 	}
 
     public void testStatefulApprovalWithArtifacts() throws Exception {
+        setupRepository();
+        
         // some setup: we need a helper.
         ArtifactHelper myHelper = new MockArtifactHelper("mymime");
 
@@ -168,9 +173,16 @@ public class TemplateProcessorTest exten
         m_feature2distributionRepository.create(g, l);
 
         m_distribution2targetRepository.create(l, sgo.getTargetObject());
-
         try {
             sgo.approve();
+            
+            runAndWaitForEvent(new Callable<Void>() {
+                public Void call() throws Exception {
+                    m_repositoryAdmin.commit();
+                    return null;
+                }
+            }, true, TOPIC_STATUS_CHANGED);        
+            
             assertTrue("Without a resource processor for our artifact, approve should go
wrong.", false);
         }
         catch (IllegalStateException ise) {
@@ -187,6 +199,13 @@ public class TemplateProcessorTest exten
         ArtifactObject b2 = m_artifactRepository.create(attr, tags);
 
         sgo.approve();
+        
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
+                return null;
+            }
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);        
 
         DeploymentVersionObject dep = m_deploymentVersionRepository.getMostRecentDeploymentVersion(sgo.getID());
 
@@ -214,11 +233,35 @@ public class TemplateProcessorTest exten
         m_dependencyManager.remove(myHelperService);
     }
 
+    private void setupRepository() throws IOException, InterruptedException, InvalidSyntaxException
{
+        User user = new MockUser();
+
+        startRepositoryService();
+
+        addRepository("storeInstance", "apache", "store", true);
+        addRepository("targetInstance", "apache", "target", true);
+        addRepository("deploymentInstance", "apache", "deployment", true);
+
+        RepositoryAdminLoginContext loginContext = m_repositoryAdmin.createLoginContext(user);
+        loginContext
+            .add(loginContext.createShopRepositoryContext()
+                .setLocation(m_endpoint).setCustomer("apache").setName("store").setWriteable())
+            .add(loginContext.createTargetRepositoryContext()
+                .setLocation(m_endpoint).setCustomer("apache").setName("target").setWriteable())
+            .add(loginContext.createDeploymentRepositoryContext()
+                .setLocation(m_endpoint).setCustomer("apache").setName("deployment").setWriteable());
+
+        m_repositoryAdmin.login(loginContext);
+        m_repositoryAdmin.checkout();
+    }
+
     /**
      * Tests the full template mechanism, from importing templatable artifacts, to creating
deployment
      * versions with it. It uses the configuration (autoconf) helper, which uses a VelocityBased
preprocessor.
      */
     public void testTemplateProcessing() throws Exception {
+        setupRepository();
+        
         addObr("/obr", "store");
         m_artifactRepository.setObrBase(new URL("http://localhost:" + TestConstants.PORT
+ "/obr/"));
 
@@ -260,13 +303,15 @@ public class TemplateProcessorTest exten
         // create a deploymentversion
         assertTrue("With the new assignments, the SGO should need approval.", sgo.needsApprove());
         
-        runAndWaitForEvent(new Callable<Object>() {
-            public Object call() throws Exception {
-                sgo.approve();
+        sgo.approve();
+
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
                 return null;
             }
-        }, false, TOPIC_STATUS_CHANGED);
-
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);  
+        
         // find the deployment version
         DeploymentVersionObject dvo = m_deploymentVersionRepository.getMostRecentDeploymentVersion("templatetarget2");
         String inFile = tryGetStringFromURL(findXmlUrlInDeploymentObject(dvo), 10, 100);
@@ -279,6 +324,14 @@ public class TemplateProcessorTest exten
         a2g = m_artifact2featureRepository.create(a1, go);
 
         sgo.approve();
+        
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
+                return null;
+            }
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);  
+
 
         // find the deployment version
         dvo = m_deploymentVersionRepository.getMostRecentDeploymentVersion("templatetarget2");
@@ -296,6 +349,8 @@ public class TemplateProcessorTest exten
      * Tests the template processing mechanism: given a custom processor, do the correct
calls go out?
      */
     public void testTemplateProcessingInfrastructure() throws Exception {
+        setupRepository();
+        
         // create a preprocessor
         MockArtifactPreprocessor preprocessor = new MockArtifactPreprocessor();
 
@@ -346,6 +401,14 @@ public class TemplateProcessorTest exten
         assertTrue("With the new assignments, the SGO should need approval.", sgo.needsApprove());
         // create a deploymentversion
         sgo.approve();
+        
+        
+        runAndWaitForEvent(new Callable<Void>() {
+            public Void call() throws Exception {
+                m_repositoryAdmin.commit();
+                return null;
+            }
+        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);  
 
         // the preprocessor now has gotten its properties; inspect these
         PropertyResolver target = preprocessor.getProps();

Added: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/PreCommitMember.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/PreCommitMember.java?rev=1506031&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/PreCommitMember.java
(added)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/PreCommitMember.java
Tue Jul 23 13:19:04 2013
@@ -0,0 +1,46 @@
+/*
+ * 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.client.repository;
+
+import java.io.IOException;
+
+/**
+ * An interface that can be implemented by anybody that wants to be invoked as part of the
+ * pre-commit cycle of a RepositoryAdmin.
+ */
+public interface PreCommitMember {
+    /**
+     * Resets any volatile changes that might have been made as part of earlier operations.
+     */
+    public void reset();
+
+    /**
+     * Checks if there are any changes that need to be applied as part of the pre-commit
+     * cycle.
+     */
+    public boolean hasChanges();
+
+    /**
+     * Invokes the pre-commit cycle. You should do all the work here and throw an exception
+     * if for some reason the work fails.
+     * 
+     * @throws IOException when the work fails and the commit should be aborted
+     */
+    public void preCommit() throws IOException;
+}

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/RepositoryObject.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/RepositoryObject.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/RepositoryObject.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/RepositoryObject.java
Tue Jul 23 13:19:04 2013
@@ -47,39 +47,47 @@ public interface RepositoryObject extend
      * when the value is new.
      */
     public String addAttribute(String key, String value);
+    
     /**
      * Removes a names attribute from this object's attributes.
      */
     public String removeAttribute(String key);
+    
     /**
      * Gets a named attribute. Returns <code>null<code> when the attribute named
by
      * <code>key</code> does not exist.
      */
     public String getAttribute(String key);
+    
     /**
      * Returns an enumeration of all attribute keys.
      */
     public Enumeration<String> getAttributeKeys();
+    
     /**
      * Adds a named tag to this object's attributes. If the name already exists,
      * it will be overwritten, and the old value is returned; will return <code>null</code>
      * when the value is new.
      */
     public String addTag(String key, String value);
+    
     /**
      * Removes a named tag from this object's attributes.
      */
     public String removeTag(String key);
+    
     /**
      * Gets a named tag. Returns <code>null<code> when the attribute named by
      * <code>key</code> does not exist.
      */
     public String getTag(String key);
+    
     /**
      * Returns an enumeration of all tags in this object, coming from both the
      * tags and the attributes.
      */
     public Enumeration<String> getTagKeys();
+    
     /**
      * Returns a <code>Dictionary</code> representing this object. It will contain
all keys,
      * from <code>getTagKeys</code>, and all values that correspond to them.
If a key is present
@@ -87,10 +95,12 @@ public interface RepositoryObject extend
      * <code>String</code> objects; otherwise a single <code>String</code>
is returned.
      */
     public Dictionary<String, Object> getDictionary();
+    
     /**
      * Indicates that this object should no longer be used.
      */
     public boolean isDeleted();
+    
     /**
      * Creates a filter string for use in associations, optionally with some
      * additional properties. The basic implementation will use all <code>getDefiningKeys</code>.
@@ -113,7 +123,7 @@ public interface RepositoryObject extend
      * and otherwise (if no order is natural), return <code>null</code>.
      * @return A <code>Comparator</code> for this type of object
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings("rawtypes")
     public Comparator getComparator();
 
     /**
@@ -123,7 +133,15 @@ public interface RepositoryObject extend
      */
     public String getDefinition();
 
+    /**
+     * Different working states of this object.
+     */
     public enum WorkingState {
         New, Changed, Unchanged, Removed;
     }
+
+    /**
+     * Notifies interested parties that "something" has changed in this object.
+     */
+    void notifyChanged();
 }
\ No newline at end of file

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/Activator.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/Activator.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/Activator.java
Tue Jul 23 13:19:04 2013
@@ -148,7 +148,7 @@ public class Activator extends Dependenc
     @SuppressWarnings("unchecked")
     private void createSessionServices(SessionData sd, String sessionID) {
         RepositoryAdminImpl rai = new RepositoryAdminImpl(sessionID);
-        Component comp1 = createComponent()
+        Component repositoryAdminComponent = createComponent()
             .setInterface(RepositoryAdmin.class.getName(), rai.getSessionProps())
             .setImplementation(rai)
             .setComposition("getInstances")
@@ -176,7 +176,7 @@ public class Activator extends Dependenc
         });
         
         StatefulTargetRepositoryImpl statefulTargetRepositoryImpl = new StatefulTargetRepositoryImpl(sessionID);
-        Component comp2 = createComponent()
+        Component statefulTargetRepositoryComponent = createComponent()
             .setInterface(new String[] { StatefulTargetRepository.class.getName(), EventHandler.class.getName()
}, topic)
             .setImplementation(statefulTargetRepositoryImpl)
             .add(createServiceDependency().setService(ArtifactRepository.class, sessionFilter).setRequired(true))
@@ -186,9 +186,11 @@ public class Activator extends Dependenc
             .add(createServiceDependency().setService(BundleHelper.class).setRequired(true))
             .add(createServiceDependency().setService(EventAdmin.class).setRequired(true))
             .add(createServiceDependency().setService(LogService.class).setRequired(false));
+        
+        rai.addPreCommitMember(statefulTargetRepositoryImpl);
 
         // Publish our components to our session data for later use...
-        sd.addComponents(m_dependencyManager, comp1, comp2);
+        sd.addComponents(m_dependencyManager, repositoryAdminComponent, statefulTargetRepositoryComponent);
     }
 
     /**

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/AssociationImpl.java
Tue Jul 23 13:19:04 2013
@@ -211,7 +211,8 @@ public class AssociationImpl<L extends R
                     props.put(EVENT_OLD, oldEndpoints);
                     props.put(EVENT_NEW, newEndpoints);
                     notifyChanged(props);
-                } else {
+                }
+                else {
                     m_left = newEndpoints;
                 }
             }
@@ -234,7 +235,8 @@ public class AssociationImpl<L extends R
                     props.put(EVENT_OLD, oldEndpoints);
                     props.put(EVENT_NEW, newEndpoints);
                     notifyChanged(props);
-                } else {
+                }
+                else {
                     m_right = newEndpoints;
                 }
             }

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
Tue Jul 23 13:19:04 2013
@@ -30,6 +30,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.ace.client.repository.ObjectRepository;
+import org.apache.ace.client.repository.PreCommitMember;
 import org.apache.ace.client.repository.RepositoryAdmin;
 import org.apache.ace.client.repository.RepositoryAdminLoginContext;
 import org.apache.ace.client.repository.RepositoryObject;
@@ -53,6 +54,7 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.repository.Feature2DistributionAssociationRepository;
 import org.apache.ace.client.repository.repository.FeatureRepository;
 import org.apache.ace.client.repository.repository.TargetRepository;
+import org.apache.ace.client.repository.stateful.impl.StatefulTargetRepositoryImpl;
 import org.apache.ace.connectionfactory.ConnectionFactory;
 import org.apache.ace.repository.Repository;
 import org.apache.ace.repository.ext.BackupRepository;
@@ -103,6 +105,8 @@ public class RepositoryAdminImpl impleme
 
     private User m_user;
     private RepositorySet[] m_repositorySets;
+    
+    private List<PreCommitMember> m_preCommitMembers;
 
     private List<Component[]> m_services;
     private ArtifactRepositoryImpl m_artifactRepositoryImpl;
@@ -118,6 +122,7 @@ public class RepositoryAdminImpl impleme
 
     public RepositoryAdminImpl(String sessionID) {
         m_sessionID = sessionID;
+        m_preCommitMembers = new ArrayList<PreCommitMember>();
         m_sessionProps = new Properties();
         m_sessionProps.put(SessionFactory.SERVICE_SID, sessionID);
         m_changeNotifierManager = new ChangeNotifierManager();
@@ -263,6 +268,9 @@ public class RepositoryAdminImpl impleme
     public void checkout() throws IOException {
         synchronized (m_lock) {
             ensureLogin();
+            for (PreCommitMember member : m_preCommitMembers) {
+                member.reset();
+            }
             for (RepositorySet set : m_repositorySets) {
                 set.checkout();
             }
@@ -273,6 +281,9 @@ public class RepositoryAdminImpl impleme
     public void commit() throws IOException {
         synchronized (m_lock) {
             ensureLogin();
+            for (PreCommitMember member : m_preCommitMembers) {
+                member.preCommit();
+            }
             for (RepositorySet set : m_repositorySets) {
                 set.commit();
             }
@@ -294,6 +305,9 @@ public class RepositoryAdminImpl impleme
     public void revert() throws IOException {
         synchronized (m_lock) {
             ensureLogin();
+            for (PreCommitMember member : m_preCommitMembers) {
+                member.reset();
+            }
             for (RepositorySet set : m_repositorySets) {
                 set.revert();
             }
@@ -315,6 +329,11 @@ public class RepositoryAdminImpl impleme
     public boolean isModified() {
         synchronized (m_lock) {
             ensureLogin();
+            for (PreCommitMember member : m_preCommitMembers) {
+                if (member.hasChanges()) {
+                    return true;
+                }
+            }
             for (RepositorySet set : m_repositorySets) {
                 if (set.isModified()) {
                     return true;
@@ -586,4 +605,10 @@ public class RepositoryAdminImpl impleme
         String mimetype = (String) ref.getProperty(ArtifactHelper.KEY_MIMETYPE);
         m_artifactRepositoryImpl.removeHelper(mimetype, helper);
     }
+
+    void addPreCommitMember(PreCommitMember member) {
+        synchronized (m_lock) {
+            m_preCommitMembers.add(member);
+        }
+    }
 }

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
Tue Jul 23 13:19:04 2013
@@ -65,6 +65,11 @@ public class RepositoryObjectImpl<T exte
         }
         m_notifier = notifier;
     }
+    
+    @Override
+    public void notifyChanged() {
+        notifyChanged(null);
+    }
 
     protected void notifyChanged(Properties props) {
         if (props == null) {

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/StatefulTargetObject.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/StatefulTargetObject.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/StatefulTargetObject.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/StatefulTargetObject.java
Tue Jul 23 13:19:04 2013
@@ -51,6 +51,7 @@ public interface StatefulTargetObject ex
     public final static String KEY_REGISTRATION_STATE = "KEY_REGISTRATION_STATE";
     public final static String KEY_STORE_STATE = "KEY_STORE_STATE";
     public final static String KEY_PROVISIONING_STATE = "KEY_PROVISIONING_STATE";
+    public final static String KEY_APPROVAL_STATE = "KEY_APPROVAL_STATE";
     public final static String KEY_LAST_INSTALL_VERSION = "KEY_LAST_INSTALL_VERSION";
     public final static String KEY_LAST_INSTALL_SUCCESS = "KEY_LAST_INSTALL_SUCCESS";
     public final static String KEY_ACKNOWLEDGED_INSTALL_VERSION = "KEY_ACKNOWLEDGED_INSTALL_VERSION";
@@ -204,4 +205,11 @@ public interface StatefulTargetObject ex
     public enum ProvisioningState {
         Idle, InProgress, OK, Failed;
     }
+    
+    /** Indicates if the user has approved changes for this target or not. */
+    public enum ApprovalState {
+        Unapproved, Approved;
+    }
+
+    public ApprovalState getApprovalState();
 }

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetObjectImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetObjectImpl.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetObjectImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful/impl/StatefulTargetObjectImpl.java
Tue Jul 23 13:19:04 2013
@@ -77,7 +77,7 @@ public class StatefulTargetObjectImpl im
     public String approve() throws IllegalStateException {
         try {
             String version = m_repository.approve(getID());
-            setStoreState(StoreState.Approved);
+            setApprovalState(ApprovalState.Approved);
             return version;
         }
         catch (IOException e) {
@@ -152,7 +152,7 @@ public class StatefulTargetObjectImpl im
     }
 
     public boolean needsApprove() {
-        return getStoreState() == StoreState.Unapproved;
+        return !(getStoreState() == StoreState.Approved);
     }
 
     public ProvisioningState getProvisioningState() {
@@ -162,6 +162,11 @@ public class StatefulTargetObjectImpl im
     public RegistrationState getRegistrationState() {
         return RegistrationState.valueOf(getStatusAttribute(KEY_REGISTRATION_STATE));
     }
+    
+    public ApprovalState getApprovalState() {
+        String state = getStatusAttribute(KEY_APPROVAL_STATE);
+        return state == null ? ApprovalState.Unapproved : ApprovalState.valueOf(state);
+    }
 
     public StoreState getStoreState() {
         String statusAttribute = getStatusAttribute(KEY_STORE_STATE);
@@ -236,7 +241,7 @@ public class StatefulTargetObjectImpl im
     }
 
     private void determineStoreState(DeploymentVersionObject deploymentVersionObject) {
-        synchronized(m_lock) {
+        synchronized (m_lock) {
             List<String> fromShop = new ArrayList<String>();
             ArtifactObject[] artifactsFromShop = m_repository.getNecessaryArtifacts(getID());
             DeploymentVersionObject mostRecentVersion;
@@ -270,6 +275,7 @@ public class StatefulTargetObjectImpl im
             }
             else if (fromShop.containsAll(fromDeployment) && fromDeployment.containsAll(fromShop))
{
                 // great, we have the same artifacts. But... do they need to be reprocessed?
+                // this might be the case when the target has new tags that affect templates
                 for (ArtifactObject ao : artifactsFromShop) {
                     if (m_repository.needsNewVersion(ao, getID(), mostRecentVersion.getVersion()))
{
                         setStoreState(StoreState.Unapproved);
@@ -370,6 +376,15 @@ public class StatefulTargetObjectImpl im
     private void setProvisioningState(ProvisioningState state) {
         setStatus(KEY_PROVISIONING_STATE, state.toString());
     }
+    
+    private void setApprovalState(ApprovalState state) {
+        setStatus(KEY_APPROVAL_STATE, state.toString());
+        if (isRegistered() && state == ApprovalState.Approved && needsApprove())
{
+            // trigger a change here, because we know the target will change as part of the
+            // pre-commit phase
+            getTargetObject().notifyChanged();
+        }
+    }
 
     private void setStatus(String key, String status) {
         if (!status.equals(getStatusAttribute(key))) {
@@ -383,7 +398,9 @@ public class StatefulTargetObjectImpl im
 
     private void handleStatechangeAutomation() {
         if (getStoreState().equals(StoreState.Unapproved) && isRegistered() &&
getAutoApprove()) {
-            approve();
+            if (getApprovalState().equals(ApprovalState.Unapproved)) {
+                approve();
+            }
         }
     }
 
@@ -733,4 +750,12 @@ public class StatefulTargetObjectImpl im
     public String toString() {
     	return "StatefulTargetObjectImpl[" + getStatusAttribute(KEY_ID) + " " + getRegistrationState()
+ " " + getStoreState() + " " + getProvisioningState() + "]";
     }
+
+    public void resetApprovalState() {
+        setApprovalState(ApprovalState.Unapproved);
+    }
+
+    @Override
+    public void notifyChanged() {
+    }
 }
\ No newline at end of file

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=1506031&r1=1506030&r2=1506031&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 Jul 23 13:19:04 2013
@@ -32,6 +32,7 @@ import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.ace.client.repository.PreCommitMember;
 import org.apache.ace.client.repository.RepositoryAdmin;
 import org.apache.ace.client.repository.RepositoryObject;
 import org.apache.ace.client.repository.RepositoryUtil;
@@ -47,6 +48,7 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.repository.DeploymentVersionRepository;
 import org.apache.ace.client.repository.repository.TargetRepository;
 import org.apache.ace.client.repository.stateful.StatefulTargetObject;
+import org.apache.ace.client.repository.stateful.StatefulTargetObject.ApprovalState;
 import org.apache.ace.client.repository.stateful.StatefulTargetRepository;
 import org.apache.ace.log.LogDescriptor;
 import org.apache.ace.log.LogEvent;
@@ -64,7 +66,7 @@ import org.osgi.service.log.LogService;
  * Implements the StatefulTargetRepository. If an <code>AuditLogStore</code>
is present,
  * it will be used; it is assumed that the auditlog store is up to date.
  */
-public class StatefulTargetRepositoryImpl implements StatefulTargetRepository, EventHandler
{
+public class StatefulTargetRepositoryImpl implements StatefulTargetRepository, EventHandler,
PreCommitMember {
     private BundleContext m_context; /* Injected by dependency manager */
     private ArtifactRepository m_artifactRepository; /* Injected by dependency manager */
     private TargetRepository m_targetRepository; /* Injected by dependency manager */
@@ -214,6 +216,7 @@ public class StatefulTargetRepositoryImp
     void removeStateful(StatefulTargetObjectImpl entity) {
         synchronized (m_repository) {
             m_repository.remove(entity.getID());
+            m_index.remove(entity.getDefinition());
             notifyChanged(entity, StatefulTargetObject.TOPIC_REMOVED);
         }
     }
@@ -466,7 +469,17 @@ public class StatefulTargetRepositoryImp
      * @throws java.io.IOException When there is a problem generating the deployment version.
      */
     String approve(String targetID) throws IOException {
-        return generateDeploymentVersion(targetID).getVersion();
+        System.out.println("Approving " + targetID);
+        DeploymentVersionObject mostRecentDeploymentVersion = getMostRecentDeploymentVersion(targetID);
+        String nextVersion;
+        if (mostRecentDeploymentVersion == null) {
+            nextVersion = nextVersion(null);
+        }
+        else {
+            nextVersion = nextVersion(mostRecentDeploymentVersion.getVersion());
+        }
+        return nextVersion;
+//        return generateDeploymentVersion(targetID).getVersion();
     }
 
     /**
@@ -598,6 +611,7 @@ public class StatefulTargetRepositoryImp
     /**
      * Quick method to find all artifacts that need to be deployed to a target.
      */
+    // TODO this method strongly resembles part of getNecessaryDeploymentArtifacts(), merge
code?!
     ArtifactObject[] getNecessaryArtifacts(String targetID) {
         List<ArtifactObject> result = new ArrayList<ArtifactObject>();
         TargetObject to = getTargetObject(targetID);
@@ -751,4 +765,41 @@ public class StatefulTargetRepositoryImp
     boolean needsNewVersion(ArtifactObject artifact, String targetID, String version) {
         return m_artifactRepository.needsNewVersion(artifact, getTargetObject(targetID),
targetID, version);
     }
+
+    @Override
+    public void preCommit() throws IOException {
+        synchronized (m_repository) {
+            for (StatefulTargetObjectImpl stoi : m_repository.values()) {
+                if (preCommitHasChanges(stoi)) {
+                    generateDeploymentVersion(stoi.getID());
+                }
+                stoi.resetApprovalState();
+            }
+        }
+    }
+    
+    @Override
+    public void reset() {
+        synchronized (m_repository) {
+            for (StatefulTargetObjectImpl stoi : m_repository.values()) {
+                stoi.resetApprovalState();
+            }
+        }
+    }
+
+    @Override
+    public boolean hasChanges() {
+        synchronized (m_repository) {
+            for (StatefulTargetObjectImpl stoi : m_repository.values()) {
+                if (preCommitHasChanges(stoi)) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+    
+    private boolean preCommitHasChanges(StatefulTargetObjectImpl stoi) {
+        return stoi.getApprovalState().equals(ApprovalState.Approved) && stoi.needsApprove();
+    }
 }
\ No newline at end of file

Modified: ace/trunk/org.apache.ace.target.mgmt.ui/src/org/apache/ace/target/management/ui/TargetManagementExtension.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.target.mgmt.ui/src/org/apache/ace/target/management/ui/TargetManagementExtension.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.target.mgmt.ui/src/org/apache/ace/target/management/ui/TargetManagementExtension.java
(original)
+++ ace/trunk/org.apache.ace.target.mgmt.ui/src/org/apache/ace/target/management/ui/TargetManagementExtension.java
Tue Jul 23 13:19:04 2013
@@ -22,6 +22,7 @@ import java.util.Map;
 
 import org.apache.ace.client.repository.RepositoryObject;
 import org.apache.ace.client.repository.stateful.StatefulTargetObject;
+import org.apache.ace.client.repository.stateful.StatefulTargetObject.ApprovalState;
 import org.apache.ace.webui.NamedObject;
 import org.apache.ace.webui.UIExtensionFactory;
 
@@ -39,9 +40,6 @@ public class TargetManagementExtension i
 
     private static final String CAPTION = "Management";
 
-    /**
-     * {@inheritDoc}
-     */
     public Component create(Map<String, Object> context) {
         GridLayout result = new GridLayout(1, 4);
         result.setCaption(CAPTION);
@@ -52,7 +50,7 @@ public class TargetManagementExtension i
 
         RepositoryObject object = getRepositoryObjectFromContext(context);
         if (!(object instanceof StatefulTargetObject)) {
-            result.addComponent(new Label("This target is not a stateful gateway object."));
+            result.addComponent(new Label("This target is not a stateful target object."));
             return result;
         }
 
@@ -72,10 +70,9 @@ public class TargetManagementExtension i
 
         result.addComponent(autoApproveCB);
 
-
         final Button approveButton = new Button("Approve changes");
         approveButton.setImmediate(true);
-        approveButton.setEnabled(target.needsApprove());
+        approveButton.setEnabled(getApproveButtonEnabledState(target));
 
         result.addComponent(approveButton);
         
@@ -96,18 +93,22 @@ public class TargetManagementExtension i
         autoApproveCB.addListener(new Button.ClickListener() {
             public void buttonClick(ClickEvent event) {
                 target.setAutoApprove(event.getButton().booleanValue());
-                approveButton.setEnabled(target.needsApprove());
+                approveButton.setEnabled(getApproveButtonEnabledState(target));
             }
         });
         approveButton.addListener(new Button.ClickListener() {
             public void buttonClick(ClickEvent event) {
                 target.approve();
-                approveButton.setEnabled(target.needsApprove());
+                approveButton.setEnabled(getApproveButtonEnabledState(target));
             }
         });
 
         return result;
     }
+    
+    private boolean getApproveButtonEnabledState(StatefulTargetObject target) {
+        return ApprovalState.Unapproved.equals(target.getApprovalState()) && target.needsApprove();
+    }
 
     private RepositoryObject getRepositoryObjectFromContext(Map<String, Object> context)
{
         Object contextObject = context.get("object");
@@ -115,7 +116,6 @@ public class TargetManagementExtension i
             throw new IllegalStateException("No context object found");
         }
 
-        return (contextObject instanceof NamedObject ? ((NamedObject) contextObject).getObject()
-            : (RepositoryObject) contextObject);
+        return (contextObject instanceof NamedObject ? ((NamedObject) contextObject).getObject()
: (RepositoryObject) contextObject);
     }
 }

Modified: ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/Activator.java?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/Activator.java (original)
+++ ace/trunk/org.apache.ace.webui.vaadin/src/org/apache/ace/webui/vaadin/Activator.java Tue
Jul 23 13:19:04 2013
@@ -72,6 +72,7 @@ public class Activator extends Dependenc
                         "Target ID          : " + namedObject.getName() + "\n" +
                         "Installed version  : " + (target.getLastInstallVersion() == null
? "(none)" : target.getLastInstallVersion()) + "\n" +
                         "Available version  : " + target.getCurrentVersion() + "\n" +
+                        "Approval state     : " + target.getApprovalState() + "\n" +
                         "Store state        : " + target.getStoreState() + "\n" +
                         "Provisioning state : " + target.getProvisioningState() + "\n" +
                         "Registration state : " + target.getRegistrationState());

Modified: ace/trunk/run-server-allinone/server-allinone.bndrun
URL: http://svn.apache.org/viewvc/ace/trunk/run-server-allinone/server-allinone.bndrun?rev=1506031&r1=1506030&r2=1506031&view=diff
==============================================================================
--- ace/trunk/run-server-allinone/server-allinone.bndrun (original)
+++ ace/trunk/run-server-allinone/server-allinone.bndrun Tue Jul 23 13:19:04 2013
@@ -68,8 +68,8 @@
 	Library Repository
 -runproperties: org.apache.felix.log.storeDebug=true,\
 	org.apache.felix.eventadmin.Timeout=0,\
-	org.apache.ace.server.port=8080,\
-	org.osgi.service.http.port=8080,\
+	org.apache.ace.server.port=18080,\
+	org.osgi.service.http.port=18080,\
 	org.apache.felix.log.maxSize=1000,\
 	launch.keep=true,\
 	launch.storage.dir=bundle-cache



Mime
View raw message