mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
so many traps in rpc call: you can't use aop in a thread, you need to intercept finalize call etc
This commit is contained in:
parent
4b2d9f4415
commit
d99161399e
@ -41,4 +41,5 @@ public interface PrimaryDataStoreInfo {
|
||||
public String getType();
|
||||
public PrimaryDataStoreLifeCycle getLifeCycle();
|
||||
PrimaryDataStoreProvider getProvider();
|
||||
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class ChildTestConfiguration extends TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public HostEndpointRpcServer rpcServer() {
|
||||
return new MockHypervsiorHostEndPointRpcServer();
|
||||
return new MockHostEndpointRpcServerDirectCallResource();
|
||||
}
|
||||
/* @Override
|
||||
@Bean
|
||||
|
||||
@ -6,6 +6,7 @@ import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
@ -17,13 +18,23 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||
private String hostGuid;
|
||||
private String templateUrl;
|
||||
private String localStorageUuid;
|
||||
private String primaryStorageUrl;
|
||||
private Transaction txn;
|
||||
|
||||
protected void injectMockito() {
|
||||
|
||||
}
|
||||
|
||||
@BeforeMethod(alwaysRun = true)
|
||||
protected void injectDB(Method testMethod) throws Exception {
|
||||
txn = Transaction.open(testMethod.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
protected void injectMockitoTest() {
|
||||
injectMockito();
|
||||
}
|
||||
|
||||
@AfterMethod(alwaysRun = true)
|
||||
protected void closeDB(Method testMethod) throws Exception {
|
||||
if (txn != null) {
|
||||
@ -32,14 +43,19 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||
}
|
||||
|
||||
@BeforeMethod(alwaysRun = true)
|
||||
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr", "devcloud-host-ip", "template-url", "devcloud-local-storage-uuid"})
|
||||
protected void setup(String hostuuid, String gateway, String cidr, String hostIp, String templateUrl, String localStorageUuid) {
|
||||
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr",
|
||||
"devcloud-host-ip", "template-url", "devcloud-local-storage-uuid",
|
||||
"primary-storage-want-to-add"})
|
||||
protected void setup(String hostuuid, String gateway, String cidr,
|
||||
String hostIp, String templateUrl, String localStorageUuid,
|
||||
String primaryStorage) {
|
||||
this.hostGuid = hostuuid;
|
||||
this.hostGateway = gateway;
|
||||
this.hostCidr = cidr;
|
||||
this.hostIp = hostIp;
|
||||
this.templateUrl = templateUrl;
|
||||
this.localStorageUuid = localStorageUuid;
|
||||
this.primaryStorageUrl = primaryStorage;
|
||||
}
|
||||
|
||||
protected String getHostGuid() {
|
||||
@ -65,4 +81,8 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
|
||||
protected String getLocalStorageUuid() {
|
||||
return this.localStorageUuid;
|
||||
}
|
||||
|
||||
protected String getPrimaryStorageUrl() {
|
||||
return this.primaryStorageUrl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,6 +37,9 @@ import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
|
||||
public class MockHostEndpointRpcServerDirectCallResource implements HostEndpointRpcServer {
|
||||
@ -47,29 +50,14 @@ public class MockHostEndpointRpcServerDirectCallResource implements HostEndpoint
|
||||
public MockHostEndpointRpcServerDirectCallResource() {
|
||||
executor = Executors.newScheduledThreadPool(10);
|
||||
}
|
||||
protected class MockRpcCallBack implements Runnable {
|
||||
private final Command cmd;
|
||||
private final long hostId;
|
||||
private final AsyncCompletionCallback<Answer> callback;
|
||||
public MockRpcCallBack(long hostId, Command cmd, final AsyncCompletionCallback<Answer> callback) {
|
||||
this.cmd = cmd;
|
||||
this.callback = callback;
|
||||
this.hostId = hostId;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Answer answer = agentMgr.send(hostId, cmd);
|
||||
callback.complete(answer);
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("send command failed:" + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void sendCommandAsync(HypervisorHostEndPoint host, final Command command, final AsyncCompletionCallback<Answer> callback) {
|
||||
executor.schedule(new MockRpcCallBack(host.getHostId(), command, callback), 10, TimeUnit.SECONDS);
|
||||
// new MockRpcCallBack(host.getHostId(), command, callback);
|
||||
MockRpcCallBack run = ComponentInject.inject(MockRpcCallBack.class);
|
||||
run.setCallback(callback);
|
||||
run.setCmd(command);
|
||||
run.setHostId(host.getHostId());
|
||||
executor.schedule(run, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
public class MockRpcCallBack implements Runnable {
|
||||
@Inject
|
||||
AgentManager agentMgr;
|
||||
private Command cmd;
|
||||
private long hostId;
|
||||
private AsyncCompletionCallback<Answer> callback;
|
||||
|
||||
public void setCmd(Command cmd) {
|
||||
this.cmd = cmd;
|
||||
}
|
||||
|
||||
public void setHostId(long hostId) {
|
||||
this.hostId = hostId;
|
||||
}
|
||||
|
||||
public void setCallback(AsyncCompletionCallback<Answer> callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void run() {
|
||||
try {
|
||||
Answer answer = agentMgr.send(hostId, cmd);
|
||||
|
||||
callback.complete(answer);
|
||||
} catch (Throwable e) {
|
||||
//s_logger.debug("send command failed:" + e.toString());
|
||||
} finally {
|
||||
int i =1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -18,8 +18,9 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.AssertJUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -51,7 +52,6 @@ import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
|
||||
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl;
|
||||
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.ImageService;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
@ -68,14 +68,7 @@ import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCyc
|
||||
import org.apache.cloudstack.storage.volume.VolumeService;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeVO;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Mockito.*;
|
||||
|
||||
@ -100,13 +93,9 @@ import com.cloud.org.Cluster.ClusterType;
|
||||
import com.cloud.org.Managed.ManagedState;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="classpath:/storageContext.xml")
|
||||
public class volumeServiceTest {
|
||||
public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
@Inject
|
||||
ImageDataStoreProviderManager imageProviderMgr;
|
||||
@Inject
|
||||
@ -134,8 +123,19 @@ public class volumeServiceTest {
|
||||
Long dcId;
|
||||
Long clusterId;
|
||||
Long podId;
|
||||
@Before
|
||||
HostVO host;
|
||||
String primaryName = "my primary data store";
|
||||
|
||||
@Test(priority = -1)
|
||||
public void setUp() {
|
||||
|
||||
host = hostDao.findByGuid(this.getHostGuid());
|
||||
if (host != null) {
|
||||
dcId = host.getDataCenterId();
|
||||
clusterId = host.getClusterId();
|
||||
podId = host.getPodId();
|
||||
return;
|
||||
}
|
||||
//create data center
|
||||
DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24",
|
||||
null, null, NetworkType.Basic, null, null, true, true);
|
||||
@ -143,7 +143,7 @@ public class volumeServiceTest {
|
||||
dcId = dc.getId();
|
||||
//create pod
|
||||
|
||||
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "192.168.56.1", "192.168.56.0/24", 8, "test");
|
||||
HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), this.getHostGateway(), this.getHostCidr(), 8, "test");
|
||||
pod = podDao.persist(pod);
|
||||
podId = pod.getId();
|
||||
//create xen cluster
|
||||
@ -155,23 +155,23 @@ public class volumeServiceTest {
|
||||
clusterId = cluster.getId();
|
||||
//create xen host
|
||||
|
||||
HostVO host = new HostVO(UUID.randomUUID().toString());
|
||||
host = new HostVO(this.getHostGuid());
|
||||
host.setName("devcloud xen host");
|
||||
host.setType(Host.Type.Routing);
|
||||
host.setPrivateIpAddress("192.168.56.2");
|
||||
host.setPrivateIpAddress(this.getHostIp());
|
||||
host.setDataCenterId(dc.getId());
|
||||
host.setVersion("6.0.1");
|
||||
host.setAvailable(true);
|
||||
host.setSetup(true);
|
||||
host.setPodId(podId);
|
||||
host.setLastPinged(0);
|
||||
host.setResourceState(ResourceState.Enabled);
|
||||
host.setHypervisorType(HypervisorType.XenServer);
|
||||
host.setClusterId(cluster.getId());
|
||||
|
||||
host = hostDao.persist(host);
|
||||
List<HostVO> results = new ArrayList<HostVO>();
|
||||
results.add(host);
|
||||
Mockito.when(hostDao.listAll()).thenReturn(results);
|
||||
Mockito.when(hostDao.findHypervisorHostInCluster(Mockito.anyLong())).thenReturn(results);
|
||||
|
||||
|
||||
//CreateVolumeAnswer createVolumeFromImageAnswer = new CreateVolumeAnswer(UUID.randomUUID().toString());
|
||||
|
||||
/*try {
|
||||
@ -187,11 +187,22 @@ public class volumeServiceTest {
|
||||
|
||||
//Mockito.when(primaryStoreDao.findById(Mockito.anyLong())).thenReturn(primaryStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void injectMockito() {
|
||||
if (host == null) {
|
||||
return;
|
||||
}
|
||||
List<HostVO> results = new ArrayList<HostVO>();
|
||||
results.add(host);
|
||||
Mockito.when(hostDao.listAll()).thenReturn(results);
|
||||
Mockito.when(hostDao.findHypervisorHostInCluster(Mockito.anyLong())).thenReturn(results);
|
||||
}
|
||||
|
||||
private ImageDataVO createImageData() {
|
||||
ImageDataVO image = new ImageDataVO();
|
||||
image.setTemplateType(TemplateType.USER);
|
||||
image.setUrl("http://testurl/test.vhd");
|
||||
image.setUrl(this.getTemplateUrl());
|
||||
image.setUniqueName(UUID.randomUUID().toString());
|
||||
image.setName(UUID.randomUUID().toString());
|
||||
image.setPublicTemplate(true);
|
||||
@ -226,21 +237,29 @@ public class volumeServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createTemplateTest() {
|
||||
createTemplate();
|
||||
}
|
||||
|
||||
private PrimaryDataStoreInfo createPrimaryDataStore() {
|
||||
try {
|
||||
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
|
||||
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
|
||||
|
||||
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
|
||||
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
|
||||
|
||||
List<PrimaryDataStoreVO> ds = primaryStoreDao.findPoolByName(this.primaryName);
|
||||
if (ds.size() >= 1) {
|
||||
PrimaryDataStoreVO store = ds.get(0);
|
||||
if (store.getRemoved() == null) {
|
||||
return provider.getDataStore(store.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("url", "nfs://localhost/primarynfs");
|
||||
params.put("url", this.getPrimaryStorageUrl());
|
||||
params.put("dcId", dcId.toString());
|
||||
params.put("clusterId", clusterId.toString());
|
||||
params.put("name", "my primary data store");
|
||||
params.put("name", this.primaryName);
|
||||
PrimaryDataStoreInfo primaryDataStoreInfo = provider.registerDataStore(params);
|
||||
PrimaryDataStoreLifeCycle lc = primaryDataStoreInfo.getLifeCycle();
|
||||
ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
|
||||
@ -251,11 +270,6 @@ public class volumeServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPrimaryDataStoreTest() {
|
||||
createPrimaryDataStore();
|
||||
}
|
||||
|
||||
private VolumeVO createVolume(long templateId) {
|
||||
VolumeVO volume = new VolumeVO(1000, new RootDisk().toString(), UUID.randomUUID().toString(), templateId);
|
||||
volume = volumeDao.persist(volume);
|
||||
@ -263,7 +277,7 @@ public class volumeServiceTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(priority=2)
|
||||
public void createVolumeFromTemplate() {
|
||||
TemplateEntity te = createTemplate();
|
||||
PrimaryDataStoreInfo dataStoreInfo = createPrimaryDataStore();
|
||||
@ -271,37 +285,40 @@ public class volumeServiceTest {
|
||||
VolumeEntity ve = volumeService.getVolumeEntity(volume.getId());
|
||||
ve.createVolumeFromTemplate(dataStoreInfo.getId(), new VHD(), te);
|
||||
}
|
||||
|
||||
@Test(priority=3)
|
||||
public void tearDown() {
|
||||
List<PrimaryDataStoreVO> ds = primaryStoreDao.findPoolByName(this.primaryName);
|
||||
for (int i = 0; i < ds.size(); i++) {
|
||||
PrimaryDataStoreVO store = ds.get(i);
|
||||
store.setUuid(null);
|
||||
primaryStoreDao.remove(ds.get(i).getId());
|
||||
primaryStoreDao.expunge(ds.get(i).getId());
|
||||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void test1() {
|
||||
@Test
|
||||
public void test1() {
|
||||
System.out.println(VolumeTypeHelper.getType("Root"));
|
||||
System.out.println(VolumeDiskTypeHelper.getDiskType("vmdk"));
|
||||
System.out.println(ImageFormatHelper.getFormat("ova"));
|
||||
assertFalse(new VMDK().equals(new VHD()));
|
||||
AssertJUnit.assertFalse(new VMDK().equals(new VHD()));
|
||||
VMDK vmdk = new VMDK();
|
||||
assertTrue(vmdk.equals(vmdk));
|
||||
AssertJUnit.assertTrue(vmdk.equals(vmdk));
|
||||
VMDK newvmdk = new VMDK();
|
||||
assertTrue(vmdk.equals(newvmdk));
|
||||
AssertJUnit.assertTrue(vmdk.equals(newvmdk));
|
||||
|
||||
ImageFormat ova = new OVA();
|
||||
ImageFormat iso = new ISO();
|
||||
assertTrue(ova.equals(new OVA()));
|
||||
assertFalse(ova.equals(iso));
|
||||
assertTrue(ImageFormatHelper.getFormat("test").equals(new Unknown()));
|
||||
AssertJUnit.assertTrue(ova.equals(new OVA()));
|
||||
AssertJUnit.assertFalse(ova.equals(iso));
|
||||
AssertJUnit.assertTrue(ImageFormatHelper.getFormat("test").equals(new Unknown()));
|
||||
|
||||
VolumeDiskType qcow2 = new QCOW2();
|
||||
ImageFormat qcow2format = new org.apache.cloudstack.storage.image.format.QCOW2();
|
||||
assertFalse(qcow2.equals(qcow2format));
|
||||
AssertJUnit.assertFalse(qcow2.equals(qcow2format));
|
||||
|
||||
}
|
||||
|
||||
//@Test
|
||||
public void testStaticBean() {
|
||||
DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class);
|
||||
//assertNotNull(provider.dataStoreDao);
|
||||
|
||||
DefaultPrimaryDataStore dpdsi = DefaultPrimaryDataStore.createDataStore(null);
|
||||
//assertNotNull(dpdsi.volumeDao);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
|
||||
<suite thread-count="1" verbose="1" name="storage test" annotations="JDK" parallel="methods">
|
||||
<suite thread-count="1" verbose="1" name="storage test" annotations="JDK" parallel="classes">
|
||||
<!--describe your test environment-->
|
||||
<parameter name="devcloud-host-ip" value="192.168.56.2"/>
|
||||
<parameter name="devcloud-host-gateway" value="192.168.56.1"/>
|
||||
|
||||
@ -18,15 +18,14 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.command;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class AttachPrimaryDataStoreCmd extends Command implements StorageSubSystemCommand {
|
||||
private final PrimaryDataStoreTO dataStore;
|
||||
public AttachPrimaryDataStoreCmd(PrimaryDataStoreInfo dataStore) {
|
||||
this.dataStore = new PrimaryDataStoreTO(dataStore);
|
||||
public AttachPrimaryDataStoreCmd(PrimaryDataStoreTO dataStore) {
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
||||
public PrimaryDataStoreTO getDataStore() {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package org.apache.cloudstack.storage.command;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
@ -27,6 +27,8 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.command.CommandResult;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
|
||||
public interface PrimaryDataStore extends PrimaryDataStoreInfo {
|
||||
@ -53,4 +55,8 @@ public interface PrimaryDataStore extends PrimaryDataStoreInfo {
|
||||
boolean installTemplate(TemplateOnPrimaryDataStoreInfo template);
|
||||
|
||||
VolumeDiskType getDefaultDiskType();
|
||||
|
||||
PrimaryDataStoreTO getDataStoreTO();
|
||||
|
||||
VolumeTO getVolumeTO(VolumeInfo volume);
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package org.apache.cloudstack.storage.datastore.protocol;
|
||||
|
||||
public enum DataStoreProtocol {
|
||||
NFS("nfs"),
|
||||
ISCSI("iscsi");
|
||||
|
||||
private String name;
|
||||
DataStoreProtocol(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ public class ImageOnPrimayDataStoreTO {
|
||||
private final TemplateTO template;
|
||||
public ImageOnPrimayDataStoreTO(TemplateOnPrimaryDataStoreInfo template) {
|
||||
this.pathOnPrimaryDataStore = template.getPath();
|
||||
this.dataStore = new PrimaryDataStoreTO(template.getPrimaryDataStore());
|
||||
this.dataStore = template.getPrimaryDataStore().getDataStoreTO();
|
||||
this.template = new TemplateTO(template.getTemplate());
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package org.apache.cloudstack.storage.to;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
|
||||
public class NfsPrimaryDataStoreTO extends PrimaryDataStoreTO {
|
||||
private String server;
|
||||
private String path;
|
||||
|
||||
public NfsPrimaryDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
super(dataStore);
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return this.server;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
@ -6,10 +6,16 @@ public class PrimaryDataStoreTO {
|
||||
private final String uuid;
|
||||
private final String name;
|
||||
private final String type;
|
||||
private final long id;
|
||||
public PrimaryDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
this.uuid = dataStore.getUuid();
|
||||
this.name = dataStore.getName();
|
||||
this.type = dataStore.getType();
|
||||
this.id = dataStore.getId();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
|
||||
@ -19,5 +19,5 @@
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
public enum DataStoreStatus {
|
||||
Initial, Initialized, Creating, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Removed;
|
||||
Initial, Initialized, Creating, Attaching, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Removed;
|
||||
}
|
||||
|
||||
@ -15,9 +15,13 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
|
||||
import org.apache.cloudstack.storage.command.CommandResult;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.volume.TemplatePrimaryDataStoreManager;
|
||||
import org.apache.cloudstack.storage.volume.VolumeObject;
|
||||
@ -36,18 +40,20 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStore.class);
|
||||
protected PrimaryDataStoreDriver driver;
|
||||
protected PrimaryDataStoreVO pdsv;
|
||||
protected PrimaryDataStoreInfo pdsInfo;
|
||||
protected PrimaryDataStoreLifeCycle lifeCycle;
|
||||
protected PrimaryDataStoreProvider provider;
|
||||
protected StorageProtocolTransformer protocalTransformer;
|
||||
private HypervisorType supportedHypervisor;
|
||||
private boolean isLocalStorageSupported = false;
|
||||
@Inject
|
||||
private VolumeDao volumeDao;
|
||||
@Inject
|
||||
HostDao hostDao;
|
||||
private HostDao hostDao;
|
||||
@Inject
|
||||
TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
|
||||
|
||||
private PrimaryDataStoreDao dataStoreDao;
|
||||
@Inject
|
||||
private TemplatePrimaryDataStoreManager templatePrimaryStoreMgr;
|
||||
|
||||
private DefaultPrimaryDataStore(PrimaryDataStoreVO pdsv) {
|
||||
this.pdsv = pdsv;
|
||||
}
|
||||
@ -66,6 +72,20 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public void setProtocolTransFormer(StorageProtocolTransformer transformer) {
|
||||
this.protocalTransformer = transformer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreTO getDataStoreTO() {
|
||||
return this.protocalTransformer.getDataStoreTO(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
return this.protocalTransformer.getVolumeTO(volume);
|
||||
}
|
||||
|
||||
public static DefaultPrimaryDataStore createDataStore(PrimaryDataStoreVO pdsv) {
|
||||
DefaultPrimaryDataStore dataStore = new DefaultPrimaryDataStore(pdsv);
|
||||
return ComponentInject.inject(dataStore);
|
||||
@ -97,8 +117,13 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
public List<EndPoint> getEndPoints() {
|
||||
Long clusterId = pdsv.getClusterId();
|
||||
if (clusterId == null) {
|
||||
return null;
|
||||
pdsv = dataStoreDao.findById(pdsv.getId());
|
||||
clusterId = pdsv.getClusterId();
|
||||
if (clusterId == null) {
|
||||
return new ArrayList<EndPoint>();
|
||||
}
|
||||
}
|
||||
|
||||
List<EndPoint> endpoints = new ArrayList<EndPoint>();
|
||||
List<HostVO> hosts = hostDao.findHypervisorHostInCluster(clusterId);
|
||||
for (HostVO host : hosts) {
|
||||
@ -206,26 +231,22 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this.pdsv.getUuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataCenterResourceEntity.State getManagedState() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this.pdsv.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this.pdsv.getPoolType();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -12,19 +12,13 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public abstract class AbstractPrimaryDataStoreConfigurator implements PrimaryDataStoreConfigurator {
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
protected PrimaryDataStoreDao dataStoreDao;
|
||||
|
||||
protected PrimaryDataStoreLifeCycle getLifeCycle() {
|
||||
return null;
|
||||
}
|
||||
protected abstract PrimaryDataStoreLifeCycle getLifeCycle();
|
||||
|
||||
protected PrimaryDataStoreDriver getDriver() {
|
||||
return null;
|
||||
}
|
||||
protected abstract PrimaryDataStoreDriver getDriver();
|
||||
|
||||
protected boolean isLocalStorageSupported() {
|
||||
return false;
|
||||
}
|
||||
protected abstract boolean isLocalStorageSupported();
|
||||
|
||||
@Override
|
||||
public PrimaryDataStore getDataStore(long dataStoreId) {
|
||||
@ -34,10 +28,11 @@ public abstract class AbstractPrimaryDataStoreConfigurator implements PrimaryDat
|
||||
}
|
||||
|
||||
DefaultPrimaryDataStore dataStore = DefaultPrimaryDataStore.createDataStore(dataStoreVO);
|
||||
dataStore.setDriver(this.getDriver());
|
||||
dataStore.setDriver(getDriver());
|
||||
dataStore.setLifeCycle(getLifeCycle());
|
||||
dataStore.setSupportedHypervisor(getSupportedHypervisor());
|
||||
dataStore.setLocalStorageFlag(isLocalStorageSupported());
|
||||
dataStore.setProtocolTransFormer(getProtocolTransformer());
|
||||
return dataStore;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
package org.apache.cloudstack.storage.datastore.configurator;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
@ -28,5 +28,5 @@ public interface PrimaryDataStoreConfigurator {
|
||||
public HypervisorType getSupportedHypervisor();
|
||||
public String getSupportedDataStoreType();
|
||||
public PrimaryDataStore getDataStore(long dataStoreId);
|
||||
public ProtocolValidator getValidator();
|
||||
public StorageProtocolTransformer getProtocolTransformer();
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
package org.apache.cloudstack.storage.datastore.configurator.kvm;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.CLVMValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -33,9 +33,15 @@ public class KvmCLVMConfigurator extends AbstractKvmConfigurator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new CLVMValidator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -18,22 +18,32 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.kvm;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.NfsValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.NfsProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.component.Inject;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class KvmNfsConfigurator extends AbstractKvmConfigurator {
|
||||
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
return "nfs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
return new NfsValidator();
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new NfsProtocolTransformer(dataStoreDao);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.kvm;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.RBDValidator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -29,13 +29,18 @@ import com.cloud.storage.Storage.StoragePoolType;
|
||||
@Qualifier("defaultProvider")
|
||||
public class KvmRBDConfigurator extends AbstractKvmConfigurator {
|
||||
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
return "rbd";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new RBDValidator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,10 +21,15 @@ package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CLVMValidator implements ProtocolValidator {
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
public class CLVMValidator implements StorageProtocolTransformer {
|
||||
|
||||
@Override
|
||||
public boolean validate(Map<String, String> params) {
|
||||
public boolean normalizeUserInput(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@ -35,4 +40,17 @@ public class CLVMValidator implements ProtocolValidator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -21,10 +21,15 @@ package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FileSystemValidator implements ProtocolValidator {
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
public class FileSystemValidator implements StorageProtocolTransformer {
|
||||
|
||||
@Override
|
||||
public boolean validate(Map<String, String> params) {
|
||||
public boolean normalizeUserInput(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@ -35,4 +40,17 @@ public class FileSystemValidator implements ProtocolValidator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -21,13 +21,12 @@ package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ISCSIValiator implements ProtocolValidator {
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
@Override
|
||||
public boolean validate(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
public class ISCSIValiator implements StorageProtocolTransformer {
|
||||
|
||||
@Override
|
||||
public List<String> getInputParamNames() {
|
||||
@ -35,4 +34,22 @@ public class ISCSIValiator implements ProtocolValidator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean normalizeUserInput(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -25,12 +25,25 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
import org.apache.cloudstack.storage.to.NfsPrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class NfsValidator implements ProtocolValidator {
|
||||
|
||||
public class NfsProtocolTransformer implements StorageProtocolTransformer {
|
||||
private final PrimaryDataStoreDao dataStoreDao;
|
||||
|
||||
public NfsProtocolTransformer(PrimaryDataStoreDao dao) {
|
||||
this.dataStoreDao = dao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validate(Map<String, String> params) {
|
||||
public boolean normalizeUserInput(Map<String, String> params) {
|
||||
String url = params.get("url");
|
||||
|
||||
try {
|
||||
@ -49,8 +62,7 @@ public class NfsValidator implements ProtocolValidator {
|
||||
params.put("path", hostPath);
|
||||
params.put("user", userInfo);
|
||||
params.put("port", String.valueOf(port));
|
||||
params.put("uuid", UUID.fromString(storageHost + hostPath).toString());
|
||||
|
||||
params.put("uuid", UUID.nameUUIDFromBytes((storageHost + hostPath).getBytes()).toString());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new CloudRuntimeException("invalid url: " + e.toString());
|
||||
}
|
||||
@ -65,4 +77,19 @@ public class NfsValidator implements ProtocolValidator {
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
NfsPrimaryDataStoreTO dataStoreTO = new NfsPrimaryDataStoreTO(dataStore);
|
||||
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(dataStore.getId());
|
||||
dataStoreTO.setServer(dataStoreVO.getHostAddress());
|
||||
dataStoreTO.setPath(dataStoreVO.getPath());
|
||||
return dataStoreTO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,10 +21,15 @@ package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RBDValidator implements ProtocolValidator {
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
public class RBDValidator implements StorageProtocolTransformer {
|
||||
|
||||
@Override
|
||||
public boolean validate(Map<String, String> params) {
|
||||
public boolean normalizeUserInput(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@ -35,4 +40,16 @@ public class RBDValidator implements ProtocolValidator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,7 +21,14 @@ package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ProtocolValidator {
|
||||
public boolean validate(Map<String, String> params);
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
public interface StorageProtocolTransformer {
|
||||
public boolean normalizeUserInput(Map<String, String> params);
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore);
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume);
|
||||
public List<String> getInputParamNames();
|
||||
}
|
||||
@ -21,10 +21,15 @@ package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class VMFSValidator implements ProtocolValidator {
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
public class VMFSValidator implements StorageProtocolTransformer {
|
||||
|
||||
@Override
|
||||
public boolean validate(Map<String, String> params) {
|
||||
public boolean normalizeUserInput(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
@ -35,4 +40,16 @@ public class VMFSValidator implements ProtocolValidator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
package org.apache.cloudstack.storage.datastore.configurator.vmware;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ISCSIValiator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -27,14 +27,19 @@ import org.springframework.stereotype.Component;
|
||||
@Qualifier("defaultProvider")
|
||||
public class VmwareIsciConfigurator extends AbstractVmwareConfigurator {
|
||||
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
return "iscsi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new ISCSIValiator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,24 +18,33 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.vmware;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.NfsValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.NfsProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.utils.component.Inject;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class VmwareNfsConfigurator extends AbstractVmwareConfigurator {
|
||||
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
return "nfs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
return new NfsValidator();
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new NfsProtocolTransformer(dataStoreDao);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.vmware;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.VMFSValidator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -35,7 +35,13 @@ public class VmwareVMFSConfigurator extends AbstractVmwareConfigurator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new VMFSValidator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,25 +1,14 @@
|
||||
package org.apache.cloudstack.storage.datastore.configurator.xen;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.AbstractPrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.datastore.lifecycle.DefaultXenPrimaryDataStoreLifeCycle;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public abstract class AbstractXenConfigurator extends AbstractPrimaryDataStoreConfigurator {
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
|
||||
@Override
|
||||
public HypervisorType getSupportedHypervisor() {
|
||||
return HypervisorType.XenServer;
|
||||
@ -32,17 +21,4 @@ public abstract class AbstractXenConfigurator extends AbstractPrimaryDataStoreCo
|
||||
protected PrimaryDataStoreDriver getDriver() {
|
||||
return new DefaultPrimaryDataStoreDriverImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStore getDataStore(long dataStoreId) {
|
||||
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId);
|
||||
if (dataStoreVO == null) {
|
||||
throw new CloudRuntimeException("Can't find primary data store: " + dataStoreId);
|
||||
}
|
||||
|
||||
DefaultPrimaryDataStore dataStore = DefaultPrimaryDataStore.createDataStore(dataStoreVO);
|
||||
dataStore.setDriver(this.getDriver());
|
||||
dataStore.setLifeCycle(getLifeCycle());
|
||||
return dataStore;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
package org.apache.cloudstack.storage.datastore.configurator.xen;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ISCSIValiator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -33,8 +33,13 @@ public class XenIscsiConfigurator extends AbstractXenConfigurator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new ISCSIValiator();
|
||||
}
|
||||
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,24 +18,32 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.xen;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.NfsValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.NfsProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.protocol.DataStoreProtocol;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.utils.component.Inject;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class XenNfsConfigurator extends AbstractXenConfigurator {
|
||||
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
return "nfs";
|
||||
return DataStoreProtocol.NFS.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
return new NfsValidator();
|
||||
public StorageProtocolTransformer getProtocolTransformer() {
|
||||
return new NfsProtocolTransformer(dataStoreDao);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
||||
// which can access its datastore
|
||||
List<EndPoint> endPoints = vol.getDataStore().getEndPoints();
|
||||
VolumeInfo volInfo = vol;
|
||||
CreateVolumeCommand createCmd = new CreateVolumeCommand(new VolumeTO(volInfo));
|
||||
CreateVolumeCommand createCmd = new CreateVolumeCommand(this.dataStore.getVolumeTO(volInfo));
|
||||
Answer answer = sendOutCommand(createCmd, endPoints);
|
||||
|
||||
CreateVolumeAnswer volAnswer = (CreateVolumeAnswer) answer;
|
||||
|
||||
@ -52,8 +52,8 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
|
||||
}
|
||||
|
||||
protected void attachCluster() {
|
||||
//send down createStoragePool command to all the hosts in the cluster
|
||||
AttachPrimaryDataStoreCmd cmd = new AttachPrimaryDataStoreCmd(this.dataStore);
|
||||
//send down AttachPrimaryDataStoreCmd command to all the hosts in the cluster
|
||||
AttachPrimaryDataStoreCmd cmd = new AttachPrimaryDataStoreCmd(this.dataStore.getDataStoreTO());
|
||||
for (EndPoint ep : dataStore.getEndPoints()) {
|
||||
ep.sendMessage(cmd);
|
||||
}
|
||||
@ -61,14 +61,19 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
|
||||
|
||||
@Override
|
||||
public boolean attachCluster(ClusterScope scope) {
|
||||
attachCluster();
|
||||
|
||||
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findById(this.dataStore.getId());
|
||||
dataStoreVO.setDataCenterId(scope.getZoneId());
|
||||
dataStoreVO.setPodId(scope.getPodId());
|
||||
dataStoreVO.setClusterId(scope.getScopeId());
|
||||
dataStoreVO.setStatus(DataStoreStatus.Attaching);
|
||||
dataStoreDao.update(dataStoreVO.getId(), dataStoreVO);
|
||||
|
||||
attachCluster();
|
||||
|
||||
dataStoreVO = dataStoreDao.findById(this.dataStore.getId());
|
||||
dataStoreVO.setStatus(DataStoreStatus.Up);
|
||||
dataStoreDao.update(dataStoreVO.getId(), dataStoreVO);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ package org.apache.cloudstack.storage.datastore.lifecycle;
|
||||
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreCmd;
|
||||
import org.apache.cloudstack.storage.command.CreatePrimaryDataStoreCmd;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
@ -39,7 +40,7 @@ public class DefaultXenPrimaryDataStoreLifeCycle extends DefaultPrimaryDataStore
|
||||
@Override
|
||||
public void attachCluster() {
|
||||
//send one time is enough, as xenserver is clustered
|
||||
AttachPrimaryDataStoreCmd cmd = new AttachPrimaryDataStoreCmd(this.dataStore);
|
||||
CreatePrimaryDataStoreCmd cmd = new CreatePrimaryDataStoreCmd(this.dataStore.getDataStoreTO());
|
||||
String result = null;
|
||||
for (EndPoint ep : dataStore.getEndPoints()) {
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
@ -49,8 +50,9 @@ public class DefaultXenPrimaryDataStoreLifeCycle extends DefaultPrimaryDataStore
|
||||
result = answer.getDetails();
|
||||
}
|
||||
|
||||
throw new CloudRuntimeException("AttachPrimaryDataStoreCmd failed: " + result);
|
||||
if (result != null)
|
||||
throw new CloudRuntimeException("AttachPrimaryDataStoreCmd failed: " + result);
|
||||
|
||||
super.attachCluster();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvid
|
||||
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.StorageProtocolTransformer;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
@ -44,21 +44,6 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
|
||||
protected ClusterDao clusterDao;
|
||||
protected Map<String, PrimaryDataStoreConfigurator> configuratorMaps = new HashMap<String, PrimaryDataStoreConfigurator>();
|
||||
|
||||
@Qualifier("defaultProvider")
|
||||
@Inject
|
||||
List<PrimaryDataStoreConfigurator> defaultConfigurators;
|
||||
|
||||
public DefaultPrimaryDatastoreProviderImpl() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void intialize() {
|
||||
for (PrimaryDataStoreConfigurator configurator : defaultConfigurators) {
|
||||
String key = generateKey(configurator.getSupportedHypervisor(), configurator.getSupportedDataStoreType().toString());
|
||||
configuratorMaps.put(key, configurator);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
public DefaultPrimaryDatastoreProviderImpl(@Qualifier("defaultProvider") List<PrimaryDataStoreConfigurator> configurators) {
|
||||
for (PrimaryDataStoreConfigurator configurator : configurators) {
|
||||
@ -114,10 +99,15 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
|
||||
throw new CloudRuntimeException("can't find configurator from key: " + key);
|
||||
}
|
||||
|
||||
ProtocolValidator validator = configurator.getValidator();
|
||||
validator.validate(dsInfos);
|
||||
StorageProtocolTransformer validator = configurator.getProtocolTransformer();
|
||||
validator.normalizeUserInput(dsInfos);
|
||||
|
||||
PrimaryDataStoreVO dataStoreVO = new PrimaryDataStoreVO();
|
||||
PrimaryDataStoreVO dataStoreVO = dataStoreDao.findPoolByUUID(dsInfos.get("uuid"));
|
||||
if (dataStoreVO != null) {
|
||||
throw new CloudRuntimeException("duplicate uuid: " + dsInfos.get("uuid"));
|
||||
}
|
||||
|
||||
dataStoreVO = new PrimaryDataStoreVO();
|
||||
dataStoreVO.setStorageProviderId(this.getId());
|
||||
dataStoreVO.setHostAddress(dsInfos.get("server"));
|
||||
dataStoreVO.setPath(dsInfos.get("path"));
|
||||
|
||||
@ -71,13 +71,17 @@ public class TemplateOnPrimaryDataStoreObject implements TemplateOnPrimaryDataSt
|
||||
public void updateStatus(Status status) {
|
||||
vo.setDownloadState(status);
|
||||
templateStoreDao.update(vo.getId(), vo);
|
||||
vo = templateStoreDao.findById(vo.getId());
|
||||
}
|
||||
|
||||
public void stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event event) {
|
||||
try {
|
||||
this.stateMachine.transitTo(vo, event, null, templateStoreDao);
|
||||
vo = templateStoreDao.findById(vo.getId());
|
||||
} catch (NoTransitionException e) {
|
||||
throw new CloudRuntimeException("Failed change state", e);
|
||||
} catch (Exception e) {
|
||||
throw new CloudRuntimeException("Failed change state", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,10 +187,8 @@ public class VolumeServiceImpl implements VolumeService {
|
||||
CommandResult result = callback.getResult();
|
||||
TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = context.getTemplate();
|
||||
if (result.isSuccess()) {
|
||||
templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOADED);
|
||||
templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationSuccessed);
|
||||
} else {
|
||||
templateOnPrimaryStoreObj.updateStatus(Status.ABANDONED);
|
||||
templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationFailed);
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,8 @@ package org.apache.cloudstack.framework.async;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.sf.cglib.proxy.CallbackFilter;
|
||||
import net.sf.cglib.proxy.Callback;
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
import net.sf.cglib.proxy.MethodProxy;
|
||||
@ -52,14 +54,33 @@ public class AsyncCallbackDispatcher<T> implements AsyncCompletionCallback {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getTarget() {
|
||||
return (T)Enhancer.create(_targetObject.getClass(), new MethodInterceptor() {
|
||||
@Override
|
||||
public Object intercept(Object arg0, Method arg1, Object[] arg2,
|
||||
MethodProxy arg3) throws Throwable {
|
||||
_callbackMethod = arg1;
|
||||
return null;
|
||||
}
|
||||
});
|
||||
Enhancer en = new Enhancer();
|
||||
en.setSuperclass(_targetObject.getClass());
|
||||
en.setCallbacks(new Callback[]{new MethodInterceptor() {
|
||||
@Override
|
||||
public Object intercept(Object arg0, Method arg1, Object[] arg2,
|
||||
MethodProxy arg3) throws Throwable {
|
||||
_callbackMethod = arg1;
|
||||
return null;
|
||||
}
|
||||
},
|
||||
new MethodInterceptor() {
|
||||
@Override
|
||||
public Object intercept(Object arg0, Method arg1, Object[] arg2,
|
||||
MethodProxy arg3) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
en.setCallbackFilter(new CallbackFilter() {
|
||||
public int accept(Method method) {
|
||||
if (method.getParameterTypes().length == 0 && method.getName().equals("finalize")) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}}
|
||||
);
|
||||
return (T)en.create();
|
||||
}
|
||||
|
||||
public AsyncCallbackDispatcher<T> setCallback(Object useless) {
|
||||
|
||||
@ -338,6 +338,9 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
||||
s_statesTable.put(Types.VmPowerState.UNRECOGNIZED, State.Unknown);
|
||||
}
|
||||
|
||||
public XsHost getHost() {
|
||||
return this._host;
|
||||
}
|
||||
|
||||
protected boolean cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException {
|
||||
Host host = Host.getByUuid(conn, _host.uuid);
|
||||
|
||||
@ -33,9 +33,13 @@ import org.apache.cloudstack.storage.command.AttachPrimaryDataStoreCmd;
|
||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
|
||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreatePrimaryDataStoreCmd;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
|
||||
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
|
||||
import org.apache.cloudstack.storage.datastore.protocol.DataStoreProtocol;
|
||||
import org.apache.cloudstack.storage.to.ImageDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.NfsPrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.TemplateTO;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
@ -86,14 +90,20 @@ public class XenServerStorageResource {
|
||||
return this.execute((AttachPrimaryDataStoreCmd)command);
|
||||
} else if (command instanceof CreatePrimaryDataStoreCmd) {
|
||||
return execute((CreatePrimaryDataStoreCmd) command);
|
||||
} else if (command instanceof CreateVolumeFromBaseImageCommand) {
|
||||
return execute((CreateVolumeFromBaseImageCommand)command);
|
||||
}
|
||||
return new Answer((Command)command, false, "not implemented yet");
|
||||
}
|
||||
/*
|
||||
protected SR getNfsSR(Connection conn, PrimaryDataStoreTO pool) {
|
||||
|
||||
public Answer execute(CreateVolumeFromBaseImageCommand cmd) {
|
||||
return new CreateVolumeAnswer(cmd, UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
protected SR getNfsSR(Connection conn, NfsPrimaryDataStoreTO pool) {
|
||||
Map<String, String> deviceConfig = new HashMap<String, String>();
|
||||
try {
|
||||
String server = pool.getHost();
|
||||
String server = pool.getServer();
|
||||
String serverpath = pool.getPath();
|
||||
serverpath = serverpath.replace("//", "/");
|
||||
Set<SR> srs = SR.getAll(conn);
|
||||
@ -125,13 +135,13 @@ public class XenServerStorageResource {
|
||||
|
||||
if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) {
|
||||
throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:"
|
||||
+ dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + _host.uuid);
|
||||
+ dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + hypervisorResource.getHost().uuid);
|
||||
}
|
||||
|
||||
}
|
||||
deviceConfig.put("server", server);
|
||||
deviceConfig.put("serverpath", serverpath);
|
||||
Host host = Host.getByUuid(conn, _host.uuid);
|
||||
Host host = Host.getByUuid(conn, hypervisorResource.getHost().uuid);
|
||||
SR sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), Long.toString(pool.getId()), SRType.NFS.toString(), "user", true,
|
||||
new HashMap<String, String>());
|
||||
sr.scan(conn);
|
||||
@ -142,7 +152,7 @@ public class XenServerStorageResource {
|
||||
throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
protected SR getIscsiSR(Connection conn, PrimaryDataStoreTO pool) {
|
||||
synchronized (pool.getUuid().intern()) {
|
||||
Map<String, String> deviceConfig = new HashMap<String, String>();
|
||||
@ -271,9 +281,9 @@ public class XenServerStorageResource {
|
||||
Connection conn = hypervisorResource.getConnection();
|
||||
PrimaryDataStoreTO dataStore = cmd.getDataStore();
|
||||
try {
|
||||
if (dataStore.getType() == StoragePoolType.NetworkFilesystem.toString()) {
|
||||
//getNfsSR(conn, dataStore);
|
||||
} else if (dataStore.getType() == StoragePoolType.IscsiLUN.toString()) {
|
||||
if (DataStoreProtocol.NFS.toString().equalsIgnoreCase(dataStore.getType())) {
|
||||
getNfsSR(conn, (NfsPrimaryDataStoreTO)dataStore);
|
||||
} else if (DataStoreProtocol.NFS.toString().equalsIgnoreCase(dataStore.getType())) {
|
||||
//getIscsiSR(conn, dataStore);
|
||||
} else if (dataStore.getType() == StoragePoolType.PreSetup.toString()) {
|
||||
} else {
|
||||
@ -366,11 +376,11 @@ public class XenServerStorageResource {
|
||||
boolean result = false;
|
||||
try {
|
||||
|
||||
SR sr = SR.getByUuid(conn, primaryStoreUuid);
|
||||
if (sr == null) {
|
||||
Set<SR> srs = SR.getByNameLabel(conn, primaryStoreUuid);
|
||||
if (srs.size() != 1) {
|
||||
throw new CloudRuntimeException("storage uuid: " + primaryStoreUuid + " is not unique");
|
||||
}
|
||||
poolsr = sr;
|
||||
poolsr = srs.iterator().next();
|
||||
VDI.Record vdir = new VDI.Record();
|
||||
vdir.nameLabel = "Base-Image-" + UUID.randomUUID().toString();
|
||||
vdir.SR = poolsr;
|
||||
@ -381,15 +391,20 @@ public class XenServerStorageResource {
|
||||
|
||||
vdir = vdi.getRecord(conn);
|
||||
String vdiLocation = vdir.location;
|
||||
Set<PBD> pbds = poolsr.getPBDs(conn);
|
||||
if (pbds.size() != 1) {
|
||||
throw new CloudRuntimeException("Don't how to handle multiple pbds:" + pbds.size() + " for sr: " + poolsr.getUuid(conn));
|
||||
String pbdLocation = null;
|
||||
if (primarDataStore.getType().equalsIgnoreCase(DataStoreProtocol.NFS.toString())) {
|
||||
pbdLocation = "/run/sr-mount/" + poolsr.getUuid(conn);
|
||||
} else {
|
||||
Set<PBD> pbds = poolsr.getPBDs(conn);
|
||||
if (pbds.size() != 1) {
|
||||
throw new CloudRuntimeException("Don't how to handle multiple pbds:" + pbds.size() + " for sr: " + poolsr.getUuid(conn));
|
||||
}
|
||||
PBD pbd = pbds.iterator().next();
|
||||
Map<String, String> deviceCfg = pbd.getDeviceConfig(conn);
|
||||
pbdLocation = deviceCfg.get("location");
|
||||
}
|
||||
PBD pbd = pbds.iterator().next();
|
||||
Map<String, String> deviceCfg = pbd.getDeviceConfig(conn);
|
||||
String pbdLocation = deviceCfg.get("location");
|
||||
if (pbdLocation == null) {
|
||||
throw new CloudRuntimeException("Can't get pbd: " + pbd.getUuid(conn) + " location");
|
||||
throw new CloudRuntimeException("Can't get pbd location");
|
||||
}
|
||||
|
||||
String vdiPath = pbdLocation + "/" + vdiLocation + ".vhd";
|
||||
@ -454,8 +469,7 @@ public class XenServerStorageResource {
|
||||
protected Answer execute(CopyTemplateToPrimaryStorageCmd cmd) {
|
||||
ImageOnPrimayDataStoreTO imageTO = cmd.getImage();
|
||||
TemplateTO template = imageTO.getTemplate();
|
||||
ImageDataStoreTO imageStore = template.getImageDataStore();
|
||||
if (imageStore.getType().equalsIgnoreCase("http")) {
|
||||
if (template.getPath().startsWith("http")) {
|
||||
return directDownloadHttpTemplate(cmd, template, imageTO.getPrimaryDataStore());
|
||||
} else {
|
||||
return new Answer(cmd, false, "not implemented yet");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user