ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1521506 - in /ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/stateful: StatefulTargetObject.java impl/StatefulTargetObjectImpl.java
Date Tue, 10 Sep 2013 14:27:20 GMT
Author: marrs
Date: Tue Sep 10 14:27:19 2013
New Revision: 1521506

URL: http://svn.apache.org/r1521506
Log:
ACE-372 Added code that picks up properties from the auditlog and sets them (with a prefix)
as tags on the target.

Modified:
    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

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=1521506&r1=1521505&r2=1521506&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 Sep 10 14:27:19 2013
@@ -56,6 +56,7 @@ public interface StatefulTargetObject ex
     public final static String KEY_LAST_INSTALL_SUCCESS = "KEY_LAST_INSTALL_SUCCESS";
     public final static String KEY_ACKNOWLEDGED_INSTALL_VERSION = "KEY_ACKNOWLEDGED_INSTALL_VERSION";
     public final static String[] KEYS_ALL = new String[] {KEY_ID, KEY_REGISTRATION_STATE,
KEY_STORE_STATE, KEY_PROVISIONING_STATE, KEY_LAST_INSTALL_VERSION, KEY_LAST_INSTALL_SUCCESS,
KEY_ACKNOWLEDGED_INSTALL_VERSION};
+    public static final String TARGETPROPERTIES_PREFIX = "target.";
 
     /**
      * Represents a current deployment package version which cannot be found, i.e.,

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=1521506&r1=1521505&r2=1521506&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 Sep 10 14:27:19 2013
@@ -54,9 +54,12 @@ public class StatefulTargetObjectImpl im
     private final Object m_lock = new Object();
     private TargetObject m_targetObject;
     private List<LogDescriptor> m_processedAuditEvents = new ArrayList<LogDescriptor>();
+    private Dictionary m_processedTargetProperties;
     private Map<String, String> m_attributes = new HashMap<String, String>();
     /** This boolean is used to suppress STATUS_CHANGED events during the creation of the
object. */
     private boolean m_inConstructor = true;
+    /** Boolean to ensure we don't recursively enter the determineProvisioningState() method.
*/
+    private boolean m_determiningProvisioningState = false;
 
     /**
      * Creates a new <code>StatefulTargetObjectImpl</code>. After creation, it
will have the
@@ -185,6 +188,7 @@ public class StatefulTargetObjectImpl im
         synchronized (m_lock) {
             m_targetObject = m_repository.getTargetObject(getID());
             determineRegistrationState();
+            determineTargetPropertiesState();
             if (needsVerify) {
                 verifyExistence();
             }
@@ -295,53 +299,79 @@ public class StatefulTargetObjectImpl im
     private void determineProvisioningState() {
         /*
          * This method gets all audit events it has not yet seen, and goes through them,
backward
-         * in time, to find either and INSTALL or a COMPLETE event. A INSTALL event gives
us a version,
-         * and tells us we're in InProgress. A COMPLETE tells gives us a version, and a success.
The success
+         * in time, to find either an INSTALL or a COMPLETE and a TARGETPROPERTIES event.
+         * An INSTALL event gives us a version, and tells us we're in InProgress.
+         * A COMPLETE event tells gives us a version, and a success. The success
          * will be stored, and also sets the state to OK or Failed, unless the version we
found has already been
          * acknowledged, the the state is set to Idle. Also, if there is no information whatsoever,
we assume Idle.
+         * A TARGETPROPERTIES event will set the target properties accordingly, with the
right prefix, overwriting
+         * any old target properties.
          */
         synchronized (m_lock) {
+            // make sure we don't recursively execute, which can happen when target properties
+            // are being set or removed (which triggers a notification, which in turn triggers
+            // a call to determineStatus).
+            if (m_determiningProvisioningState) {
+                return;
+            }
+            m_determiningProvisioningState = true;
             List<LogDescriptor> allDescriptors = m_repository.getAllDescriptors(getID());
             List<LogDescriptor> newDescriptors = m_repository.diffLogDescriptorLists(allDescriptors,
m_processedAuditEvents);
 
             List<LogEvent> newEvents = m_repository.getAuditEvents(newDescriptors);
+            boolean foundDeploymentEvent = false;
+            boolean foundPropertiesEvent = false;
             for (int position = newEvents.size() - 1; position >= 0; position--) {
                 LogEvent event = newEvents.get(position);
                 
-                // TODO we need to check here if the deployment package is actually the right
one
-                String currentVersion = (String) event.getProperties().get(AuditEvent.KEY_VERSION);
-                if (event.getType() == AuditEvent.DEPLOYMENTCONTROL_INSTALL) {
-                    addStatusAttribute(KEY_LAST_INSTALL_VERSION, currentVersion);
-                    setProvisioningState(ProvisioningState.InProgress);
-                    sendNewAuditlog(newDescriptors);
-                    m_processedAuditEvents = allDescriptors;
-                    return;
-                }
-                else if (event.getType() == AuditEvent.DEPLOYMENTADMIN_COMPLETE) {
-                    addStatusAttribute(KEY_LAST_INSTALL_VERSION, currentVersion);
-                    if ((currentVersion != null) && currentVersion.equals(getStatusAttribute(KEY_ACKNOWLEDGED_INSTALL_VERSION)))
{
-                        setProvisioningState(ProvisioningState.Idle);
+                if (!foundDeploymentEvent) {
+                    // TODO we need to check here if the deployment package is actually the
right one
+                    String currentVersion = (String) event.getProperties().get(AuditEvent.KEY_VERSION);
+                    if (event.getType() == AuditEvent.DEPLOYMENTCONTROL_INSTALL) {
+                        addStatusAttribute(KEY_LAST_INSTALL_VERSION, currentVersion);
+                        setProvisioningState(ProvisioningState.InProgress);
                         sendNewAuditlog(newDescriptors);
                         m_processedAuditEvents = allDescriptors;
-                        return;
+                        foundDeploymentEvent = true;
                     }
-                    else {
-                        String value = (String) event.getProperties().get(AuditEvent.KEY_SUCCESS);
-                        addStatusAttribute(KEY_LAST_INSTALL_SUCCESS, value);
-                        if (Boolean.parseBoolean(value)) {
-                            setProvisioningState(ProvisioningState.OK);
+                    if (event.getType() == AuditEvent.DEPLOYMENTADMIN_COMPLETE) {
+                        addStatusAttribute(KEY_LAST_INSTALL_VERSION, currentVersion);
+                        if ((currentVersion != null) && currentVersion.equals(getStatusAttribute(KEY_ACKNOWLEDGED_INSTALL_VERSION)))
{
+                            setProvisioningState(ProvisioningState.Idle);
                             sendNewAuditlog(newDescriptors);
                             m_processedAuditEvents = allDescriptors;
-                            return;
+                            foundDeploymentEvent = true;
                         }
                         else {
-                            setProvisioningState(ProvisioningState.Failed);
-                            sendNewAuditlog(newDescriptors);
-                            m_processedAuditEvents = allDescriptors;
-                            return;
+                            String value = (String) event.getProperties().get(AuditEvent.KEY_SUCCESS);
+                            addStatusAttribute(KEY_LAST_INSTALL_SUCCESS, value);
+                            if (Boolean.parseBoolean(value)) {
+                                setProvisioningState(ProvisioningState.OK);
+                                sendNewAuditlog(newDescriptors);
+                                m_processedAuditEvents = allDescriptors;
+                                foundDeploymentEvent = true;
+                            }
+                            else {
+                                setProvisioningState(ProvisioningState.Failed);
+                                sendNewAuditlog(newDescriptors);
+                                m_processedAuditEvents = allDescriptors;
+                                foundDeploymentEvent = true;
+                            }
                         }
                     }
                 }
+                if (!foundPropertiesEvent) {
+                    if (event.getType() == AuditEvent.TARGETPROPERTIES_SET) {
+                        m_processedTargetProperties = event.getProperties();
+                        foundPropertiesEvent = true;
+                        determineTargetPropertiesState();
+                    }
+                }
+                // as soon as we've found the latest of both types of events, we're done
+                if (foundDeploymentEvent && foundPropertiesEvent) {
+                    m_determiningProvisioningState = false;
+                    return;
+                }
             }
 
             if (m_processedAuditEvents.isEmpty()) {
@@ -349,9 +379,36 @@ public class StatefulTargetObjectImpl im
             }
             sendNewAuditlog(newDescriptors);
             m_processedAuditEvents = allDescriptors;
+            m_determiningProvisioningState = false;
         }
     }
 
+    private void determineTargetPropertiesState() {
+        // only process them if the target is already registered
+        if (isRegistered() && m_processedTargetProperties != null) {
+            Dictionary tags = m_processedTargetProperties;
+            m_processedTargetProperties = null;
+            // clear "old" tags starting with the prefix
+            Enumeration<String> keys = m_targetObject.getTagKeys();
+            ArrayList<String> keysToDelete = new ArrayList<String>();
+            while (keys.hasMoreElements()) {
+                String key = keys.nextElement();
+                if (key.startsWith(TARGETPROPERTIES_PREFIX)) {
+                    keysToDelete.add(key);
+                }
+            }
+            for (String keyToDelete : keysToDelete) {
+                m_targetObject.removeTag(keyToDelete);
+            }
+            // add new tags and prefix them
+            Enumeration newKeys = tags.keys();
+            while (newKeys.hasMoreElements()) {
+                String newKey = (String) newKeys.nextElement();
+                m_targetObject.addTag(TARGETPROPERTIES_PREFIX + newKey, (String) tags.get(newKey));
+            }
+        }
+    }
+    
     private void sendNewAuditlog(List<LogDescriptor> events) {
         // Check whether there are actually events in the list.
         boolean containsData = false;



Mime
View raw message