Search in sources :

Example 6 with CreatePrivateTemplateFromSnapshotCommand

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

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandCloudRuntime.

@SuppressWarnings("unchecked")
@Test
public void testCreatePrivateTemplateFromSnapshotCommandCloudRuntime() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool snapshotPool = Mockito.mock(KVMStoragePool.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenThrow(CloudRuntimeException.class);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
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) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) Test(org.junit.Test)

Example 7 with CreatePrivateTemplateFromSnapshotCommand

use of com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand 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)

Example 8 with CreatePrivateTemplateFromSnapshotCommand

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

the class VMwareGuru method getCommandHostDelegation.

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

Example 9 with CreatePrivateTemplateFromSnapshotCommand

use of com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand 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 10 with CreatePrivateTemplateFromSnapshotCommand

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

the class LibvirtComputingResourceTest method testCreatePrivateTemplateFromSnapshotCommandConfigurationException.

@SuppressWarnings("unchecked")
@Test
public void testCreatePrivateTemplateFromSnapshotCommandConfigurationException() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final String secondaryStoragePoolURL = "nfs:/127.0.0.1/storage/secondary";
    final Long dcId = 1l;
    final Long accountId = 1l;
    final Long volumeId = 1l;
    final String backedUpSnapshotUuid = "/run/9a0afe7c-26a7-4585-bf87-abf82ae106d9/";
    final String backedUpSnapshotName = "snap";
    final String origTemplateInstallPath = "/install/path/";
    final Long newTemplateId = 2l;
    final String templateName = "templ";
    final int wait = 0;
    final CreatePrivateTemplateFromSnapshotCommand command = new CreatePrivateTemplateFromSnapshotCommand(pool, secondaryStoragePoolURL, dcId, accountId, volumeId, backedUpSnapshotUuid, backedUpSnapshotName, origTemplateInstallPath, newTemplateId, templateName, wait);
    final String templatePath = "/template/path";
    final String localPath = "/mnt/local";
    final String tmplName = "ce97bbc1-34fe-4259-9202-74bbce2562ab";
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool secondaryPool = Mockito.mock(KVMStoragePool.class);
    final KVMStoragePool snapshotPool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk snapshot = Mockito.mock(KVMPhysicalDisk.class);
    final StorageLayer storage = Mockito.mock(StorageLayer.class);
    final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class);
    final TemplateLocation location = Mockito.mock(TemplateLocation.class);
    final Processor qcow2Processor = Mockito.mock(Processor.class);
    final FormatInfo info = Mockito.mock(FormatInfo.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    String snapshotPath = command.getSnapshotUuid();
    final int index = snapshotPath.lastIndexOf("/");
    snapshotPath = snapshotPath.substring(0, index);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath)).thenReturn(snapshotPool);
    when(storagePoolMgr.getStoragePoolByURI(command.getSecondaryStorageUrl())).thenReturn(secondaryPool);
    when(snapshotPool.getPhysicalDisk(command.getSnapshotName())).thenReturn(snapshot);
    when(secondaryPool.getLocalPath()).thenReturn(localPath);
    when(libvirtComputingResource.getStorage()).thenReturn(storage);
    when(libvirtComputingResource.createTmplPath()).thenReturn(templatePath);
    when(libvirtComputingResource.getCmdsTimeout()).thenReturn(1);
    final String templateFolder = command.getAccountId() + File.separator + command.getNewTemplateId();
    final String templateInstallFolder = "template/tmpl/" + templateFolder;
    final String tmplPath = secondaryPool.getLocalPath() + File.separator + templateInstallFolder;
    when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper);
    when(libvirtUtilitiesHelper.buildTemplateLocation(storage, tmplPath)).thenReturn(location);
    when(libvirtUtilitiesHelper.generateUUIDName()).thenReturn(tmplName);
    try {
        when(libvirtUtilitiesHelper.buildQCOW2Processor(storage)).thenThrow(ConfigurationException.class);
        when(qcow2Processor.process(tmplPath, null, tmplName)).thenReturn(info);
    } catch (final ConfigurationException e) {
        fail(e.getMessage());
    } catch (final InternalErrorException e) {
        fail(e.getMessage());
    }
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl() + snapshotPath);
    verify(storagePoolMgr, times(1)).getStoragePoolByURI(command.getSecondaryStorageUrl());
}
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) StorageLayer(com.cloud.storage.StorageLayer) Processor(com.cloud.storage.template.Processor) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) InternalErrorException(com.cloud.exception.InternalErrorException) LibvirtUtilitiesHelper(com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper) 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) ConfigurationException(javax.naming.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) TemplateLocation(com.cloud.storage.template.TemplateLocation) CreatePrivateTemplateFromSnapshotCommand(com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand) FormatInfo(com.cloud.storage.template.Processor.FormatInfo) Test(org.junit.Test)

Aggregations

CreatePrivateTemplateFromSnapshotCommand (com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand)10 Answer (com.cloud.agent.api.Answer)9 ConfigurationException (javax.naming.ConfigurationException)7 BackupSnapshotCommand (com.cloud.agent.api.BackupSnapshotCommand)5 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)5 CreatePrivateTemplateFromVolumeCommand (com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand)5 CreateVolumeFromSnapshotCommand (com.cloud.agent.api.CreateVolumeFromSnapshotCommand)5 CopyVolumeCommand (com.cloud.agent.api.storage.CopyVolumeCommand)5 InternalErrorException (com.cloud.exception.InternalErrorException)5 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)5 PrimaryStorageDownloadCommand (com.cloud.agent.api.storage.PrimaryStorageDownloadCommand)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