Search in sources :

Example 1 with ModuleDependency

use of org.alfresco.service.cmr.module.ModuleDependency 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 2 with ModuleDependency

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

the class ModuleDetailsImpl method getProperties.

public Properties getProperties() {
    Properties properties = new Properties();
    // Mandatory properties
    properties.setProperty(PROP_ID, id);
    properties.setProperty(PROP_VERSION, version.toString());
    properties.setProperty(PROP_TITLE, title);
    properties.setProperty(PROP_DESCRIPTION, description);
    // Optional properites
    if (repoVersionMin != null) {
        properties.setProperty(PROP_REPO_VERSION_MIN, repoVersionMin.toString());
    }
    if (repoVersionMax != null) {
        properties.setProperty(PROP_REPO_VERSION_MAX, repoVersionMax.toString());
    }
    if (editions != null) {
        properties.setProperty(PROP_EDITIONS, join(editions.toArray(new String[editions.size()]), ','));
    }
    if (dependencies.size() > 0) {
        for (ModuleDependency dependency : dependencies) {
            String key = PROP_DEPENDS_PREFIX + dependency.getDependencyId();
            String value = dependency.getVersionString();
            properties.setProperty(key, value);
        }
    }
    if (installDate != null) {
        String installDateStr = ISO8601DateFormat.format(installDate);
        properties.setProperty(PROP_INSTALL_DATE, installDateStr);
    }
    if (installState != null) {
        String installStateStr = installState.toString();
        properties.setProperty(PROP_INSTALL_STATE, installStateStr);
    }
    if (aliases.size() > 0) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (String oldId : aliases) {
            if (!first) {
                sb.append(", ");
            }
            sb.append(oldId);
            first = false;
        }
        properties.setProperty(PROP_ALIASES, sb.toString());
    }
    // Done
    return properties;
}
Also used : ModuleDependency(org.alfresco.service.cmr.module.ModuleDependency) Properties(java.util.Properties)

Example 3 with ModuleDependency

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

the class ModuleDetailsImpl method extractDependencies.

private static List<ModuleDependency> extractDependencies(Properties properties) {
    int prefixLength = PROP_DEPENDS_PREFIX.length();
    List<ModuleDependency> dependencies = new ArrayList<ModuleDependency>(2);
    for (Map.Entry entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();
        if (!key.startsWith(PROP_DEPENDS_PREFIX)) {
            continue;
        }
        if (key.length() == prefixLength) {
            // Just ignore it
            continue;
        }
        String dependencyId = key.substring(prefixLength);
        // Build the dependency
        ModuleDependency dependency = new ModuleDependencyImpl(dependencyId, value);
        // Add it
        dependencies.add(dependency);
    }
    // Done
    return dependencies;
}
Also used : ModuleDependency(org.alfresco.service.cmr.module.ModuleDependency) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 4 with ModuleDependency

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

the class WarHelperImpl method checkModuleDependencies.

@Override
public void checkModuleDependencies(TFile war, ModuleDetails installingModuleDetails) {
    // Check that the target war has the necessary dependencies for this install
    List<ModuleDependency> installingModuleDependencies = installingModuleDetails.getDependencies();
    List<ModuleDependency> missingDependencies = new ArrayList<ModuleDependency>(0);
    for (ModuleDependency dependency : installingModuleDependencies) {
        String dependencyId = dependency.getDependencyId();
        ModuleDetails dependencyModuleDetails = getModuleDetails(war, dependencyId);
        // Check the dependency.  The API specifies that a null returns false, so no null check is required
        if (!dependency.isValidDependency(dependencyModuleDetails)) {
            missingDependencies.add(dependency);
            continue;
        }
    }
    if (missingDependencies.size() > 0) {
        throw new ModuleManagementToolException("The following modules must first be installed: " + missingDependencies);
    }
}
Also used : ModuleDependency(org.alfresco.service.cmr.module.ModuleDependency) ArrayList(java.util.ArrayList) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails)

Example 5 with ModuleDependency

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

the class ModuleDetailsImplTest method testDependencyChecks.

public void testDependencyChecks() {
    Properties props = new Properties();
    props.putAll(DEFAULT_PROPS);
    ModuleDetails details = new ModuleDetailsImpl(props);
    Properties tempProperties = new Properties();
    tempProperties.setProperty(ModuleDetails.PROP_ID, "a");
    tempProperties.setProperty(ModuleDetails.PROP_TITLE, "A");
    tempProperties.setProperty(ModuleDetails.PROP_DESCRIPTION, "A description");
    tempProperties.setProperty(ModuleDetails.PROP_VERSION, "1.0.0");
    ModuleDetails tempDetails = new ModuleDetailsImpl(tempProperties);
    List<ModuleDependency> dependencies = details.getDependencies();
    assertEquals("Incorrect number of dependencies", 8, dependencies.size());
    for (ModuleDependency dependency : dependencies) {
        if (dependency.getDependencyId().equals(tempDetails.getId())) {
            // It should not match
            assertFalse("No match expected", dependency.isValidDependency(tempDetails));
        }
    }
}
Also used : ModuleDependency(org.alfresco.service.cmr.module.ModuleDependency) ModuleDetails(org.alfresco.service.cmr.module.ModuleDetails) Properties(java.util.Properties)

Aggregations

ModuleDependency (org.alfresco.service.cmr.module.ModuleDependency)5 ModuleDetails (org.alfresco.service.cmr.module.ModuleDetails)3 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 Serializable (java.io.Serializable)1 Map (java.util.Map)1 RegistryKey (org.alfresco.repo.admin.registry.RegistryKey)1 VersionNumber (org.alfresco.util.VersionNumber)1