Skip to content

Commit

Permalink
core: make register-vm a sync operation
Browse files Browse the repository at this point in the history
In 38d5120 we've changed adding vm from configuration to
be blocking/sync operations. Here we do the same for calls to
register-vm for the same reason - this operation doesn't involve
copying the disks, only add-lease is asynchronous and it is a
relatively short operation, so the caller won't wait much and
at the end of the call the vm is ready to be used.

This is particularly important for disaster recovery as we try
to start highly available vms right after registering them. It
might have been better to change the disaster recovery scripts
to specify async=false, but that would require more efforts.

Bug-Url: https://bugzilla.redhat.com/1968433
Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed Sep 14, 2022
1 parent 622567a commit 690fabb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected Response doAction(final ActionType task, final ActionParametersBase pa
if (actionResult.getJobId() != null) {
setJobLink(action, actionResult);
}
if (actionResult.getHasAsyncTasks()) {
if (isAsyncTaskOrJobExists(pollingType, actionResult)) {
if (expectBlocking(action)) {
CreationStatus status = awaitCompletion(actionResult, pollingType);
return actionStatus(status, action, addLinks(newModel(id)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,28 +263,6 @@ private <T> Response fetchCreatedEntity(IResolver<T, Q> entityResolver,
return response;
}

/**
* Returns true if there are still processes running in the
* background, associated with the current request.
*
* For vdsm-task polling, the indication is the existence of running
* vdsm tasks.
*
* For job polling, the indication is that the job is in PENDING or
* IN_PROGRESS status.
*/
private boolean isAsyncTaskOrJobExists(PollingType pollingType, ActionReturnValue createResult) {
if (pollingType==PollingType.VDSM_TASKS) {
//when the polling-type is vdsm_tasks, check for existing async-tasks
return createResult.getHasAsyncTasks();
} else if (pollingType==PollingType.JOB) {
//when the polling-type is job, check if the job is pending or in progress
CreationStatus status = getJobIdStatus(createResult);
return status==CreationStatus.PENDING || status==CreationStatus.IN_PROGRESS;
}
return false; //shouldn't reach here
}

/**
* In rare cases, after entity creation there is a need to make modifications
* to the created entity. Such changes should be done here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ private CreationStatus getVdsmTasksStatus(ActionReturnValue result) {
return asyncStatus;
}

/**
* Returns true if there are still processes running in the
* background, associated with the current request.
*
* For vdsm-task polling, the indication is the existence of running
* vdsm tasks.
*
* For job polling, the indication is that the job is in PENDING or
* IN_PROGRESS status.
*/
protected boolean isAsyncTaskOrJobExists(PollingType pollingType, ActionReturnValue createResult) {
if (pollingType==PollingType.VDSM_TASKS) {
//when the polling-type is vdsm_tasks, check for existing async-tasks
return createResult.getHasAsyncTasks();
} else if (pollingType==PollingType.JOB) {
//when the polling-type is job, check if the job is pending or in progress
CreationStatus status = getJobIdStatus(createResult);
return status==CreationStatus.PENDING || status==CreationStatus.IN_PROGRESS;
}
return false; //shouldn't reach here
}

protected CreationStatus getJobIdStatus(ActionReturnValue result) {
Guid jobId = result.getJobId();
if (jobId == null || jobId.equals(Guid.Empty)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public Response register(Action action) {
params.setClusterId(getClusterId(action));
}
params.setImagesExistOnTargetStorageDomain(true);
action.setAsync(false);

if (action.isSetClone()) {
params.setImportAsNewEntity(action.isClone());
Expand All @@ -117,7 +118,7 @@ public Response register(Action action) {
if (action.isSetName()) {
params.setName(action.getName());
}
return doAction(ActionType.ImportVmFromConfiguration, params, action);
return doAction(ActionType.ImportVmFromConfiguration, params, action, PollingType.JOB);
}

@Override
Expand Down

0 comments on commit 690fabb

Please sign in to comment.