Search in sources :

Example 11 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class ImportHostedEngineStorageDomainCommandTest method prepareCommand.

protected void prepareCommand() {
    parameters.setStoragePoolId(HE_SP_ID);
    parameters.setVdsId(HE_VDS_ID);
    parameters.setStorageDomainId(HE_SD_ID);
    // vds
    VDS vds = new VDS();
    vds.setId(Guid.Empty);
    vds.setStoragePoolId(HE_SP_ID);
    when(vdsDao.get(any())).thenReturn(vds);
    List<BaseDisk> baseDisks = Collections.singletonList(new BaseDisk());
    when(baseDiskDao.getDisksByAlias(any())).thenReturn(baseDisks);
    // Data center
    StoragePool pool = new StoragePool();
    pool.setStatus(StoragePoolStatus.Up);
    pool.setId(HE_SP_ID);
    when(storagePoolDao.get(HE_SP_ID)).thenReturn(pool);
    // compensation
    CompensationContext compensationContext = mock(CompensationContext.class);
    when(cmd.getCompensationContext()).thenReturn(compensationContext);
    when(cmd.getContext()).thenReturn(new CommandContext(new EngineContext()));
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) CompensationContext(org.ovirt.engine.core.bll.context.CompensationContext) BaseDisk(org.ovirt.engine.core.common.businessentities.storage.BaseDisk) EngineContext(org.ovirt.engine.core.bll.context.EngineContext)

Example 12 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class TryBackToAllSnapshotsOfVmCommand method updateVm.

private boolean updateVm(VmStatic vm, Version oldClusterVersion, boolean disableLock) {
    VmManagementParametersBase updateParams = new VmManagementParametersBase(vm);
    updateParams.setClusterLevelChangeFromVersion(oldClusterVersion);
    CommandContext context;
    if (disableLock) {
        updateParams.setLockProperties(LockProperties.create(LockProperties.Scope.None));
        context = cloneContextAndDetachFromParent();
    } else {
        // Wait for VM lock
        EngineLock updateVmLock = createUpdateVmLock();
        // will be released by UpdateVmCommand
        lockManager.acquireLockWait(updateVmLock);
        context = ExecutionHandler.createInternalJobContext(updateVmLock);
    }
    ActionReturnValue result = runInternalAction(ActionType.UpdateVm, updateParams, context);
    if (!result.getSucceeded()) {
        getReturnValue().setFault(result.getFault());
        return false;
    }
    return true;
}
Also used : CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 13 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class InitVdsOnUpCommand method refreshHostDeviceList.

private void refreshHostDeviceList() {
    try {
        CommandContext ctx = cloneContext();
        ctx.getExecutionContext().setJobRequired(false);
        runInternalAction(ActionType.RefreshHostDevices, new VdsActionParameters(getVdsId()), ctx);
    } catch (EngineException e) {
        log.error("Could not refresh host devices for host '{}'", getVds().getName());
    }
}
Also used : CommandContext(org.ovirt.engine.core.bll.context.CommandContext) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 14 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class NetworkClustersToSetupNetworksParametersTransformerImpl method createSetupNetworksParameters.

private List<PersistentHostSetupNetworksParameters> createSetupNetworksParameters(Map<Guid, List<Network>> attachNetworksByHost, Map<Guid, Map<String, VdsNetworkInterface>> labelsToNicsByHost, Map<Guid, List<Network>> detachNetworksByHost, Map<Guid, List<Network>> updates) {
    final List<PersistentHostSetupNetworksParameters> parameters = new ArrayList<>(attachNetworksByHost.size());
    final ManageNetworksParametersBuilder builder = manageNetworksParametersBuilderFactory.create(commandContext, interfaceDao, vdsStaticDao, networkClusterDao, networkAttachmentDao);
    Set<Guid> hostIds = Stream.of(attachNetworksByHost, detachNetworksByHost, updates).flatMap(e -> e.keySet().stream()).collect(Collectors.toSet());
    for (Guid hostId : hostIds) {
        final Map<String, VdsNetworkInterface> nicsByLabel = labelsToNicsByHost.get(hostId);
        parameters.add(builder.buildParameters(hostId, nullToEmptyList(attachNetworksByHost.get(hostId)), nullToEmptyList(detachNetworksByHost.get(hostId)), nicsByLabel == null ? Collections.emptyMap() : nicsByLabel, nullToEmptyList(updates.get(hostId))));
    }
    return parameters;
}
Also used : ManageNetworksParametersBuilderFactory(org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilderFactory) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) NetworkImplementationDetailsUtils(org.ovirt.engine.core.vdsbroker.NetworkImplementationDetailsUtils) Function(java.util.function.Function) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) NetworkAttachmentDao(org.ovirt.engine.core.dao.network.NetworkAttachmentDao) ArrayList(java.util.ArrayList) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) Map(java.util.Map) Network(org.ovirt.engine.core.common.businessentities.network.Network) ManageNetworksParametersBuilder(org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilder) PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) CollectionUtils.nullToEmptyList(org.ovirt.engine.core.utils.CollectionUtils.nullToEmptyList) Collection(java.util.Collection) Set(java.util.Set) NetworkDao(org.ovirt.engine.core.dao.network.NetworkDao) Collectors(java.util.stream.Collectors) VdsStaticDao(org.ovirt.engine.core.dao.VdsStaticDao) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) InterfaceDao(org.ovirt.engine.core.dao.network.InterfaceDao) Collections(java.util.Collections) NetworkClusterDao(org.ovirt.engine.core.dao.network.NetworkClusterDao) PersistentHostSetupNetworksParameters(org.ovirt.engine.core.common.action.PersistentHostSetupNetworksParameters) ManageNetworksParametersBuilder(org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilder) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) Guid(org.ovirt.engine.core.compat.Guid)

Example 15 with CommandContext

use of org.ovirt.engine.core.bll.context.CommandContext in project ovirt-engine by oVirt.

the class CommandHelper method buildCommand.

public static CommandBase<?> buildCommand(ActionType actionType, ActionParametersBase parameters, ExecutionContext executionContext, CommandStatus cmdStatus) {
    ExecutionContext cmdExecutionContext = executionContext == null ? new ExecutionContext() : executionContext;
    CommandBase<?> command = CommandsFactory.createCommand(actionType, parameters, new CommandContext(new EngineContext()).withExecutionContext(cmdExecutionContext));
    command.setCommandStatus(cmdStatus, false);
    return command;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) EngineContext(org.ovirt.engine.core.bll.context.EngineContext)

Aggregations

CommandContext (org.ovirt.engine.core.bll.context.CommandContext)15 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)9 EngineContext (org.ovirt.engine.core.bll.context.EngineContext)5 Step (org.ovirt.engine.core.common.job.Step)5 HashMap (java.util.HashMap)3 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 CompensationContext (org.ovirt.engine.core.bll.context.CompensationContext)1 ManageNetworksParametersBuilder (org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilder)1 ManageNetworksParametersBuilderFactory (org.ovirt.engine.core.bll.network.ManageNetworksParametersBuilderFactory)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1