Search in sources :

Example 11 with ModifyStoragePoolCommand

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

the class HypervDirectConnectResourceTest method testModifyStoragePoolCommand2.

// Check
@Test
public final void testModifyStoragePoolCommand2() {
    // Should return existing pool
    // Create dummy folder
    String folderName = "." + File.separator + "Dummy";
    File folder = new File(folderName);
    if (!folder.exists()) {
        if (!folder.mkdir()) {
            Assert.assertTrue(false);
        }
    }
    // Use same spec for pool
    s_logger.info("Createing pool at : " + folderName);
    StoragePoolVO pool = new StoragePoolVO(StoragePoolType.Filesystem, "127.0.0.1", -1, folderName);
    pool.setUuid(s_testLocalStoreUUID);
    ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool, folderName);
    Answer ans = s_hypervresource.executeRequest(cmd);
    Assert.assertTrue(ans.getResult());
    DeleteStoragePoolCommand delCmd = new DeleteStoragePoolCommand(pool, folderName);
    Answer ans2 = s_hypervresource.executeRequest(delCmd);
    Assert.assertTrue(ans2.getResult());
}
Also used : StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DeleteStoragePoolCommand(com.cloud.agent.api.DeleteStoragePoolCommand) File(java.io.File) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) Test(org.junit.Test)

Example 12 with ModifyStoragePoolCommand

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

the class StoragePoolAutomationImpl method maintain.

@Override
public boolean maintain(DataStore store) {
    Long userId = CallContext.current().getCallingUserId();
    User user = _userDao.findById(userId);
    Account account = CallContext.current().getCallingAccount();
    StoragePoolVO pool = primaryDataStoreDao.findById(store.getId());
    try {
        List<StoragePoolVO> spes = null;
        // if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS
        if (pool.getScope() == ScopeType.ZONE) {
            spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), null, null, ScopeType.ZONE);
        } else {
            spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), pool.getPodId(), pool.getClusterId(), ScopeType.CLUSTER);
        }
        for (StoragePoolVO sp : spes) {
            if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
                throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId() + " is already in  PrepareForMaintenance mode ");
            }
        }
        StoragePool storagePool = (StoragePool) store;
        //Handeling the Zone wide and cluster wide primay storage
        List<HostVO> hosts = new ArrayList<HostVO>();
        //TODO: if it's zone wide, this code will list a lot of hosts in the zone, which may cause performance/OOM issue.
        if (pool.getScope().equals(ScopeType.ZONE)) {
            if (HypervisorType.Any.equals(pool.getHypervisor())) {
                hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId());
            } else {
                hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor(), pool.getDataCenterId());
            }
        } else {
            hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
        }
        if (hosts == null || hosts.size() == 0) {
            pool.setStatus(StoragePoolStatus.Maintenance);
            primaryDataStoreDao.update(pool.getId(), pool);
            return true;
        } else {
            // set the pool state to prepare for maintenance
            pool.setStatus(StoragePoolStatus.PrepareForMaintenance);
            primaryDataStoreDao.update(pool.getId(), pool);
        }
        // remove heartbeat
        for (HostVO host : hosts) {
            ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(false, storagePool);
            final Answer answer = agentMgr.easySend(host.getId(), cmd);
            if (answer == null || !answer.getResult()) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("ModifyStoragePool false failed due to " + ((answer == null) ? "answer null" : answer.getDetails()));
                }
            } else {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("ModifyStoragePool false succeeded");
                }
            }
        }
        // check to see if other ps exist
        // if they do, then we can migrate over the system vms to them
        // if they dont, then just stop all vms on this one
        List<StoragePoolVO> upPools = primaryDataStoreDao.listByStatusInZone(pool.getDataCenterId(), StoragePoolStatus.Up);
        boolean restart = true;
        if (upPools == null || upPools.size() == 0) {
            restart = false;
        }
        // 2. Get a list of all the ROOT volumes within this storage pool
        List<VolumeVO> allVolumes = volumeDao.findByPoolId(pool.getId());
        // 3. Enqueue to the work queue
        for (VolumeVO volume : allVolumes) {
            VMInstanceVO vmInstance = vmDao.findById(volume.getInstanceId());
            if (vmInstance == null) {
                continue;
            }
            // enqueue sp work
            if (vmInstance.getState().equals(State.Running) || vmInstance.getState().equals(State.Starting) || vmInstance.getState().equals(State.Stopping)) {
                try {
                    StoragePoolWorkVO work = new StoragePoolWorkVO(vmInstance.getId(), pool.getId(), false, false, server.getId());
                    _storagePoolWorkDao.persist(work);
                } catch (Exception e) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Work record already exists, re-using by re-setting values");
                    }
                    StoragePoolWorkVO work = _storagePoolWorkDao.findByPoolIdAndVmId(pool.getId(), vmInstance.getId());
                    work.setStartedAfterMaintenance(false);
                    work.setStoppedForMaintenance(false);
                    work.setManagementServerId(server.getId());
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
        }
        // 4. Process the queue
        List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForPrepareForMaintenanceByPoolId(pool.getId());
        for (StoragePoolWorkVO work : pendingWork) {
            // shut down the running vms
            VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
            if (vmInstance == null) {
                continue;
            }
            // proxy
            if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
                // call the consoleproxymanager
                ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId());
                vmMgr.advanceStop(consoleProxy.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
                if (restart) {
                    vmMgr.advanceStart(consoleProxy.getUuid(), null, null);
                    // update work status
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
            // if the instance is of type uservm, call the user vm manager
            if (vmInstance.getType() == VirtualMachine.Type.User) {
                UserVmVO userVm = userVmDao.findById(vmInstance.getId());
                vmMgr.advanceStop(userVm.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
            }
            // secondary storage vm manager
            if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
                SecondaryStorageVmVO secStrgVm = _secStrgDao.findById(vmInstance.getId());
                vmMgr.advanceStop(secStrgVm.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
                if (restart) {
                    vmMgr.advanceStart(secStrgVm.getUuid(), null, null);
                    // update work status
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
            // manager
            if (vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) {
                DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
                vmMgr.advanceStop(domR.getUuid(), false);
                // update work status
                work.setStoppedForMaintenance(true);
                _storagePoolWorkDao.update(work.getId(), work);
                if (restart) {
                    vmMgr.advanceStart(domR.getUuid(), null, null);
                    // update work status
                    work.setStartedAfterMaintenance(true);
                    _storagePoolWorkDao.update(work.getId(), work);
                }
            }
        }
    } catch (Exception e) {
        s_logger.error("Exception in enabling primary storage maintenance:", e);
        pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
        primaryDataStoreDao.update(pool.getId(), pool);
        throw new CloudRuntimeException(e.getMessage());
    }
    return true;
}
Also used : Account(com.cloud.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) UserVmVO(com.cloud.vm.UserVmVO) User(com.cloud.user.User) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostVO(com.cloud.host.HostVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Answer(com.cloud.agent.api.Answer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 13 with ModifyStoragePoolCommand

use of com.cloud.agent.api.ModifyStoragePoolCommand 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();
    }
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) VpnUsersCfgCommand(com.cloud.agent.api.routing.VpnUsersCfgCommand) GetRouterAlertsCommand(com.cloud.agent.api.routing.GetRouterAlertsCommand) Site2SiteVpnCfgCommand(com.cloud.agent.api.routing.Site2SiteVpnCfgCommand) 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) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) DeleteCommand(org.apache.cloudstack.storage.command.DeleteCommand) UploadStatusCommand(org.apache.cloudstack.storage.command.UploadStatusCommand) SetMonitorServiceCommand(com.cloud.agent.api.routing.SetMonitorServiceCommand) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) CreateVolumeFromSnapshotCommand(com.cloud.agent.api.CreateVolumeFromSnapshotCommand) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) CheckNetworkCommand(com.cloud.agent.api.CheckNetworkCommand) CheckS2SVpnConnectionsCommand(com.cloud.agent.api.CheckS2SVpnConnectionsCommand) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand) PingTestCommand(com.cloud.agent.api.PingTestCommand) BackupSnapshotCommand(com.cloud.agent.api.BackupSnapshotCommand) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) CreateCommand(com.cloud.agent.api.storage.CreateCommand) SetStaticRouteCommand(com.cloud.agent.api.routing.SetStaticRouteCommand) DestroyCommand(com.cloud.agent.api.storage.DestroyCommand) SecStorageFirewallCfgCommand(com.cloud.agent.api.SecStorageFirewallCfgCommand) SecStorageSetupCommand(com.cloud.agent.api.SecStorageSetupCommand) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) IpAssocVpcCommand(com.cloud.agent.api.routing.IpAssocVpcCommand) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand) AttachIsoCommand(com.cloud.agent.api.AttachIsoCommand) CleanupNetworkRulesCmd(com.cloud.agent.api.CleanupNetworkRulesCmd) GetVmStatsCommand(com.cloud.agent.api.GetVmStatsCommand) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) 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) SecStorageVMSetupCommand(com.cloud.agent.api.SecStorageVMSetupCommand) Map(java.util.Map) HashMap(java.util.HashMap) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand) MockConfigurationVO(com.cloud.simulator.MockConfigurationVO) CheckSshCommand(com.cloud.agent.api.check.CheckSshCommand) RebootCommand(com.cloud.agent.api.RebootCommand) StartCommand(com.cloud.agent.api.StartCommand) RevertToVMSnapshotCommand(com.cloud.agent.api.RevertToVMSnapshotCommand) CheckConsoleProxyLoadCommand(com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand) SavePasswordCommand(com.cloud.agent.api.routing.SavePasswordCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) PrimaryStorageDownloadCommand(com.cloud.agent.api.storage.PrimaryStorageDownloadCommand) DownloadCommand(org.apache.cloudstack.storage.command.DownloadCommand) NetworkRulesVmSecondaryIpCommand(com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand) CopyVolumeCommand(com.cloud.agent.api.storage.CopyVolumeCommand) WatchConsoleProxyLoadCommand(com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand) SetSourceNatCommand(com.cloud.agent.api.routing.SetSourceNatCommand) GetHostStatsCommand(com.cloud.agent.api.GetHostStatsCommand) CreateVMSnapshotCommand(com.cloud.agent.api.CreateVMSnapshotCommand) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) StringReader(java.io.StringReader) IpAssocCommand(com.cloud.agent.api.routing.IpAssocCommand) JsonReader(com.google.gson.stream.JsonReader) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) UnPlugNicCommand(com.cloud.agent.api.UnPlugNicCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) MaintainCommand(com.cloud.agent.api.MaintainCommand) SetNetworkACLCommand(com.cloud.agent.api.routing.SetNetworkACLCommand) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConfigurationException(javax.naming.ConfigurationException) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) GetStorageStatsCommand(com.cloud.agent.api.GetStorageStatsCommand) DownloadProgressCommand(org.apache.cloudstack.storage.command.DownloadProgressCommand) Answer(com.cloud.agent.api.Answer) ListVolumeCommand(com.cloud.agent.api.storage.ListVolumeCommand) FenceCommand(com.cloud.agent.api.FenceCommand) GetVncPortCommand(com.cloud.agent.api.GetVncPortCommand) MockHost(com.cloud.simulator.MockHost) SetPortForwardingRulesVpcCommand(com.cloud.agent.api.routing.SetPortForwardingRulesVpcCommand) RemoteAccessVpnCfgCommand(com.cloud.agent.api.routing.RemoteAccessVpnCfgCommand) CreatePrivateTemplateFromVolumeCommand(com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand) CreateStoragePoolCommand(com.cloud.agent.api.CreateStoragePoolCommand) CheckHealthCommand(com.cloud.agent.api.CheckHealthCommand) DB(com.cloud.utils.db.DB)

Example 14 with ModifyStoragePoolCommand

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

the class ElastistorHostListener method hostConnect.

@Override
public boolean hostConnect(long hostId, long poolId) {
    StoragePool pool = (StoragePool) this.dataStoreMgr.getDataStore(poolId, DataStoreRole.Primary);
    StoragePoolHostVO storagePoolHost = storagePoolHostDao.findByPoolHost(poolId, hostId);
    HostVO host = _hostDao.findById(hostId);
    if (storagePoolHost == null) {
        storagePoolHost = new StoragePoolHostVO(poolId, hostId, "");
        storagePoolHostDao.persist(storagePoolHost);
    }
    StoragePoolVO poolVO = storagePoolDao.findById(pool.getId());
    if (poolVO.isManaged() && (host.getHypervisorType() != HypervisorType.KVM)) {
        return true;
    }
    ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
    final Answer answer = agentMgr.easySend(hostId, cmd);
    if (answer == null) {
        throw new CloudRuntimeException("Unable to get an answer to the modify storage pool command" + pool.getId());
    }
    if (!answer.getResult()) {
        String msg = "Unable to attach storage pool" + poolId + " to the host" + hostId;
        alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, pool.getDataCenterId(), pool.getPodId(), msg, msg);
        throw new CloudRuntimeException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails() + pool.getId());
    }
    assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId() + "Host=" + hostId;
    s_logger.info("Connection established between " + pool + " host + " + hostId);
    return true;
}
Also used : ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) Answer(com.cloud.agent.api.Answer) StoragePool(com.cloud.storage.StoragePool) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand)

Example 15 with ModifyStoragePoolCommand

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

the class LibvirtComputingResourceTest method testModifyStoragePoolCommand.

@Test
public void testModifyStoragePoolCommand() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    ;
    final ModifyStoragePoolCommand command = new ModifyStoragePoolCommand(true, pool);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool kvmStoragePool = Mockito.mock(KVMStoragePool.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType())).thenReturn(kvmStoragePool);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertTrue(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).createStoragePool(command.getPool().getUuid(), command.getPool().getHost(), command.getPool().getPort(), command.getPool().getPath(), command.getPool().getUserInfo(), command.getPool().getType());
}
Also used : AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) KVMStoragePoolManager(com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager) LibvirtRequestWrapper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) StoragePool(com.cloud.storage.StoragePool) NfsStoragePool(com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool) KVMStoragePool(com.cloud.hypervisor.kvm.storage.KVMStoragePool) ModifyStoragePoolCommand(com.cloud.agent.api.ModifyStoragePoolCommand) Test(org.junit.Test)

Aggregations

ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)15 Answer (com.cloud.agent.api.Answer)12 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8 StoragePool (com.cloud.storage.StoragePool)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 DeleteStoragePoolCommand (com.cloud.agent.api.DeleteStoragePoolCommand)5 Test (org.junit.Test)5 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)4 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)3 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)3 CheckHealthCommand (com.cloud.agent.api.CheckHealthCommand)3 CheckNetworkCommand (com.cloud.agent.api.CheckNetworkCommand)3 CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)3 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)3 CreateStoragePoolCommand (com.cloud.agent.api.CreateStoragePoolCommand)3 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)3 GetHostStatsAnswer (com.cloud.agent.api.GetHostStatsAnswer)3 GetHostStatsCommand (com.cloud.agent.api.GetHostStatsCommand)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)3 GetStorageStatsCommand (com.cloud.agent.api.GetStorageStatsCommand)3