diff --git a/core/src/com/cloud/agent/api/AttachVolumeAnswer.java b/core/src/com/cloud/agent/api/AttachVolumeAnswer.java deleted file mode 100644 index 3e869abba0d..00000000000 --- a/core/src/com/cloud/agent/api/AttachVolumeAnswer.java +++ /dev/null @@ -1,64 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.agent.api; - -public class AttachVolumeAnswer extends Answer { - private Long deviceId; - private String vdiUuid; - private String chainInfo; - - public AttachVolumeAnswer(AttachVolumeCommand cmd, String result) { - super(cmd, false, result); - this.deviceId = null; - } - - public AttachVolumeAnswer(AttachVolumeCommand cmd, Long deviceId) { - super(cmd); - this.deviceId = deviceId; - this.vdiUuid = ""; - } - - public AttachVolumeAnswer(AttachVolumeCommand cmd, Long deviceId, String vdiUuid) { - super(cmd); - this.deviceId = deviceId; - this.vdiUuid = vdiUuid; - } - - public AttachVolumeAnswer(AttachVolumeCommand cmd) { - super(cmd); - this.deviceId = null; - } - - public Long getDeviceId() { - return deviceId; - } - - public String getVdiUuid() { - return vdiUuid; - } - - public void setChainInfo(String chainInfo) { - this.chainInfo = chainInfo; - } - - public String getChainInfo() { - return chainInfo; - } -} diff --git a/core/src/com/cloud/agent/api/AttachVolumeCommand.java b/core/src/com/cloud/agent/api/AttachVolumeCommand.java deleted file mode 100644 index af44d728591..00000000000 --- a/core/src/com/cloud/agent/api/AttachVolumeCommand.java +++ /dev/null @@ -1,216 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.agent.api; - -import com.cloud.storage.Storage.StoragePoolType; - -public class AttachVolumeCommand extends Command { - private boolean attach; - private boolean _managed; - private String vmName; - private StoragePoolType pooltype; - private String volumePath; - private String volumeName; - private Long volumeSize; - private Long deviceId; - private String chainInfo; - private String poolUuid; - private String _storageHost; - private int _storagePort; - private String _iScsiName; - private String _chapInitiatorUsername; - private String _chapInitiatorPassword; - private String _chapTargetUsername; - private String _chapTargetPassword; - private Long bytesReadRate; - private Long bytesWriteRate; - private Long iopsReadRate; - private Long iopsWriteRate; - private String cacheMode; - - protected AttachVolumeCommand() { - } - - public AttachVolumeCommand(boolean attach, boolean managed, String vmName, StoragePoolType pooltype, String volumePath, String volumeName, Long volumeSize, - Long deviceId, String chainInfo) { - this.attach = attach; - this._managed = managed; - this.vmName = vmName; - this.pooltype = pooltype; - this.volumePath = volumePath; - this.volumeName = volumeName; - this.volumeSize = volumeSize; - this.deviceId = deviceId; - this.chainInfo = chainInfo; - } - - @Override - public boolean executeInSequence() { - return true; - } - - public boolean getAttach() { - return attach; - } - - public String getVmName() { - return vmName; - } - - public StoragePoolType getPooltype() { - return pooltype; - } - - public void setPooltype(StoragePoolType pooltype) { - this.pooltype = pooltype; - } - - public String getVolumePath() { - return volumePath; - } - - public String getVolumeName() { - return volumeName; - } - - public Long getVolumeSize() { - return volumeSize; - } - - public Long getDeviceId() { - return deviceId; - } - - public void setDeviceId(Long deviceId) { - this.deviceId = deviceId; - } - - public String getPoolUuid() { - return poolUuid; - } - - public void setPoolUuid(String poolUuid) { - this.poolUuid = poolUuid; - } - - public String getChainInfo() { - return chainInfo; - } - - public void setStorageHost(String storageHost) { - _storageHost = storageHost; - } - - public String getStorageHost() { - return _storageHost; - } - - public void setStoragePort(int storagePort) { - _storagePort = storagePort; - } - - public int getStoragePort() { - return _storagePort; - } - - public boolean isManaged() { - return _managed; - } - - public void set_iScsiName(String iScsiName) { - this._iScsiName = iScsiName; - } - - public String get_iScsiName() { - return _iScsiName; - } - - public void setChapInitiatorUsername(String chapInitiatorUsername) { - _chapInitiatorUsername = chapInitiatorUsername; - } - - public String getChapInitiatorUsername() { - return _chapInitiatorUsername; - } - - public void setChapInitiatorPassword(String chapInitiatorPassword) { - _chapInitiatorPassword = chapInitiatorPassword; - } - - public String getChapInitiatorPassword() { - return _chapInitiatorPassword; - } - - public void setChapTargetUsername(String chapTargetUsername) { - _chapTargetUsername = chapTargetUsername; - } - - public String getChapTargetUsername() { - return _chapTargetUsername; - } - - public void setChapTargetPassword(String chapTargetPassword) { - _chapTargetPassword = chapTargetPassword; - } - - public String getChapTargetPassword() { - return _chapTargetPassword; - } - - public void setBytesReadRate(Long bytesReadRate) { - this.bytesReadRate = bytesReadRate; - } - - public Long getBytesReadRate() { - return bytesReadRate; - } - - public void setBytesWriteRate(Long bytesWriteRate) { - this.bytesWriteRate = bytesWriteRate; - } - - public Long getBytesWriteRate() { - return bytesWriteRate; - } - - public void setIopsReadRate(Long iopsReadRate) { - this.iopsReadRate = iopsReadRate; - } - - public Long getIopsReadRate() { - return iopsReadRate; - } - - public void setIopsWriteRate(Long iopsWriteRate) { - this.iopsWriteRate = iopsWriteRate; - } - - public Long getIopsWriteRate() { - return iopsWriteRate; - } - - public void setCacheMode(String cacheMode) { - this.cacheMode = cacheMode; - } - - public String getCacheMode() { - return cacheMode; - } -} diff --git a/core/test/org/apache/cloudstack/api/agent/test/AttachVolumeAnswerTest.java b/core/test/org/apache/cloudstack/api/agent/test/AttachVolumeAnswerTest.java deleted file mode 100644 index 3390fd1884d..00000000000 --- a/core/test/org/apache/cloudstack/api/agent/test/AttachVolumeAnswerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package org.apache.cloudstack.api.agent.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.cloud.agent.api.AttachVolumeAnswer; -import com.cloud.agent.api.AttachVolumeCommand; -import com.cloud.storage.Storage.StoragePoolType; - -public class AttachVolumeAnswerTest { - AttachVolumeCommand avc = new AttachVolumeCommand(true, false, "vmname", StoragePoolType.Filesystem, "vPath", "vName", 1073741824L, 123456789L, "chainInfo"); - AttachVolumeAnswer ava1 = new AttachVolumeAnswer(avc); - String results = ""; - AttachVolumeAnswer ava2 = new AttachVolumeAnswer(avc, results); - Long deviceId = 10L; - AttachVolumeAnswer ava3 = new AttachVolumeAnswer(avc, deviceId); - - @Test - public void testGetDeviceId() { - Long dId = ava1.getDeviceId(); - assertTrue(dId == null); - - dId = ava2.getDeviceId(); - assertTrue(dId == null); - - dId = ava3.getDeviceId(); - Long expected = 10L; - assertEquals(expected, dId); - } - - @Test - public void testGetChainInfo() { - ava1.setChainInfo("chainInfo"); - String chainInfo = ava1.getChainInfo(); - assertTrue(chainInfo.equals("chainInfo")); - - ava2.setChainInfo("chainInfo"); - chainInfo = ava2.getChainInfo(); - assertTrue(chainInfo.equals("chainInfo")); - - ava3.setChainInfo("chainInfo"); - chainInfo = ava3.getChainInfo(); - assertTrue(chainInfo.equals("chainInfo")); - } -} diff --git a/core/test/org/apache/cloudstack/api/agent/test/AttachVolumeCommandTest.java b/core/test/org/apache/cloudstack/api/agent/test/AttachVolumeCommandTest.java deleted file mode 100644 index 17dab239d78..00000000000 --- a/core/test/org/apache/cloudstack/api/agent/test/AttachVolumeCommandTest.java +++ /dev/null @@ -1,115 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package org.apache.cloudstack.api.agent.test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -import com.cloud.agent.api.AttachVolumeCommand; -import com.cloud.storage.Storage.StoragePoolType; - -public class AttachVolumeCommandTest { - AttachVolumeCommand avc = new AttachVolumeCommand(true, false, "vmname", StoragePoolType.Filesystem, "vPath", "vName", 1073741824L, 123456789L, "chainInfo"); - - @Test - public void testExecuteInSequence() { - boolean b = avc.executeInSequence(); - assertTrue(b); - } - - @Test - public void testGetAttach() { - boolean b = avc.getAttach(); - assertTrue(b); - } - - @Test - public void testGetVmName() { - String vmName = avc.getVmName(); - assertTrue(vmName.equals("vmname")); - } - - @Test - public void testGetPooltype() { - StoragePoolType pt = avc.getPooltype(); - assertTrue(pt.equals(StoragePoolType.Filesystem)); - - avc.setPooltype(StoragePoolType.NetworkFilesystem); - pt = avc.getPooltype(); - assertTrue(pt.equals(StoragePoolType.NetworkFilesystem)); - - avc.setPooltype(StoragePoolType.IscsiLUN); - pt = avc.getPooltype(); - assertTrue(pt.equals(StoragePoolType.IscsiLUN)); - - avc.setPooltype(StoragePoolType.Iscsi); - pt = avc.getPooltype(); - assertTrue(pt.equals(StoragePoolType.Iscsi)); - } - - @Test - public void testGetVolumePath() { - String vPath = avc.getVolumePath(); - assertTrue(vPath.equals("vPath")); - } - - @Test - public void testGetVolumeName() { - String vName = avc.getVolumeName(); - assertTrue(vName.equals("vName")); - } - - @Test - public void testGetDeviceId() { - Long dId = avc.getDeviceId(); - Long expected = 123456789L; - assertEquals(expected, dId); - - avc.setDeviceId(5L); - dId = avc.getDeviceId(); - expected = 5L; - assertEquals(expected, dId); - - avc.setDeviceId(0L); - dId = avc.getDeviceId(); - expected = 0L; - assertEquals(expected, dId); - - avc.setDeviceId(-5L); - dId = avc.getDeviceId(); - expected = -5L; - assertEquals(expected, dId); - } - - @Test - public void testGetPoolUuid() { - avc.setPoolUuid("420fa39c-4ef1-a83c-fd93-46dc1ff515ae"); - String pUuid = avc.getPoolUuid(); - assertTrue(pUuid.equals("420fa39c-4ef1-a83c-fd93-46dc1ff515ae")); - } - - @Test - public void testGetWait() { - String cInfo = avc.getChainInfo(); - assertTrue(cInfo.equals("chainInfo")); - } -} diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs index aa36ed86436..6e1df24f27a 100644 --- a/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs +++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/CloudStackTypes.cs @@ -668,8 +668,6 @@ namespace HypervResource { public const string Answer = "com.cloud.agent.api.Answer"; public const string AttachIsoCommand = "com.cloud.agent.api.AttachIsoCommand"; - public const string AttachVolumeAnswer = "com.cloud.agent.api.AttachVolumeAnswer"; - public const string AttachVolumeCommand = "com.cloud.agent.api.AttachVolumeCommand"; public const string AnsBackupSnapshotAnswerwer = "com.cloud.agent.api.BackupSnapshotAnswer"; public const string BackupSnapshotCommand = "com.cloud.agent.api.BackupSnapshotCommand"; public const string BumpUpPriorityCommand = "com.cloud.agent.api.BumpUpPriorityCommand"; diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtAttachVolumeCommandWrapper.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtAttachVolumeCommandWrapper.java deleted file mode 100644 index c78f0ed6078..00000000000 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtAttachVolumeCommandWrapper.java +++ /dev/null @@ -1,60 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.hypervisor.kvm.resource.wrapper; - -import org.libvirt.Connect; -import org.libvirt.LibvirtException; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.AttachVolumeAnswer; -import com.cloud.agent.api.AttachVolumeCommand; -import com.cloud.exception.InternalErrorException; -import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource; -import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk; -import com.cloud.hypervisor.kvm.storage.KVMStoragePool; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; - -@ResourceWrapper(handles = AttachVolumeCommand.class) -public final class LibvirtAttachVolumeCommandWrapper extends CommandWrapper { - - @Override - public Answer execute(final AttachVolumeCommand command, final LibvirtComputingResource libvirtComputingResource) { - try { - final LibvirtUtilitiesHelper libvirtUtilitiesHelper = libvirtComputingResource.getLibvirtUtilitiesHelper(); - - final Connect conn = libvirtUtilitiesHelper.getConnectionByVmName(command.getVmName()); - - final KVMStoragePool primary = libvirtComputingResource.getStoragePoolMgr().getStoragePool(command.getPooltype(), command.getPoolUuid()); - final KVMPhysicalDisk disk = primary.getPhysicalDisk(command.getVolumePath()); - - libvirtComputingResource.attachOrDetachDisk(conn, command.getAttach(), command.getVmName(), disk, - command.getDeviceId().intValue(), command.getBytesReadRate(), command.getBytesWriteRate(), command.getIopsReadRate(), command.getIopsWriteRate(), - command.getCacheMode()); - - } catch (final LibvirtException e) { - return new AttachVolumeAnswer(command, e.toString()); - } catch (final InternalErrorException e) { - return new AttachVolumeAnswer(command, e.toString()); - } - - return new AttachVolumeAnswer(command, command.getDeviceId(), command.getVolumePath()); - } -} \ No newline at end of file diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index 1651299cfc6..03d9f49bcbf 100644 --- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -76,7 +76,6 @@ import org.xml.sax.SAXException; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; -import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.BackupSnapshotCommand; import com.cloud.agent.api.CheckHealthCommand; import com.cloud.agent.api.CheckNetworkCommand; @@ -1503,141 +1502,6 @@ public class LibvirtComputingResourceTest { } } - @Test - public void testAttachVolumeCommand() { - final Connect conn = Mockito.mock(Connect.class); - final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class); - - final boolean attach = true; - final boolean managed = true; - final String vmName = "Test"; - final StoragePoolType poolType = StoragePoolType.ISO; - final String volumePath = "/path"; - final String volumeName = "volume"; - final Long volumeSize = 200l; - final Long deviceId = 1l; - final String chainInfo = "none"; - final AttachVolumeCommand command = new AttachVolumeCommand(attach, managed, vmName, poolType, volumePath, volumeName, volumeSize, deviceId, chainInfo); - - final KVMStoragePoolManager poolManager = Mockito.mock(KVMStoragePoolManager.class); - final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class); - final KVMPhysicalDisk disk = Mockito.mock(KVMPhysicalDisk.class); - - when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper); - try { - when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenReturn(conn); - } catch (final LibvirtException e) { - fail(e.getMessage()); - } - - when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager); - when(poolManager.getStoragePool(command.getPooltype(), command.getPoolUuid())).thenReturn(primary); - when(primary.getPhysicalDisk(command.getVolumePath())).thenReturn(disk); - - final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance(); - assertNotNull(wrapper); - - final Answer answer = wrapper.execute(command, libvirtComputingResource); - assertTrue(answer.getResult()); - - verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper(); - try { - verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName); - } catch (final LibvirtException e) { - fail(e.getMessage()); - } - } - - @SuppressWarnings("unchecked") - @Test - public void testAttachVolumeCommandLibvirtException() { - final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class); - - final boolean attach = true; - final boolean managed = true; - final String vmName = "Test"; - final StoragePoolType poolType = StoragePoolType.ISO; - final String volumePath = "/path"; - final String volumeName = "volume"; - final Long volumeSize = 200l; - final Long deviceId = 1l; - final String chainInfo = "none"; - final AttachVolumeCommand command = new AttachVolumeCommand(attach, managed, vmName, poolType, volumePath, volumeName, volumeSize, deviceId, chainInfo); - - final KVMStoragePoolManager poolManager = Mockito.mock(KVMStoragePoolManager.class); - final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class); - final KVMPhysicalDisk disk = Mockito.mock(KVMPhysicalDisk.class); - - when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper); - try { - when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(LibvirtException.class); - } catch (final LibvirtException e) { - fail(e.getMessage()); - } - - when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager); - when(poolManager.getStoragePool(command.getPooltype(), command.getPoolUuid())).thenReturn(primary); - when(primary.getPhysicalDisk(command.getVolumePath())).thenReturn(disk); - - final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance(); - assertNotNull(wrapper); - - final Answer answer = wrapper.execute(command, libvirtComputingResource); - assertFalse(answer.getResult()); - - verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper(); - try { - verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName); - } catch (final LibvirtException e) { - fail(e.getMessage()); - } - } - - @SuppressWarnings("unchecked") - @Test - public void testAttachVolumeCommandInternalErrorException() { - final LibvirtUtilitiesHelper libvirtUtilitiesHelper = Mockito.mock(LibvirtUtilitiesHelper.class); - - final boolean attach = true; - final boolean managed = true; - final String vmName = "Test"; - final StoragePoolType poolType = StoragePoolType.ISO; - final String volumePath = "/path"; - final String volumeName = "volume"; - final Long volumeSize = 200l; - final Long deviceId = 1l; - final String chainInfo = "none"; - final AttachVolumeCommand command = new AttachVolumeCommand(attach, managed, vmName, poolType, volumePath, volumeName, volumeSize, deviceId, chainInfo); - - final KVMStoragePoolManager poolManager = Mockito.mock(KVMStoragePoolManager.class); - final KVMStoragePool primary = Mockito.mock(KVMStoragePool.class); - final KVMPhysicalDisk disk = Mockito.mock(KVMPhysicalDisk.class); - - when(libvirtComputingResource.getLibvirtUtilitiesHelper()).thenReturn(libvirtUtilitiesHelper); - try { - when(libvirtUtilitiesHelper.getConnectionByVmName(vmName)).thenThrow(InternalErrorException.class); - } catch (final LibvirtException e) { - fail(e.getMessage()); - } - - when(libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager); - when(poolManager.getStoragePool(command.getPooltype(), command.getPoolUuid())).thenReturn(primary); - when(primary.getPhysicalDisk(command.getVolumePath())).thenReturn(disk); - - final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance(); - assertNotNull(wrapper); - - final Answer answer = wrapper.execute(command, libvirtComputingResource); - assertFalse(answer.getResult()); - - verify(libvirtComputingResource, times(1)).getLibvirtUtilitiesHelper(); - try { - verify(libvirtUtilitiesHelper, times(1)).getConnectionByVmName(vmName); - } catch (final LibvirtException e) { - fail(e.getMessage()); - } - } - @Test public void testWatchConsoleProxyLoadCommand() { final int interval = 0; diff --git a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java index 0b83ea4e5b6..0541b7e61a2 100644 --- a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java +++ b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java @@ -40,8 +40,6 @@ import org.apache.cloudstack.storage.to.VolumeObjectTO; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; -import com.cloud.agent.api.AttachVolumeAnswer; -import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.CheckNetworkAnswer; import com.cloud.agent.api.CheckNetworkCommand; import com.cloud.agent.api.CheckVirtualMachineAnswer; @@ -810,10 +808,6 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { return new GetVmStatsAnswer(cmd, vmStatsNameMap); } - protected AttachVolumeAnswer execute(AttachVolumeCommand cmd) { - return new AttachVolumeAnswer(cmd, "You must stop " + cmd.getVmName() + " first, OVM doesn't support hotplug datadisk"); - } - public Answer execute(DestroyCommand cmd) { try { OvmVolume.destroy(_conn, cmd.getVolume().getPoolUuid(), cmd.getVolume().getPath()); @@ -1183,8 +1177,6 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { return execute((GetStorageStatsCommand)cmd); } else if (clazz == GetVmStatsCommand.class) { return execute((GetVmStatsCommand)cmd); - } else if (clazz == AttachVolumeCommand.class) { - return execute((AttachVolumeCommand)cmd); } else if (clazz == DestroyCommand.class) { return execute((DestroyCommand)cmd); } else if (clazz == PrepareForMigrationCommand.class) { diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java index ea0d4075b50..5af2b8f0a21 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/Ovm3HypervisorResource.java @@ -38,7 +38,6 @@ import org.apache.cloudstack.storage.command.StorageSubSystemCommand; import com.cloud.agent.IAgentControl; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; -// import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.CheckHealthCommand; import com.cloud.agent.api.CheckNetworkCommand; import com.cloud.agent.api.CheckOnHostCommand; diff --git a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java index f75cdc935ea..407e6b5df46 100644 --- a/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java +++ b/plugins/hypervisors/ovm3/src/main/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupport.java @@ -28,8 +28,6 @@ import org.apache.log4j.Logger; import org.apache.xmlrpc.XmlRpcException; import com.cloud.agent.api.Answer; -// import com.cloud.agent.api.AttachVolumeAnswer; -// import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.GetVmStatsAnswer; import com.cloud.agent.api.GetVmStatsCommand; import com.cloud.agent.api.GetVncPortAnswer; @@ -152,12 +150,7 @@ public class Ovm3VmSupport { } return true; } -/* - public AttachVolumeAnswer execute(AttachVolumeCommand cmd) { - return new AttachVolumeAnswer(cmd, "You must stop " + cmd.getVmName() - + " first, Ovm3 doesn't support hotplug datadisk"); - } -*/ + /* Migration should make sure both HVs are the same ? */ public PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) { VirtualMachineTO vm = cmd.getVirtualMachine(); diff --git a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java index fc2b0a17b85..e65f0d4f762 100644 --- a/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java +++ b/plugins/hypervisors/ovm3/src/test/java/com/cloud/hypervisor/ovm3/resources/helpers/Ovm3VmSupportTest.java @@ -125,16 +125,4 @@ public class Ovm3VmSupportTest { Answer ra = hypervisor.executeRequest(cmd); results.basicBooleanTest(ra.getResult()); } -/* - @Test - public void AttachVolumeCommandTest() throws ConfigurationException { - hypervisor = support.prepare(configTest.getParams()); - // boolean attach, boolean managed, String vmName, StoragePoolType pooltype, - // String volumePath, String volumeName, Long volumeSize, Long deviceId, String chainInfo - AttachVolumeCommand cmd = new AttachVolumeCommand(true, false, xen.getVmName(), StoragePoolType.NetworkFilesystem, - "x", "x", 0L, 0L, "x"); - Answer ra = hypervisor.executeRequest(cmd); - results.basicBooleanTest(ra.getResult()); - } -*/ } diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java index 6f5a494c27f..f60e13321ae 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java +++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManager.java @@ -24,8 +24,6 @@ import org.apache.cloudstack.storage.command.UploadStatusCommand; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; -import com.cloud.agent.api.AttachVolumeAnswer; -import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.BackupSnapshotCommand; import com.cloud.agent.api.ComputeChecksumCommand; import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand; @@ -59,8 +57,6 @@ public interface MockStorageManager extends Manager { public CreateAnswer createVolume(CreateCommand cmd); - public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd); - public Answer AttachIso(AttachIsoCommand cmd); public Answer DeleteStoragePool(DeleteStoragePoolCommand cmd); diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java index ba24dc7310c..a4fc2f9c10b 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java +++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockStorageManagerImpl.java @@ -42,8 +42,6 @@ import org.apache.cloudstack.storage.command.UploadStatusCommand; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; -import com.cloud.agent.api.AttachVolumeAnswer; -import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.BackupSnapshotAnswer; import com.cloud.agent.api.BackupSnapshotCommand; import com.cloud.agent.api.ComputeChecksumCommand; @@ -245,36 +243,6 @@ public class MockStorageManagerImpl extends ManagerBase implements MockStorageMa return new CreateAnswer(cmd, volumeTo); } - @Override - public AttachVolumeAnswer AttachVolume(AttachVolumeCommand cmd) { - TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.SIMULATOR_DB); - try { - txn.start(); - String poolid = cmd.getPoolUuid(); - String volumeName = cmd.getVolumeName(); - MockVolumeVO volume = _mockVolumeDao.findByStoragePathAndType(cmd.getVolumePath()); - if (volume == null) { - return new AttachVolumeAnswer(cmd, "Can't find volume:" + volumeName + "on pool:" + poolid); - } - - String vmName = cmd.getVmName(); - MockVMVO vm = _mockVMDao.findByVmName(vmName); - if (vm == null) { - return new AttachVolumeAnswer(cmd, "can't vm :" + vmName); - } - txn.commit(); - - return new AttachVolumeAnswer(cmd, cmd.getDeviceId(), cmd.getVolumePath()); - } catch (Exception ex) { - txn.rollback(); - throw new CloudRuntimeException("Error when attaching volume " + cmd.getVolumeName() + " to VM " + cmd.getVmName(), ex); - } finally { - txn.close(); - txn = TransactionLegacy.open(TransactionLegacy.CLOUD_DB); - txn.close(); - } - } - @Override public Answer AttachIso(AttachIsoCommand cmd) { MockVolumeVO iso = findVolumeFromSecondary(cmd.getIsoPath(), cmd.getStoreUrl(), MockVolumeType.ISO); diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java index bd7e9e8eb33..f9ed9ed65d4 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java +++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java @@ -37,7 +37,6 @@ import org.springframework.stereotype.Component; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; -import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.BackupSnapshotCommand; import com.cloud.agent.api.CheckHealthCommand; import com.cloud.agent.api.CheckNetworkCommand; @@ -331,8 +330,6 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage answer = _mockStorageMgr.primaryStorageDownload((PrimaryStorageDownloadCommand)cmd); } else if (cmd instanceof CreateCommand) { answer = _mockStorageMgr.createVolume((CreateCommand)cmd); - } else if (cmd instanceof AttachVolumeCommand) { - answer = _mockStorageMgr.AttachVolume((AttachVolumeCommand)cmd); } else if (cmd instanceof AttachIsoCommand) { answer = _mockStorageMgr.AttachIso((AttachIsoCommand)cmd); } else if (cmd instanceof DeleteStoragePoolCommand) { diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java index ec819f8a184..cc7071523bf 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -1303,7 +1303,7 @@ public class VmwareStorageProcessor implements StorageProcessor { VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null); VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); if (vmMo == null) { - String msg = "Unable to find the VM to execute AttachVolumeCommand, vmName: " + vmName; + String msg = "Unable to find the VM to execute AttachCommand, vmName: " + vmName; s_logger.error(msg); throw new Exception(msg); } @@ -1329,7 +1329,7 @@ public class VmwareStorageProcessor implements StorageProcessor { } if (morDs == null) { - String msg = "Unable to find the mounted datastore to execute AttachVolumeCommand, vmName: " + vmName; + String msg = "Unable to find the mounted datastore to execute AttachCommand, vmName: " + vmName; s_logger.error(msg); throw new Exception(msg); } diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachVolumeCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachVolumeCommandWrapper.java deleted file mode 100644 index 436419e75f0..00000000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixAttachVolumeCommandWrapper.java +++ /dev/null @@ -1,146 +0,0 @@ -// -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -// - -package com.cloud.hypervisor.xenserver.resource.wrapper.xenbase; - -import java.util.Set; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.AttachVolumeAnswer; -import com.cloud.agent.api.AttachVolumeCommand; -import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; -import com.cloud.resource.CommandWrapper; -import com.cloud.resource.ResourceWrapper; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.SR; -import com.xensource.xenapi.Types; -import com.xensource.xenapi.Types.XenAPIException; -import com.xensource.xenapi.VBD; -import com.xensource.xenapi.VDI; -import com.xensource.xenapi.VM; - -@ResourceWrapper(handles = AttachVolumeCommand.class) -public final class CitrixAttachVolumeCommandWrapper extends CommandWrapper { - - private static final Logger s_logger = Logger.getLogger(CitrixAttachVolumeCommandWrapper.class); - - @Override - public Answer execute(final AttachVolumeCommand command, final CitrixResourceBase citrixResourceBase) { - final Connection conn = citrixResourceBase.getConnection(); - final boolean attach = command.getAttach(); - final String vmName = command.getVmName(); - final String vdiNameLabel = vmName + "-DATA"; - final Long deviceId = command.getDeviceId(); - - String errorMsg; - if (attach) { - errorMsg = "Failed to attach volume"; - } else { - errorMsg = "Failed to detach volume"; - } - - try { - VDI vdi = null; - - if (command.getAttach() && command.isManaged()) { - final SR sr = citrixResourceBase.getIscsiSR(conn, command.get_iScsiName(), command.getStorageHost(), command.get_iScsiName(), command.getChapInitiatorUsername(), - command.getChapInitiatorPassword(), true); - - vdi = citrixResourceBase.getVDIbyUuid(conn, command.getVolumePath(), false); - - if (vdi == null) { - vdi = citrixResourceBase.createVdi(sr, vdiNameLabel, command.getVolumeSize()); - } - } else { - vdi = citrixResourceBase.getVDIbyUuid(conn, command.getVolumePath()); - } - - // Look up the VM - final VM vm = citrixResourceBase.getVM(conn, vmName); - if (attach) { - // Figure out the disk number to attach the VM to - String diskNumber = null; - if (deviceId != null) { - if (deviceId.longValue() == 3) { - final String msg = "Device 3 is reserved for CD-ROM, choose other device"; - return new AttachVolumeAnswer(command, msg); - } - if (citrixResourceBase.isDeviceUsed(conn, vm, deviceId)) { - final String msg = "Device " + deviceId + " is used in VM " + vmName; - return new AttachVolumeAnswer(command, msg); - } - diskNumber = deviceId.toString(); - } else { - diskNumber = citrixResourceBase.getUnusedDeviceNum(conn, vm); - } - // Create a new VBD - final VBD.Record vbdr = new VBD.Record(); - vbdr.VM = vm; - vbdr.VDI = vdi; - vbdr.bootable = false; - vbdr.userdevice = diskNumber; - vbdr.mode = Types.VbdMode.RW; - vbdr.type = Types.VbdType.DISK; - vbdr.unpluggable = true; - final VBD vbd = VBD.create(conn, vbdr); - - // Attach the VBD to the VM - vbd.plug(conn); - - // Update the VDI's label to include the VM name - vdi.setNameLabel(conn, vdiNameLabel); - - return new AttachVolumeAnswer(command, Long.parseLong(diskNumber), vdi.getUuid(conn)); - } else { - // Look up all VBDs for this VDI - final Set vbds = vdi.getVBDs(conn); - - // Detach each VBD from its VM, and then destroy it - for (final VBD vbd : vbds) { - final VBD.Record vbdr = vbd.getRecord(conn); - - if (vbdr.currentlyAttached) { - vbd.unplug(conn); - } - - vbd.destroy(conn); - } - - // Update the VDI's label to be "detached" - vdi.setNameLabel(conn, "detached"); - - if (command.isManaged()) { - citrixResourceBase.handleSrAndVdiDetach(command.get_iScsiName(), conn); - } - - return new AttachVolumeAnswer(command); - } - } catch (final XenAPIException e) { - final String msg = errorMsg + " for uuid: " + command.getVolumePath() + " due to " + e.toString(); - s_logger.warn(msg, e); - return new AttachVolumeAnswer(command, msg); - } catch (final Exception e) { - final String msg = errorMsg + " for uuid: " + command.getVolumePath() + " due to " + e.getMessage(); - s_logger.warn(msg, e); - return new AttachVolumeAnswer(command, msg); - } - } -} \ No newline at end of file diff --git a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java index 34cf7f635ed..ca58f355336 100644 --- a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java +++ b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixRequestWrapperTest.java @@ -49,7 +49,6 @@ import org.powermock.api.mockito.PowerMockito; import com.cloud.agent.api.Answer; import com.cloud.agent.api.AttachIsoCommand; -import com.cloud.agent.api.AttachVolumeCommand; import com.cloud.agent.api.CheckHealthCommand; import com.cloud.agent.api.CheckNetworkCommand; import com.cloud.agent.api.CheckOnHostCommand; @@ -127,7 +126,6 @@ import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork; import com.cloud.network.Networks.TrafficType; import com.cloud.network.PhysicalNetworkSetupInfo; import com.cloud.storage.Storage.ImageFormat; -import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.VMTemplateStorageResourceAssoc; import com.cloud.storage.resource.StorageSubsystemCommandHandler; import com.cloud.utils.Pair; @@ -439,19 +437,6 @@ public class CitrixRequestWrapperTest { assertFalse(answer.getResult()); } - @Test - public void testAttachVolumeCommand() { - final AttachVolumeCommand attachCommand = new AttachVolumeCommand(false, true, "Test", StoragePoolType.LVM, "/", "DATA", 100l, 1l, "123"); - - final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance(); - assertNotNull(wrapper); - - final Answer answer = wrapper.execute(attachCommand, citrixResourceBase); - verify(citrixResourceBase, times(1)).getConnection(); - - assertFalse(answer.getResult()); - } - @Test public void testAttachIsoCommand() { final AttachIsoCommand attachCommand = new AttachIsoCommand("Test", "/", true);