mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-QA to HEAD (4.2) (including moving test classes into separate folders)
51903 to 54309 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@54310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.alfresco.repo.descriptor;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -28,6 +29,7 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransacti
|
||||
import org.alfresco.repo.usage.RepoUsageComponent;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage.LicenseMode;
|
||||
import org.alfresco.service.cmr.admin.RepoUsage.UsageType;
|
||||
import org.alfresco.service.descriptor.Descriptor;
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.service.license.LicenseDescriptor;
|
||||
@@ -190,6 +192,40 @@ public class DescriptorServiceImpl extends AbstractLifecycleBean
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String loadLicense(final InputStream licenseStream)
|
||||
{
|
||||
// Ensure that we force a writable txn for this operation
|
||||
final RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
|
||||
txnHelper.setForceWritable(true);
|
||||
|
||||
final RetryingTransactionCallback<String> loadCallback = new RetryingTransactionCallback<String>()
|
||||
{
|
||||
@Override
|
||||
public String execute() throws Throwable
|
||||
{
|
||||
return licenseService.loadLicense(licenseStream);
|
||||
}
|
||||
};
|
||||
// ... and we have to be 'system' for this, too
|
||||
String result = AuthenticationUtil.runAs(new RunAsWork<String>()
|
||||
{
|
||||
public String doWork() throws Exception
|
||||
{
|
||||
return txnHelper.doInTransaction(loadCallback, false, true);
|
||||
}
|
||||
}, AuthenticationUtil.getSystemUserName());
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Load license call returning: " + result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* On bootstrap load the special services for LicenseComponent and HeartBeat
|
||||
*
|
||||
@@ -221,7 +257,15 @@ public class DescriptorServiceImpl extends AbstractLifecycleBean
|
||||
helper.setForceWritable(true);
|
||||
|
||||
// create the initial installed descriptor
|
||||
Descriptor installed = installedRepoDescriptorDAO.getDescriptor();
|
||||
RetryingTransactionCallback<Descriptor> getDescriptorCallback = new RetryingTransactionCallback<Descriptor>()
|
||||
{
|
||||
public Descriptor execute()
|
||||
{
|
||||
return installedRepoDescriptorDAO.getDescriptor();
|
||||
}
|
||||
};
|
||||
Descriptor installed = helper.doInTransaction(getDescriptorCallback, false, false);
|
||||
|
||||
if(installed != null)
|
||||
{
|
||||
installedRepoDescriptor = installed;
|
||||
@@ -392,6 +436,12 @@ public class DescriptorServiceImpl extends AbstractLifecycleBean
|
||||
return "Done";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loadLicense(InputStream licenseStream)
|
||||
{
|
||||
return loadLicense();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -647,6 +697,16 @@ public class DescriptorServiceImpl extends AbstractLifecycleBean
|
||||
false);
|
||||
repoUsageComponent.setRestrictions(restrictions);
|
||||
|
||||
// Reset usage upon loading the unlimited license
|
||||
if (restrictions.getUsers() == null)
|
||||
{
|
||||
repoUsageComponent.resetUsage(UsageType.USAGE_USERS);
|
||||
}
|
||||
if (restrictions.getDocuments() == null)
|
||||
{
|
||||
repoUsageComponent.resetUsage(UsageType.USAGE_DOCUMENTS);
|
||||
}
|
||||
|
||||
// persist the server descriptor values in the current repository descriptor
|
||||
if (currentRepoDescriptor == null || newMode != currentRepoDescriptor.getLicenseMode())
|
||||
{
|
||||
@@ -667,6 +727,8 @@ public class DescriptorServiceImpl extends AbstractLifecycleBean
|
||||
};
|
||||
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
|
||||
txnHelper.setForceWritable(true);
|
||||
// ALF-19629 - Need to sort out trnsaction retry and do we need to Job Lock?
|
||||
//txnHelper.doInTransaction(updateLicenseCallback, false, true);
|
||||
txnHelper.doInTransaction(updateLicenseCallback);
|
||||
}
|
||||
}
|
||||
|
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.descriptor;
|
||||
|
||||
import org.alfresco.repo.importer.ImporterBootstrap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.transaction.TransactionServiceImpl;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.descriptor.Descriptor;
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.BaseSpringTest;
|
||||
|
||||
public class DescriptorServiceTest extends BaseSpringTest
|
||||
{
|
||||
private NodeService nodeService;
|
||||
private ImporterBootstrap systemBootstrap;
|
||||
private StoreRef storeRef;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSetUpInTransaction() throws Exception
|
||||
{
|
||||
nodeService = (NodeService)applicationContext.getBean(ServiceRegistry.NODE_SERVICE.getLocalName());
|
||||
systemBootstrap = (ImporterBootstrap)applicationContext.getBean("systemBootstrap");
|
||||
|
||||
storeRef = new StoreRef("system", "Test_" + System.currentTimeMillis());
|
||||
systemBootstrap.setStoreUrl(storeRef.toString());
|
||||
systemBootstrap.bootstrap();
|
||||
|
||||
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
|
||||
|
||||
this.authenticationComponent.setSystemUserAsCurrentUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTearDownInTransaction() throws Exception
|
||||
{
|
||||
authenticationComponent.clearCurrentSecurityContext();
|
||||
super.onTearDownInTransaction();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test server decriptor
|
||||
*/
|
||||
public void testServerDescriptor()
|
||||
{
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
DescriptorService descriptorService = registry.getDescriptorService();
|
||||
Descriptor serverDescriptor = descriptorService.getServerDescriptor();
|
||||
|
||||
String major = serverDescriptor.getVersionMajor();
|
||||
String minor = serverDescriptor.getVersionMinor();
|
||||
String revision = serverDescriptor.getVersionRevision();
|
||||
String label = serverDescriptor.getVersionLabel();
|
||||
String build = serverDescriptor.getVersionBuild();
|
||||
String edition = serverDescriptor.getEdition();
|
||||
String id = serverDescriptor.getId();
|
||||
|
||||
String version = major + "." + minor + "." + revision;
|
||||
version = buildVersionString(version, label, build);
|
||||
|
||||
assertEquals(version, serverDescriptor.getVersion());
|
||||
|
||||
int schemaVersion = serverDescriptor.getSchema();
|
||||
assertTrue("Server schema version must be greater than 0", schemaVersion > 0);
|
||||
|
||||
assertNotNull("edition is null", edition);
|
||||
assertEquals("id ", id, "Unknown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test current repository descriptor
|
||||
*/
|
||||
public void testCurrentRepositoryDescriptor()
|
||||
{
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
DescriptorService descriptorService = registry.getDescriptorService();
|
||||
Descriptor repoDescriptor = descriptorService.getCurrentRepositoryDescriptor();
|
||||
|
||||
String major = repoDescriptor.getVersionMajor();
|
||||
String minor = repoDescriptor.getVersionMinor();
|
||||
String revision = repoDescriptor.getVersionRevision();
|
||||
String label = repoDescriptor.getVersionLabel();
|
||||
String build = repoDescriptor.getVersionBuild();
|
||||
String id = repoDescriptor.getId();
|
||||
|
||||
String version = major + "." + minor + "." + revision;
|
||||
version = buildVersionString(version, label, build);
|
||||
|
||||
assertEquals(version, repoDescriptor.getVersion());
|
||||
|
||||
assertNotNull("repository id is null", id);
|
||||
assertNotNull("major is null", major);
|
||||
assertNotNull("minor is null", minor);
|
||||
assertNotNull("revision is null", revision);
|
||||
|
||||
int schemaVersion = repoDescriptor.getSchema();
|
||||
assertTrue("Repository schema version must be greater than -1", schemaVersion > -1);
|
||||
}
|
||||
|
||||
public void testCompareDescriptors()
|
||||
{
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
DescriptorService descriptorService = registry.getDescriptorService();
|
||||
Descriptor serverDescriptor = descriptorService.getServerDescriptor();
|
||||
Descriptor repoDescriptor = descriptorService.getCurrentRepositoryDescriptor();
|
||||
|
||||
String major1 = repoDescriptor.getVersionMajor();
|
||||
String minor1 = repoDescriptor.getVersionMinor();
|
||||
String revision1 = repoDescriptor.getVersionRevision();
|
||||
String label1 = repoDescriptor.getVersionLabel();
|
||||
String build1 = repoDescriptor.getVersionBuild();
|
||||
String id1 = repoDescriptor.getId();
|
||||
|
||||
String major2 = serverDescriptor.getVersionMajor();
|
||||
String minor2 = serverDescriptor.getVersionMinor();
|
||||
String revision2 = serverDescriptor.getVersionRevision();
|
||||
String label2 = serverDescriptor.getVersionLabel();
|
||||
String build2 = serverDescriptor.getVersionBuild();
|
||||
String id2 = serverDescriptor.getId();
|
||||
|
||||
assertEquals("major version different", major1, major2);
|
||||
assertEquals("minor version different", minor1, minor2);
|
||||
assertEquals("revision version different", revision1, revision2);
|
||||
assertEquals("label version different", label1, label2);
|
||||
assertEquals("build version different", build1, build2);
|
||||
|
||||
|
||||
}
|
||||
|
||||
// TODO : missing getLicenceDescriptor
|
||||
|
||||
/**
|
||||
* Test installed repository descriptor
|
||||
*/
|
||||
public void testInstalledRepositoryDescriptor()
|
||||
{
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
DescriptorService descriptorService = registry.getDescriptorService();
|
||||
Descriptor repoDescriptor = descriptorService.getInstalledRepositoryDescriptor();
|
||||
|
||||
String major = repoDescriptor.getVersionMajor();
|
||||
String minor = repoDescriptor.getVersionMinor();
|
||||
String revision = repoDescriptor.getVersionRevision();
|
||||
String label = repoDescriptor.getVersionLabel();
|
||||
String build = repoDescriptor.getVersionBuild();
|
||||
String version = major + "." + minor + "." + revision;
|
||||
version = buildVersionString(version, label, build);
|
||||
|
||||
assertEquals(version, repoDescriptor.getVersion());
|
||||
|
||||
int schemaVersion = repoDescriptor.getSchema();
|
||||
assertTrue("Repository schema version must be greater than -1", schemaVersion > -1);
|
||||
}
|
||||
|
||||
private String buildVersionString(String version, String label, String build)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder(version);
|
||||
|
||||
boolean hasLabel = (label != null && label.length() > 0);
|
||||
boolean hasBuild = (build != null && build.length() > 0);
|
||||
|
||||
// add opening bracket if either a label or build number is present
|
||||
if (hasLabel || hasBuild)
|
||||
{
|
||||
builder.append(" (");
|
||||
}
|
||||
|
||||
// add label if present
|
||||
if (hasLabel)
|
||||
{
|
||||
builder.append(label);
|
||||
}
|
||||
|
||||
// add build number is present
|
||||
if (hasBuild)
|
||||
{
|
||||
// if there is also a label we need a separating space
|
||||
if (hasLabel)
|
||||
{
|
||||
builder.append(" ");
|
||||
}
|
||||
|
||||
builder.append(build);
|
||||
}
|
||||
|
||||
// add closing bracket if either a label or build number is present
|
||||
if (hasLabel || hasBuild)
|
||||
{
|
||||
builder.append(")");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public void testReadOnlyLicenseLoad_ALF10110() throws Exception
|
||||
{
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
QName vetoName = QName.createQName("{test}veto");
|
||||
TransactionServiceImpl txnService = (TransactionServiceImpl) applicationContext.getBean("TransactionService");
|
||||
ServiceRegistry registry = (ServiceRegistry)applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
|
||||
DescriptorService descriptorService = registry.getDescriptorService();
|
||||
// Veto writes
|
||||
try
|
||||
{
|
||||
txnService.setAllowWrite(false, vetoName);
|
||||
// Now reload the license
|
||||
descriptorService.loadLicense();
|
||||
}
|
||||
finally
|
||||
{
|
||||
txnService.setAllowWrite(true, vetoName);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -67,36 +67,6 @@ public class DescriptorStartupLog extends AbstractLifecycleBean
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Organisation from Principal
|
||||
*
|
||||
* @param holderPrincipal
|
||||
* @return organisation
|
||||
*/
|
||||
private String getHolderOrganisation(Principal holderPrincipal)
|
||||
{
|
||||
String holder = null;
|
||||
if (holderPrincipal != null)
|
||||
{
|
||||
holder = holderPrincipal.getName();
|
||||
if (holder != null)
|
||||
{
|
||||
String[] properties = holder.split(",");
|
||||
for (String property : properties)
|
||||
{
|
||||
String[] parts = property.split("=");
|
||||
if (parts[0].equals("O"))
|
||||
{
|
||||
holder = parts[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
@@ -132,7 +102,16 @@ public class DescriptorStartupLog extends AbstractLifecycleBean
|
||||
|
||||
String msg = "Alfresco license: Mode " + licenseMode;
|
||||
|
||||
String holder = getHolderOrganisation(license.getHolder());
|
||||
if(license.isClusterEnabled())
|
||||
{
|
||||
msg += ", cluster:enabled";
|
||||
}
|
||||
else
|
||||
{
|
||||
msg += ", NO CLUSTER";
|
||||
}
|
||||
|
||||
String holder = license.getHolderOrganisation();
|
||||
if (holder != null)
|
||||
{
|
||||
msg += " granted to " + holder;
|
||||
|
Reference in New Issue
Block a user