mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
finish configurator, the default primary storage provider can cover all the hypervisors and protocols
This commit is contained in:
parent
7652a44be7
commit
cdf5511664
@ -37,6 +37,9 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
protected PrimaryDataStoreVO pdsv;
|
||||
protected PrimaryDataStoreInfo pdsInfo;
|
||||
protected PrimaryDataStoreLifeCycle lifeCycle;
|
||||
protected PrimaryDataStoreProvider provider;
|
||||
private HypervisorType supportedHypervisor;
|
||||
private boolean isLocalStorageSupported = false;
|
||||
@Inject
|
||||
private VolumeDao volumeDao;
|
||||
@Inject
|
||||
@ -58,6 +61,10 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
this.lifeCycle = lifeCycle;
|
||||
}
|
||||
|
||||
public void setProvider(PrimaryDataStoreProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public static DefaultPrimaryDataStore createDataStore(PrimaryDataStoreVO pdsv) {
|
||||
DefaultPrimaryDataStore dataStore = new DefaultPrimaryDataStore(pdsv);
|
||||
return ComponentInject.inject(dataStore);
|
||||
@ -102,16 +109,22 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
public void setSupportedHypervisor(HypervisorType type) {
|
||||
this.supportedHypervisor = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHypervisorSupported(HypervisorType hypervisor) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return (this.supportedHypervisor == hypervisor) ? true : false;
|
||||
}
|
||||
|
||||
public void setLocalStorageFlag(boolean supported) {
|
||||
this.isLocalStorageSupported = supported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLocalStorageSupported() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return this.isLocalStorageSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -208,13 +221,11 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreLifeCycle getLifeCycle() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return lifeCycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreProvider getProvider() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return this.provider;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
package org.apache.cloudstack.storage.datastore.configurator;
|
||||
|
||||
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.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public abstract class AbstractPrimaryDataStoreConfigurator implements PrimaryDataStoreConfigurator {
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
|
||||
protected PrimaryDataStoreLifeCycle getLifeCycle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected PrimaryDataStoreDriver getDriver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean isLocalStorageSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@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());
|
||||
dataStore.setSupportedHypervisor(getSupportedHypervisor());
|
||||
dataStore.setLocalStorageFlag(isLocalStorageSupported());
|
||||
return dataStore;
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,7 @@ import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
public interface PrimaryDataStoreConfigurator {
|
||||
public HypervisorType getSupportedHypervisor();
|
||||
public StoragePoolType getSupportedDataStoreType();
|
||||
public String getSupportedDataStoreType();
|
||||
public PrimaryDataStore getDataStore(long dataStoreId);
|
||||
public ProtocolValidator getValidator();
|
||||
}
|
||||
|
||||
@ -21,21 +21,18 @@ package org.apache.cloudstack.storage.datastore.configurator.kvm;
|
||||
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.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.AbstractPrimaryDataStoreConfigurator;
|
||||
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.DefaultKvmPrimaryDataStoreLifeCycle;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public abstract class AbstractKvmConfigurator implements PrimaryDataStoreConfigurator {
|
||||
public abstract class AbstractKvmConfigurator extends AbstractPrimaryDataStoreConfigurator {
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
|
||||
@Override
|
||||
public HypervisorType getSupportedHypervisor() {
|
||||
return HypervisorType.KVM;
|
||||
@ -48,17 +45,4 @@ public abstract class AbstractKvmConfigurator implements PrimaryDataStoreConfigu
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,23 +18,18 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.kvm;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.CLVMValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class KvmCLVMConfigurator extends AbstractKvmConfigurator {
|
||||
|
||||
@Override
|
||||
public StoragePoolType getSupportedDataStoreType() {
|
||||
return StoragePoolType.CLVM;
|
||||
public String getSupportedDataStoreType() {
|
||||
return "clvm";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -23,15 +23,13 @@ import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolVa
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class KvmNfsConfigurator extends AbstractKvmConfigurator {
|
||||
|
||||
@Override
|
||||
public StoragePoolType getSupportedDataStoreType() {
|
||||
return StoragePoolType.NetworkFilesystem;
|
||||
public String getSupportedDataStoreType() {
|
||||
return "nfs";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -30,8 +30,8 @@ import com.cloud.storage.Storage.StoragePoolType;
|
||||
public class KvmRBDConfigurator extends AbstractKvmConfigurator {
|
||||
|
||||
@Override
|
||||
public StoragePoolType getSupportedDataStoreType() {
|
||||
return StoragePoolType.RBD;
|
||||
public String getSupportedDataStoreType() {
|
||||
return "rbd";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -18,21 +18,49 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public class NfsValidator implements ProtocolValidator {
|
||||
|
||||
@Override
|
||||
public boolean validate(Map<String, String> params) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
String url = params.get("url");
|
||||
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
if (!"nfs".equalsIgnoreCase(uri.getScheme())) {
|
||||
throw new CloudRuntimeException("invalid protocol, must starting with nfs");
|
||||
}
|
||||
String storageHost = uri.getHost();
|
||||
String hostPath = uri.getPath();
|
||||
String userInfo = uri.getUserInfo();
|
||||
int port = uri.getPort();
|
||||
if (port == -1) {
|
||||
port = 2049;
|
||||
}
|
||||
params.put("server", storageHost);
|
||||
params.put("path", hostPath);
|
||||
params.put("user", userInfo);
|
||||
params.put("port", String.valueOf(port));
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
throw new CloudRuntimeException("invalid url: " + e.toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getInputParamNames() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
List<String> paramNames = new ArrayList<String>();
|
||||
paramNames.add("server");
|
||||
paramNames.add("path");
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,19 +21,14 @@ package org.apache.cloudstack.storage.datastore.configurator.vmware;
|
||||
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.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.AbstractPrimaryDataStoreConfigurator;
|
||||
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.DefaultVmwarePrimaryDataStoreLifeCycle;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public abstract class AbstractVmwareConfigurator implements PrimaryDataStoreConfigurator {
|
||||
public abstract class AbstractVmwareConfigurator extends AbstractPrimaryDataStoreConfigurator {
|
||||
|
||||
@Inject
|
||||
PrimaryDataStoreDao dataStoreDao;
|
||||
@ -42,25 +37,13 @@ public abstract class AbstractVmwareConfigurator implements PrimaryDataStoreConf
|
||||
return HypervisorType.VMware;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PrimaryDataStoreLifeCycle getLifeCycle() {
|
||||
return new DefaultVmwarePrimaryDataStoreLifeCycle();
|
||||
return new DefaultVmwarePrimaryDataStoreLifeCycle(dataStoreDao);
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,19 +23,18 @@ import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolVa
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class VmwareIsciConfigurator extends AbstractVmwareConfigurator {
|
||||
|
||||
@Override
|
||||
public StoragePoolType getSupportedDataStoreType() {
|
||||
return StoragePoolType.Iscsi;
|
||||
public String getSupportedDataStoreType() {
|
||||
return "iscsi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
return new ISCSIValiator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,14 +20,18 @@ 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.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class VmwareNfsConfigurator extends AbstractVmwareConfigurator {
|
||||
|
||||
@Override
|
||||
public StoragePoolType getSupportedDataStoreType() {
|
||||
return StoragePoolType.NetworkFilesystem;
|
||||
public String getSupportedDataStoreType() {
|
||||
return "nfs";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -20,14 +20,18 @@ 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.VMFSValidator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class VmwareVMFSConfigurator extends AbstractVmwareConfigurator {
|
||||
|
||||
@Override
|
||||
public StoragePoolType getSupportedDataStoreType() {
|
||||
return StoragePoolType.VMFS;
|
||||
public String getSupportedDataStoreType() {
|
||||
return "vmfs";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
|
||||
protected PrimaryDataStoreLifeCycle getLifeCycle() {
|
||||
return new DefaultXenPrimaryDataStoreLifeCycle(dataStoreDao);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -18,29 +18,23 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.xen;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ISCSIValiator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class XenIscsiConfigurator extends AbstractXenConfigurator {
|
||||
|
||||
public class XenIscsiConfigurator implements PrimaryDataStoreConfigurator {
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
return "iscsi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getSupportedHypervisor() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStore getDataStore() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
return new ISCSIValiator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,29 +18,24 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.xen;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.NfsValidator;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.validator.ProtocolValidator;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
|
||||
public class XenNfsConfigurator implements PrimaryDataStoreConfigurator {
|
||||
@Component
|
||||
@Qualifier("defaultProvider")
|
||||
public class XenNfsConfigurator extends AbstractXenConfigurator {
|
||||
|
||||
@Override
|
||||
public HypervisorType getSupportedHypervisor() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStore getDataStore() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public String getSupportedDataStoreType() {
|
||||
return "nfs";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolValidator getValidator() {
|
||||
return new NfsValidator();
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,6 +98,9 @@ public class PrimaryDataStoreVO implements Identity {
|
||||
|
||||
@Column(name = "cluster_id")
|
||||
private Long clusterId;
|
||||
|
||||
@Column(name = "configurator_key")
|
||||
private String key;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
@ -234,6 +237,14 @@ public class PrimaryDataStoreVO implements Identity {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
@ -48,55 +48,12 @@ public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLif
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
||||
protected class DataStoreUrlParser {
|
||||
private String schema;
|
||||
private String host;
|
||||
private String path;
|
||||
private int port;
|
||||
|
||||
public DataStoreUrlParser(String url) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
schema = uri.getScheme();
|
||||
host = uri.getHost();
|
||||
path = uri.getPath();
|
||||
port = (uri.getPort() == -1) ? 0 : uri.getPort();
|
||||
} catch (URISyntaxException e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
return this.schema;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialize(Map<String, String> dsInfos) {
|
||||
DataStoreUrlParser parser = new DataStoreUrlParser(dsInfos.get("url"));
|
||||
PrimaryDataStoreVO dataStore = dataStoreDao.findById(this.dataStore.getId());
|
||||
dataStore.setName(dsInfos.get("name"));
|
||||
dataStore.setPoolType(parser.getSchema());
|
||||
dataStore.setPort(parser.port);
|
||||
dataStore.setHostAddress(parser.getHost());
|
||||
dataStore.setPath(parser.getPath());
|
||||
dataStore.setStatus(DataStoreStatus.Initialized);
|
||||
dataStoreDao.update(this.dataStore.getId(), dataStore);
|
||||
//TODO: add extension point for each data store
|
||||
|
||||
this.dataStore = this.dataStore.getProvider().getDataStore(dataStore.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -27,13 +27,9 @@ public class DefaultVmwarePrimaryDataStoreLifeCycle extends DefaultPrimaryDataSt
|
||||
* @param dataStoreDao
|
||||
* @param dataStore
|
||||
*/
|
||||
public DefaultVmwarePrimaryDataStoreLifeCycle(PrimaryDataStoreDao dataStoreDao, PrimaryDataStore dataStore) {
|
||||
super(dataStoreDao, dataStore);
|
||||
public DefaultVmwarePrimaryDataStoreLifeCycle(PrimaryDataStoreDao dataStoreDao) {
|
||||
super(dataStoreDao);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public DefaultVmwarePrimaryDataStoreLifeCycle() {
|
||||
super(null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.lifecycle;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
|
||||
public class DefaultXenPrimaryDataStoreLifeCycle extends DefaultPrimaryDataStoreLifeCycleImpl {
|
||||
@ -27,8 +26,8 @@ public class DefaultXenPrimaryDataStoreLifeCycle extends DefaultPrimaryDataStore
|
||||
* @param dataStoreDao
|
||||
* @param dataStore
|
||||
*/
|
||||
public DefaultXenPrimaryDataStoreLifeCycle(PrimaryDataStoreDao dataStoreDao, PrimaryDataStore dataStore) {
|
||||
super(dataStoreDao, dataStore);
|
||||
public DefaultXenPrimaryDataStoreLifeCycle(PrimaryDataStoreDao dataStoreDao) {
|
||||
super(dataStoreDao);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,9 @@
|
||||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -8,6 +12,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCy
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
|
||||
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.db.PrimaryDataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
@ -15,8 +21,15 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.datastore.lifecycle.DefaultPrimaryDataStoreLifeCycleImpl;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProvider {
|
||||
private final String providerName = "default primary data store provider";
|
||||
@ -26,9 +39,20 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
|
||||
protected PrimaryDataStoreDao dataStoreDao;
|
||||
@Inject
|
||||
protected PrimaryDataStoreProviderDao providerDao;
|
||||
@Inject
|
||||
protected ClusterDao clusterDao;
|
||||
protected Map<String, PrimaryDataStoreConfigurator> configuratorMaps = new HashMap<String, PrimaryDataStoreConfigurator>();
|
||||
|
||||
public DefaultPrimaryDatastoreProviderImpl() {
|
||||
|
||||
@Inject
|
||||
public DefaultPrimaryDatastoreProviderImpl(@Qualifier("defaultProvider") List<PrimaryDataStoreConfigurator> configurators) {
|
||||
for (PrimaryDataStoreConfigurator configurator : configurators) {
|
||||
String key = generateKey(configurator.getSupportedHypervisor(), configurator.getSupportedDataStoreType().toString());
|
||||
configuratorMaps.put(key, configurator);
|
||||
}
|
||||
}
|
||||
|
||||
protected String generateKey(HypervisorType hypervisor, String poolType) {
|
||||
return hypervisor.toString().toLowerCase() + "_" + poolType.toString().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -38,24 +62,58 @@ public class DefaultPrimaryDatastoreProviderImpl implements PrimaryDataStoreProv
|
||||
return null;
|
||||
}
|
||||
|
||||
DefaultPrimaryDataStore pds = DefaultPrimaryDataStore.createDataStore(dsv);
|
||||
|
||||
PrimaryDataStoreDriver driver = new DefaultPrimaryDataStoreDriverImpl(pds);
|
||||
pds.setDriver(driver);
|
||||
|
||||
DefaultPrimaryDataStoreLifeCycleImpl lifeCycle = new DefaultPrimaryDataStoreLifeCycleImpl(dataStoreDao, pds);
|
||||
pds.setLifeCycle(lifeCycle);
|
||||
|
||||
return pds;
|
||||
String key = dsv.getKey();
|
||||
|
||||
PrimaryDataStoreConfigurator configurator = configuratorMaps.get(key);
|
||||
|
||||
DefaultPrimaryDataStore dataStore = (DefaultPrimaryDataStore)configurator.getDataStore(dataStoreId);
|
||||
dataStore.setProvider(this);
|
||||
return dataStore;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public PrimaryDataStore registerDataStore(Map<String, String> dsInfos) {
|
||||
String url = dsInfos.get("url");
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new CloudRuntimeException("invalid url: " + e.toString());
|
||||
}
|
||||
String protocol = uri.getScheme();
|
||||
Long cluster = null;
|
||||
try {
|
||||
cluster = Long.parseLong(dsInfos.get("clusterId"));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new CloudRuntimeException("Failed to get clusterId");
|
||||
}
|
||||
ClusterVO clusterVO = clusterDao.findById(cluster);
|
||||
if (clusterVO == null) {
|
||||
throw new CloudRuntimeException("Can't find cluster: " + cluster);
|
||||
}
|
||||
HypervisorType hypervisor = clusterVO.getHypervisorType();
|
||||
String key = generateKey(hypervisor, protocol);
|
||||
PrimaryDataStoreConfigurator configurator = configuratorMaps.get(key);
|
||||
if (configurator == null) {
|
||||
throw new CloudRuntimeException("can't find configurator from key: " + key);
|
||||
}
|
||||
|
||||
ProtocolValidator validator = configurator.getValidator();
|
||||
validator.validate(dsInfos);
|
||||
|
||||
PrimaryDataStoreVO dataStoreVO = new PrimaryDataStoreVO();
|
||||
dataStoreVO.setStorageProviderId(this.getId());
|
||||
dataStoreVO.setHostAddress(dsInfos.get("server"));
|
||||
dataStoreVO.setPath(dsInfos.get("path"));
|
||||
dataStoreVO.setPoolType(protocol);
|
||||
dataStoreVO.setPort(Integer.parseInt(dsInfos.get("port")));
|
||||
dataStoreVO.setKey(key);
|
||||
dataStoreVO.setName(dsInfos.get("name"));
|
||||
dataStoreVO = dataStoreDao.persist(dataStoreVO);
|
||||
|
||||
DefaultPrimaryDataStore dataStore = (DefaultPrimaryDataStore)configurator.getDataStore(dataStoreVO.getId());
|
||||
dataStore.setProvider(this);
|
||||
|
||||
PrimaryDataStore dataStore = this.getDataStore(dataStoreVO.getId());
|
||||
PrimaryDataStoreLifeCycle lifeCycle = dataStore.getLifeCycle();
|
||||
lifeCycle.initialize(dsInfos);
|
||||
return getDataStore(dataStore.getId());
|
||||
|
||||
@ -29,6 +29,8 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.db.DB;
|
||||
|
||||
@Component
|
||||
public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProviderManager {
|
||||
@Inject
|
||||
@ -47,6 +49,7 @@ public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProv
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
List<PrimaryDataStoreProviderVO> providerVos = providerDao.listAll();
|
||||
for (PrimaryDataStoreProvider provider : providers) {
|
||||
|
||||
@ -18,17 +18,30 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.volume.test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
|
||||
import org.apache.cloudstack.storage.datastore.configurator.PrimaryDataStoreConfigurator;
|
||||
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations="classpath:/resource/testContext.xml")
|
||||
public class ConfiguratorTest {
|
||||
@ -36,10 +49,53 @@ public class ConfiguratorTest {
|
||||
@Qualifier("defaultProvider")
|
||||
List<PrimaryDataStoreConfigurator> configurators;
|
||||
|
||||
@Inject
|
||||
List<PrimaryDataStoreProvider> providers;
|
||||
|
||||
@Inject
|
||||
PrimaryDataStoreProviderManager providerMgr;
|
||||
@Inject
|
||||
ClusterDao clusterDao;
|
||||
@Before
|
||||
public void setup() {
|
||||
ClusterVO cluster = new ClusterVO();
|
||||
cluster.setHypervisorType(HypervisorType.XenServer.toString());
|
||||
Mockito.when(clusterDao.findById(Mockito.anyLong())).thenReturn(cluster);
|
||||
try {
|
||||
providerMgr.configure("manager", null);
|
||||
} catch (ConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testLoadConfigurator() {
|
||||
for (PrimaryDataStoreConfigurator configurator : configurators) {
|
||||
System.out.println(configurator.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProvider() {
|
||||
for (PrimaryDataStoreProvider provider : providers) {
|
||||
if (provider.getName().startsWith("default")) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProvider() {
|
||||
assertNotNull(providerMgr.getDataStoreProvider("default primary data store provider"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDataStore() {
|
||||
PrimaryDataStoreProvider provider = providerMgr.getDataStoreProvider("default primary data store provider");
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
params.put("url", "nfs://localhost/mnt");
|
||||
params.put("clusterId", "1");
|
||||
params.put("name", "nfsprimary");
|
||||
assertNotNull(provider.registerDataStore(params));
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,9 @@ import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.ClusterDaoImpl;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class TestConfiguration {
|
||||
@ -30,4 +33,9 @@ public class TestConfiguration {
|
||||
public ImageMotionService imageMotion() {
|
||||
return Mockito.mock(ImageMotionService.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ClusterDao clusterDao() {
|
||||
return Mockito.mock(ClusterDaoImpl.class);
|
||||
}
|
||||
}
|
||||
@ -12,13 +12,23 @@
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
<context:annotation-config />
|
||||
<context:component-scan base-package="org.apache.cloudstack.storage" />
|
||||
<context:component-scan base-package="org.apache.cloudstack.engine.subsystem.api.storage" />
|
||||
<context:component-scan
|
||||
base-package="org.apache.cloudstack.engine.subsystem.api.storage" />
|
||||
<context:component-scan base-package="com.cloud.utils.db" />
|
||||
<context:component-scan base-package="com.cloud.utils.component" />
|
||||
<context:component-scan base-package="com.cloud.host.dao" />
|
||||
<context:component-scan base-package="com.cloud.dc.dao" />
|
||||
|
||||
<context:component-scan base-package=" com.cloud.upgrade.dao" />
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
<bean class="org.cloudstack.storage.volume.test.TestConfiguration" />
|
||||
|
||||
<context:component-scan base-package=" com.cloud.upgrade.dao" />
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
<bean class="org.apache.cloudstack.storage.volume.test.TestConfiguration" />
|
||||
<aop:config proxy-target-class="true">
|
||||
<aop:aspect id="dbContextBuilder" ref="transactionContextBuilder">
|
||||
<aop:pointcut id="captureAnyMethod" expression="@annotation(com.cloud.utils.db.DB)" />
|
||||
<aop:around pointcut-ref="captureAnyMethod" method="AroundAnyMethod" />
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="transactionContextBuilder" class="com.cloud.utils.db.TransactionContextBuilder" />
|
||||
|
||||
</beans>
|
||||
@ -17,6 +17,7 @@
|
||||
|
||||
alter table vm_template add image_data_store_id bigint unsigned;
|
||||
alter table storage_pool add storage_provider_id bigint unsigned;
|
||||
alter table storage_pool add configurator_key varchar(255);
|
||||
alter table storage_pool modify id bigint unsigned AUTO_INCREMENT UNIQUE NOT NULL;
|
||||
alter table volumes add disk_type varchar(255);
|
||||
alter table volumes drop foreign key `fk_volumes__account_id`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user