Search in sources :

Example 1 with CommandExecLogVO

use of com.cloud.secstorage.CommandExecLogVO in project cloudstack by apache.

the class BaseImageStoreDriverImpl method sendToLeastBusyEndpoint.

private Answer sendToLeastBusyEndpoint(List<EndPoint> eps, CopyCommand cmd) {
    Answer answer = null;
    EndPoint endPoint = null;
    List<Long> epIds = ssvmWithLeastMigrateJobs();
    if (epIds.isEmpty()) {
        Collections.shuffle(eps);
        endPoint = eps.get(0);
    } else {
        List<EndPoint> remainingEps = eps.stream().filter(ep -> !epIds.contains(ep.getId())).collect(Collectors.toList());
        if (!remainingEps.isEmpty()) {
            Collections.shuffle(remainingEps);
            endPoint = remainingEps.get(0);
        } else {
            endPoint = _defaultEpSelector.getEndPointFromHostId(epIds.get(0));
        }
    }
    CommandExecLogVO execLog = new CommandExecLogVO(endPoint.getId(), _secStorageVmDao.findByInstanceName(hostDao.findById(endPoint.getId()).getName()).getId(), "DataMigrationCommand", 1);
    Long cmdExecId = _cmdExecLogDao.persist(execLog).getId();
    String errMsg = null;
    try {
        answer = agentMgr.send(endPoint.getId(), cmd);
        answer.setContextParam("cmd", cmdExecId.toString());
        return answer;
    } catch (AgentUnavailableException e) {
        errMsg = e.toString();
        LOGGER.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString());
    } catch (OperationTimedoutException e) {
        errMsg = e.toString();
        LOGGER.debug("Failed to send command, due to Agent:" + endPoint.getId() + ", " + e.toString());
    }
    throw new CloudRuntimeException("Failed to send command, due to Agent:" + endPoint.getId() + ", " + errMsg);
}
Also used : HostDao(com.cloud.host.dao.HostDao) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) GetDatadisksAnswer(com.cloud.agent.api.storage.GetDatadisksAnswer) AlertManager(com.cloud.alert.AlertManager) TemplateDataStoreDao(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao) AgentManager(com.cloud.agent.AgentManager) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Logger(org.apache.log4j.Logger) CommandExecLogDao(com.cloud.secstorage.CommandExecLogDao) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) CommandResult(org.apache.cloudstack.storage.command.CommandResult) ResultSet(java.sql.ResultSet) DeployAsIsHelper(org.apache.cloudstack.storage.image.deployasis.DeployAsIsHelper) Map(java.util.Map) ResourceLimitService(com.cloud.user.ResourceLimitService) URI(java.net.URI) Answer(com.cloud.agent.api.Answer) Config(com.cloud.configuration.Config) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) DataTO(com.cloud.agent.api.to.DataTO) VolumeDataStoreDao(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) List(java.util.List) VolumeDataStoreVO(org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) AccountDao(com.cloud.user.dao.AccountDao) Upload(com.cloud.storage.Upload) NumbersUtil(com.cloud.utils.NumbersUtil) DataObjectType(com.cloud.agent.api.to.DataObjectType) AsyncCompletionCallback(org.apache.cloudstack.framework.async.AsyncCompletionCallback) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) VMTemplateDao(com.cloud.storage.dao.VMTemplateDao) Proxy(com.cloud.utils.net.Proxy) OVFInformationTO(com.cloud.agent.api.to.OVFInformationTO) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) TemplateInfo(org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo) TemplateDataStoreVO(org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO) DefaultEndPointSelector(org.apache.cloudstack.storage.endpoint.DefaultEndPointSelector) VolumeDao(com.cloud.storage.dao.VolumeDao) VMTemplateStorageResourceAssoc(com.cloud.storage.VMTemplateStorageResourceAssoc) DatadiskTO(com.cloud.agent.api.to.DatadiskTO) AsyncCallbackDispatcher(org.apache.cloudstack.framework.async.AsyncCallbackDispatcher) VMTemplateVO(com.cloud.storage.VMTemplateVO) GetDatadisksCommand(com.cloud.agent.api.storage.GetDatadisksCommand) NfsTO(com.cloud.agent.api.to.NfsTO) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DownloadMonitor(com.cloud.storage.download.DownloadMonitor) EndPointSelector(org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector) AsyncRpcContext(org.apache.cloudstack.framework.async.AsyncRpcContext) Host(com.cloud.host.Host) VMTemplateZoneDao(com.cloud.storage.dao.VMTemplateZoneDao) DataStoreRole(com.cloud.storage.DataStoreRole) CreateDatadiskTemplateCommand(com.cloud.agent.api.storage.CreateDatadiskTemplateCommand) SecondaryStorageVmDao(com.cloud.vm.dao.SecondaryStorageVmDao) ConfigurationDao(org.apache.cloudstack.framework.config.dao.ConfigurationDao) Collections(java.util.Collections) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) VolumeVO(com.cloud.storage.VolumeVO) StorageManager(com.cloud.storage.StorageManager) GetDatadisksAnswer(com.cloud.agent.api.storage.GetDatadisksAnswer) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)

Example 2 with CommandExecLogVO

use of com.cloud.secstorage.CommandExecLogVO in project cloudstack by apache.

the class PremiumSecondaryStorageManagerImpl method findAllActiveCopyCommands.

private List<CommandExecLogVO> findAllActiveCopyCommands(long dcId, Date cutTime) {
    SearchCriteria<CommandExecLogVO> sc = activeCopyCommandSearch.create();
    sc.setParameters("created", cutTime);
    sc.setParameters("command_name", "DataMigrationCommand");
    sc.setJoinParameters("hostSearch", "dc", dcId);
    sc.setJoinParameters("hostSearch", "status", Status.Up);
    Filter filter = new Filter(CommandExecLogVO.class, "created", true, null, null);
    return _cmdExecLogDao.search(sc, filter);
}
Also used : CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) Filter(com.cloud.utils.db.Filter)

Example 3 with CommandExecLogVO

use of com.cloud.secstorage.CommandExecLogVO in project cloudstack by apache.

the class VMwareGuru method getCommandHostDelegation.

@Override
@DB
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
    boolean needDelegation = false;
    if (cmd instanceof StorageSubSystemCommand) {
        Boolean fullCloneEnabled = VmwareFullClone.value();
        StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
        c.setExecuteInSequence(fullCloneEnabled);
    }
    if (cmd instanceof DownloadCommand) {
        cmd.setContextParam(VmwareManager.s_vmwareOVAPackageTimeout.key(), String.valueOf(VmwareManager.s_vmwareOVAPackageTimeout.value()));
    }
    // type is empty, so we need to check the format of volume at first.
    if (cmd instanceof CopyCommand) {
        CopyCommand cpyCommand = (CopyCommand) cmd;
        DataTO srcData = cpyCommand.getSrcTO();
        DataStoreTO srcStoreTO = srcData.getDataStore();
        DataTO destData = cpyCommand.getDestTO();
        DataStoreTO destStoreTO = destData.getDataStore();
        boolean inSeq = true;
        if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) || (destData.getObjectType() == DataObjectType.SNAPSHOT)) {
            inSeq = false;
        } else if ((destStoreTO.getRole() == DataStoreRole.Image) || (destStoreTO.getRole() == DataStoreRole.ImageCache)) {
            inSeq = false;
        } else if (!VmwareFullClone.value()) {
            inSeq = false;
        }
        cpyCommand.setExecuteInSequence(inSeq);
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
        if (!needDelegation && !(HypervisorType.VMware == srcData.getHypervisorType() || HypervisorType.VMware == destData.getHypervisorType())) {
            return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
        }
        if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) {
            needDelegation = false;
        } else {
            needDelegation = true;
        }
    } else if (cmd instanceof CreateEntityDownloadURLCommand) {
        DataTO srcData = ((CreateEntityDownloadURLCommand) cmd).getData();
        if ((HypervisorType.VMware == srcData.getHypervisorType())) {
            needDelegation = true;
        }
        if (srcData.getObjectType() == DataObjectType.VOLUME) {
            VolumeObjectTO volumeObjectTO = (VolumeObjectTO) srcData;
            if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) {
                needDelegation = true;
            }
        }
    }
    if (!needDelegation) {
        return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
    }
    HostVO host = _hostDao.findById(hostId);
    long dcId = host.getDataCenterId();
    Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
    if (cmdTarget != null) {
        // TODO, we need to make sure agent is actually connected too
        cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
        if (host.getType() == Host.Type.Routing) {
            Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
            cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
            cmd.setContextParam("username", hostDetails.get("username"));
            cmd.setContextParam("password", hostDetails.get("password"));
            cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
            cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
        }
        CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
        _cmdExecLogDao.persist(execLog);
        cmd.setContextParam("execid", String.valueOf(execLog.getId()));
        cmd.setContextParam("noderuninfo", String.format("%d-%d", _clusterMgr.getManagementNodeId(), _clusterMgr.getCurrentRunId()));
        cmd.setContextParam("vCenterSessionTimeout", String.valueOf(_vmwareMgr.getVcenterSessionTimeout()));
        cmd.setContextParam(VmwareManager.s_vmwareOVAPackageTimeout.key(), String.valueOf(VmwareManager.s_vmwareOVAPackageTimeout.value()));
        if (cmd instanceof BackupSnapshotCommand || cmd instanceof CreatePrivateTemplateFromVolumeCommand || cmd instanceof CreatePrivateTemplateFromSnapshotCommand || cmd instanceof CopyVolumeCommand || cmd instanceof CopyCommand || cmd instanceof CreateVolumeOVACommand || cmd instanceof PrepareOVAPackingCommand || cmd instanceof CreateVolumeFromSnapshotCommand) {
            String workerName = _vmwareMgr.composeWorkerName();
            long checkPointId = 1;
            // FIXME: Fix                    long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
            cmd.setContextParam("worker", workerName);
            cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
            // some commands use 2 workers
            String workerName2 = _vmwareMgr.composeWorkerName();
            long checkPointId2 = 1;
            // FIXME: Fix                    long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
            cmd.setContextParam("worker2", workerName2);
            cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
            cmd.setContextParam("searchexludefolders", _vmwareMgr.s_vmwareSearchExcludeFolder.value());
        }
        return new Pair<Boolean, Long>(Boolean.TRUE, cmdTarget.first().getId());
    }
    return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId));
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) CopyCommand(org.apache.cloudstack.storage.command.CopyCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) CreateVolumeOVACommand(com.cloud.agent.api.storage.CreateVolumeOVACommand) DataTO(com.cloud.agent.api.to.DataTO) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) Pair(com.cloud.utils.Pair) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) PrepareOVAPackingCommand(com.cloud.agent.api.storage.PrepareOVAPackingCommand) HostVO(com.cloud.host.HostVO) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) DB(com.cloud.utils.db.DB)

Example 4 with CommandExecLogVO

use of com.cloud.secstorage.CommandExecLogVO in project cloudstack by apache.

the class PremiumSecondaryStorageManagerImpl method scanPool.

@Override
public Pair<AfterScanAction, Object> scanPool(Long pool) {
    long dataCenterId = pool.longValue();
    if (!isSecondaryStorageVmRequired(dataCenterId)) {
        return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
    }
    Date cutTime = new Date(DateUtil.currentGMTTime().getTime() - _maxExecutionTimeMs);
    _cmdExecLogDao.expungeExpiredRecords(cutTime);
    boolean suspendAutoLoading = !reserveStandbyCapacity();
    if (!suspendAutoLoading) {
        // this is a hacking, has nothing to do with console proxy, it is just a flag that primary storage is being under maintenance mode
        String restart = _configDao.getValue("consoleproxy.restart");
        if (restart != null && restart.equalsIgnoreCase("false")) {
            s_logger.debug("Capacity scan disabled purposefully, consoleproxy.restart = false. This happens when the primarystorage is in maintenance mode");
            suspendAutoLoading = true;
        }
    }
    List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Running, State.Migrating, State.Starting);
    if (alreadyRunning.size() == 0) {
        s_logger.info("No running secondary storage vms found in datacenter id=" + dataCenterId + ", starting one");
        List<SecondaryStorageVmVO> stopped = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, dataCenterId, State.Stopped, State.Stopping);
        if (stopped.size() == 0 || !suspendAutoLoading) {
            List<SecondaryStorageVmVO> stopping = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, State.Stopping);
            if (stopping.size() > 0) {
                s_logger.info("Found SSVMs that are currently at stopping state, wait until they are settled");
                return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
            }
            expandPool(pool, SecondaryStorageVm.Role.templateProcessor);
        }
    }
    if (!suspendAutoLoading) {
        // this is to avoid surprises that people may accidently see two SSVMs being launched, capacity expanding only happens when we have at least the primary SSVM is up
        if (alreadyRunning.size() == 0) {
            s_logger.info("Primary secondary storage is not even started, wait until next turn");
            return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
        }
        alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(null, dataCenterId, State.Running, State.Migrating, State.Starting);
        List<CommandExecLogVO> activeCmds = findActiveCommands(dataCenterId, cutTime);
        List<CommandExecLogVO> copyCmdsInPipeline = findAllActiveCopyCommands(dataCenterId, cutTime);
        return scaleSSVMOnLoad(alreadyRunning, activeCmds, copyCmdsInPipeline, dataCenterId);
    }
    return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) CommandExecLogVO(com.cloud.secstorage.CommandExecLogVO) Date(java.util.Date) Pair(com.cloud.utils.Pair)

Aggregations

CommandExecLogVO (com.cloud.secstorage.CommandExecLogVO)4 DataTO (com.cloud.agent.api.to.DataTO)2 Pair (com.cloud.utils.Pair)2 SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)2 AgentManager (com.cloud.agent.AgentManager)1 Answer (com.cloud.agent.api.Answer)1 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)1 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)1 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)1 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)1 CopyVolumeCommand (com.cloud.agent.api.storage.CopyVolumeCommand)1 CreateDatadiskTemplateCommand (com.cloud.agent.api.storage.CreateDatadiskTemplateCommand)1 CreateEntityDownloadURLCommand (com.cloud.agent.api.storage.CreateEntityDownloadURLCommand)1 CreateVolumeOVACommand (com.cloud.agent.api.storage.CreateVolumeOVACommand)1 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)1 GetDatadisksAnswer (com.cloud.agent.api.storage.GetDatadisksAnswer)1 GetDatadisksCommand (com.cloud.agent.api.storage.GetDatadisksCommand)1 PrepareOVAPackingCommand (com.cloud.agent.api.storage.PrepareOVAPackingCommand)1 DataObjectType (com.cloud.agent.api.to.DataObjectType)1 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)1