mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-23 13:15:14 +09:00
Feature #3805: Document lock in ruby & java oca
This commit is contained in:
1 parent
9f21f40272
commit
da8ccbb0f1
5 files changed
+93
-3
No files matched your search
@@ -106,8 +106,16 @@ public class Client{
|
||||
}
|
||||
catch (ClassCastException e)
|
||||
{
|
||||
// The result may be an Integer
|
||||
msg = ((Integer) result[1]).toString();
|
||||
try
|
||||
{
|
||||
// The result may be an Integer
|
||||
msg = ((Integer) result[1]).toString();
|
||||
}
|
||||
catch (ClassCastException ei)
|
||||
{
|
||||
// The result may be a Boolean
|
||||
msg = ((Boolean) result[1]).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +91,20 @@ public class OneResponse{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the string returned by getMessage
|
||||
*
|
||||
* @return The parsed boolean. False in case of error
|
||||
*
|
||||
* @see #getMessage
|
||||
*/
|
||||
public boolean getBooleanMessage()
|
||||
{
|
||||
boolean ret = Boolean.parseBoolean( getMessage() );
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// PRIVATE ATTRIBUTES
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -66,6 +66,8 @@ public abstract class Document extends PoolElement
|
||||
private static final String CHMOD = METHOD_PREFIX + "chmod";
|
||||
private static final String CLONE = METHOD_PREFIX + "clone";
|
||||
private static final String RENAME = METHOD_PREFIX + "rename";
|
||||
private static final String LOCK = METHOD_PREFIX + "lock";
|
||||
private static final String UNLOCK = METHOD_PREFIX + "unlock";
|
||||
|
||||
/**
|
||||
* Creates a new Document representation.
|
||||
@@ -239,6 +241,29 @@ public abstract class Document extends PoolElement
|
||||
return client.call(RENAME, id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks this object
|
||||
*
|
||||
* @param owner String to identify the application requestiong the lock
|
||||
* @return In case of success, a boolean with true if the lock was granted,
|
||||
* and false if the object is already locked.
|
||||
*/
|
||||
public OneResponse lock(String owner)
|
||||
{
|
||||
return client.call(LOCK, id, owner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlocks this object
|
||||
*
|
||||
* @param owner String to identify the application requestiong the lock
|
||||
* @return If an error occurs the error message contains the reason.
|
||||
*/
|
||||
public OneResponse unlock(String owner)
|
||||
{
|
||||
return client.call(UNLOCK, id, owner);
|
||||
}
|
||||
|
||||
// =================================
|
||||
// Helpers
|
||||
// =================================
|
||||
|
||||
@@ -145,4 +145,19 @@ public class DocumentTest
|
||||
assertTrue( !foundA );
|
||||
assertTrue( foundB );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lock()
|
||||
{
|
||||
res = objA.lock("doctest");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
assertTrue( res.getMessage(), res.getBooleanMessage() == true );
|
||||
|
||||
res = objA.lock("doctest");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
assertTrue( res.getMessage(), res.getBooleanMessage() == false );
|
||||
|
||||
res = objA.unlock("doctest");
|
||||
assertTrue( res.getErrorMessage(), !res.isError() );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user