diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2014-06-05 15:02:07 +0200 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2014-06-05 15:02:07 +0200 |
| commit | d4fa3bd9dd48f4d5e26850a23f5ba48a9c10ad64 (patch) | |
| tree | 5ad7bfbce8ba9df9aad53ef33a8b908ca0680fc4 /src/main/java/com/c2kernel/lookup/NextKeyManager.java | |
| parent | 8bb86312d4f07dcb343ca2d212f4020906dbdb52 (diff) | |
LDAP refactored behind interfaces. All functions of LDAP now hidden
behind interfaces: Authenticator, Lookup and NextKeyManager (LDAP
property storage was already a ClusterStorage). Gateway holds additional
objects, and
Fixes #26 #191. Refs #27 (needs additional work for read perms and auth
tokens)
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/NextKeyManager.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/NextKeyManager.java | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/src/main/java/com/c2kernel/lookup/NextKeyManager.java b/src/main/java/com/c2kernel/lookup/NextKeyManager.java deleted file mode 100644 index 9aea50d..0000000 --- a/src/main/java/com/c2kernel/lookup/NextKeyManager.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.c2kernel.lookup;
-
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.persistency.ClusterStorageException;
-import com.c2kernel.process.Gateway;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPEntry;
-
-/**************************************************************************
- *
- * $Revision: 1.2 $
- * $Date: 2005/04/27 13:47:24 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-// public static final String codeRevision = "$Revision: 1.2 $ $Date: 2005/04/27 13:47:24 $ $Author: abranson $";
-public class NextKeyManager {
-
- LDAPLookup ldap;
- String lastKeyPath;
-
- public NextKeyManager(LDAPLookup ldap, String lastKeyPath) {
- super();
- this.ldap = ldap;
- this.lastKeyPath = lastKeyPath;
- }
-
- public synchronized ItemPath generateNextEntityKey()
- throws ObjectCannotBeUpdated, ObjectNotFoundException
- {
- ItemPath lastKey = getLastEntityPath();
-
- try {
- lastKey.setSysKey(lastKey.getSysKey()+1);
- } catch (InvalidItemPathException ex) {
- throw new ObjectCannotBeUpdated("Invalid syskey "+(lastKey.getSysKey()+1)+". Maybe centre is full.");
- }
- //test that storage is empty for that key
- try {
- if (Gateway.getStorage().getClusterContents(lastKey.getSysKey(), "").length > 0)
- throw new ObjectCannotBeUpdated("NextKeyManager: Storage already contains data for syskey "+lastKey.getSysKey()+
- ". Storage is out of sync with nextkey. Please contact an administrator", "");
- } catch (ClusterStorageException e) {
- Logger.error(e);
- throw new ObjectCannotBeUpdated("Could not check storage for prior data for the next generated systemKey: "+e.getMessage());
- }
-
- //set the last key
- writeLastEntityKey(lastKey.getSysKey());
-
- return lastKey;
- }
-
- public synchronized AgentPath generateNextAgentKey()
- throws ObjectCannotBeUpdated, ObjectNotFoundException {
- ItemPath newEntity = generateNextEntityKey();
- return new AgentPath(newEntity);
- }
-
- public void writeLastEntityKey(int sysKey) throws ObjectCannotBeUpdated, ObjectNotFoundException {
- LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getConnection(),lastKeyPath);
- LDAPLookupUtils.setAttributeValue(ldap.getConnection(), lastKeyEntry,"intsyskey",Integer.toString(sysKey));
- }
-
- public ItemPath getLastEntityPath() throws ObjectNotFoundException
- {
- LDAPEntry lastKeyEntry = LDAPLookupUtils.getEntry(ldap.getConnection(),lastKeyPath);
- String lastKey = LDAPLookupUtils.getFirstAttributeValue(lastKeyEntry,"intsyskey");
- try {
- int sysKey = Integer.parseInt(lastKey);
- ItemPath sysPath = new ItemPath(sysKey);
- return sysPath;
- } catch (InvalidItemPathException ex) {
- throw new ObjectNotFoundException("Invalid syskey. Maybe centre is full.");
- } catch (NumberFormatException ex) {
- throw new ObjectNotFoundException("Invalid syskey in lastkey.");
- }
-
- }
-
-}
|
