public class Operation extends Object implements Serializable
getOperationId()
. getOperationId()
returns GlobalOperationId
for global
operations, RegionOperationId
for region operations, and ZoneOperationId
for zone
operations. To get an Operation
object with the most recent information, use reload(Compute.OperationOption...)
.Modifier and Type | Class and Description |
---|---|
static class |
Operation.OperationError
An error that can occur during the processing of a Google Compute Engine operation.
|
static class |
Operation.OperationWarning
A warning message that is generated during the processing of a Google Compute Engine operation.
|
static class |
Operation.Status
Status of an operation.
|
Modifier and Type | Method and Description |
---|---|
boolean |
delete()
Deletes this operation.
|
boolean |
equals(Object obj) |
boolean |
exists()
Checks if this operation exists.
|
Compute |
getCompute()
Returns the operation's
Compute object used to issue requests. |
String |
getDescription()
Returns an optional textual description of the operation.
|
Long |
getEndTime()
Returns the time that this operation was completed.
|
List<Operation.OperationError> |
getErrors()
Returns the errors encountered while processing this operation, if any.
|
String |
getGeneratedId()
Returns the service-generated unique identifier for the operation.
|
String |
getHttpErrorMessage()
Returns the the HTTP error message that was returned, if the operation failed.
|
Integer |
getHttpErrorStatusCode()
Returns the HTTP error status code that was returned, if the operation failed.
|
Long |
getInsertTime()
Returns the time that this operation was requested.
|
<T extends OperationId> |
getOperationId()
Returns the operation's identity.
|
String |
getOperationType()
Returns the type of operation.
|
Integer |
getProgress()
Returns an optional progress indicator that ranges from 0 to 100.
|
Long |
getStartTime()
Returns the time that this operation was started by the service.
|
Operation.Status |
getStatus()
Returns the status of the operation.
|
String |
getStatusMessage()
Returns an optional textual description of the current status of the operation.
|
String |
getTargetId()
Returns the unique service-defined target ID, which identifies the resource that the operation
is modifying.
|
String |
getTargetLink()
Returns the URL of the resource that the operation is modifying.
|
String |
getUser()
Returns the user who requested the operation, for example:
user@example.com . |
List<Operation.OperationWarning> |
getWarnings()
Returns the warnings encountered while processing this operation, if any.
|
int |
hashCode() |
boolean |
isDone()
Checks if this operation has completed its execution, either failing or succeeding.
|
Operation |
reload(Compute.OperationOption... options)
Fetches current operation's latest information.
|
String |
toString() |
Operation |
waitFor(com.google.cloud.RetryOption... waitOptions)
Blocks until this operation completes its execution, either failing or succeeding.
|
public Compute getCompute()
Compute
object used to issue requests.public String getGeneratedId()
public <T extends OperationId> T getOperationId()
GlobalOperationId
for global
operations, a RegionOperationId
for region operations and a ZoneOperationId
for
zone operations.public String getOperationType()
public String getTargetLink()
public String getTargetId()
public Operation.Status getStatus()
public String getStatusMessage()
public String getUser()
user@example.com
.public Integer getProgress()
public Long getInsertTime()
public Long getStartTime()
null
if the operation has not started yet.public Long getEndTime()
null
if the operation has not finished yet.public List<Operation.OperationError> getErrors()
null
if
no error occurred.public List<Operation.OperationWarning> getWarnings()
null
if no warning occurred.public Integer getHttpErrorStatusCode()
404
means the resource was not found.public String getHttpErrorMessage()
NOT FOUND
message is returned if the resource was not found.public String getDescription()
public boolean exists()
true
if this operation exists, false
otherwiseComputeException
- upon failurepublic boolean isDone()
true
. You can wait for operation
completion with:
while(!operation.isDone()) {
Thread.sleep(1000L);
}
true
if this operation is in Operation.Status.DONE
state or if it does
not exist, false
if the state is not Operation.Status.DONE
ComputeException
- upon failurepublic Operation waitFor(com.google.cloud.RetryOption... waitOptions) throws InterruptedException
null
. By default, the operation status is checked using jittered exponential
backoff with 1 second as an initial delay, 2.0 as a backoff factor, 1 minute as maximum delay
between polls, 12 hours as a total timeout and unlimited number of attempts.
Example usage of waitFor()
:
Operation completedOperation = operation.waitFor();
if (completedOperation == null) {
// operation no longer exists
} else if (completedOperation.errors() != null) {
// operation failed, handle error
} else {
// operation completed successfully
}
Example usage of waitFor()
with checking period and timeout:
Operation completedOperation =
operation.waitFor(
RetryOption.maxRetryDelay(Duration.ofSeconds(30)),
RetryOption.totalTimeout(Duration.ofMinutes(1)),
RetryOption.jittered(false));
if (completedOperation == null) {
// operation no longer exists
} else if (completedOperation.errors() != null) {
// operation failed, handle error
} else {
// operation completed successfully
}
waitOptions
- options to configure checking period and timeoutComputeException
- upon failure, check Throwable.getCause()
for detailsInterruptedException
- if the current thread gets interrupted while waiting for the
operation to completepublic Operation reload(Compute.OperationOption... options)
null
if the operation does not
exist.options
- operation optionsOperation
object with latest information or null
if not foundComputeException
- upon failurepublic boolean delete()
true
if operation was deleted, false
if it was not foundComputeException
- upon failureCopyright © 2019 Google LLC. All rights reserved.