use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class FenceVdsBaseCommand method executeCommand.
@Override
protected void executeCommand() {
log.info("Power-Management: {} of host '{}' initiated.", getAction(), getVdsName());
audit(AuditLogType.FENCE_OPERATION_STARTED);
VDSStatus lastStatus = getVds().getStatus();
FenceOperationResult result = null;
try {
setup();
result = createHostFenceActionExecutor(getVds(), getParameters().getFencingPolicy()).fence(getAction());
handleResult(result);
if (getSucceeded()) {
log.info("Power-Management: {} host '{}' succeeded.", getAction(), getVdsName());
audit(AuditLogType.FENCE_OPERATION_SUCCEEDED);
} else {
log.info("Power-Management: {} host '{}' failed.", getAction(), getVdsName());
audit(AuditLogType.FENCE_OPERATION_FAILED);
}
} finally {
if (!getSucceeded()) {
setStatus(lastStatus);
if (result != null && result.getStatus() != Status.SKIPPED_DUE_TO_POLICY) {
// show alert only if command was not skipped due to fencing policy
alertIfPowerManagementOperationFailed();
}
throw new EngineException(EngineError.VDS_FENCE_OPERATION_FAILED);
} else {
teardown();
}
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class ExternalNetworkManagerTest method testDeallocateIfExternalThrowException.
@Test
public void testDeallocateIfExternalThrowException() {
nic.setName(NIC_NAME);
nic.setId(NIC_ID);
provider.setName(PROVIDER_NAME);
doThrow(new EngineException()).when(networkProviderProxy).deallocate(nic);
underTest.deallocateIfExternal();
verify(auditLogDirector).log(auditLogableCaptor.capture(), same(AuditLogType.REMOVE_PORT_FROM_EXTERNAL_PROVIDER_FAILED));
final Map<String, String> capturedCustomValues = auditLogableCaptor.getValue().getCustomValues();
assertThat(capturedCustomValues, hasEntry("nicname", NIC_NAME));
assertThat(capturedCustomValues, hasEntry("nicid", NIC_ID.toString()));
assertThat(capturedCustomValues, hasEntry("providername", PROVIDER_NAME));
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class UpdateGlusterHookCommand method executeCommand.
@Override
protected void executeCommand() {
// check source to copy hook from - if engine copy or server copy
final boolean copyfromEngine = getParameters().getSourceServerId() == null;
entity = getGlusterHook();
addCustomValue(GlusterConstants.HOOK_NAME, entity.getName());
final String hookContent;
final String hookChecksum;
final GlusterHookContentType hookContentType;
if (copyfromEngine) {
hookContent = entity.getContent();
hookChecksum = entity.getChecksum();
hookContentType = entity.getContentType();
} else {
// use a server's copy
GlusterServerHook sourceServerHook = glusterHooksDao.getGlusterServerHook(entity.getId(), getParameters().getSourceServerId());
VDSReturnValue retValue = runVdsCommand(VDSCommandType.GetGlusterHookContent, new GlusterHookVDSParameters(getParameters().getSourceServerId(), entity.getGlusterCommand(), entity.getStage(), entity.getName()));
if (!retValue.getSucceeded()) {
// throw exception as we cannot continue without content
log.error("Failed to get content from server with id '{}': {}", getParameters().getSourceServerId(), retValue.getExceptionString());
throw new EngineException(retValue.getVdsError().getCode(), retValue.getVdsError().getMessage());
}
hookContent = (String) retValue.getReturnValue();
hookChecksum = sourceServerHook.getChecksum();
hookContentType = sourceServerHook.getContentType();
}
List<Callable<Pair<Guid, VDSReturnValue>>> taskList = new ArrayList<>();
List<Guid> serverIdsToUpdate = new ArrayList<>();
if (copyfromEngine) {
for (final GlusterServerHook serverHook : getContentConflictServerHooks()) {
serverIdsToUpdate.add(serverHook.getServerId());
}
} else {
// need to be updated with hook content
for (final VDS server : glusterUtil.getAllUpServers(entity.getClusterId())) {
if (!server.getId().equals(getParameters().getSourceServerId())) {
serverIdsToUpdate.add(server.getId());
}
}
}
for (final Guid serverId : serverIdsToUpdate) {
taskList.add(() -> {
VDSReturnValue returnValue;
returnValue = runVdsCommand(VDSCommandType.UpdateGlusterHook, new GlusterHookVDSParameters(serverId, entity.getGlusterCommand(), entity.getStage(), entity.getName(), hookContent, hookChecksum));
return new Pair<>(serverId, returnValue);
});
}
setSucceeded(true);
if (!taskList.isEmpty()) {
List<Pair<Guid, VDSReturnValue>> pairResults = ThreadPoolUtil.invokeAll(taskList);
for (Pair<Guid, VDSReturnValue> pairResult : pairResults) {
VDSReturnValue retValue = pairResult.getSecond();
if (!retValue.getSucceeded()) {
errors.add(retValue.getVdsError().getMessage());
}
}
} else {
setSucceeded(false);
}
if (errors.size() > 0) {
setSucceeded(false);
errorType = AuditLogType.GLUSTER_HOOK_UPDATE_FAILED;
handleVdsErrors(getAuditLogTypeValue(), errors);
addCustomValue(GlusterConstants.FAILURE_MESSAGE, StringUtils.join(errors, System.lineSeparator()));
}
if (getSucceeded() && !copyfromEngine) {
// update server's content copy
entity.setChecksum(hookChecksum);
entity.setContent(hookContent);
entity.setContentType(hookContentType);
}
if (getSucceeded()) {
entity.removeContentConflict();
updateGlusterHook(entity);
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class UpdateHostNicVfsConfigCommand method executeCommand.
@Override
protected void executeCommand() {
boolean result = true;
HostNicVfsConfig oldVfsConfig = getVfsConfig();
boolean allNetworksAllowedChanged = isAllNetworksAllowed() != oldVfsConfig.isAllNetworksAllowed();
super.executeCommand();
// Check if 'allNetworksAllowed' has changed
if (allNetworksAllowedChanged) {
oldVfsConfig.setAllNetworksAllowed(isAllNetworksAllowed());
if (isAllNetworksAllowed()) {
oldVfsConfig.setNetworks(Collections.emptySet());
oldVfsConfig.setNetworkLabels(Collections.emptySet());
}
}
boolean shouldRefreshHost = false;
if (wasNumOfVfsChanged()) {
shouldRefreshHost = true;
String deviceName = networkDeviceHelper.getPciDeviceNameByNic(getNic());
try {
VDSReturnValue returnValue = runVdsCommand(VDSCommandType.HostDevChangeNumVfs, new HostDevChangeNumVfsVDSParameters(getVdsId(), deviceName, getNumOfVfs()));
result = returnValue.getSucceeded();
} catch (EngineException e) {
throw new EngineException(EngineError.UPDATE_NUM_VFS_FAILURE);
}
}
if (result) {
setSucceeded(saveChangesToDb(shouldRefreshHost, oldVfsConfig, allNetworksAllowedChanged));
}
}
use of org.ovirt.engine.core.common.errors.EngineException in project ovirt-engine by oVirt.
the class DestroyImageCommand method executeCommand.
@Override
protected void executeCommand() {
getParameters().setEntityInfo(new EntityInfo(VdcObjectType.Disk, getParameters().getImageGroupId()));
VDSReturnValue vdsReturnValue = null;
try {
vdsReturnValue = runVdsCommand(VDSCommandType.DestroyImage, createVDSParameters());
} catch (EngineException e) {
log.error("Failed to delete image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get(), e);
if (!getParameters().isLiveMerge()) {
throw e;
}
}
if (vdsReturnValue != null && vdsReturnValue.getCreationInfo() != null) {
Guid taskId = persistAsyncTaskPlaceHolder(getParameters().getParentCommand());
Guid result = createTask(taskId, vdsReturnValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, getParameters().getStorageDomainId());
getTaskIdList().add(result);
log.info("Successfully started task to remove orphaned volumes resulting from live merge");
} else {
log.info("Retrying deleting image {}/{}", getParameters().getImageGroupId(), getParameters().getImageList().stream().findFirst().get());
MergeStatusReturnValue returnValue = new MergeStatusReturnValue(VmBlockJobType.COMMIT, new HashSet<>(getParameters().getImageList()));
getReturnValue().setActionReturnValue(returnValue);
// At this point, we know that this command was executed during live merge and it is safe to do
// the casting in the next line.
((RemoveSnapshotSingleDiskParameters) getParameters().getParentParameters()).setNextCommandStep(RemoveSnapshotSingleDiskStep.DESTROY_IMAGE);
}
setSucceeded(true);
setCommandStatus(CommandStatus.SUCCEEDED);
}
Aggregations