Search in sources :

Example 16 with StorageFilerTO

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

the class LibvirtComputingResourceTest method testResizeVolumeCommandShrink.

@Test
public void testResizeVolumeCommandShrink() {
    final String path = "nfs:/127.0.0.1/storage/secondary";
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final Long currentSize = 100l;
    final Long newSize = 200l;
    final boolean shrinkOk = true;
    final String vmInstance = "Test";
    final ResizeVolumeCommand command = new ResizeVolumeCommand(path, pool, currentSize, newSize, shrinkOk, vmInstance);
    final KVMStoragePoolManager storagePoolMgr = Mockito.mock(KVMStoragePoolManager.class);
    final KVMStoragePool storagePool = Mockito.mock(KVMStoragePool.class);
    final KVMPhysicalDisk vol = Mockito.mock(KVMPhysicalDisk.class);
    when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(storagePoolMgr);
    when(storagePoolMgr.getStoragePool(pool.getType(), pool.getUuid())).thenReturn(storagePool);
    when(storagePool.getPhysicalDisk(path)).thenReturn(vol);
    when(vol.getPath()).thenReturn(path);
    when(libvirtComputingResource.getResizeScriptType(storagePool, vol)).thenReturn("QCOW2");
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, libvirtComputingResource);
    assertFalse(answer.getResult());
}
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) KVMPhysicalDisk(com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test)

Example 17 with StorageFilerTO

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

the class VmwareResource method execute.

protected Answer execute(ModifyStoragePoolCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource ModifyStoragePoolCommand: " + _gson.toJson(cmd));
    }
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        StorageFilerTO pool = cmd.getPool();
        if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS) {
            throw new Exception("Unsupported storage pool type " + pool.getType());
        }
        ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
        if (morDatastore == null) {
            morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""));
        }
        assert (morDatastore != null);
        DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary();
        long capacity = summary.getCapacity();
        long available = summary.getFreeSpace();
        Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
        ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
        if (cmd.getAdd() && pool.getType() == StoragePoolType.VMFS) {
            answer.setLocalDatastoreName(morDatastore.getValue());
        }
        return answer;
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        return new Answer(cmd, false, msg);
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) 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) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) 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) DatastoreSummary(com.vmware.vim25.DatastoreSummary) RemoteException(java.rmi.RemoteException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 18 with StorageFilerTO

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

the class XenServerStorageMotionStrategy method migrateVmWithVolumesWithinCluster.

private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    // Initiate migration of a virtual machine with its volumes.
    try {
        List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volume = entry.getKey();
            VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
            StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
            volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
        }
        MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto);
        MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(destHost.getId(), command);
        if (answer == null) {
            s_logger.error("Migration with storage of vm " + vm + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!answer.getResult()) {
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails());
        } else {
            // Update the volume details after migration.
            updateVolumePathsAfterMigration(volumeToPool, answer.getVolumeTos(), srcHost);
        }
        return answer;
    } catch (OperationTimedoutException e) {
        s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
        throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
    }
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 19 with StorageFilerTO

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

the class NotAValidCommand method testResizeVolumeCommand.

@Test
public void testResizeVolumeCommand() {
    final StorageFilerTO pool = Mockito.mock(StorageFilerTO.class);
    final ResizeVolumeCommand resizeCommand = new ResizeVolumeCommand("Test", pool, 1l, 3l, false, "Tests-1");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(resizeCommand, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) ResizeVolumeCommand(com.cloud.agent.api.storage.ResizeVolumeCommand) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) Test(org.junit.Test)

Example 20 with StorageFilerTO

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

the class Ovm3StoragePool method execute.

/**
     * Gets the details of a storage pool, size etc
     *
     * @param cmd
     * @return
     */
public Answer execute(ModifyStoragePoolCommand cmd) {
    StorageFilerTO pool = cmd.getPool();
    LOGGER.debug("modifying pool " + pool);
    try {
        if (config.getAgentInOvm3Cluster()) {
        // no native ovm cluster for now, I got to break it in horrible
        // ways
        }
        if (pool.getType() == StoragePoolType.NetworkFilesystem) {
            createRepo(pool);
            StoragePlugin store = new StoragePlugin(c);
            String propUuid = store.deDash(pool.getUuid());
            String mntUuid = pool.getUuid();
            String nfsHost = pool.getHost();
            String nfsPath = pool.getPath();
            StorageDetails ss = store.storagePluginGetFileSystemInfo(propUuid, mntUuid, nfsHost, nfsPath);
            Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
            return new ModifyStoragePoolAnswer(cmd, Long.parseLong(ss.getSize()), Long.parseLong(ss.getFreeSize()), tInfo);
        } else if (pool.getType() == StoragePoolType.OCFS2) {
            createOCFS2Sr(pool);
        }
        return new Answer(cmd, false, "The pool type: " + pool.getType().name() + " is not supported.");
    } catch (Exception e) {
        LOGGER.debug("ModifyStoragePoolCommand failed", e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Answer(com.cloud.agent.api.Answer) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) StorageDetails(com.cloud.hypervisor.ovm3.objects.StoragePlugin.StorageDetails) StoragePlugin(com.cloud.hypervisor.ovm3.objects.StoragePlugin) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Aggregations

StorageFilerTO (com.cloud.agent.api.to.StorageFilerTO)54 Answer (com.cloud.agent.api.Answer)30 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)27 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)21 KVMStoragePool (com.cloud.hypervisor.kvm.storage.KVMStoragePool)20 Test (org.junit.Test)19 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)17 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)16 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)16 VolumeTO (com.cloud.agent.api.to.VolumeTO)15 KVMPhysicalDisk (com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk)15 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)10 DiskProfile (com.cloud.vm.DiskProfile)10 ConfigurationException (javax.naming.ConfigurationException)10 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)9 ResizeVolumeCommand (com.cloud.agent.api.storage.ResizeVolumeCommand)8 NfsStoragePool (com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool)8 Pair (com.cloud.utils.Pair)8 Connection (com.xensource.xenapi.Connection)8 HashMap (java.util.HashMap)8