Search in sources :

Example 46 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class RunVmCommand method createContextForStatelessSnapshotCreation.

private CommandContext createContextForStatelessSnapshotCreation() {
    Map<String, String> values = getVmValuesForMsgResolving();
    // Creating snapshots as sub step of run stateless
    Step createSnapshotsStep = addSubStep(StepEnum.EXECUTING, StepEnum.CREATING_SNAPSHOTS, values);
    // Add the step as the first step of the new context
    ExecutionContext createSnapshotsCtx = new ExecutionContext();
    createSnapshotsCtx.setMonitored(true);
    createSnapshotsCtx.setStep(createSnapshotsStep);
    getContext().withExecutionContext(createSnapshotsCtx);
    persistCommandIfNeeded();
    return getContext().clone().withoutCompensationContext();
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

Example 47 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class MaintenanceNumberOfVdssCommand method validateNoRunningJobs.

private boolean validateNoRunningJobs(VDS vds) {
    List<Step> steps = stepDao.getStartedStepsByStepSubjectEntity(new SubjectEntity(VdcObjectType.EXECUTION_HOST, vds.getId()));
    if (!steps.isEmpty()) {
        List<String> replacements = new ArrayList<>(2);
        replacements.add(ReplacementUtils.createSetVariableString("host", vds.getName()));
        replacements.addAll(ReplacementUtils.replaceWith("jobs", steps.stream().map(s -> s.getDescription()).collect(Collectors.toList())));
        return failValidation(EngineMessage.VDS_CANNOT_MAINTENANCE_HOST_WITH_RUNNING_OPERATIONS, replacements);
    }
    return true;
}
Also used : SetVdsStatusVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.SetVdsStatusVDSCommandParameters) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) StringUtils(org.apache.commons.lang.StringUtils) AsyncTaskDao(org.ovirt.engine.core.dao.AsyncTaskDao) StepDao(org.ovirt.engine.core.dao.StepDao) CancelMigrationVDSParameters(org.ovirt.engine.core.vdsbroker.vdsbroker.CancelMigrationVDSParameters) VmDynamicDao(org.ovirt.engine.core.dao.VmDynamicDao) AsyncTask(org.ovirt.engine.core.common.businessentities.AsyncTask) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) HostedEngineHelper(org.ovirt.engine.core.bll.hostedengine.HostedEngineHelper) ActionType(org.ovirt.engine.core.common.action.ActionType) VdsDao(org.ovirt.engine.core.dao.VdsDao) Map(java.util.Map) EngineMessage(org.ovirt.engine.core.common.errors.EngineMessage) MaintenanceVdsParameters(org.ovirt.engine.core.common.action.MaintenanceVdsParameters) Set(java.util.Set) NetworkDao(org.ovirt.engine.core.dao.network.NetworkDao) Collectors(java.util.stream.Collectors) VdsSpmStatus(org.ovirt.engine.core.common.businessentities.VdsSpmStatus) VmDao(org.ovirt.engine.core.dao.VmDao) VdsDynamicDao(org.ovirt.engine.core.dao.VdsDynamicDao) List(java.util.List) VDSStatus(org.ovirt.engine.core.common.businessentities.VDSStatus) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) SubjectEntity(org.ovirt.engine.core.common.businessentities.SubjectEntity) Guid(org.ovirt.engine.core.compat.Guid) ReplacementUtils(org.ovirt.engine.core.utils.ReplacementUtils) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ExecutionHandler(org.ovirt.engine.core.bll.job.ExecutionHandler) AffinityGroupDao(org.ovirt.engine.core.dao.scheduling.AffinityGroupDao) NetworkClusterHelper(org.ovirt.engine.core.bll.network.cluster.NetworkClusterHelper) Network(org.ovirt.engine.core.common.businessentities.network.Network) Pair(org.ovirt.engine.core.common.utils.Pair) LockingGroup(org.ovirt.engine.core.common.locks.LockingGroup) Iterator(java.util.Iterator) MultipleVmsValidator(org.ovirt.engine.core.bll.validator.MultipleVmsValidator) VM(org.ovirt.engine.core.common.businessentities.VM) PermissionSubject(org.ovirt.engine.core.bll.utils.PermissionSubject) ImageTransfer(org.ovirt.engine.core.common.businessentities.storage.ImageTransfer) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) GlusterHostValidator(org.ovirt.engine.core.bll.gluster.GlusterHostValidator) MigrationSupport(org.ovirt.engine.core.common.businessentities.MigrationSupport) ImageTransferDao(org.ovirt.engine.core.dao.ImageTransferDao) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) VmDynamic(org.ovirt.engine.core.common.businessentities.VmDynamic) MaintenanceNumberOfVdssParameters(org.ovirt.engine.core.common.action.MaintenanceNumberOfVdssParameters) VMStatus(org.ovirt.engine.core.common.businessentities.VMStatus) Step(org.ovirt.engine.core.common.job.Step) SubjectEntity(org.ovirt.engine.core.common.businessentities.SubjectEntity) ArrayList(java.util.ArrayList) Step(org.ovirt.engine.core.common.job.Step)

Example 48 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class MaintenanceVdsCommand method createMigrateVmContext.

protected CommandContext createMigrateVmContext(ExecutionContext parentContext, VM vm) {
    ExecutionContext ctx = new ExecutionContext();
    try {
        Map<String, String> values = new HashMap<>();
        values.put(VdcObjectType.VM.name().toLowerCase(), vm.getName());
        values.put(VdcObjectType.VDS.name().toLowerCase(), vm.getRunOnVdsName());
        Step step = executionHandler.addSubStep(getExecutionContext(), parentContext.getJob().getStep(StepEnum.EXECUTING), StepEnum.MIGRATE_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.MIGRATE_VM, values));
        ctx.setJob(parentContext.getJob());
        ctx.setStep(step);
        ctx.setMonitored(true);
    } catch (RuntimeException e) {
        log.error("Failed to create ExecutionContext for MigrateVmCommand", e);
    }
    return cloneContextAndDetachFromParent().withExecutionContext(ctx);
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) HashMap(java.util.HashMap) Step(org.ovirt.engine.core.common.job.Step)

Example 49 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class AddUnmanagedVmsCommand method createAddExternalVmContext.

protected CommandContext createAddExternalVmContext(VmStatic vmStatic) {
    ExecutionContext ctx = new ExecutionContext();
    try {
        Step step = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.ADD_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.ADD_VM, Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), vmStatic.getName())));
        ctx.setJob(getExecutionContext().getJob());
        ctx.setStep(step);
        ctx.setMonitored(true);
    } catch (RuntimeException e) {
        log.error("Failed to create ExecutionContext for AddVmFromScratch", e);
    }
    return cloneContextAndDetachFromParent().withExecutionContext(ctx);
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

Example 50 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class CommandBase method executeAction.

public ActionReturnValue executeAction() {
    getSessionDataContainer().updateSessionLastActiveTime(getParameters().getSessionId());
    determineExecutionReason();
    actionState = CommandActionState.EXECUTE;
    String tempVar = getDescription();
    getReturnValue().setDescription((tempVar != null) ? tempVar : getReturnValue().getDescription());
    setActionMessageParameters();
    Step validatingStep = null;
    boolean actionAllowed;
    boolean isExternal = this.getParameters().getJobId() != null || this.getParameters().getStepId() != null;
    if (!isExternal) {
        validatingStep = executionHandler.addStep(getExecutionContext(), StepEnum.VALIDATING, null);
    }
    try {
        if (parentHasCallback()) {
            persistCommand(getParameters().getParentCommand());
        }
        actionAllowed = getReturnValue().isValid() || internalValidate();
        if (!isExternal) {
            executionHandler.endStep(getExecutionContext(), validatingStep, actionAllowed);
        }
        if (actionAllowed) {
            execute();
        } else {
            getReturnValue().setValid(false);
        }
    } finally {
        updateCommandIfNeeded();
        freeLockExecute();
        clearAsyncTasksWithOutVdsmId();
    }
    return getReturnValue();
}
Also used : Step(org.ovirt.engine.core.common.job.Step)

Aggregations

Step (org.ovirt.engine.core.common.job.Step)52 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)14 Guid (org.ovirt.engine.core.compat.Guid)12 HashMap (java.util.HashMap)8 Job (org.ovirt.engine.core.common.job.Job)8 Date (java.util.Date)7 Test (org.junit.Test)6 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)6 ArrayList (java.util.ArrayList)5 JobExecutionStatus (org.ovirt.engine.core.common.job.JobExecutionStatus)5 List (java.util.List)4 VdcObjectType (org.ovirt.engine.core.common.VdcObjectType)4 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)4 StepSubjectEntity (org.ovirt.engine.core.common.job.StepSubjectEntity)4 Map (java.util.Map)3 StepEnum (org.ovirt.engine.core.common.job.StepEnum)3 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2