use of org.apache.cloudstack.storage.command.DeleteCommand in project cloudstack by apache.
the class UserVmManagerImpl method handleManagedStorage.
private void handleManagedStorage(UserVmVO vm, VolumeVO root) {
if (Volume.State.Allocated.equals(root.getState())) {
return;
}
StoragePoolVO storagePool = _storagePoolDao.findById(root.getPoolId());
if (storagePool != null && storagePool.isManaged()) {
Long hostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
if (hostId != null) {
VolumeInfo volumeInfo = volFactory.getVolume(root.getId());
Host host = _hostDao.findById(hostId);
final Command cmd;
if (host.getHypervisorType() == HypervisorType.XenServer) {
DiskTO disk = new DiskTO(volumeInfo.getTO(), root.getDeviceId(), root.getPath(), root.getVolumeType());
// it's OK in this case to send a detach command to the host for a root volume as this
// will simply lead to the SR that supports the root volume being removed
cmd = new DettachCommand(disk, vm.getInstanceName());
DettachCommand detachCommand = (DettachCommand) cmd;
detachCommand.setManaged(true);
detachCommand.setStorageHost(storagePool.getHostAddress());
detachCommand.setStoragePort(storagePool.getPort());
detachCommand.set_iScsiName(root.get_iScsiName());
} else if (host.getHypervisorType() == HypervisorType.VMware) {
PrimaryDataStore primaryDataStore = (PrimaryDataStore) volumeInfo.getDataStore();
Map<String, String> details = primaryDataStore.getDetails();
if (details == null) {
details = new HashMap<String, String>();
primaryDataStore.setDetails(details);
}
details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
cmd = new DeleteCommand(volumeInfo.getTO());
} else {
throw new CloudRuntimeException("This hypervisor type is not supported on managed storage for this command.");
}
Commands cmds = new Commands(Command.OnError.Stop);
cmds.addCommand(cmd);
try {
_agentMgr.send(hostId, cmds);
} catch (Exception ex) {
throw new CloudRuntimeException(ex.getMessage());
}
if (!cmds.isSuccessful()) {
for (Answer answer : cmds.getAnswers()) {
if (!answer.getResult()) {
s_logger.warn("Failed to reset vm due to: " + answer.getDetails());
throw new CloudRuntimeException("Unable to reset " + vm + " due to " + answer.getDetails());
}
}
}
// root.getPoolId() should be null if the VM we are detaching the disk from has never been started before
DataStore dataStore = root.getPoolId() != null ? _dataStoreMgr.getDataStore(root.getPoolId(), DataStoreRole.Primary) : null;
volumeMgr.revokeAccess(volFactory.getVolume(root.getId()), host, dataStore);
}
}
}
use of org.apache.cloudstack.storage.command.DeleteCommand in project cloudstack by apache.
the class TemplateServiceImpl method handleTemplateSync.
@Override
public void handleTemplateSync(DataStore store) {
if (store == null) {
s_logger.warn("Huh? image store is null");
return;
}
long storeId = store.getId();
// add lock to make template sync for a data store only be done once
String lockString = "templatesync.storeId:" + storeId;
GlobalLock syncLock = GlobalLock.getInternLock(lockString);
try {
if (syncLock.lock(3)) {
try {
Long zoneId = store.getScope().getScopeId();
Map<String, TemplateProp> templateInfos = listTemplate(store);
if (templateInfos == null) {
return;
}
Set<VMTemplateVO> toBeDownloaded = new HashSet<VMTemplateVO>();
List<VMTemplateVO> allTemplates = null;
if (zoneId == null) {
// region wide store
allTemplates = _templateDao.listByState(VirtualMachineTemplate.State.Active, VirtualMachineTemplate.State.NotUploaded, VirtualMachineTemplate.State.UploadInProgress);
} else {
// zone wide store
allTemplates = _templateDao.listInZoneByState(zoneId, VirtualMachineTemplate.State.Active, VirtualMachineTemplate.State.NotUploaded, VirtualMachineTemplate.State.UploadInProgress);
}
List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
List<VMTemplateVO> defaultBuiltin = _templateDao.listDefaultBuiltinTemplates();
if (rtngTmplts != null) {
for (VMTemplateVO rtngTmplt : rtngTmplts) {
if (!allTemplates.contains(rtngTmplt)) {
allTemplates.add(rtngTmplt);
}
}
}
if (defaultBuiltin != null) {
for (VMTemplateVO builtinTmplt : defaultBuiltin) {
if (!allTemplates.contains(builtinTmplt)) {
allTemplates.add(builtinTmplt);
}
}
}
toBeDownloaded.addAll(allTemplates);
final StateMachine2<VirtualMachineTemplate.State, VirtualMachineTemplate.Event, VirtualMachineTemplate> stateMachine = VirtualMachineTemplate.State.getStateMachine();
for (VMTemplateVO tmplt : allTemplates) {
String uniqueName = tmplt.getUniqueName();
TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId());
if (templateInfos.containsKey(uniqueName)) {
TemplateProp tmpltInfo = templateInfos.remove(uniqueName);
toBeDownloaded.remove(tmplt);
if (tmpltStore != null) {
s_logger.info("Template Sync found " + uniqueName + " already in the image store");
if (tmpltStore.getDownloadState() != Status.DOWNLOADED) {
tmpltStore.setErrorString("");
}
if (tmpltInfo.isCorrupted()) {
tmpltStore.setDownloadState(Status.DOWNLOAD_ERROR);
String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltStore.getId();
tmpltStore.setErrorString(msg);
s_logger.info(msg);
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPLOAD_FAILED, zoneId, null, msg, msg);
if (tmplt.getState() == VirtualMachineTemplate.State.NotUploaded || tmplt.getState() == VirtualMachineTemplate.State.UploadInProgress) {
s_logger.info("Template Sync found " + uniqueName + " on image store " + storeId + " uploaded using SSVM as corrupted, marking it as failed");
tmpltStore.setState(State.Failed);
try {
stateMachine.transitTo(tmplt, VirtualMachineTemplate.Event.OperationFailed, null, _templateDao);
} catch (NoTransitionException e) {
s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage());
}
} else if (tmplt.getUrl() == null) {
msg = "Private template (" + tmplt + ") with install path " + tmpltInfo.getInstallPath() + " is corrupted, please check in image store: " + tmpltStore.getDataStoreId();
s_logger.warn(msg);
} else {
s_logger.info("Removing template_store_ref entry for corrupted template " + tmplt.getName());
_vmTemplateStoreDao.remove(tmpltStore.getId());
toBeDownloaded.add(tmplt);
}
} else {
if (tmpltStore.getDownloadState() != Status.DOWNLOADED) {
String etype = EventTypes.EVENT_TEMPLATE_CREATE;
if (tmplt.getFormat() == ImageFormat.ISO) {
etype = EventTypes.EVENT_ISO_CREATE;
}
if (zoneId != null) {
UsageEventUtils.publishUsageEvent(etype, tmplt.getAccountId(), zoneId, tmplt.getId(), tmplt.getName(), null, null, tmpltInfo.getPhysicalSize(), tmpltInfo.getSize(), VirtualMachineTemplate.class.getName(), tmplt.getUuid());
}
}
tmpltStore.setDownloadPercent(100);
tmpltStore.setDownloadState(Status.DOWNLOADED);
tmpltStore.setState(ObjectInDataStoreStateMachine.State.Ready);
tmpltStore.setInstallPath(tmpltInfo.getInstallPath());
tmpltStore.setSize(tmpltInfo.getSize());
tmpltStore.setPhysicalSize(tmpltInfo.getPhysicalSize());
tmpltStore.setLastUpdated(new Date());
// update size in vm_template table
VMTemplateVO tmlpt = _templateDao.findById(tmplt.getId());
tmlpt.setSize(tmpltInfo.getSize());
_templateDao.update(tmplt.getId(), tmlpt);
if (tmplt.getState() == VirtualMachineTemplate.State.NotUploaded || tmplt.getState() == VirtualMachineTemplate.State.UploadInProgress) {
try {
stateMachine.transitTo(tmplt, VirtualMachineTemplate.Event.OperationSucceeded, null, _templateDao);
} catch (NoTransitionException e) {
s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage());
}
}
// which already got checked and incremented during createTemplate API call.
if (tmpltInfo.getSize() > 0 && tmplt.getAccountId() != Account.ACCOUNT_ID_SYSTEM && tmplt.getUrl() != null) {
long accountId = tmplt.getAccountId();
try {
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(accountId), com.cloud.configuration.Resource.ResourceType.secondary_storage, tmpltInfo.getSize() - UriUtils.getRemoteSize(tmplt.getUrl()));
} catch (ResourceAllocationException e) {
s_logger.warn(e.getMessage());
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_RESOURCE_LIMIT_EXCEEDED, zoneId, null, e.getMessage(), e.getMessage());
} finally {
_resourceLimitMgr.recalculateResourceCount(accountId, _accountMgr.getAccount(accountId).getDomainId(), com.cloud.configuration.Resource.ResourceType.secondary_storage.getOrdinal());
}
}
}
_vmTemplateStoreDao.update(tmpltStore.getId(), tmpltStore);
} else {
tmpltStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 100, Status.DOWNLOADED, null, null, null, tmpltInfo.getInstallPath(), tmplt.getUrl());
tmpltStore.setSize(tmpltInfo.getSize());
tmpltStore.setPhysicalSize(tmpltInfo.getPhysicalSize());
tmpltStore.setDataStoreRole(store.getRole());
_vmTemplateStoreDao.persist(tmpltStore);
// update size in vm_template table
VMTemplateVO tmlpt = _templateDao.findById(tmplt.getId());
tmlpt.setSize(tmpltInfo.getSize());
_templateDao.update(tmplt.getId(), tmlpt);
associateTemplateToZone(tmplt.getId(), zoneId);
String etype = EventTypes.EVENT_TEMPLATE_CREATE;
if (tmplt.getFormat() == ImageFormat.ISO) {
etype = EventTypes.EVENT_ISO_CREATE;
}
UsageEventUtils.publishUsageEvent(etype, tmplt.getAccountId(), zoneId, tmplt.getId(), tmplt.getName(), null, null, tmpltInfo.getPhysicalSize(), tmpltInfo.getSize(), VirtualMachineTemplate.class.getName(), tmplt.getUuid());
}
} else if (tmplt.getState() == VirtualMachineTemplate.State.NotUploaded || tmplt.getState() == VirtualMachineTemplate.State.UploadInProgress) {
s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + " uploaded using SSVM, marking it as failed");
toBeDownloaded.remove(tmplt);
tmpltStore.setDownloadState(Status.DOWNLOAD_ERROR);
String msg = "Template " + tmplt.getName() + ":" + tmplt.getId() + " is corrupted on secondary storage " + tmpltStore.getId();
tmpltStore.setErrorString(msg);
tmpltStore.setState(State.Failed);
_vmTemplateStoreDao.update(tmpltStore.getId(), tmpltStore);
try {
stateMachine.transitTo(tmplt, VirtualMachineTemplate.Event.OperationFailed, null, _templateDao);
} catch (NoTransitionException e) {
s_logger.error("Unexpected state transition exception for template " + tmplt.getName() + ". Details: " + e.getMessage());
}
} else {
s_logger.info("Template Sync did not find " + uniqueName + " on image store " + storeId + ", may request download based on available hypervisor types");
if (tmpltStore != null) {
if (_storeMgr.isRegionStore(store) && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && tmpltStore.getState() == State.Ready && tmpltStore.getInstallPath() == null) {
s_logger.info("Keep fake entry in template store table for migration of previous NFS to object store");
} else {
s_logger.info("Removing leftover template " + uniqueName + " entry from template store table");
// remove those leftover entries
_vmTemplateStoreDao.remove(tmpltStore.getId());
}
}
}
}
if (toBeDownloaded.size() > 0) {
/* Only download templates whose hypervirsor type is in the zone */
List<HypervisorType> availHypers = _clusterDao.getAvailableHypervisorInZone(zoneId);
if (availHypers.isEmpty()) {
/*
* This is for cloudzone, local secondary storage resource
* started before cluster created
*/
availHypers.add(HypervisorType.KVM);
}
/* Baremetal need not to download any template */
availHypers.remove(HypervisorType.BareMetal);
// bug 9809: resume ISO
availHypers.add(HypervisorType.None);
// download.
for (VMTemplateVO tmplt : toBeDownloaded) {
if (tmplt.getUrl() == null) {
// If url is null, skip downloading
s_logger.info("Skip downloading template " + tmplt.getUniqueName() + " since no url is specified.");
continue;
}
// if this is private template, skip sync to a new image store
if (!tmplt.isPublicTemplate() && !tmplt.isFeatured() && tmplt.getTemplateType() != TemplateType.SYSTEM) {
s_logger.info("Skip sync downloading private template " + tmplt.getUniqueName() + " to a new image store");
continue;
}
// means that this is a duplicate entry from migration of previous NFS to staging.
if (_storeMgr.isRegionStore(store)) {
TemplateDataStoreVO tmpltStore = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId());
if (tmpltStore != null && tmpltStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED && tmpltStore.getState() == State.Ready && tmpltStore.getInstallPath() == null) {
s_logger.info("Skip sync template for migration of previous NFS to object store");
continue;
}
}
if (availHypers.contains(tmplt.getHypervisorType())) {
s_logger.info("Downloading template " + tmplt.getUniqueName() + " to image store " + store.getName());
associateTemplateToZone(tmplt.getId(), zoneId);
TemplateInfo tmpl = _templateFactory.getTemplate(tmplt.getId(), store);
TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) tmpl, null);
AsyncCallbackDispatcher<TemplateServiceImpl, TemplateApiResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createTemplateAsyncCallBack(null, null));
caller.setContext(context);
createTemplateAsync(tmpl, store, caller);
} else {
s_logger.info("Skip downloading template " + tmplt.getUniqueName() + " since current data center does not have hypervisor " + tmplt.getHypervisorType().toString());
}
}
}
for (String uniqueName : templateInfos.keySet()) {
TemplateProp tInfo = templateInfos.get(uniqueName);
if (_tmpltMgr.templateIsDeleteable(tInfo.getId())) {
// we cannot directly call deleteTemplateSync here to reuse delete logic since in this case db does not have this template at all.
TemplateObjectTO tmplTO = new TemplateObjectTO();
tmplTO.setDataStore(store.getTO());
tmplTO.setPath(tInfo.getInstallPath());
tmplTO.setId(tInfo.getId());
DeleteCommand dtCommand = new DeleteCommand(tmplTO);
EndPoint ep = _epSelector.select(store);
Answer answer = null;
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
answer = new Answer(dtCommand, false, errMsg);
} else {
answer = ep.sendMessage(dtCommand);
}
if (answer == null || !answer.getResult()) {
s_logger.info("Failed to deleted template at store: " + store.getName());
} else {
String description = "Deleted template " + tInfo.getTemplateName() + " on secondary storage " + storeId;
s_logger.info(description);
}
}
}
} finally {
syncLock.unlock();
}
} else {
s_logger.info("Couldn't get global lock on " + lockString + ", another thread may be doing template sync on data store " + storeId + " now.");
}
} finally {
syncLock.releaseRef();
}
}
use of org.apache.cloudstack.storage.command.DeleteCommand in project cloudstack by apache.
the class VMwareGuru method finalizeExpungeVolumes.
@Override
public List<Command> finalizeExpungeVolumes(VirtualMachine vm) {
List<Command> commands = new ArrayList<Command>();
List<VolumeVO> volumes = _volumeDao.findByInstance(vm.getId());
if (volumes != null) {
for (VolumeVO volume : volumes) {
StoragePoolVO storagePool = _storagePoolDao.findById(volume.getPoolId());
// so the volume was never assigned to a storage pool)
if (storagePool != null && storagePool.isManaged() && volume.getVolumeType() == Volume.Type.ROOT) {
VolumeInfo volumeInfo = _volFactory.getVolume(volume.getId());
PrimaryDataStore primaryDataStore = (PrimaryDataStore) volumeInfo.getDataStore();
Map<String, String> details = primaryDataStore.getDetails();
if (details == null) {
details = new HashMap<String, String>();
primaryDataStore.setDetails(details);
}
details.put(DiskTO.MANAGED, Boolean.TRUE.toString());
DeleteCommand cmd = new DeleteCommand(volumeInfo.getTO());
commands.add(cmd);
break;
}
}
}
return commands;
}
use of org.apache.cloudstack.storage.command.DeleteCommand in project cloudstack by apache.
the class SimulatorManagerImpl method simulate.
@DB
@Override
public Answer simulate(final Command cmd, final String hostGuid) {
Answer answer = null;
Exception exception = null;
TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB);
try {
final MockHost host = _mockHost.findByGuid(hostGuid);
String cmdName = cmd.toString();
final int index = cmdName.lastIndexOf(".");
if (index != -1) {
cmdName = cmdName.substring(index + 1);
}
final SimulatorInfo info = new SimulatorInfo();
info.setHostUuid(hostGuid);
final MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);
if (config != null && (config.getCount() == null || config.getCount().intValue() > 0)) {
final Map<String, String> configParameters = config.getParameters();
for (final Map.Entry<String, String> entry : configParameters.entrySet()) {
if (entry.getKey().equalsIgnoreCase("enabled")) {
info.setEnabled(Boolean.parseBoolean(entry.getValue()));
} else if (entry.getKey().equalsIgnoreCase("timeout")) {
try {
info.setTimeout(Integer.valueOf(entry.getValue()));
} catch (final NumberFormatException e) {
s_logger.debug("invalid timeout parameter: " + e.toString());
}
}
if (entry.getKey().equalsIgnoreCase("wait")) {
try {
final int wait = Integer.valueOf(entry.getValue());
Thread.sleep(wait);
} catch (final NumberFormatException e) {
s_logger.debug("invalid wait parameter: " + e.toString());
} catch (final InterruptedException e) {
s_logger.debug("thread is interrupted: " + e.toString());
}
}
if (entry.getKey().equalsIgnoreCase("result")) {
final String value = entry.getValue();
if (value.equalsIgnoreCase("fail")) {
answer = new Answer(cmd, false, "Simulated failure");
} else if (value.equalsIgnoreCase("fault")) {
exception = new Exception("Simulated fault");
}
}
}
if (exception != null) {
throw exception;
}
if (answer == null) {
final String message = config.getJsonResponse();
if (message != null) {
// json response looks like {"<Type>":....}
final String objectType = message.split(":")[0].substring(2).replace("\"", "");
final String objectData = message.substring(message.indexOf(':') + 1, message.length() - 1);
if (objectType != null) {
Class<?> clz = null;
try {
clz = Class.forName(objectType);
} catch (final ClassNotFoundException e) {
}
if (clz != null) {
final StringReader reader = new StringReader(objectData);
final JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
answer = (Answer) s_gson.fromJson(jsonReader, clz);
}
}
}
}
}
if (answer == null) {
if (cmd instanceof GetHostStatsCommand) {
answer = _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
} else if (cmd instanceof CheckHealthCommand) {
answer = _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
} else if (cmd instanceof PingTestCommand) {
answer = _mockAgentMgr.pingTest((PingTestCommand) cmd);
} else if (cmd instanceof PrepareForMigrationCommand) {
answer = _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
} else if (cmd instanceof MigrateCommand) {
answer = _mockVmMgr.migrate((MigrateCommand) cmd, info);
} else if (cmd instanceof StartCommand) {
answer = _mockVmMgr.startVM((StartCommand) cmd, info);
} else if (cmd instanceof CheckSshCommand) {
answer = _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
} else if (cmd instanceof CheckVirtualMachineCommand) {
answer = _mockVmMgr.checkVmState((CheckVirtualMachineCommand) cmd);
} else if (cmd instanceof SetStaticNatRulesCommand) {
answer = _mockNetworkMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
} else if (cmd instanceof SetFirewallRulesCommand) {
answer = _mockNetworkMgr.SetFirewallRules((SetFirewallRulesCommand) cmd);
} else if (cmd instanceof SetPortForwardingRulesCommand) {
answer = _mockNetworkMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
} else if (cmd instanceof NetworkUsageCommand) {
answer = _mockNetworkMgr.getNetworkUsage((NetworkUsageCommand) cmd);
} else if (cmd instanceof IpAssocCommand) {
answer = _mockNetworkMgr.IpAssoc((IpAssocCommand) cmd);
} else if (cmd instanceof LoadBalancerConfigCommand) {
answer = _mockNetworkMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
} else if (cmd instanceof DhcpEntryCommand) {
answer = _mockNetworkMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
} else if (cmd instanceof VmDataCommand) {
answer = _mockVmMgr.setVmData((VmDataCommand) cmd);
} else if (cmd instanceof CleanupNetworkRulesCmd) {
answer = _mockVmMgr.cleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
} else if (cmd instanceof CheckNetworkCommand) {
answer = _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
} else if (cmd instanceof StopCommand) {
answer = _mockVmMgr.stopVM((StopCommand) cmd);
} else if (cmd instanceof RebootCommand) {
answer = _mockVmMgr.rebootVM((RebootCommand) cmd);
} else if (cmd instanceof GetVncPortCommand) {
answer = _mockVmMgr.getVncPort((GetVncPortCommand) cmd);
} else if (cmd instanceof CheckConsoleProxyLoadCommand) {
answer = _mockVmMgr.checkConsoleProxyLoad((CheckConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof WatchConsoleProxyLoadCommand) {
answer = _mockVmMgr.watchConsoleProxyLoad((WatchConsoleProxyLoadCommand) cmd);
} else if (cmd instanceof SecurityGroupRulesCmd) {
answer = _mockVmMgr.addSecurityGroupRules((SecurityGroupRulesCmd) cmd, info);
} else if (cmd instanceof SavePasswordCommand) {
answer = _mockVmMgr.savePassword((SavePasswordCommand) cmd);
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
answer = _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof CreateCommand) {
answer = _mockStorageMgr.createVolume((CreateCommand) cmd);
} else if (cmd instanceof AttachIsoCommand) {
answer = _mockStorageMgr.AttachIso((AttachIsoCommand) cmd);
} else if (cmd instanceof DeleteStoragePoolCommand) {
answer = _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand) cmd);
} else if (cmd instanceof ModifyStoragePoolCommand) {
answer = _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand) cmd);
} else if (cmd instanceof CreateStoragePoolCommand) {
answer = _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand) cmd);
} else if (cmd instanceof SecStorageSetupCommand) {
answer = _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand) cmd);
} else if (cmd instanceof ListTemplateCommand) {
answer = _mockStorageMgr.ListTemplates((ListTemplateCommand) cmd);
} else if (cmd instanceof ListVolumeCommand) {
answer = _mockStorageMgr.ListVolumes((ListVolumeCommand) cmd);
} else if (cmd instanceof DestroyCommand) {
answer = _mockStorageMgr.Destroy((DestroyCommand) cmd);
} else if (cmd instanceof DownloadProgressCommand) {
answer = _mockStorageMgr.DownloadProcess((DownloadProgressCommand) cmd);
} else if (cmd instanceof DownloadCommand) {
answer = _mockStorageMgr.Download((DownloadCommand) cmd);
} else if (cmd instanceof GetStorageStatsCommand) {
answer = _mockStorageMgr.GetStorageStats((GetStorageStatsCommand) cmd);
} else if (cmd instanceof ManageSnapshotCommand) {
answer = _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand) cmd);
} else if (cmd instanceof BackupSnapshotCommand) {
answer = _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand) cmd, info);
} else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
answer = _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand) cmd);
} else if (cmd instanceof DeleteCommand) {
answer = _mockStorageMgr.Delete((DeleteCommand) cmd);
} else if (cmd instanceof SecStorageVMSetupCommand) {
answer = _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
answer = _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (cmd instanceof ComputeChecksumCommand) {
answer = _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
answer = _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (cmd instanceof UploadStatusCommand) {
answer = _mockStorageMgr.getUploadStatus((UploadStatusCommand) cmd);
} else if (cmd instanceof MaintainCommand) {
answer = _mockAgentMgr.maintain((MaintainCommand) cmd);
} else if (cmd instanceof GetVmStatsCommand) {
answer = _mockVmMgr.getVmStats((GetVmStatsCommand) cmd);
} else if (cmd instanceof CheckRouterCommand) {
answer = _mockVmMgr.checkRouter((CheckRouterCommand) cmd);
} else if (cmd instanceof GetDomRVersionCmd) {
answer = _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
} else if (cmd instanceof CopyVolumeCommand) {
answer = _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
} else if (cmd instanceof PlugNicCommand) {
answer = _mockNetworkMgr.plugNic((PlugNicCommand) cmd);
} else if (cmd instanceof UnPlugNicCommand) {
answer = _mockNetworkMgr.unplugNic((UnPlugNicCommand) cmd);
} else if (cmd instanceof IpAssocVpcCommand) {
answer = _mockNetworkMgr.ipAssoc((IpAssocVpcCommand) cmd);
} else if (cmd instanceof SetSourceNatCommand) {
answer = _mockNetworkMgr.setSourceNat((SetSourceNatCommand) cmd);
} else if (cmd instanceof SetNetworkACLCommand) {
answer = _mockNetworkMgr.setNetworkAcl((SetNetworkACLCommand) cmd);
} else if (cmd instanceof SetupGuestNetworkCommand) {
answer = _mockNetworkMgr.setUpGuestNetwork((SetupGuestNetworkCommand) cmd);
} else if (cmd instanceof SetPortForwardingRulesVpcCommand) {
answer = _mockNetworkMgr.setVpcPortForwards((SetPortForwardingRulesVpcCommand) cmd);
} else if (cmd instanceof SetStaticNatRulesCommand) {
answer = _mockNetworkMgr.setVPCStaticNatRules((SetStaticNatRulesCommand) cmd);
} else if (cmd instanceof SetStaticRouteCommand) {
answer = _mockNetworkMgr.setStaticRoute((SetStaticRouteCommand) cmd);
} else if (cmd instanceof Site2SiteVpnCfgCommand) {
answer = _mockNetworkMgr.siteToSiteVpn((Site2SiteVpnCfgCommand) cmd);
} else if (cmd instanceof CheckS2SVpnConnectionsCommand) {
answer = _mockNetworkMgr.checkSiteToSiteVpnConnection((CheckS2SVpnConnectionsCommand) cmd);
} else if (cmd instanceof CreateVMSnapshotCommand) {
answer = _mockVmMgr.createVmSnapshot((CreateVMSnapshotCommand) cmd);
} else if (cmd instanceof DeleteVMSnapshotCommand) {
answer = _mockVmMgr.deleteVmSnapshot((DeleteVMSnapshotCommand) cmd);
} else if (cmd instanceof RevertToVMSnapshotCommand) {
answer = _mockVmMgr.revertVmSnapshot((RevertToVMSnapshotCommand) cmd);
} else if (cmd instanceof NetworkRulesVmSecondaryIpCommand) {
answer = _mockVmMgr.plugSecondaryIp((NetworkRulesVmSecondaryIpCommand) cmd);
} else if (cmd instanceof ScaleVmCommand) {
answer = _mockVmMgr.scaleVm((ScaleVmCommand) cmd);
} else if (cmd instanceof PvlanSetupCommand) {
answer = _mockNetworkMgr.setupPVLAN((PvlanSetupCommand) cmd);
} else if (cmd instanceof StorageSubSystemCommand) {
answer = storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
} else if (cmd instanceof FenceCommand) {
answer = _mockVmMgr.fence((FenceCommand) cmd);
} else if (cmd instanceof GetRouterAlertsCommand || cmd instanceof VpnUsersCfgCommand || cmd instanceof RemoteAccessVpnCfgCommand || cmd instanceof SetMonitorServiceCommand || cmd instanceof AggregationControlCommand || cmd instanceof SecStorageFirewallCfgCommand) {
answer = new Answer(cmd);
} else {
s_logger.error("Simulator does not implement command of type " + cmd.toString());
answer = Answer.createUnsupportedCommandAnswer(cmd);
}
}
if (config != null && config.getCount() != null && config.getCount().intValue() > 0) {
if (answer != null) {
config.setCount(config.getCount().intValue() - 1);
_mockConfigDao.update(config.getId(), config);
}
}
return answer;
} catch (final Exception e) {
s_logger.error("Failed execute cmd: ", e);
txn.rollback();
return new Answer(cmd, false, e.toString());
} finally {
txn.close();
txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB);
txn.close();
}
}
use of org.apache.cloudstack.storage.command.DeleteCommand in project cloudstack by apache.
the class NfsSecondaryStorageResource method cleanupStagingNfs.
/**
* clean up template data on staging area
* @param newTemplate: The template on the secondary storage that needs to be cleaned up
*/
protected void cleanupStagingNfs(TemplateObjectTO newTemplate) {
try {
DeleteCommand deleteCommand = new DeleteCommand(newTemplate);
execute(deleteCommand);
} catch (Exception e) {
s_logger.debug("Failed to clean up staging area:", e);
}
}
Aggregations