Search in sources :

Example 21 with Step

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

the class JobRepositoryImpl method buildStepsTree.

/**
 * Gets a list of {@link Step} entities ordered by:
 * <li> parent step id, preceded by nulls
 * <li> step number
 * @return a collection of the steps.
 */
private List<Step> buildStepsTree(List<Step> steps) {
    List<Step> jobDirectSteps = new ArrayList<>();
    // a map of parent step id and a list of child-steps
    Map<Guid, List<Step>> parentStepMap = new HashMap<>();
    for (Step step : steps) {
        if (step.getParentStepId() == null) {
            jobDirectSteps.add(step);
        } else {
            parentStepMap.computeIfAbsent(step.getParentStepId(), k -> new ArrayList<>()).add(step);
        }
    }
    for (Step step : steps) {
        if (parentStepMap.containsKey(step.getId())) {
            step.setSteps(parentStepMap.get(step.getId()));
        }
    }
    return jobDirectSteps;
}
Also used : StepSubjectEntity(org.ovirt.engine.core.common.job.StepSubjectEntity) StepDao(org.ovirt.engine.core.dao.StepDao) Date(java.util.Date) Job(org.ovirt.engine.core.common.job.Job) Guid(org.ovirt.engine.core.compat.Guid) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Singleton(javax.inject.Singleton) JobSubjectEntityDao(org.ovirt.engine.core.dao.JobSubjectEntityDao) TransactionSupport(org.ovirt.engine.core.utils.transaction.TransactionSupport) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ActionType(org.ovirt.engine.core.common.action.ActionType) Map(java.util.Map) JobExecutionStatus(org.ovirt.engine.core.common.job.JobExecutionStatus) Logger(org.slf4j.Logger) JobDao(org.ovirt.engine.core.dao.JobDao) Collection(java.util.Collection) Set(java.util.Set) StepSubjectEntityDao(org.ovirt.engine.core.dao.StepSubjectEntityDao) List(java.util.List) Entry(java.util.Map.Entry) VdcObjectType(org.ovirt.engine.core.common.VdcObjectType) Collections(java.util.Collections) Step(org.ovirt.engine.core.common.job.Step) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Step(org.ovirt.engine.core.common.job.Step) Guid(org.ovirt.engine.core.compat.Guid)

Example 22 with Step

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

the class StepDaoTest method updateJobStepsCompleted.

@Test
public void updateJobStepsCompleted() {
    Step step = dao.get(IN_PROGRESS_STEP_ID);
    assertNotNull("Started step with ID " + IN_PROGRESS_STEP_ID, step);
    step.setStatus(JobExecutionStatus.FINISHED);
    Date endTime = new Date();
    step.setEndTime(endTime);
    dao.updateJobStepsCompleted(IN_PROGRESS_JOB_ID, JobExecutionStatus.FINISHED, endTime);
    Step afterUpdate = dao.get(IN_PROGRESS_STEP_ID);
    assertEquals("Compare step to itself after update in DB", step, afterUpdate);
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Date(java.util.Date) Test(org.junit.Test)

Example 23 with Step

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

the class StepDaoTest method getStepsByExternalId.

@Test
public void getStepsByExternalId() {
    List<Step> steps = dao.getStepsByExternalId(IN_PROGRESS_REBALANCING_GLUSTER_VOLUME_TASK_ID);
    assertEquals("Verify Rebalancing Gluster Volume Job has steps", TOTAL_STEPS_OF_REBALANCING_GLUSTER_VOLUME, steps.size());
    Step step = steps.get(0);
    assertEquals("Verify the Step Type status", StepEnum.REBALANCING_VOLUME, step.getStepType());
    assertEquals("Verify the Step status", JobExecutionStatus.STARTED, step.getStatus());
    assertEquals("Invalid Step", REBALANCING_GLUSTER_VOLUME_STEP_ID, step.getId());
}
Also used : Step(org.ovirt.engine.core.common.job.Step) Test(org.junit.Test)

Example 24 with Step

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

the class AddVdsCommand method executeCommand.

@Override
protected void executeCommand() {
    Guid oVirtId = getParameters().getVdsForUniqueId();
    if (oVirtId != null) {
        // if fails to remove deprecated entry, we might attempt to add new oVirt host with an existing unique-id.
        if (!removeDeprecatedOvirtEntry(oVirtId)) {
            log.error("Failed to remove duplicated oVirt entry with id '{}'. Abort adding oVirt Host type", oVirtId);
            throw new EngineException(EngineError.HOST_ALREADY_EXISTS);
        }
    }
    completeOpenstackNetworkProviderId();
    TransactionSupport.executeInNewTransaction(() -> {
        addVdsStaticToDb();
        addVdsDynamicToDb();
        addVdsStatisticsToDb();
        addAffinityLabels();
        getCompensationContext().stateChanged();
        return null;
    });
    if (getParameters().isProvisioned()) {
        HostProviderProxy proxy = providerProxyFactory.create(getHostProvider());
        proxy.provisionHost(getParameters().getvds(), getParameters().getHostGroup(), getParameters().getComputeResource(), getParameters().getHostMac(), getParameters().getDiscoverName(), getParameters().getPassword(), getParameters().getDiscoverIp());
        addCustomValue("HostGroupName", getParameters().getHostGroup().getName());
        auditLogDirector.log(this, AuditLogType.VDS_PROVISION);
    }
    // set vds spm id
    if (getCluster().getStoragePoolId() != null) {
        VdsActionParameters tempVar = new VdsActionParameters(getVdsIdRef());
        tempVar.setSessionId(getParameters().getSessionId());
        tempVar.setCompensationEnabled(true);
        ActionReturnValue addVdsSpmIdReturn = runInternalAction(ActionType.AddVdsSpmId, tempVar, cloneContext().withoutLock().withoutExecutionContext());
        if (!addVdsSpmIdReturn.getSucceeded()) {
            setSucceeded(false);
            getReturnValue().setFault(addVdsSpmIdReturn.getFault());
            return;
        }
    }
    TransactionSupport.executeInNewTransaction(() -> {
        initializeVds(true);
        alertIfPowerManagementNotConfigured(getParameters().getVdsStaticData());
        testVdsPowerManagementStatus(getParameters().getVdsStaticData());
        setSucceeded(true);
        setActionReturnValue(getVdsIdRef());
        // If the installation failed, we don't want to compensate for the failure since it will remove the
        // host, but instead the host should be left in an "install failed" status.
        getCompensationContext().cleanupCompensationDataAfterSuccessfulCommand();
        return null;
    });
    // clients). they are installed as part of the approve process or automatically after provision
    if (Config.<Boolean>getValue(ConfigValues.InstallVds) && !getParameters().isPending() && !getParameters().isProvisioned()) {
        final InstallVdsParameters installVdsParameters = new InstallVdsParameters(getVdsId(), getParameters().getPassword());
        installVdsParameters.setAuthMethod(getParameters().getAuthMethod());
        installVdsParameters.setOverrideFirewall(getParameters().getOverrideFirewall());
        installVdsParameters.setActivateHost(getParameters().getActivateHost());
        installVdsParameters.setNetworkProviderId(getParameters().getVdsStaticData().getOpenstackNetworkProviderId());
        installVdsParameters.setNetworkMappings(getParameters().getNetworkMappings());
        installVdsParameters.setEnableSerialConsole(getParameters().getEnableSerialConsole());
        if (getParameters().getHostedEngineDeployConfiguration() != null) {
            Map<String, String> vdsDeployParams = hostedEngineHelper.createVdsDeployParams(getVdsId(), getParameters().getHostedEngineDeployConfiguration().getDeployAction());
            installVdsParameters.setHostedEngineConfiguration(vdsDeployParams);
        }
        Map<String, String> values = new HashMap<>();
        values.put(VdcObjectType.VDS.name().toLowerCase(), getParameters().getvds().getName());
        Step installStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.INSTALLING_HOST, ExecutionMessageDirector.resolveStepMessage(StepEnum.INSTALLING_HOST, values));
        final ExecutionContext installCtx = new ExecutionContext();
        installCtx.setJob(getExecutionContext().getJob());
        installCtx.setStep(installStep);
        installCtx.setMonitored(true);
        installCtx.setShouldEndJob(true);
        ThreadPoolUtil.execute(() -> runInternalAction(ActionType.InstallVdsInternal, installVdsParameters, cloneContextAndDetachFromParent().withExecutionContext(installCtx)));
        ExecutionHandler.setAsyncJob(getExecutionContext(), true);
    }
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) HashMap(java.util.HashMap) InstallVdsParameters(org.ovirt.engine.core.common.action.hostdeploy.InstallVdsParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) AddVdsActionParameters(org.ovirt.engine.core.common.action.hostdeploy.AddVdsActionParameters) Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step) HostProviderProxy(org.ovirt.engine.core.bll.host.provider.HostProviderProxy)

Example 25 with Step

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

the class GlusterTaskUtils method updateSteps.

public void updateSteps(Cluster cluster, GlusterAsyncTask task, List<Step> steps) {
    // update status in step table
    for (Step step : steps) {
        if (step.getEndTime() != null) {
            // we have already processed the task
            continue;
        }
        JobExecutionStatus oldStatus = step.getStatus();
        step.setDescription(getTaskMessage(cluster, step.getStepType(), task));
        step.setStatus(task.getStatus());
        logEventMessage(task, oldStatus, cluster);
        if (hasTaskCompleted(task)) {
            step.markStepEnded(task.getStatus());
            endStepJob(step);
            releaseVolumeLock(task.getTaskId());
        } else {
            jobRepository.updateStep(step);
        }
    }
}
Also used : JobExecutionStatus(org.ovirt.engine.core.common.job.JobExecutionStatus) 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