Search in sources :

Example 6 with ModuleDetails

use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.

the class WarHelperImplTest method testNoVersionProperties.

@Test
public void testNoVersionProperties() {
    TFile theWar = getFile(".war", "module/empty.war");
    ModuleDetails installingModuleDetails = new ModuleDetailsImpl("test_it", new ModuleVersionNumber("9999"), "Test Mod", "Testing module");
    installingModuleDetails.setRepoVersionMin(new VersionNumber("10.1"));
    // does not throw exception
    this.checkCompatibleVersion(theWar, installingModuleDetails);
    // does not throw exception
    this.checkCompatibleEdition(theWar, installingModuleDetails);
}
Also used : TFile(de.schlichtherle.truezip.file.TFile) ModuleDetailsImpl(org.alfresco.repo.module.ModuleDetailsImpl) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) VersionNumber(org.alfresco.util.VersionNumber) ModuleVersionNumber(org.alfresco.repo.module.ModuleVersionNumber) Test(org.junit.Test)

Example 7 with ModuleDetails

use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.

the class ConfigurationDataCollectorTest method setUp.

@Before
public void setUp() {
    smartFoldersBundle = mock(SpringExtensionBundle.class);
    mockDescriptorDAO = mock(DescriptorDAO.class);
    mockServerDescriptorDAO = mock(DescriptorDAO.class);
    mockCollectorService = mock(HBDataCollectorService.class);
    mockScheduler = mock(HeartBeatJobScheduler.class);
    Descriptor mockDescriptor = mock(Descriptor.class);
    when(mockDescriptor.getId()).thenReturn("mock_id");
    when(mockServerDescriptorDAO.getDescriptor()).thenReturn(mockDescriptor);
    when(mockDescriptorDAO.getDescriptor()).thenReturn(mockDescriptor);
    BasicDataSource mockBasicDataSource = mock(BasicDataSource.class);
    RepoUsageComponent mockRepoUsageComponent = mock(RepoUsageComponent.class);
    ServerModeProvider mockServerModeProvider = mock(ServerModeProvider.class);
    when(mockServerModeProvider.getServerMode()).thenReturn(SERVER_MODE);
    ChildApplicationContextFactory mockFileServerSubsystem = mock(ChildApplicationContextFactory.class);
    WebDavService mockWebDavService = mock(WebDavService.class);
    ThumbnailService mockThumbnailService = mock(ThumbnailService.class);
    ChildApplicationContextFactory mockActivitiesFeedSubsystem = mock(ChildApplicationContextFactory.class);
    WorkflowAdminService mockWorkflowAdminService = mock(WorkflowAdminService.class);
    ChildApplicationContextFactory mockInboundSMTPSubsystem = mock(ChildApplicationContextFactory.class);
    ChildApplicationContextFactory mockImapSubsystem = mock(ChildApplicationContextFactory.class);
    ChildApplicationContextFactory mockReplication = mock(ChildApplicationContextFactory.class);
    // mock modules and module service
    ModuleService mockModuleService = mock(ModuleService.class);
    ModuleDetails mockInstalledModule1 = mock(ModuleDetails.class);
    when(mockInstalledModule1.getId()).thenReturn(INSTALLED_MODULE_ID_1);
    when(mockInstalledModule1.getModuleVersionNumber()).thenReturn(INSTALLED_MODULE_VERSION_1);
    ModuleDetails mockInstalledModule2 = mock(ModuleDetails.class);
    when(mockInstalledModule2.getId()).thenReturn(INSTALLED_MODULE_ID_2);
    when(mockInstalledModule2.getModuleVersionNumber()).thenReturn(INSTALLED_MODULE_VERSION_2);
    ModuleDetails mockMissingModule = mock(ModuleDetails.class);
    when(mockMissingModule.getId()).thenReturn(MISSING_MODULE_ID_1);
    when(mockMissingModule.getModuleVersionNumber()).thenReturn(MISSING_MODULE_VERSION_1);
    when(mockModuleService.getAllModules()).thenReturn(Arrays.asList(mockInstalledModule1, mockInstalledModule2));
    when(mockModuleService.getMissingModules()).thenReturn(Arrays.asList(mockMissingModule));
    // mock audit applications and audit service
    AuditService mockAuditService = mock(AuditService.class);
    AuditService.AuditApplication mockAuditApp = mock(AuditService.AuditApplication.class);
    when(mockAuditApp.isEnabled()).thenReturn(AUDIT_APP_ENABLED);
    Map<String, AuditService.AuditApplication> auditApps = new HashMap<>();
    auditApps.put(AUDIT_APP_NAME, mockAuditApp);
    TransactionService mockTransactionService = mock(TransactionService.class);
    RetryingTransactionHelper mockRetryingTransactionHelper = mock(RetryingTransactionHelper.class);
    // Mock transaction service calls
    when(mockRetryingTransactionHelper.doInTransaction(any(RetryingTransactionHelper.RetryingTransactionCallback.class), anyBoolean())).thenReturn(// First call made by the collector to get the server readOnly value via transformation service
    true).thenReturn(// Second call to get the audit applications
    auditApps);
    when(mockTransactionService.getRetryingTransactionHelper()).thenReturn(mockRetryingTransactionHelper);
    // mock authentication chain
    DefaultChildApplicationContextManager mockAuthenticationSubsystem = mock(DefaultChildApplicationContextManager.class);
    configurationCollector = new ConfigurationDataCollector("acs.repository.configuration", "1.0", "0 0 0 ? * SUN", mockScheduler);
    configurationCollector.setHbDataCollectorService(mockCollectorService);
    configurationCollector.setCurrentRepoDescriptorDAO(mockDescriptorDAO);
    configurationCollector.setSmartFoldersBundle(smartFoldersBundle);
    configurationCollector.setDataSource(mockBasicDataSource);
    configurationCollector.setTransactionService(mockTransactionService);
    configurationCollector.setRepoUsageComponent(mockRepoUsageComponent);
    configurationCollector.setServerModeProvider(mockServerModeProvider);
    configurationCollector.setFileServersSubsystem(mockFileServerSubsystem);
    configurationCollector.setWebdavService(mockWebDavService);
    configurationCollector.setThumbnailService(mockThumbnailService);
    configurationCollector.setActivitiesFeedSubsystem(mockActivitiesFeedSubsystem);
    configurationCollector.setWorkflowAdminService(mockWorkflowAdminService);
    configurationCollector.setInboundSMTPSubsystem(mockInboundSMTPSubsystem);
    configurationCollector.setImapSubsystem(mockImapSubsystem);
    configurationCollector.setReplicationSubsystem(mockReplication);
    configurationCollector.setModuleService(mockModuleService);
    configurationCollector.setAuditService(mockAuditService);
    configurationCollector.setAuthenticationSubsystem(mockAuthenticationSubsystem);
    collectedData = configurationCollector.collectData();
}
Also used : ModuleService(org.alfresco.service.cmr.module.ModuleService) ThumbnailService(org.alfresco.service.cmr.thumbnail.ThumbnailService) TransactionService(org.alfresco.service.transaction.TransactionService) HashMap(java.util.HashMap) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) DefaultChildApplicationContextManager(org.alfresco.repo.management.subsystems.DefaultChildApplicationContextManager) SpringExtensionBundle(org.alfresco.traitextender.SpringExtensionBundle) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) ChildApplicationContextFactory(org.alfresco.repo.management.subsystems.ChildApplicationContextFactory) RepoUsageComponent(org.alfresco.repo.usage.RepoUsageComponent) WebDavService(org.alfresco.service.cmr.webdav.WebDavService) HeartBeatJobScheduler(org.alfresco.heartbeat.jobs.HeartBeatJobScheduler) HBDataCollectorService(org.alfresco.service.cmr.repository.HBDataCollectorService) WorkflowAdminService(org.alfresco.service.cmr.workflow.WorkflowAdminService) Descriptor(org.alfresco.service.descriptor.Descriptor) DescriptorDAO(org.alfresco.repo.descriptor.DescriptorDAO) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) AuditService(org.alfresco.service.cmr.audit.AuditService) ServerModeProvider(org.alfresco.repo.mode.ServerModeProvider) Before(org.junit.Before)

Example 8 with ModuleDetails

use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.

the class WarHelperImpl method getModuleDetailsOrAlias.

@Override
public ModuleDetails getModuleDetailsOrAlias(TFile war, ModuleDetails installingModuleDetails) {
    ModuleDetails installedModuleDetails = getModuleDetails(war, installingModuleDetails.getId());
    if (installedModuleDetails == null) {
        // It might be there as one of the aliases
        List<String> installingAliases = installingModuleDetails.getAliases();
        for (String installingAlias : installingAliases) {
            ModuleDetails installedAliasModuleDetails = getModuleDetails(war, installingAlias);
            if (installedAliasModuleDetails == null) {
                // There is nothing by that alias
                continue;
            }
            // We found an alias and will treat it as the same module
            installedModuleDetails = installedAliasModuleDetails;
            // outputMessage("Module '" + installingAlias + "' is installed and is an alias of '" + installingModuleDetails + "'", false);
            break;
        }
    }
    return installedModuleDetails;
}
Also used : ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails)

Example 9 with ModuleDetails

use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.

the class ModuleComponentHelper method startModule.

/**
 * Does the actual work without fussing about transactions and authentication.
 * Module dependencies will be started first, but a module will only be started
 * once.
 *
 * @param module                the module to start
 * @param startedModules        the IDs of modules that have already started
 * @param executedComponents    keep track of the executed components
 */
private void startModule(ModuleDetails module, Set<String> startedModules, Set<ModuleComponent> executedComponents) {
    String moduleId = module.getId();
    ModuleVersionNumber moduleNewVersion = module.getModuleVersionNumber();
    // Double check whether we have done this module already
    if (startedModules.contains(moduleId)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Module '" + module + "' already started");
        }
        return;
    }
    // Start dependencies
    List<ModuleDependency> moduleDependencies = module.getDependencies();
    for (ModuleDependency moduleDependency : moduleDependencies) {
        if (logger.isDebugEnabled()) {
            logger.debug("Module '" + module + "' depends on: " + moduleDependency);
        }
        // Get the dependency
        String moduleDependencyId = moduleDependency.getDependencyId();
        ModuleDetails moduleDependencyDetails = moduleService.getModule(moduleDependencyId);
        // Check that it is there
        if (moduleDependencyDetails == null) {
            // The dependency is not there
            // List required dependencies
            StringBuilder sb = new StringBuilder(128);
            for (ModuleDependency dependency : moduleDependencies) {
                sb.append("\n").append(dependency);
            }
            String msg = I18NUtil.getMessage(MSG_DEPENDENCIES, moduleId, moduleNewVersion, sb.toString());
            logger.info(msg);
            // Now fail
            throw AlfrescoRuntimeException.create(ERR_MISSING_DEPENDENCY, moduleId, moduleNewVersion, moduleDependency);
        }
        // The dependency is installed, so start it
        startModule(moduleDependencyDetails, startedModules, executedComponents);
    }
    // Check if the module needs a rename first
    renameModule(module);
    // First check that the module version is fundamentally compatible with the repository
    VersionNumber repoVersionNumber = descriptorService.getServerDescriptor().getVersionNumber();
    VersionNumber minRepoVersionNumber = module.getRepoVersionMin();
    VersionNumber maxRepoVersionNumber = module.getRepoVersionMax();
    if ((minRepoVersionNumber != null && repoVersionNumber.compareTo(minRepoVersionNumber) < 0) || (maxRepoVersionNumber != null && repoVersionNumber.compareTo(maxRepoVersionNumber) > 0)) {
        // The current repo version is not supported
        throw AlfrescoRuntimeException.create(ERR_UNSUPPORTED_REPO_VERSION, moduleId, moduleNewVersion, repoVersionNumber, minRepoVersionNumber, maxRepoVersionNumber);
    }
    // Get the module details from the registry
    RegistryKey moduleKeyInstalledVersion = new RegistryKey(ModuleComponentHelper.URI_MODULES_1_0, REGISTRY_PATH_MODULES, moduleId, REGISTRY_PROPERTY_INSTALLED_VERSION);
    RegistryKey moduleKeyCurrentVersion = new RegistryKey(ModuleComponentHelper.URI_MODULES_1_0, REGISTRY_PATH_MODULES, moduleId, REGISTRY_PROPERTY_CURRENT_VERSION);
    Serializable moduleInstallVersion = registryService.getProperty(moduleKeyInstalledVersion);
    Serializable moduleCurrentVersion = registryService.getProperty(moduleKeyCurrentVersion);
    String msg = null;
    if (// No previous record of it
    moduleCurrentVersion == null) {
        msg = I18NUtil.getMessage(MSG_INSTALLING, moduleId, moduleNewVersion);
        // Record the install version
        registryService.addProperty(moduleKeyInstalledVersion, moduleNewVersion);
        moduleInstallVersion = moduleNewVersion;
        moduleCurrentVersion = moduleNewVersion;
    } else // It is an upgrade or is the same
    {
        ModuleVersionNumber currentModuleVersion = getModuleVersionNumber(moduleCurrentVersion);
        // Check that we have an installed version
        if (moduleInstallVersion == null) {
            // A current version, but no installed version
            logger.warn(I18NUtil.getMessage(WARN_NO_INSTALL_VERSION, moduleId, moduleCurrentVersion));
            // Record the install version
            registryService.addProperty(moduleKeyInstalledVersion, currentModuleVersion);
            moduleInstallVersion = moduleCurrentVersion;
        }
        if (// The current version is the same
        currentModuleVersion.compareTo(moduleNewVersion) == 0) {
            msg = I18NUtil.getMessage(MSG_STARTING, moduleId, moduleNewVersion);
        } else if (// Downgrading not supported
        currentModuleVersion.compareTo(moduleNewVersion) > 0) {
            throw AlfrescoRuntimeException.create(ERR_NO_DOWNGRADE, moduleId, moduleCurrentVersion, moduleNewVersion);
        } else // This is an upgrade
        {
            msg = I18NUtil.getMessage(MSG_UPGRADING, moduleId, moduleNewVersion, moduleCurrentVersion);
        }
    }
    loggerService.info(msg);
    // Record the current version
    registryService.addProperty(moduleKeyCurrentVersion, moduleNewVersion);
    Map<String, ModuleComponent> componentsByName = getComponents(moduleId);
    for (ModuleComponent component : componentsByName.values()) {
        executeComponent(moduleId, moduleNewVersion, component, executedComponents);
    }
    // Keep track of the ID as it started successfully
    startedModules.add(moduleId);
    // Done
    if (logger.isDebugEnabled()) {
        logger.debug("Started module '" + module + "' including " + executedComponents.size() + "components.");
    }
}
Also used : Serializable(java.io.Serializable) ModuleDependency(org.alfresco.service.cmr.module.ModuleDependency) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) VersionNumber(org.alfresco.util.VersionNumber) RegistryKey(org.alfresco.repo.admin.registry.RegistryKey)

Example 10 with ModuleDetails

use of org.alfresco.service.cmr.module.ModuleDetails in project alfresco-repository by Alfresco.

the class ModuleComponentHelper method checkForMissingModules.

/**
 * Checks to see if there are any modules registered as installed that aren't in the
 * list of modules taken from the WAR.
 * <p>
 * Currently, the behaviour specified is that a warning is generated only.
 */
private void checkForMissingModules() {
    // Get the IDs of all modules from the registry
    Collection<String> moduleIds = getRegistryModuleIDs();
    // Check that each module is present in the distribution
    for (String moduleId : moduleIds) {
        ModuleDetails moduleDetails = moduleService.getModule(moduleId);
        if (moduleDetails != null) {
            if (logger.isDebugEnabled()) {
                logger.debug("Installed module found in distribution: " + moduleId);
            }
        } else {
            // Get the specifics of the missing module
            ModuleVersionNumber versionCurrent = getVersion(moduleId);
            // The module is missing, so warn
            loggerService.warn(I18NUtil.getMessage(MSG_MISSING, moduleId, versionCurrent));
        }
    }
}
Also used : ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails)

Aggregations

ModuleDetails (org.alfresco.service.cmr.module.ModuleDetails)27 TFile (de.schlichtherle.truezip.file.TFile)9 Properties (java.util.Properties)7 ModuleDetailsImpl (org.alfresco.repo.module.ModuleDetailsImpl)7 Test (org.junit.Test)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ModuleVersionNumber (org.alfresco.repo.module.ModuleVersionNumber)4 VersionNumber (org.alfresco.util.VersionNumber)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 ModuleDependency (org.alfresco.service.cmr.module.ModuleDependency)3 TFileInputStream (de.schlichtherle.truezip.file.TFileInputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 ModulePackage (org.alfresco.rest.api.model.ModulePackage)2 AuditService (org.alfresco.service.cmr.audit.AuditService)2 BasicDataSource (org.apache.commons.dbcp.BasicDataSource)2 FsSyncException (de.schlichtherle.truezip.fs.FsSyncException)1 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1