use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class AutoStartVmsRunner method startFailedAutoStartVmsImpl.
private void startFailedAutoStartVmsImpl() {
LinkedList<AutoStartVmToRestart> vmsToRemove = new LinkedList<>();
final DateTime iterationStartTime = DateTime.getNow();
final Date nextTimeOfRetryToRun = iterationStartTime.addSeconds(RETRY_TO_RUN_AUTO_START_VM_INTERVAL);
final Date delayedTimeOfRetryToRun = iterationStartTime.addSeconds(DELAY_TO_RUN_AUTO_START_VM_INTERVAL);
for (AutoStartVmToRestart autoStartVmToRestart : autoStartVmsToRestart) {
// (we'll try again in the next iteration)
if (!autoStartVmToRestart.isTimeToRun(iterationStartTime)) {
continue;
}
Guid vmId = autoStartVmToRestart.getVmId();
if (isNextRunConfiguration(vmId)) {
// if the NextRun config exists then give the ProcessDownVmCommand time to apply it
log.debug("NextRun config found for '{}' vm, the RunVm will be delayed", vmId);
if (autoStartVmToRestart.delayNextTimeToRun(delayedTimeOfRetryToRun)) {
// The priority is to run the VM even if the NextRun fails to be applied
continue;
}
// Waiting for NextRun config is over, let's run the VM even with the non-applied Next-Run
log.warn("Failed to wait for the NextRun config to be applied on vm '{}', trying to run the VM anyway", vmId);
}
EngineLock runVmLock = createEngineLockForRunVm(vmId);
// acquired, skip for now and we'll try again in the next iteration
if (!acquireLock(runVmLock)) {
log.debug("Could not acquire lock for auto starting VM '{}'", vmId);
continue;
}
if (!isVmNeedsToBeAutoStarted(vmId)) {
// if the VM doesn't need to be auto started anymore, release the lock and
// remove the VM from the collection of VMs that should be auto started
releaseLock(runVmLock);
vmsToRemove.add(autoStartVmToRestart);
continue;
}
if (runVm(vmId, runVmLock)) {
// the VM reached WaitForLunch, so from now on this job is not responsible
// to auto start it, future failures will be detected by the monitoring
vmsToRemove.add(autoStartVmToRestart);
} else {
logFailedAttemptToRestartVm(vmId);
if (!autoStartVmToRestart.scheduleNextTimeToRun(nextTimeOfRetryToRun)) {
// if we could not schedule the next time to run the VM, it means
// that we reached the maximum number of tried so don't try anymore
vmsToRemove.add(autoStartVmToRestart);
logFailureToRestartVm(vmId);
}
}
}
autoStartVmsToRestart.removeAll(vmsToRemove);
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class ChangeVDSClusterCommand method glusterHostAdd.
private boolean glusterHostAdd(Guid targetClusterId) {
// condition.
try (EngineLock lock = glusterUtil.acquireGlusterLockWait(targetClusterId)) {
VDS runningHostInTargetCluster = glusterUtil.getUpServer(targetClusterId);
if (runningHostInTargetCluster == null) {
log.error("Cannot add host to target cluster, no host in Up status found in target cluster");
handleError(-1, "No host in Up status found in target cluster");
errorType = AuditLogType.GLUSTER_SERVER_ADD_FAILED;
return false;
}
VDSReturnValue returnValue = runVdsCommand(VDSCommandType.AddGlusterServer, new AddGlusterServerVDSParameters(runningHostInTargetCluster.getId(), getVds().getHostName()));
if (!returnValue.getSucceeded()) {
handleVdsError(returnValue);
errorType = AuditLogType.GLUSTER_SERVER_ADD_FAILED;
return false;
}
return true;
}
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class ChangeVDSClusterCommand method glusterHostRemove.
private boolean glusterHostRemove(Guid sourceClusterId) {
// condition.
try (EngineLock lock = glusterUtil.acquireGlusterLockWait(sourceClusterId)) {
VDS runningHostInSourceCluster = glusterUtil.getUpServer(sourceClusterId);
if (runningHostInSourceCluster == null) {
log.error("Cannot remove host from source cluster, no host in Up status found in source cluster");
handleError(-1, "No host in Up status found in source cluster");
errorType = AuditLogType.GLUSTER_SERVER_REMOVE_FAILED;
return false;
}
VDSReturnValue returnValue = runVdsCommand(VDSCommandType.RemoveGlusterServer, new RemoveGlusterServerVDSParameters(runningHostInSourceCluster.getId(), getVds().getHostName(), false));
if (!returnValue.getSucceeded()) {
handleVdsError(returnValue);
errorType = AuditLogType.GLUSTER_SERVER_REMOVE_FAILED;
return false;
}
return true;
}
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class HostLocking method acquireMonitorLock.
public EngineLock acquireMonitorLock(VDS host, String lockReleaseMessage, Logger log) {
Guid hostId = host.getId();
Map<String, Pair<String, String>> exclusiveLocks = Collections.singletonMap(hostId.toString(), new Pair<>(LockingGroup.VDS_INIT.name(), ""));
String closingMessage = calculateClosingMessage(lockReleaseMessage, host);
EngineLock monitoringLock = new HostEngineLock(exclusiveLocks, null, closingMessage, log);
log.info("Before acquiring lock in order to prevent monitoring for host '{}' from data-center '{}'", host.getName(), host.getStoragePoolName());
lockManager.acquireLockWait(monitoringLock);
log.info("Lock acquired, from now a monitoring of host will be skipped for host '{}' from data-center '{}'", host.getName(), host.getStoragePoolName());
return monitoringLock;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class GlusterSnapshotSyncJob method addOrUpdateSnapshotsConfig.
private void addOrUpdateSnapshotsConfig(Guid clusterId, GlusterSnapshotConfigInfo configInfo) {
Cluster cluster = clusterDao.get(clusterId);
try (EngineLock lock = acquireVolumeSnapshotLock(clusterId)) {
for (Map.Entry<String, String> entry : configInfo.getClusterConfigOptions().entrySet()) {
if (entry.getValue() != null) {
addOrUpdateClusterConfig(cluster, entry.getKey(), entry.getValue());
}
}
} catch (Exception e) {
log.error("Exception ocuured while adding/updating snapshots configurations from CLI - '{}'", e.getMessage());
log.debug("Exception", e);
throw new EngineException(EngineError.GlusterSnapshotInfoFailedException, e.getLocalizedMessage());
}
Map<String, Map<String, String>> volumeConfigs = configInfo.getVolumeConfigOptions();
for (Map.Entry<String, Map<String, String>> entry : volumeConfigs.entrySet()) {
GlusterVolumeEntity volume = volumeDao.getByName(clusterId, entry.getKey());
if (volume == null) {
continue;
}
try (EngineLock lock = acquireVolumeSnapshotLock(volume.getId())) {
Map<String, String> volumeConfig = entry.getValue();
if (volumeConfig != null) {
for (Map.Entry<String, String> entry1 : volumeConfig.entrySet()) {
if (entry.getValue() != null) {
addOrUpdateVolumeConfig(cluster, volume, entry1.getKey(), entry1.getValue());
}
}
}
} catch (Exception e) {
log.error("Exception ocuured while adding/updating snapshots configurations from CLI - '{}'", e.getMessage());
log.debug("Exception", e);
throw new EngineException(EngineError.GlusterSnapshotInfoFailedException, e.getLocalizedMessage());
}
}
}
Aggregations