Merged 5.0.N (5.0.3) to HEAD (5.1) (PARTIAL MERGE)

110088: Merged 5.0.2 (5.0.2) to 5.0.N (5.0.3)
      110052: MNT-14579: TS starting in read-only mode after applying 5.0.2 build 64
       - This intermittent issue was probably caused by the SysAdminParams.afterPropertiesSet
         checking for a valid dictionary.  If this call took place too early, then it would
         never allow the system to be in read-write mode unless rebooted.
       - Removed the dictionary check from SysAdminParamsImpl; it is now only responsible for the 'server.allowWrite' property
       - Call the TransactionServiceImpl's read-write veto code if the 'server.allowWrite' property changes
       - Better logging when vetoes are placed but also when vetoes are removed


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@110214 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tatyana Valkevych
2015-08-17 11:47:37 +00:00
parent c7e7ff3fef
commit e11febd09e
4 changed files with 20 additions and 38 deletions

View File

@@ -241,9 +241,6 @@
<property name="transactionManager"> <property name="transactionManager">
<ref bean="transactionManager" /> <ref bean="transactionManager" />
</property> </property>
<property name="sysAdminParams">
<ref bean="sysAdminParams"/>
</property>
<property name="allowWrite"> <property name="allowWrite">
<value>${server.transaction.allow-writes}</value> <value>${server.transaction.allow-writes}</value>
</property> </property>

View File

@@ -23,12 +23,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.alfresco.repo.transaction.TransactionServiceImpl;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.license.LicenseService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
@@ -41,6 +42,7 @@ public class SysAdminParamsImpl implements SysAdminParams, ApplicationContextAwa
/** Token name to substitute current servers DNS name or TCP/IP address into a host name **/ /** Token name to substitute current servers DNS name or TCP/IP address into a host name **/
private static final String TOKEN_LOCAL_NAME = "${localname}"; private static final String TOKEN_LOCAL_NAME = "${localname}";
private static final QName VETO = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "SysAdminParams");
/** The local server name to which the above token will expand. */ /** The local server name to which the above token will expand. */
private final String localName; private final String localName;
@@ -108,23 +110,12 @@ public class SysAdminParamsImpl implements SysAdminParams, ApplicationContextAwa
@Override @Override
public void afterPropertiesSet() throws Exception public void afterPropertiesSet() throws Exception
{ {
if (this.allowWrite) // Set the transaction read-write state by veto
{ // There is no need to attempt to check the dictionary or any other component as they will handle
LicenseService licenseService = null; // their own vetoes (MNT-14579)
try // No logging is required here: it is done in the TransactionService code, already
{ TransactionServiceImpl transactionService = (TransactionServiceImpl) ctx.getBean("transactionService");
licenseService = (LicenseService) this.ctx.getBean("licenseService"); transactionService.setAllowWrite(allowWrite, VETO);
this.allowWrite = licenseService.isLicenseValid();
if (logger.isInfoEnabled())
{
logger.info("'allowWrite' being set to false: licenseService.isLicenseValid() returned false.");
}
}
catch (NoSuchBeanDefinitionException e)
{
// ignore
}
}
} }
/** /**

View File

@@ -26,7 +26,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import javax.transaction.UserTransaction; import javax.transaction.UserTransaction;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
@@ -57,9 +56,6 @@ public class TransactionServiceImpl implements TransactionService
private static final Log logger = LogFactory.getLog(TransactionServiceImpl.class); private static final Log logger = LogFactory.getLog(TransactionServiceImpl.class);
// SysAdmin cache - used to cluster certain configuration parameters
private SysAdminParams sysAdminParams;
// Veto for allow write // Veto for allow write
private Set<QName> writeVeto = new HashSet<QName>(); private Set<QName> writeVeto = new HashSet<QName>();
private final QName generalVetoName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "GeneralVeto"); private final QName generalVetoName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, "GeneralVeto");
@@ -85,11 +81,6 @@ public class TransactionServiceImpl implements TransactionService
this.transactionManager = transactionManager; this.transactionManager = transactionManager;
} }
public void setSysAdminParams(SysAdminParams sysAdminParams)
{
this.sysAdminParams = sysAdminParams;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@@ -99,7 +90,7 @@ public class TransactionServiceImpl implements TransactionService
vetoReadLock.lock(); vetoReadLock.lock();
try try
{ {
return writeVeto.isEmpty() && this.sysAdminParams.getAllowWrite(); return writeVeto.isEmpty();
} }
finally finally
{ {
@@ -138,20 +129,25 @@ public class TransactionServiceImpl implements TransactionService
*/ */
public void setAllowWrite(boolean allowWrite, QName nameOfVeto) public void setAllowWrite(boolean allowWrite, QName nameOfVeto)
{ {
if(logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("setAllowWrite:" + allowWrite + ", name of veto:" + nameOfVeto); logger.debug("setAllowWrite:" + allowWrite + ". Name of veto:" + nameOfVeto);
} }
vetoWriteLock.lock(); vetoWriteLock.lock();
try try
{ {
if(allowWrite) if(allowWrite)
{ {
writeVeto.remove(nameOfVeto); boolean removed = writeVeto.remove(nameOfVeto);
if (removed)
{
logger.warn("setAllowWrite:" + allowWrite + ". Removing veto on write operations: " + nameOfVeto);
}
} }
else else
{ {
writeVeto.add(nameOfVeto); writeVeto.add(nameOfVeto);
logger.warn("setAllowWrite:" + allowWrite + ". Applying veto on write operations: " + nameOfVeto);
} }
} }
finally finally
@@ -178,7 +174,7 @@ public class TransactionServiceImpl implements TransactionService
} }
else else
{ {
return !writeVeto.isEmpty() || !this.sysAdminParams.getAllowWrite(); return !writeVeto.isEmpty();
} }
} }
finally finally

View File

@@ -25,7 +25,6 @@ import javax.transaction.UserTransaction;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.admin.SysAdminParams;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
@@ -76,7 +75,6 @@ public class TransactionServiceImplTest extends TestCase
transactionService = new TransactionServiceImpl(); transactionService = new TransactionServiceImpl();
transactionService.setTransactionManager(transactionManager); transactionService.setTransactionManager(transactionManager);
transactionService.setAllowWrite(true, vetoName); transactionService.setAllowWrite(true, vetoName);
transactionService.setSysAdminParams((SysAdminParams) ctx.getBean("sysAdminParams"));
nodeService = (NodeService) ctx.getBean("dbNodeService"); nodeService = (NodeService) ctx.getBean("dbNodeService");
authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService"); authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");