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);
}
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);
}
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));
}
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);
}
Aggregations