MT - fixes for version2Store upgrade, skip SiteService patch

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11017 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-09-25 12:37:59 +00:00
parent d2c08c8307
commit 714b725148
6 changed files with 124 additions and 50 deletions

View File

@@ -1484,6 +1484,12 @@
<property name="versionMigrator"> <property name="versionMigrator">
<ref bean="versionMigrator" /> <ref bean="versionMigrator" />
</property> </property>
<property name="tenantService">
<ref bean="tenantService" />
</property>
<property name="importerBootstrap">
<ref bean="version2Bootstrap" />
</property>
</bean> </bean>
<bean id="patch.inviteEmailTemplate" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" > <bean id="patch.inviteEmailTemplate" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >

View File

@@ -507,6 +507,9 @@
<entry key="versionMigrator"> <entry key="versionMigrator">
<ref bean="versionMigrator" /> <ref bean="versionMigrator" />
</entry> </entry>
<entry key="tenantAdminService">
<ref bean="tenantAdminService" />
</entry>
</map> </map>
</property> </property>
</bean> </bean>

View File

@@ -27,7 +27,11 @@ package org.alfresco.repo.admin.patch.impl;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.i18n.I18NUtil; import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch; import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.importer.ImporterBootstrap;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantService;
import org.alfresco.repo.version.VersionMigrator; import org.alfresco.repo.version.VersionMigrator;
import org.alfresco.service.cmr.repository.StoreRef;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -41,6 +45,9 @@ public class MigrateVersionStorePatch extends AbstractPatch
private static final String MSG_SUCCESS = "patch.migrateVersionStore.result"; private static final String MSG_SUCCESS = "patch.migrateVersionStore.result";
private VersionMigrator versionMigrator; private VersionMigrator versionMigrator;
private TenantService tenantService;
private ImporterBootstrap version2ImporterBootstrap;
private int batchSize = 1; private int batchSize = 1;
private boolean deleteImmediately = false; private boolean deleteImmediately = false;
@@ -49,6 +56,16 @@ public class MigrateVersionStorePatch extends AbstractPatch
this.versionMigrator = versionMigrator; this.versionMigrator = versionMigrator;
} }
public void setTenantService(TenantService tenantService)
{
this.tenantService = tenantService;
}
public void setImporterBootstrap(ImporterBootstrap version2ImporterBootstrap)
{
this.version2ImporterBootstrap = version2ImporterBootstrap;
}
public void setBatchSize(int batchSize) public void setBatchSize(int batchSize)
{ {
this.batchSize = batchSize; this.batchSize = batchSize;
@@ -74,6 +91,16 @@ public class MigrateVersionStorePatch extends AbstractPatch
@Override @Override
protected String applyInternal() throws Exception protected String applyInternal() throws Exception
{ {
if (tenantService.isEnabled() && tenantService.isTenantUser())
{
// bootstrap new version store
StoreRef bootstrapStoreRef = version2ImporterBootstrap.getStoreRef();
bootstrapStoreRef = tenantService.getName(AuthenticationUtil.getCurrentEffectiveUserName(), bootstrapStoreRef);
version2ImporterBootstrap.setStoreUrl(bootstrapStoreRef.toString());
version2ImporterBootstrap.bootstrap();
}
int vhCount = versionMigrator.migrateVersions(batchSize, deleteImmediately); int vhCount = versionMigrator.migrateVersions(batchSize, deleteImmediately);
// build the result message // build the result message

View File

@@ -29,6 +29,7 @@ import java.util.Set;
import org.alfresco.i18n.I18NUtil; import org.alfresco.i18n.I18NUtil;
import org.alfresco.repo.admin.patch.AbstractPatch; import org.alfresco.repo.admin.patch.AbstractPatch;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.site.SiteInfo; import org.alfresco.repo.site.SiteInfo;
import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.site.SiteModel;
import org.alfresco.repo.site.SiteService; import org.alfresco.repo.site.SiteService;
@@ -37,6 +38,7 @@ import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.util.EqualsHelper;
/** /**
* Patch's the site permission model to use groups to contain users. * Patch's the site permission model to use groups to contain users.
@@ -88,6 +90,13 @@ public class SitePermissionRefactorPatch extends AbstractPatch
*/ */
@Override @Override
protected String applyInternal() throws Exception protected String applyInternal() throws Exception
{
// NOTE: SiteService is not currently MT-enabled (eg. getSiteRoot) so skip if applied to tenant
if (EqualsHelper.nullSafeEquals(
AuthenticationUtil.SYSTEM_USER_NAME,
AuthenticationUtil.getCurrentEffectiveUserName())
||
!AuthenticationUtil.isMtEnabled())
{ {
// Set all the sites in the repository // Set all the sites in the repository
List<SiteInfo> sites = this.siteService.listSites(null, null); List<SiteInfo> sites = this.siteService.listSites(null, null);
@@ -134,6 +143,7 @@ public class SitePermissionRefactorPatch extends AbstractPatch
} }
} }
} }
}
// Report status // Report status
return I18NUtil.getMessage(STATUS_MSG); return I18NUtil.getMessage(STATUS_MSG);

View File

@@ -500,7 +500,7 @@ public class MultiTServiceImpl implements TenantService
*/ */
public boolean isTenantUser() public boolean isTenantUser()
{ {
return isTenantUser(AuthenticationUtil.getCurrentUserName()); return isTenantUser(AuthenticationUtil.getCurrentEffectiveUserName());
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -567,7 +567,7 @@ public class MultiTServiceImpl implements TenantService
*/ */
public String getCurrentUserDomain() public String getCurrentUserDomain()
{ {
String user = AuthenticationUtil.getCurrentUserName(); String user = AuthenticationUtil.getCurrentEffectiveUserName();
return getUserDomain(user); return getUserDomain(user);
} }

View File

@@ -24,7 +24,13 @@
*/ */
package org.alfresco.repo.version; package org.alfresco.repo.version;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.tenant.Tenant;
import org.alfresco.repo.tenant.TenantAdminService;
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.quartz.Job; import org.quartz.Job;
@@ -39,7 +45,9 @@ public class MigrationCleanupJob implements Job
{ {
private static Log logger = LogFactory.getLog(MigrationCleanupJob.class); private static Log logger = LogFactory.getLog(MigrationCleanupJob.class);
private static final String KEY_COMPONENT = "versionMigrator"; private static final String KEY_VERSION_MIGRATOR = "versionMigrator";
private static final String KEY_TENANT_ADMIN_SERVICE = "tenantAdminService";
private static final String KEY_BATCHSIZE = "batchSize"; private static final String KEY_BATCHSIZE = "batchSize";
private int batchSize = 1; private int batchSize = 1;
@@ -47,10 +55,13 @@ public class MigrationCleanupJob implements Job
public void execute(JobExecutionContext context) throws JobExecutionException public void execute(JobExecutionContext context) throws JobExecutionException
{ {
JobDataMap jobData = context.getJobDetail().getJobDataMap(); JobDataMap jobData = context.getJobDetail().getJobDataMap();
VersionMigrator migrationCleanup = (VersionMigrator)jobData.get(KEY_COMPONENT);
final VersionMigrator migrationCleanup = (VersionMigrator)jobData.get(KEY_VERSION_MIGRATOR);
final TenantAdminService tenantAdminService = (TenantAdminService)jobData.get(KEY_TENANT_ADMIN_SERVICE);
if (migrationCleanup == null) if (migrationCleanup == null)
{ {
throw new JobExecutionException("Missing job data: " + KEY_COMPONENT); throw new JobExecutionException("Missing job data: " + KEY_VERSION_MIGRATOR);
} }
String batchSizeStr = (String)jobData.get(KEY_BATCHSIZE); String batchSizeStr = (String)jobData.get(KEY_BATCHSIZE);
@@ -75,5 +86,22 @@ public class MigrationCleanupJob implements Job
// perform the cleanup of the old version store // perform the cleanup of the old version store
migrationCleanup.executeCleanup(batchSize); migrationCleanup.executeCleanup(batchSize);
if ((tenantAdminService != null) && tenantAdminService.isEnabled())
{
List<Tenant> tenants = tenantAdminService.getAllTenants();
for (Tenant tenant : tenants)
{
String tenantDomain = tenant.getTenantDomain();
AuthenticationUtil.runAs(new RunAsWork<Object>()
{
public Object doWork() throws Exception
{
migrationCleanup.executeCleanup(batchSize);
return null;
}
}, tenantAdminService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain));
}
}
} }
} }