From ba691ef7a9ee4b0abd121dd487859f8fb38a0fa1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 22 Jun 2015 17:30:12 +0200 Subject: Update api --- .../openslx/bwlp/thrift/iface/LectureWrite.java | 77 ++++++++-------- src/main/java/org/openslx/util/TimeoutHashMap.java | 102 +++++++++++++++++++++ .../java/org/openslx/util/TimeoutReference.java | 12 +++ src/main/thrift/bwlp.thrift | 34 +++---- 4 files changed, 173 insertions(+), 52 deletions(-) create mode 100644 src/main/java/org/openslx/util/TimeoutHashMap.java (limited to 'src/main') diff --git a/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java b/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java index ea4bd53..2259b45 100644 --- a/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java +++ b/src/main/java/org/openslx/bwlp/thrift/iface/LectureWrite.java @@ -67,8 +67,8 @@ public class LectureWrite implements org.apache.thrift.TBase nics; // required - public List allowedUsers; // required - public List networkExceptions; // required + public List allowedUsers; // optional + public List networkExceptions; // optional public boolean isExam; // required public boolean hasInternetAccess; // required public LecturePermissions defaultPermissions; // required @@ -181,6 +181,7 @@ public class LectureWrite implements org.apache.thrift.TBase metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); @@ -205,10 +206,10 @@ public class LectureWrite implements org.apache.thrift.TBase nics, - List allowedUsers, - List networkExceptions, boolean isExam, boolean hasInternetAccess, LecturePermissions defaultPermissions) @@ -256,8 +255,6 @@ public class LectureWrite implements org.apache.thrift.TBase implements Map +{ + + private final Map> map; + private final long timeout; + + public TimeoutHashMap( long timeout ) + { + this.map = new HashMap<>(); + this.timeout = timeout; + } + + @Override + public int size() + { + return map.size(); + } + + @Override + public boolean isEmpty() + { + return map.isEmpty(); + } + + @Override + public boolean containsKey( Object key ) + { + return map.containsKey( key ); + } + + @Override + public boolean containsValue( Object value ) + { + return map.containsValue( value ); + } + + @Override + public V get( Object key ) + { + TimeoutReference timeoutReference = map.get( key ); + if ( timeoutReference == null ) + return null; + return timeoutReference.get(); + } + + @Override + public V put( K key, V value ) + { + map.put( key, new TimeoutReference( + false, timeout, value ) ); + return value; + } + + @Override + public V remove( Object key ) + { + TimeoutReference remove = map.remove( key ); + if ( remove == null ) + return null; + return remove.get(); + } + + @Override + public void putAll( Map m ) + { + for ( java.util.Map.Entry entry : m.entrySet() ) { + put( entry.getKey(), entry.getValue() ); + } + } + + @Override + public void clear() + { + map.clear(); + } + + @Override + public Set keySet() + { + return map.keySet(); + } + + @Override + public Collection values() + { + throw new UnsupportedOperationException(); + } + + @Override + public Set> entrySet() + { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/org/openslx/util/TimeoutReference.java b/src/main/java/org/openslx/util/TimeoutReference.java index 4d7a992..e86c6c7 100644 --- a/src/main/java/org/openslx/util/TimeoutReference.java +++ b/src/main/java/org/openslx/util/TimeoutReference.java @@ -46,4 +46,16 @@ public class TimeoutReference this.deadline = System.currentTimeMillis() + timeoutMs; } + @Override + public int hashCode() + { + return item.hashCode(); + } + + @Override + public boolean equals( Object o ) + { + return this == o || item.equals( o ); + } + } diff --git a/src/main/thrift/bwlp.thrift b/src/main/thrift/bwlp.thrift index 0f003b4..44c6169 100644 --- a/src/main/thrift/bwlp.thrift +++ b/src/main/thrift/bwlp.thrift @@ -106,6 +106,21 @@ struct OperatingSystem { 4: string architecture, } +// Sat <-> Master +struct ImagePublishData { + 1: UUID imageBaseId, + 2: UUID currentVersionId, + 3: string imageName, + 4: i32 osId, + 5: string virtId, + 6: UnixTimestamp baseCreateTime, + 7: UnixTimestamp versionCreateTime, + 8: UUID ownerId, + 9: UUID uploaderId, + 11: i64 fileSize, + 16: bool isTemplate, +} + struct ImagePermissions { 1: bool link 2: bool download @@ -128,20 +143,6 @@ struct ImageBaseWrite { 7: optional UUID ownerId, } -struct ImagePublishData { - 1: UUID imageBaseId, - 2: UUID currentVersionId, - 3: string imageName, - 4: i32 osId, - 5: string virtId, - 6: UnixTimestamp baseCreateTime, - 7: UnixTimestamp versionCreateTime, - 8: UUID ownerId, - 9: UUID uploaderId, - 11: i64 fileSize, - 16: bool isTemplate, -} - struct ImageVersionWrite { 1: bool isEnabled, 2: bool isRestricted, @@ -209,6 +210,7 @@ struct NetRule { 4: i32 port, } +// Write lecture to sat. if optional fields are not set or null, their value stays unchanged struct LectureWrite { 1: string lectureName, 2: string description, @@ -220,8 +222,8 @@ struct LectureWrite { 8: UUID ownerId, 9: string runscript, 10: list nics, - 11: list allowedUsers, // allowed to see/select image in vmchooser. These are local accounts, not bwIDM/Master - 12: list networkExceptions, + 11: optional list allowedUsers, // allowed to see/select image in vmchooser. These are local accounts, not bwIDM/Master + 12: optional list networkExceptions, 13: bool isExam, 14: bool hasInternetAccess, 15: LecturePermissions defaultPermissions, -- cgit v1.2.3-55-g7522