Point checkin for virt server notifiction.

Now the virt server can react properly when a file in WEB-INF
 (such as a jar or web.xml file) is submitted to staging.


 Details
 -------
 
 More testing is needed, but the basic stuff looks ok.
 Here's a list of the events within the webapp that
 the virt server is now able to receive & handle properly:

     o  Invite user to web project
     o  Create web project
     o  Delete sandbox
     o  Delete web project 
     o  Submission of files to WEB-INF  


 The virt server does not yet get: 
     o  Revert events
     o  Out-of-band changes from CIFS (and probably never will).
  
 The plan to deal with changes made to critical files in WEB-INF
 is to have an exlicit control available within the webapp. 
 

 It does not yet handle "approved with changes" very gracefully.
 That can probably be fixed over the next few days.



 Gory details
 -----------

   projects/core/source/java/org/alfresco/util/VirtServerUtils.java
        Moved pattern that detects whether virt server needs
        updating in from AVMConstants, due to build dependencies;
        now this function is needed by workflow, which is in the
        repository package.

   projects/repository/config/alfresco/avm-services-context.xml
        Added AVMSubmitTransactionListener bean to allow virt
        server notification to hapen immediately after the
        submit transaction has been committed sucessfully.


   projects/repository/source/java/org/alfresco/repo/avm/wf/AVMSubmitPackageHandler.java
        Added transaction listner that does the virt server update,
        and added the list of staging diffs to AlfrescoTransactionSupport
        as a bound resource.


   projects/repository/source/java/org/alfresco/repo/avm/wf/AVMSubmitTransactionListener.java
        Does the actual notification of the virt server.
        The logic in this class still needs some work to handle
        "approved with changes" gracefully, but it does do
        the right thing when it comes to recursively reloading
        staging when a jar or web.xml file is modified.
        Light testing so far, but looks ok.  Consider this
        a point checkin only.  A singleton of this class is
        instantiated via the Spring config avm-services-context.xml,
        and used by AVMSubmitPackageHandler.


   projects/web-client/source/java/org/alfresco/web/bean/wcm/AVMConstants.java
        Removed the utility function that tests whether or not
        updating a file would require the virt server to be notified.
        This class would benifit from a major cleanup when time permits.

   projects/web-client/source/java/org/alfresco/web/bean/wcm/SubmitDialog.java
        Using the function that was moved/renamed from AVMConstants
        to VirtServerUtils that tests if a given file update requires
        a virt server notification message.




git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4990 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jon Cox
2007-02-01 02:18:54 +00:00
parent 41002b0ff1
commit b80c73be52
3 changed files with 162 additions and 8 deletions

View File

@@ -21,6 +21,7 @@ import java.util.List;
import org.alfresco.repo.avm.AVMDAOs;
import org.alfresco.repo.avm.AVMNodeConverter;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.workflow.jbpm.JBPMNode;
import org.alfresco.repo.workflow.jbpm.JBPMSpringActionHandler;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
@@ -52,6 +53,12 @@ public class AVMSubmitPackageHandler extends JBPMSpringActionHandler implements
*/
private AVMSubmittedAspect fAVMSubmittedAspect;
/**
* The AVMSubmitTransactionListener instance
* (for JMX notification of virtualization server after commit/rollback).
*/
private AVMSubmitTransactionListener fAVMSubmitTransactionListener;
/**
* Initialize service references.
@@ -63,6 +70,9 @@ public class AVMSubmitPackageHandler extends JBPMSpringActionHandler implements
fAVMService = (AVMService)factory.getBean("AVMService");
fAVMSyncService = (AVMSyncService)factory.getBean("AVMSyncService");
fAVMSubmittedAspect = (AVMSubmittedAspect)factory.getBean("AVMSubmittedAspect");
fAVMSubmitTransactionListener = (AVMSubmitTransactionListener) factory.getBean("AVMSubmitTransactionListener");
AlfrescoTransactionSupport.bindListener(fAVMSubmitTransactionListener);
}
/**
@@ -87,6 +97,17 @@ public class AVMSubmitPackageHandler extends JBPMSpringActionHandler implements
{
fAVMSubmittedAspect.clearSubmitted(diff.getSourceVersion(), diff.getSourcePath());
}
// Allow AVMSubmitTransactionListener to inspect the staging diffs
// so it can notify the virtualization server via JMX if when this
// submit succeeds or fails. This allows virtual webapps devoted
// to the workarea to be destroyed, and staging to be updated in
// the event that some of the files alter the behavior of the
// webapp itself (e.g.: WEB-INF/web.xml, WEB-INF/lib/*.jar), etc.
AlfrescoTransactionSupport.bindResource("staging_diffs", stagingDiffs);
fAVMSyncService.update(stagingDiffs, null, false, false, true, true, tag, description);
// flatten source folder where changes were submitted from

View File

@@ -0,0 +1,128 @@
/*-----------------------------------------------------------------------------
* Copyright 2007 Alfresco Inc.
*
* Licensed under the Mozilla Public License version 1.1
* with a permitted attribution clause. You may obtain a
* copy of the License at:
*
* http://www.alfresco.org/legal/license.txt
*
* 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.
*
*
* Author Jon Cox <jcox@alfresco.com>
* File AVMSubmitTransactionListener.java
*----------------------------------------------------------------------------*/
package org.alfresco.repo.avm.wf;
import java.util.List;
import org.alfresco.mbeans.VirtServerRegistry;
import org.alfresco.repo.avm.util.RawServices;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.transaction.TransactionListenerAdapter;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.util.VirtServerUtils;
import org.springframework.context.ApplicationContext;
/**
* Gets callbacks at critical moments within a transaction
* (commit, rollback, etc.) to perform JMX update notifications
* to the virtualization server.
*/
public class AVMSubmitTransactionListener extends TransactionListenerAdapter
{
public AVMSubmitTransactionListener() { }
/**
* Notify virtualization server that webapps in workflow sandbox
* are not longer needed, and possibly trigger a notification
* instrucing the virtualization server to reload staging
* and every virtual webapp that depends on it.
*/
@Override
public void afterCommit()
{
List<AVMDifference> stagingDiffs =
(List<AVMDifference>)
AlfrescoTransactionSupport.getResource("staging_diffs");
if ( stagingDiffs == null) { return; } // TODO: log this?
AVMDifference requiresUpdate = null;
for (AVMDifference diff : stagingDiffs)
{
// Example values:
//
// diff.getSourceVersion() == -1; diff.getSourcePath() ==
// mysite--workflow-21edf548-b17e-11db-bd90-35dd2ee4a5c6:/www/avm_webapps/ROOT/x.txt
//
// diff.getDestinationVersion() == -1; diff.getDestinationPath() ==
// mysite:/www/avm_webapps/ROOT/x.txt
if ( requiresUpdate == null )
{
if ( VirtServerUtils.requiresUpdateNotification( diff.getDestinationPath() ) )
{
requiresUpdate = diff;
}
}
}
ApplicationContext springContext = RawServices.Instance().getContext();
VirtServerRegistry vServerRegistry = (VirtServerRegistry)
springContext.getBean("VirtServerRegistry");
// TODO: In the future, we might want to allow a single submit to
// update multiple staging areas & versions. If so,
// the logic above will have to look for each unique
// version/webapp tuple, rather than assume everything
// is going into the same version and into the same
// store/webapp.
// Only update staging if necessary
if ( requiresUpdate != null )
{
vServerRegistry.webappUpdated( requiresUpdate.getDestinationVersion(),
requiresUpdate.getDestinationPath(),
true
);
}
// Remove virtual weapps from workflow sandbox
if ( ! stagingDiffs.isEmpty() )
{
// All the files are from the same workflow sandbox;
// so to remove all the webapps, you just need to
// look at the 1st difference
AVMDifference d = stagingDiffs.iterator().next();
vServerRegistry.webappRemoved( d.getSourceVersion(), d.getSourcePath(), true );
}
AlfrescoTransactionSupport.unbindResource("staging_diffs");
}
/**
* Handle failed transaction.
*/
@Override
public void afterRollback()
{
AlfrescoTransactionSupport.unbindResource("staging_diffs");
}
}