From 1996a4dc85e5b9ca473f61dab2572777b531d84a Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Fri, 27 Jun 2014 02:24:22 +0000 Subject: [PATCH] RM Performance testing: * added helper code to load large numbers of users and groups into RM roles * improved performance of role user/group management console from 13 seconds with 100 groups with a 100 users, down to less than a second * role user/group console now only shows users and groups explicitly assigned to the role to help scale the UI (and make more sense!) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@75102 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../role/FilePlanRoleServiceImpl.java | 4 +- .../admin/RoleDeclarativeWebScript.java | 7 +- .../test/system/DataLoadSystemTest.java | 104 +++++++++++++++++- 3 files changed, 106 insertions(+), 9 deletions(-) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java index 43386b0210..89193d0def 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/role/FilePlanRoleServiceImpl.java @@ -583,7 +583,7 @@ public class FilePlanRoleServiceImpl implements FilePlanRoleService, { String capabilityName = permission.getPermission(); Capability capability = capabilityService.getCapability(capabilityName); - if (capability != null) + if (capability != null && !capability.isPrivate()) { capabilities.add(capability); } @@ -790,7 +790,7 @@ public class FilePlanRoleServiceImpl implements FilePlanRoleService, { throw new AlfrescoRuntimeException("Can not get authorities for role " + roleName + ", because it does not exist. (filePlan=" + filePlan.toString() + ")"); } - return authorityService.getContainedAuthorities(authorityType, role.getRoleGroupName(), false); + return authorityService.getContainedAuthorities(authorityType, role.getRoleGroupName(), true); } }, AuthenticationUtil.getSystemUserName()); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RoleDeclarativeWebScript.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RoleDeclarativeWebScript.java index d84258824f..44f9745e2c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RoleDeclarativeWebScript.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/script/admin/RoleDeclarativeWebScript.java @@ -29,6 +29,7 @@ import org.alfresco.module.org_alfresco_module_rm.role.Role; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.security.AuthorityService; +import org.alfresco.service.cmr.security.AuthorityType; import org.apache.cxf.common.util.StringUtils; import org.springframework.extensions.webscripts.DeclarativeWebScript; import org.springframework.extensions.webscripts.WebScriptRequest; @@ -172,7 +173,11 @@ public class RoleDeclarativeWebScript extends DeclarativeWebScript for (String authority : authorities) { - String displayLabel = authorityService.getAuthorityDisplayName(authority); + String displayLabel = authority; + if (!AuthorityType.getAuthorityType(authority).equals(AuthorityType.USER)) + { + displayLabel = authorityService.getAuthorityDisplayName(authority); + } result.add(new AuthorityItem(authority, displayLabel)); } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DataLoadSystemTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DataLoadSystemTest.java index bea302a5de..9694368c04 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DataLoadSystemTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/system/DataLoadSystemTest.java @@ -1,16 +1,26 @@ package org.alfresco.module.org_alfresco_module_rm.test.system; +import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService; +import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; +import org.alfresco.module.org_alfresco_module_rm.test.util.CommonRMTestUtils; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.AuthorityService; +import org.alfresco.service.cmr.security.AuthorityType; +import org.alfresco.service.cmr.security.MutableAuthenticationService; +import org.alfresco.service.cmr.security.PersonService; +import org.alfresco.service.namespace.QName; import org.alfresco.service.transaction.TransactionService; import org.alfresco.util.ApplicationContextHelper; import org.junit.Assert; @@ -26,6 +36,10 @@ public class DataLoadSystemTest protected RecordFolderService recordFolderService; protected RecordService recordService; protected TransactionService transactionService; + protected AuthorityService authorityService; + protected MutableAuthenticationService authenticationService; + protected PersonService personService; + protected FilePlanRoleService filePlanRoleService; /** config locations */ protected String[] getConfigLocations() @@ -37,31 +51,98 @@ public class DataLoadSystemTest }; } - /** data sizing parameters */ + /** transaction batch size */ private static final int BATCH_SIZE = 100; - private static final int ROOT_CATEGORY_COUNT = 1; - private static final int RECORD_FOLDER_COUNT = 1; - private static final int RECORD_COUNT = 15000; + + /** file plan sizing */ + private static final int ROOT_CATEGORY_COUNT = 0; + private static final int RECORD_FOLDER_COUNT = 0; + private static final int RECORD_COUNT = 0; + + /** rm user sizing */ + private static final int RM_GROUP_COUNT = 0; + private static final int RM_USER_COUNT = 0; /** application context */ private ApplicationContext applicationContext; + CommonRMTestUtils utils; private int totalCount; private List recordCategories; private List recordFolders; + private List groups; @Before public void before() { applicationContext = ApplicationContextHelper.getApplicationContext(getConfigLocations()); + utils = new CommonRMTestUtils(applicationContext); + filePlanService = (FilePlanService)applicationContext.getBean("FilePlanService"); recordFolderService = (RecordFolderService)applicationContext.getBean("RecordFolderService"); recordService = (RecordService)applicationContext.getBean("RecordService"); transactionService = (TransactionService)applicationContext.getBean("transactionService"); + authorityService = (AuthorityService)applicationContext.getBean("authorityService"); + authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService"); + personService = (PersonService)applicationContext.getBean("personService"); + filePlanRoleService = (FilePlanRoleService)applicationContext.getBean("filePlanRoleService"); } @Test - public void loadData() + private void loadAllData() + { + loadFilePlanData(); + loadRMUsersAndGroups(); + } + + + private void loadRMUsersAndGroups() + { + AuthenticationUtil.runAsSystem(new RunAsWork() + { + public Void doWork() throws Exception + { + final NodeRef filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID); + if (filePlan == null) + { + Assert.fail("The default RM site is not present."); + } + + groups = new ArrayList(); + + repeatInTransactionBatches(new RunAsWork() + { + public Void doWork() throws Exception + { + String groupName = GUID.generate(); + System.out.println("Creating group " + groupName); + groups.add("GROUP_" + authorityService.createAuthority(AuthorityType.GROUP, groupName)); + filePlanRoleService.assignRoleToAuthority(filePlan, FilePlanRoleService.ROLE_RECORDS_MANAGER, groupName); + return null; + } + }, RM_GROUP_COUNT); + + for (final String group : groups) + { + repeatInTransactionBatches(new RunAsWork() + { + public Void doWork() throws Exception + { + String userName = GUID.generate(); + System.out.println("Creating user " + userName + " and adding to group " + group); + createPerson(userName, true); + authorityService.addAuthority(group, userName); + return null; + } + }, RM_USER_COUNT); + } + + return null; + } + }); + } + + private void loadFilePlanData() { AuthenticationUtil.runAsSystem(new RunAsWork() { @@ -117,7 +198,18 @@ public class DataLoadSystemTest }); } - protected void repeatInTransactionBatches(final RunAsWork work, final int count) throws Exception + private NodeRef createPerson(String userName, boolean createAuth) + { + if (createAuth) + { + authenticationService.createAuthentication(userName, "password".toCharArray()); + } + Map properties = new HashMap(); + properties.put(ContentModel.PROP_USERNAME, userName); + return personService.createPerson(properties); + } + + private void repeatInTransactionBatches(final RunAsWork work, final int count) throws Exception { totalCount = 0; while (totalCount < count)