Merged V2.0 to HEAD

5466, 5471-5475: ModuleManagementTool enhancements


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5487 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2007-04-12 02:52:48 +00:00
parent 9a6a22b511
commit d6e56b62a4
8 changed files with 151 additions and 5 deletions

View File

@@ -25,6 +25,7 @@
package org.alfresco.repo.admin.registry;
import java.io.Serializable;
import java.util.Collection;
/**
* Interface for service providing access to key-value pairs for storage
@@ -49,4 +50,17 @@ public interface RegistryService
* @see #addValue(String, Serializable)
*/
Serializable getValue(RegistryKey key);
/**
* Fetches all child elements for the given path. So for a registry key <b>key=/a/b/ignored</b>, the
* results of <code>getChildElements(key)</b> would be <code>b</code>. The key's last path
* element represents the key's property name, and can therefore be any value without affecting
* the outcome of the call.
*
* @param key the registry key with the path. The last element in the path
* will be ignored, and can be any acceptable property localname.
* @return Returns all child elements (not values) for the given key, ignoring
* the last element in the key.
*/
Collection<String> getChildElements(RegistryKey key);
}

View File

@@ -25,6 +25,9 @@
package org.alfresco.repo.admin.registry;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -36,8 +39,10 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.Pair;
import org.alfresco.util.PropertyCheck;
import org.alfresco.util.PropertyMap;
@@ -256,6 +261,13 @@ public class RegistryServiceImpl implements RegistryService
*/
public void addValue(RegistryKey key, Serializable value)
{
// Check the namespace being used in the key
String namespaceUri = key.getNamespaceUri();
if (!namespaceService.getURIs().contains(namespaceUri))
{
throw new NamespaceException("Unable to add a registry value with an unregistered namespace: " + namespaceUri);
}
// Get the path, with creation support
Pair<NodeRef, QName> keyPair = getPath(key, true);
// We know that the node exists, so just set the value
@@ -287,4 +299,35 @@ public class RegistryServiceImpl implements RegistryService
}
return value;
}
public Collection<String> getChildElements(RegistryKey key)
{
// Get the path without creating it
Pair<NodeRef, QName> keyPair = getPath(key, false);
if (keyPair == null)
{
// Nothing at that path
return Collections.<String>emptyList();
}
// Use a query to find the children
RegexQNamePattern qnamePattern = new RegexQNamePattern(key.getNamespaceUri(), ".*");
List<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(
keyPair.getFirst(),
ContentModel.ASSOC_CHILDREN,
qnamePattern);
// The localname of each one of the child associations represents a path element
Collection<String> results = new ArrayList<String>(childAssocRefs.size());
for (ChildAssociationRef assocRef : childAssocRefs)
{
results.add(assocRef.getQName().getLocalName());
}
// Done
if (logger.isDebugEnabled())
{
logger.debug("Retrieved child elements from registry: \n" +
" Key: " + key + "\n" +
" Elements: " + results);
}
return results;
}
}

View File

@@ -24,6 +24,8 @@
*/
package org.alfresco.repo.admin.registry;
import java.util.Collection;
import junit.framework.TestCase;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
@@ -73,6 +75,8 @@ public class RegistryServiceImplTest extends TestCase
private static final Long VALUE_ONE = 1L;
private static final Long VALUE_TWO = 2L;
private static final Long VALUE_THREE = 3L;
private static final RegistryKey KEY_A_B_0 = new RegistryKey(null, "a", "b", "0");
private static final RegistryKey KEY_A_B_1 = new RegistryKey(null, "a", "b", "1");
private static final RegistryKey KEY_A_B_C_0 = new RegistryKey(null, "a", "b", "c", "0");
private static final RegistryKey KEY_A_B_C_1 = new RegistryKey(null, "a", "b", "c", "1");
private static final RegistryKey KEY_A_B_C_2 = new RegistryKey(null, "a", "b", "c", "2");
@@ -83,6 +87,7 @@ public class RegistryServiceImplTest extends TestCase
private static final RegistryKey KEY_A_B_C_D_3 = new RegistryKey(null, "a", "b", "c", "d", "3");
private static final RegistryKey KEY_X_Y_Z_0 = new RegistryKey(null, "x", "y", "z", "0");
private static final RegistryKey KEY_SPECIAL = new RegistryKey(null, "me & you", "whatever");
private static final RegistryKey KEY_DOES_NOT_EXIST = new RegistryKey(null, "does", "not", "exist");
/**
* General writing and reading back.
*/
@@ -107,6 +112,22 @@ public class RegistryServiceImplTest extends TestCase
assertNull("Missing key should return null value", registryService.getValue(KEY_X_Y_Z_0));
}
public void testGetElements() throws Exception
{
registryService.addValue(KEY_A_B_C_1, VALUE_ONE);
registryService.addValue(KEY_A_B_C_2, VALUE_TWO);
// Check that we get an empty list for a random query
assertEquals("Excpected empty collection for random query", 0, registryService.getChildElements(KEY_DOES_NOT_EXIST).size());
// Check that the property part of the key is ignored
assertEquals("Incorrect number ofchild elements", 1, registryService.getChildElements(KEY_A_B_0).size());
assertEquals("Incorrect number ofchild elements", 1, registryService.getChildElements(KEY_A_B_1).size());
Collection<String> childElements = registryService.getChildElements(KEY_A_B_0);
assertTrue("Incorrect child elements retrieved", childElements.contains("c"));
}
public void testSpecialCharacters()
{
registryService.addValue(KEY_SPECIAL, VALUE_THREE);

View File

@@ -24,6 +24,7 @@
*/
package org.alfresco.repo.module;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -64,6 +65,7 @@ public class ModuleComponentHelper
private static final String REGISTRY_PROPERTY_CURRENT_VERSION = "currentVersion";
private static final String REGISTRY_PATH_COMPONENTS = "components";
private static final String REGISTRY_PROPERTY_EXECUTION_DATE = "executionDate";
private static final String REGISTRY_PROPERTY_DUMMY = "dummy";
private static final String MSG_FOUND_MODULES = "module.msg.found_modules";
private static final String MSG_STARTING = "module.msg.starting";
@@ -71,6 +73,7 @@ public class ModuleComponentHelper
private static final String MSG_UPGRADING = "module.msg.upgrading";
private static final String ERR_NO_DOWNGRADE = "module.err.downgrading_not_supported";
private static final String ERR_COMPONENT_ALREADY_REGISTERED = "module.err.component_already_registered";
private static final String MSG_MISSING = "module.msg.missing";
private static Log logger = LogFactory.getLog(ModuleComponentHelper.class);
private static Log loggerService = LogFactory.getLog(ModuleServiceImpl.class);
@@ -205,17 +208,60 @@ public class ModuleComponentHelper
};
TransactionUtil.executeInNonPropagatingUserTransaction(transactionService, startModuleWork);
}
// Done
// We have finished executing any components
if (logger.isDebugEnabled())
{
logger.debug("Executed " + executedComponents.size() + " components");
}
}
finally
{
// Check for missing modules.
checkForMissingModules();
// Restore the original authentication
authenticationComponent.setCurrentAuthentication(authentication);
}
catch (Throwable e)
{
throw new AlfrescoRuntimeException("Failed to start modules", e);
}
}
/**
* 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
RegistryKey moduleKeyAllIds = new RegistryKey(
ModuleComponentHelper.URI_MODULES_1_0,
REGISTRY_PATH_MODULES, REGISTRY_PROPERTY_DUMMY);
Collection<String> moduleIds = registryService.getChildElements(moduleKeyAllIds);
// 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
RegistryKey moduleKeyCurrentVersion = new RegistryKey(
ModuleComponentHelper.URI_MODULES_1_0,
REGISTRY_PATH_MODULES, moduleId, REGISTRY_PROPERTY_CURRENT_VERSION);
VersionNumber versionCurrent = (VersionNumber) registryService.getValue(moduleKeyCurrentVersion);
// The module is missing, so warn
loggerService.warn(I18NUtil.getMessage(MSG_MISSING, moduleId, versionCurrent));
}
}
}
/**

View File

@@ -215,7 +215,19 @@ public class ModuleComponentHelperTest extends BaseAlfrescoTestCase
public ModuleDetails getModule(String moduleId)
{
throw new UnsupportedOperationException();
for (int i = 0; i < MODULE_IDS.length; i++)
{
if (!MODULE_IDS[i].equals(moduleId))
{
continue;
}
new ModuleDetailsImpl(
MODULE_IDS[i],
currentVersion,
"Module-" + i,
"Description-" + i);
}
return null;
}
public void startModules()

View File

@@ -313,6 +313,13 @@ public class ModuleManagementTool
// Update the zip file's
File.update();
// Set the modified date
java.io.File warFile = new java.io.File(warFileLocation);
if (warFile.exists())
{
warFile.setLastModified(System.currentTimeMillis());
}
}
}
catch (ZipWarningException ignore)