Search in sources :

Example 1 with PrimaryStorageDownloadCommand

use of com.cloud.agent.api.storage.PrimaryStorageDownloadCommand in project CloudStack-archive by CloudStack-extras.

the class SimulatorManagerImpl method simulate.

@DB
@Override
public Answer simulate(Command cmd, String hostGuid) {
    Transaction txn = Transaction.currentTxn();
    txn.transitToUserManagedConnection(_concierge.conn());
    try {
        MockHost host = _mockHost.findByGuid(hostGuid);
        String cmdName = cmd.toString();
        int index = cmdName.lastIndexOf(".");
        if (index != -1) {
            cmdName = cmdName.substring(index + 1);
        }
        MockConfigurationVO config = _mockConfigDao.findByNameBottomUP(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), cmdName);
        SimulatorInfo info = new SimulatorInfo();
        info.setHostUuid(hostGuid);
        if (config != null) {
            Map<String, String> configParameters = config.getParameters();
            for (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 (NumberFormatException e) {
                        s_logger.debug("invalid timeout parameter: " + e.toString());
                    }
                } else if (entry.getKey().equalsIgnoreCase("wait")) {
                    try {
                        int wait = Integer.valueOf(entry.getValue());
                        Thread.sleep(wait * 1000);
                    } catch (NumberFormatException e) {
                        s_logger.debug("invalid timeout parameter: " + e.toString());
                    } catch (InterruptedException e) {
                        s_logger.debug("thread is interrupted: " + e.toString());
                    }
                }
            }
        }
        if (cmd instanceof GetHostStatsCommand) {
            return _mockAgentMgr.getHostStatistic((GetHostStatsCommand) cmd);
        } else if (cmd instanceof CheckHealthCommand) {
            return _mockAgentMgr.checkHealth((CheckHealthCommand) cmd);
        } else if (cmd instanceof PingTestCommand) {
            return _mockAgentMgr.pingTest((PingTestCommand) cmd);
        } else if (cmd instanceof MigrateCommand) {
            return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
        } else if (cmd instanceof StartCommand) {
            return _mockVmMgr.startVM((StartCommand) cmd, info);
        } else if (cmd instanceof CheckSshCommand) {
            return _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
        } else if (cmd instanceof SetStaticNatRulesCommand) {
            return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
        } else if (cmd instanceof SetPortForwardingRulesCommand) {
            return _mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
        } else if (cmd instanceof NetworkUsageCommand) {
            return _mockVmMgr.getNetworkUsage((NetworkUsageCommand) cmd);
        } else if (cmd instanceof IpAssocCommand) {
            return _mockVmMgr.IpAssoc((IpAssocCommand) cmd);
        } else if (cmd instanceof LoadBalancerConfigCommand) {
            return _mockVmMgr.LoadBalancerConfig((LoadBalancerConfigCommand) cmd);
        } else if (cmd instanceof DhcpEntryCommand) {
            return _mockVmMgr.AddDhcpEntry((DhcpEntryCommand) cmd);
        } else if (cmd instanceof VmDataCommand) {
            return _mockVmMgr.setVmData((VmDataCommand) cmd);
        } else if (cmd instanceof CleanupNetworkRulesCmd) {
            return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
        } else if (cmd instanceof CheckNetworkCommand) {
            return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
        } else if (cmd instanceof StopCommand) {
            return _mockVmMgr.stopVM((StopCommand) cmd);
        } else if (cmd instanceof RebootCommand) {
            return _mockVmMgr.rebootVM((RebootCommand) cmd);
        } else if (cmd instanceof GetVncPortCommand) {
            return _mockVmMgr.getVncPort((GetVncPortCommand) cmd);
        } else if (cmd instanceof CheckConsoleProxyLoadCommand) {
            return _mockVmMgr.CheckConsoleProxyLoad((CheckConsoleProxyLoadCommand) cmd);
        } else if (cmd instanceof WatchConsoleProxyLoadCommand) {
            return _mockVmMgr.WatchConsoleProxyLoad((WatchConsoleProxyLoadCommand) cmd);
        } else if (cmd instanceof SecurityGroupRulesCmd) {
            return _mockVmMgr.AddSecurityGroupRules((SecurityGroupRulesCmd) cmd, info);
        } else if (cmd instanceof SavePasswordCommand) {
            return _mockVmMgr.SavePassword((SavePasswordCommand) cmd);
        } else if (cmd instanceof PrimaryStorageDownloadCommand) {
            return _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand) cmd);
        } else if (cmd instanceof CreateCommand) {
            return _mockStorageMgr.createVolume((CreateCommand) cmd);
        } else if (cmd instanceof AttachVolumeCommand) {
            return _mockStorageMgr.AttachVolume((AttachVolumeCommand) cmd);
        } else if (cmd instanceof AttachIsoCommand) {
            return _mockStorageMgr.AttachIso((AttachIsoCommand) cmd);
        } else if (cmd instanceof DeleteStoragePoolCommand) {
            return _mockStorageMgr.DeleteStoragePool((DeleteStoragePoolCommand) cmd);
        } else if (cmd instanceof ModifyStoragePoolCommand) {
            return _mockStorageMgr.ModifyStoragePool((ModifyStoragePoolCommand) cmd);
        } else if (cmd instanceof CreateStoragePoolCommand) {
            return _mockStorageMgr.CreateStoragePool((CreateStoragePoolCommand) cmd);
        } else if (cmd instanceof SecStorageSetupCommand) {
            return _mockStorageMgr.SecStorageSetup((SecStorageSetupCommand) cmd);
        } else if (cmd instanceof ListTemplateCommand) {
            return _mockStorageMgr.ListTemplates((ListTemplateCommand) cmd);
        } else if (cmd instanceof DestroyCommand) {
            return _mockStorageMgr.Destroy((DestroyCommand) cmd);
        } else if (cmd instanceof DownloadProgressCommand) {
            return _mockStorageMgr.DownloadProcess((DownloadProgressCommand) cmd);
        } else if (cmd instanceof DownloadCommand) {
            return _mockStorageMgr.Download((DownloadCommand) cmd);
        } else if (cmd instanceof GetStorageStatsCommand) {
            return _mockStorageMgr.GetStorageStats((GetStorageStatsCommand) cmd);
        } else if (cmd instanceof ManageSnapshotCommand) {
            return _mockStorageMgr.ManageSnapshot((ManageSnapshotCommand) cmd);
        } else if (cmd instanceof BackupSnapshotCommand) {
            return _mockStorageMgr.BackupSnapshot((BackupSnapshotCommand) cmd, info);
        } else if (cmd instanceof DeleteSnapshotBackupCommand) {
            return _mockStorageMgr.DeleteSnapshotBackup((DeleteSnapshotBackupCommand) cmd);
        } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
            return _mockStorageMgr.CreateVolumeFromSnapshot((CreateVolumeFromSnapshotCommand) cmd);
        } else if (cmd instanceof DeleteTemplateCommand) {
            return _mockStorageMgr.DeleteTemplate((DeleteTemplateCommand) cmd);
        } else if (cmd instanceof SecStorageVMSetupCommand) {
            return _mockStorageMgr.SecStorageVMSetup((SecStorageVMSetupCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
            return _mockStorageMgr.CreatePrivateTemplateFromSnapshot((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (cmd instanceof ComputeChecksumCommand) {
            return _mockStorageMgr.ComputeChecksum((ComputeChecksumCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
            return _mockStorageMgr.CreatePrivateTemplateFromVolume((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (cmd instanceof MaintainCommand) {
            return _mockAgentMgr.MaintainCommand((MaintainCommand) cmd);
        } else if (cmd instanceof GetVmStatsCommand) {
            return _mockVmMgr.getVmStats((GetVmStatsCommand) cmd);
        } else if (cmd instanceof GetDomRVersionCmd) {
            return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
        } else if (cmd instanceof ClusterSyncCommand) {
            return new Answer(cmd);
        } else if (cmd instanceof CopyVolumeCommand) {
            return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
        } else {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
    } catch (Exception e) {
        s_logger.debug("Failed execute cmd: " + e.toString());
        txn.rollback();
        return new Answer(cmd, false, e.toString());
    } finally {
        txn.transitToAutoManagedConnection(Transaction.CLOUD_DB);
    }
}
Also used : GetDomRVersionCmd(com.cloud.agent.api.GetDomRVersionCmd) DhcpEntryCommand(com.cloud.agent.api.routing.DhcpEntryCommand) VmDataCommand(com.cloud.agent.api.routing.VmDataCommand) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) ListTemplateCommand(com.cloud.agent.api.storage.ListTemplateCommand) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) ComputeChecksumCommand(com.cloud.agent.api.ComputeChecksumCommand) MigrateCommand(com.cloud.agent.api.MigrateCommand) AttachVolumeCommand(com.cloud.agent.api.AttachVolumeCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) DeleteSnapshotBackupCommand(com.cloud.agent.api.DeleteSnapshotBackupCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) CreateCommand(com.cloud.agent.api.storage.CreateCommand) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) CleanupNetworkRulesCmd(com.cloud.agent.api.CleanupNetworkRulesCmd) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) StopCommand(com.cloud.agent.api.StopCommand) Transaction(com.cloud.utils.db.Transaction) SecStorageVMSetupCommand(com.cloud.agent.api.SecStorageVMSetupCommand) Map(java.util.Map) HashMap(java.util.HashMap) MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) RebootCommand(com.cloud.agent.api.RebootCommand) StartCommand(com.cloud.agent.api.StartCommand) CheckConsoleProxyLoadCommand(com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) DownloadCommand(com.cloud.agent.api.storage.DownloadCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) WatchConsoleProxyLoadCommand(com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) DeleteTemplateCommand(com.cloud.agent.api.storage.DeleteTemplateCommand) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) ClusterSyncCommand(com.cloud.agent.api.ClusterSyncCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SQLException(java.sql.SQLException) DownloadProgressCommand(com.cloud.agent.api.storage.DownloadProgressCommand) Answer(com.cloud.agent.api.Answer) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) MockHost(com.cloud.simulator.MockHost) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) CreateStoragePoolCommand(com.cloud.agent.api.CreateStoragePoolCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) DB(com.cloud.utils.db.DB)

Example 2 with PrimaryStorageDownloadCommand

use of com.cloud.agent.api.storage.PrimaryStorageDownloadCommand in project cloudstack by apache.

the class VmwareSecondaryStorageResourceHandler method executeRequest.

@Override
public Answer executeRequest(Command cmd) {
    try {
        Answer answer;
        NDC.push(getCommandLogTitle(cmd));
        if (s_logger.isDebugEnabled())
            s_logger.debug("Executing " + _gson.toJson(cmd));
        if (cmd instanceof PrimaryStorageDownloadCommand) {
            answer = execute((PrimaryStorageDownloadCommand) cmd);
        } else if (cmd instanceof BackupSnapshotCommand) {
            answer = execute((BackupSnapshotCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
            answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
            answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (cmd instanceof CopyVolumeCommand) {
            answer = execute((CopyVolumeCommand) cmd);
        } else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
            answer = execute((CreateVolumeFromSnapshotCommand) cmd);
        } else if (cmd instanceof StorageSubSystemCommand) {
            answer = storageSubsystemHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
        } else if (cmd instanceof CreateEntityDownloadURLCommand) {
            answer = execute((CreateEntityDownloadURLCommand) cmd);
        } else {
            answer = _resource.defaultAction(cmd);
        }
        // special handling to pass-back context info for cleanups
        if (cmd.getContextParam("execid") != null) {
            answer.setContextParam("execid", cmd.getContextParam("execid"));
        }
        if (cmd.getContextParam("checkpoint") != null) {
            answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
        }
        if (cmd.getContextParam("checkpoint2") != null) {
            answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
        }
        if (s_logger.isDebugEnabled())
            s_logger.debug("Command execution answer: " + _gson.toJson(answer));
        return answer;
    } finally {
        if (s_logger.isDebugEnabled())
            s_logger.debug("Done executing " + _gson.toJson(cmd));
        recycleServiceContext();
        NDC.pop();
    }
}
Also used : BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) CreateEntityDownloadURLCommand(com.cloud.agent.api.storage.CreateEntityDownloadURLCommand) Answer(com.cloud.agent.api.Answer) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)

Example 3 with PrimaryStorageDownloadCommand

use of com.cloud.agent.api.storage.PrimaryStorageDownloadCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandNOTemplateDisk.

@Test(expected = NullPointerException.class)
public void testPrimaryStorageDownloadCommandNOTemplateDisk() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>();
    final String name = "Test";
    final String url = "http://template/";
    final ImageFormat format = ImageFormat.QCOW2;
    final long accountId = 1l;
    final int wait = 0;
    final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool primaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk tmplVol = Mockito.mock(KVMPhysicalDisk.class);
    final KVMPhysicalDisk primaryVol = Mockito.mock(KVMPhysicalDisk.class);
    final KVMPhysicalDisk disk = new KVMPhysicalDisk("/path", "disk.qcow2", primaryPool);
    disks.add(disk);
    final int index = url.lastIndexOf("/");
    final String mountpoint = url.substring(0, index);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePoolByURI(mountpoint)).thenReturn(secondaryPool);
    when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
    when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
    when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) ArrayList(java.util.ArrayList) ImageFormat(com.cloud.storage.Storage.ImageFormat) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) Test(org.junit.Test)

Example 4 with PrimaryStorageDownloadCommand

use of com.cloud.agent.api.storage.PrimaryStorageDownloadCommand in project cloudstack by apache.

the class LibvirtComputingResourceTest method testPrimaryStorageDownloadCommandNOTemplateNODisk.

@Test
public void testPrimaryStorageDownloadCommandNOTemplateNODisk() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final List<KVMPhysicalDisk> disks = new ArrayList<KVMPhysicalDisk>();
    final String name = "Test";
    final String url = "http://template/";
    final ImageFormat format = ImageFormat.QCOW2;
    final long accountId = 1l;
    final int wait = 0;
    final PrimaryStorageDownloadCommand command = new PrimaryStorageDownloadCommand(name, url, format, accountId, pool, wait);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool primaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk tmplVol = Mockito.mock(KVMPhysicalDisk.class);
    final KVMPhysicalDisk primaryVol = Mockito.mock(KVMPhysicalDisk.class);
    final int index = url.lastIndexOf("/");
    final String mountpoint = url.substring(0, index);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePoolByURI(mountpoint)).thenReturn(secondaryPool);
    when(secondaryPool.listPhysicalDisks()).thenReturn(disks);
    when(storagePoolMgr.getStoragePool(command.getPool().getType(), command.getPoolUuid())).thenReturn(primaryPool);
    when(storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(), primaryPool, 0)).thenReturn(primaryVol);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
}
Also used : KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) ArrayList(java.util.ArrayList) ImageFormat(com.cloud.storage.Storage.ImageFormat) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) Test(org.junit.Test)

Example 5 with PrimaryStorageDownloadCommand

use of com.cloud.agent.api.storage.PrimaryStorageDownloadCommand in project cloudstack by apache.

the class VmwareResource method executeRequest.

@Override
public Answer executeRequest(Command cmd) {
    if (s_logger.isTraceEnabled())
        s_logger.trace("Begin executeRequest(), cmd: " + cmd.getClass().getSimpleName());
    Answer answer = null;
    NDC.push(getCommandLogTitle(cmd));
    try {
        long cmdSequence = _cmdSequence++;
        Date startTime = DateUtil.currentGMTTime();
        PropertyMapDynamicBean mbean = new PropertyMapDynamicBean();
        mbean.addProp("StartTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), startTime));
        mbean.addProp("Command", _gson.toJson(cmd));
        mbean.addProp("Sequence", String.valueOf(cmdSequence));
        mbean.addProp("Name", cmd.getClass().getSimpleName());
        Class<? extends Command> clz = cmd.getClass();
        if (cmd instanceof NetworkElementCommand) {
            return _vrResource.executeRequest((NetworkElementCommand) cmd);
        } else if (clz == ReadyCommand.class) {
            answer = execute((ReadyCommand) cmd);
        } else if (clz == GetHostStatsCommand.class) {
            answer = execute((GetHostStatsCommand) cmd);
        } else if (clz == GetVmStatsCommand.class) {
            answer = execute((GetVmStatsCommand) cmd);
        } else if (clz == GetVmDiskStatsCommand.class) {
            answer = execute((GetVmDiskStatsCommand) cmd);
        } else if (clz == CheckHealthCommand.class) {
            answer = execute((CheckHealthCommand) cmd);
        } else if (clz == StopCommand.class) {
            answer = execute((StopCommand) cmd);
        } else if (clz == RebootRouterCommand.class) {
            answer = execute((RebootRouterCommand) cmd);
        } else if (clz == RebootCommand.class) {
            answer = execute((RebootCommand) cmd);
        } else if (clz == CheckVirtualMachineCommand.class) {
            answer = execute((CheckVirtualMachineCommand) cmd);
        } else if (clz == PrepareForMigrationCommand.class) {
            answer = execute((PrepareForMigrationCommand) cmd);
        } else if (clz == MigrateCommand.class) {
            answer = execute((MigrateCommand) cmd);
        } else if (clz == MigrateWithStorageCommand.class) {
            answer = execute((MigrateWithStorageCommand) cmd);
        } else if (clz == MigrateVolumeCommand.class) {
            answer = execute((MigrateVolumeCommand) cmd);
        } else if (clz == DestroyCommand.class) {
            answer = execute((DestroyCommand) cmd);
        } else if (clz == CreateStoragePoolCommand.class) {
            return execute((CreateStoragePoolCommand) cmd);
        } else if (clz == ModifyTargetsCommand.class) {
            answer = execute((ModifyTargetsCommand) cmd);
        } else if (clz == ModifyStoragePoolCommand.class) {
            answer = execute((ModifyStoragePoolCommand) cmd);
        } else if (clz == DeleteStoragePoolCommand.class) {
            answer = execute((DeleteStoragePoolCommand) cmd);
        } else if (clz == CopyVolumeCommand.class) {
            answer = execute((CopyVolumeCommand) cmd);
        } else if (clz == AttachIsoCommand.class) {
            answer = execute((AttachIsoCommand) cmd);
        } else if (clz == ValidateSnapshotCommand.class) {
            answer = execute((ValidateSnapshotCommand) cmd);
        } else if (clz == ManageSnapshotCommand.class) {
            answer = execute((ManageSnapshotCommand) cmd);
        } else if (clz == BackupSnapshotCommand.class) {
            answer = execute((BackupSnapshotCommand) cmd);
        } else if (clz == CreateVolumeFromSnapshotCommand.class) {
            answer = execute((CreateVolumeFromSnapshotCommand) cmd);
        } else if (clz == CreatePrivateTemplateFromVolumeCommand.class) {
            answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
        } else if (clz == CreatePrivateTemplateFromSnapshotCommand.class) {
            answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
        } else if (clz == UpgradeSnapshotCommand.class) {
            answer = execute((UpgradeSnapshotCommand) cmd);
        } else if (clz == GetStorageStatsCommand.class) {
            answer = execute((GetStorageStatsCommand) cmd);
        } else if (clz == PrimaryStorageDownloadCommand.class) {
            answer = execute((PrimaryStorageDownloadCommand) cmd);
        } else if (clz == GetVncPortCommand.class) {
            answer = execute((GetVncPortCommand) cmd);
        } else if (clz == SetupCommand.class) {
            answer = execute((SetupCommand) cmd);
        } else if (clz == MaintainCommand.class) {
            answer = execute((MaintainCommand) cmd);
        } else if (clz == PingTestCommand.class) {
            answer = execute((PingTestCommand) cmd);
        } else if (clz == CheckOnHostCommand.class) {
            answer = execute((CheckOnHostCommand) cmd);
        } else if (clz == ModifySshKeysCommand.class) {
            answer = execute((ModifySshKeysCommand) cmd);
        } else if (clz == NetworkUsageCommand.class) {
            answer = execute((NetworkUsageCommand) cmd);
        } else if (clz == StartCommand.class) {
            answer = execute((StartCommand) cmd);
        } else if (clz == CheckSshCommand.class) {
            answer = execute((CheckSshCommand) cmd);
        } else if (clz == CheckNetworkCommand.class) {
            answer = execute((CheckNetworkCommand) cmd);
        } else if (clz == PlugNicCommand.class) {
            answer = execute((PlugNicCommand) cmd);
        } else if (clz == UnPlugNicCommand.class) {
            answer = execute((UnPlugNicCommand) cmd);
        } else if (cmd instanceof CreateVMSnapshotCommand) {
            return execute((CreateVMSnapshotCommand) cmd);
        } else if (cmd instanceof DeleteVMSnapshotCommand) {
            return execute((DeleteVMSnapshotCommand) cmd);
        } else if (cmd instanceof RevertToVMSnapshotCommand) {
            return execute((RevertToVMSnapshotCommand) cmd);
        } else if (clz == ResizeVolumeCommand.class) {
            return execute((ResizeVolumeCommand) cmd);
        } else if (clz == UnregisterVMCommand.class) {
            return execute((UnregisterVMCommand) cmd);
        } else if (cmd instanceof StorageSubSystemCommand) {
            checkStorageProcessorAndHandlerNfsVersionAttribute((StorageSubSystemCommand) cmd);
            return storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
        } else if (clz == ScaleVmCommand.class) {
            return execute((ScaleVmCommand) cmd);
        } else if (clz == PvlanSetupCommand.class) {
            return execute((PvlanSetupCommand) cmd);
        } else if (clz == GetVmIpAddressCommand.class) {
            return execute((GetVmIpAddressCommand) cmd);
        } else if (clz == UnregisterNicCommand.class) {
            answer = execute((UnregisterNicCommand) cmd);
        } else {
            answer = Answer.createUnsupportedCommandAnswer(cmd);
        }
        if (cmd.getContextParam("checkpoint") != null) {
            answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
        }
        Date doneTime = DateUtil.currentGMTTime();
        mbean.addProp("DoneTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), doneTime));
        mbean.addProp("Answer", _gson.toJson(answer));
        synchronized (this) {
            try {
                JmxUtil.registerMBean("VMware " + _morHyperHost.getValue(), "Command " + cmdSequence + "-" + cmd.getClass().getSimpleName(), mbean);
                _cmdMBeans.add(mbean);
                if (_cmdMBeans.size() >= MazCmdMBean) {
                    PropertyMapDynamicBean mbeanToRemove = _cmdMBeans.get(0);
                    _cmdMBeans.remove(0);
                    JmxUtil.unregisterMBean("VMware " + _morHyperHost.getValue(), "Command " + mbeanToRemove.getProp("Sequence") + "-" + mbeanToRemove.getProp("Name"));
                }
            } catch (Exception e) {
                if (s_logger.isTraceEnabled())
                    s_logger.trace("Unable to register JMX monitoring due to exception " + ExceptionUtil.toString(e));
            }
        }
    } finally {
        recycleServiceContext();
        NDC.pop();
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("End executeRequest(), cmd: " + cmd.getClass().getSimpleName());
    return answer;
}
Also used : MigrateVolumeCommand(com.cloud.agent.api.storage.MigrateVolumeCommand) RebootRouterCommand(com.cloud.agent.api.RebootRouterCommand) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) ManageSnapshotCommand(com.cloud.agent.api.ManageSnapshotCommand) MigrateCommand(com.cloud.agent.api.MigrateCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) GetVmDiskStatsCommand(com.cloud.agent.api.GetVmDiskStatsCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) StopCommand(com.cloud.agent.api.StopCommand) DeleteVMSnapshotCommand(com.cloud.agent.api.DeleteVMSnapshotCommand) StorageSubSystemCommand(org.apache.cloudstack.storage.command.StorageSubSystemCommand) PrepareForMigrationCommand(com.cloud.agent.api.PrepareForMigrationCommand) ReadyCommand(com.cloud.agent.api.ReadyCommand) UpgradeSnapshotCommand(com.cloud.agent.api.UpgradeSnapshotCommand) PropertyMapDynamicBean(com.cloud.utils.mgmt.PropertyMapDynamicBean) CheckOnHostCommand(com.cloud.agent.api.CheckOnHostCommand) RebootCommand(com.cloud.agent.api.RebootCommand) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) StartCommand(com.cloud.agent.api.StartCommand) RevertToVMSnapshotCommand(com.cloud.agent.api.RevertToVMSnapshotCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) NetworkElementCommand(com.cloud.agent.api.routing.NetworkElementCommand) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) CreateVMSnapshotCommand(com.cloud.agent.api.CreateVMSnapshotCommand) ModifySshKeysCommand(com.cloud.agent.api.ModifySshKeysCommand) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) ValidateSnapshotCommand(com.cloud.agent.api.ValidateSnapshotCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) SetupCommand(com.cloud.agent.api.SetupCommand) Date(java.util.Date) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) UnregisterNicCommand(com.cloud.agent.api.UnregisterNicCommand) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) ModifyTargetsCommand(com.cloud.agent.api.ModifyTargetsCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand) CreateStoragePoolCommand(com.cloud.agent.api.CreateStoragePoolCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand)

Aggregations

PrimaryStorageDownloadCommand (com.cloud.agent.api.storage.PrimaryStorageDownloadCommand)11 Answer (com.cloud.agent.api.Answer)9 Test (org.junit.Test)5 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)4 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)4 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)4 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)4 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)4 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)4 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)3 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)3 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)3 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)3 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)3 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)3 GetVmStatsCommand (com.cloud.agent.api.GetVmStatsCommand)3 GetVncPortCommand (com.cloud.agent.api.GetVncPortCommand)3 MaintainCommand (com.cloud.agent.api.MaintainCommand)3 ManageSnapshotCommand (com.cloud.agent.api.ManageSnapshotCommand)3