mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Feature #3805: Document lock in ruby & java oca
This commit is contained in:
parent
9f21f40272
commit
da8ccbb0f1
@ -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() );
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,9 @@ module OpenNebula
|
||||
:chown => "document.chown",
|
||||
:chmod => "document.chmod",
|
||||
:clone => "document.clone",
|
||||
:rename => "document.rename"
|
||||
:rename => "document.rename",
|
||||
:lock => "document.lock",
|
||||
:unlock => "document.unlock"
|
||||
}
|
||||
|
||||
# Creates a Document Object description with just its identifier
|
||||
@ -200,6 +202,32 @@ module OpenNebula
|
||||
return call(DOCUMENT_METHODS[:rename], @pe_id, name)
|
||||
end
|
||||
|
||||
# Locks this object
|
||||
#
|
||||
# @param owner [String] String to identify the application requestiong
|
||||
# the lock
|
||||
#
|
||||
# @return [Bool, OpenNebula::Error] In case of success, true if the
|
||||
# lock was granted, and false if the object is already locked.
|
||||
def lock(owner="")
|
||||
return Error.new('ID not defined') if !@pe_id
|
||||
|
||||
rc = @client.call(DOCUMENT_METHODS[:lock], @pe_id, owner)
|
||||
|
||||
return rc
|
||||
end
|
||||
|
||||
# Unlocks this object
|
||||
#
|
||||
# @param owner [String] String to identify the application requestiong
|
||||
# the unlock
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def unlock(owner="")
|
||||
return call(DOCUMENT_METHODS[:unlock], @pe_id, owner)
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
# Helpers to get Document information
|
||||
#######################################################################
|
||||
|
Loading…
x
Reference in New Issue
Block a user