Add more storage code

This commit is contained in:
Edison Su 2012-08-27 18:07:54 -07:00
parent 13542fd87b
commit 60758785b7
22 changed files with 259 additions and 163 deletions

View File

@ -103,4 +103,14 @@ public interface StoragePool {
int getPort();
Long getPodId();
/**
* @return
*/
String getStorageProvider();
/**
* @return
*/
String getStorageType();
}

View File

@ -17,6 +17,7 @@
package com.cloud.storage;
public enum StoragePoolStatus {
Creating,
Up,
PrepareForMaintenance,
ErrorInMaintenance,

View File

@ -50,7 +50,7 @@ public class StoragePoolVO implements StoragePool, Identity {
@Column(name="pool_type", updatable=false, nullable=false, length=32)
@Enumerated(value=EnumType.STRING)
private StoragePoolType poolType;
private StoragePoolType protocol;
@Column(name=GenericDao.CREATED_COLUMN)
Date created;
@ -78,6 +78,12 @@ public class StoragePoolVO implements StoragePool, Identity {
@Enumerated(value=EnumType.STRING)
private StoragePoolStatus status;
@Column(name="storage_provider", updatable=true, nullable=false)
private String storageProvider;
@Column(name="storage_type", nullable=false)
private String storageType;
@Override
public long getId() {
return id;
@ -104,7 +110,7 @@ public class StoragePoolVO implements StoragePool, Identity {
@Override
public StoragePoolType getPoolType() {
return poolType;
return protocol;
}
@Override
@ -130,6 +136,24 @@ public class StoragePoolVO implements StoragePool, Identity {
public long getAvailableBytes() {
return availableBytes;
}
@Override
public String getStorageProvider() {
return storageProvider;
}
public void setStorageProvider(String provider) {
storageProvider = provider;
}
@Override
public String getStorageType() {
return storageType;
}
public void setStorageType(String type) {
storageType = type;
}
@Override
public long getCapacityBytes() {
@ -189,7 +213,7 @@ public class StoragePoolVO implements StoragePool, Identity {
this.name = name;
this.id = poolId;
this.uuid = uuid;
this.poolType = type;
this.protocol = type;
this.dataCenterId = dataCenterId;
this.availableBytes = availableBytes;
this.capacityBytes = capacityBytes;
@ -197,29 +221,29 @@ public class StoragePoolVO implements StoragePool, Identity {
this.path = hostPath;
this.port = port;
this.podId = podId;
this.setStatus(StoragePoolStatus.Up);
this.setStatus(StoragePoolStatus.Creating);
}
public StoragePoolVO(StoragePoolVO that) {
this(that.id, that.name, that.uuid, that.poolType, that.dataCenterId, that.podId, that.availableBytes, that.capacityBytes, that.hostAddress, that.port, that.path);
this(that.id, that.name, that.uuid, that.protocol, that.dataCenterId, that.podId, that.availableBytes, that.capacityBytes, that.hostAddress, that.port, that.path);
}
public StoragePoolVO(StoragePoolType type, String hostAddress, int port, String path) {
this.poolType = type;
this.protocol = type;
this.hostAddress = hostAddress;
this.port = port;
this.path = path;
this.setStatus(StoragePoolStatus.Up);
this.setStatus(StoragePoolStatus.Creating);
this.uuid = UUID.randomUUID().toString();
}
public StoragePoolVO(StoragePoolType type, String hostAddress, int port, String path, String userInfo) {
this.poolType = type;
this.protocol = type;
this.hostAddress = hostAddress;
this.port = port;
this.path = path;
this.userInfo = userInfo;
this.setStatus(StoragePoolStatus.Up);
this.setStatus(StoragePoolStatus.Creating);
this.uuid = UUID.randomUUID().toString();
}
@ -259,12 +283,12 @@ public class StoragePoolVO implements StoragePool, Identity {
@Override
public boolean isShared() {
return poolType.isShared();
return protocol.isShared();
}
@Override
public boolean isLocal() {
return !poolType.isShared();
return !protocol.isShared();
}
@Transient
@ -315,6 +339,6 @@ public class StoragePoolVO implements StoragePool, Identity {
@Override
public String toString() {
return new StringBuilder("Pool[").append(id).append("|").append(poolType).append("]").toString();
return new StringBuilder("Pool[").append(id).append("|").append(protocol).append("]").toString();
}
}

View File

@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry combineaccessrules="false" kind="src" path="/server"/>
<classpathentry kind="output" path="bin"/>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -10,8 +10,14 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -1,13 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cloudstack</groupId>
<artifactId>cloud-platform-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Apache CloudStack platform API</name>
<parent>
<groupId>com.cloud</groupId>
<artifactId>cloud-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.cloud</groupId>
<artifactId>cloud-api</artifactId>
<version>4.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.cloud</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<!-- <testSourceDirectory>test</testSourceDirectory> -->
</build>
</project>

View File

@ -39,11 +39,14 @@ public interface DataStore {
String getURI();
String getUUID();
long getCluterId();
long getPodId();
long getZoneId();
StoreType getType();
StoreScope getScope();
Long getId();
DataStoreDriver getDataStoreDriver();
void setEndPointSelector(DataStoreEndPointSelector selector);
DataStoreEndPointSelector getEndPointSelector();
FileSystem getFileSystem();
VolumeStrategy getVolumeStrategy();
SnapshotStrategy getSnapshotStrategy();

View File

@ -18,11 +18,15 @@
*/
package org.apache.cloudstack.platform.subsystem.api.storage;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public interface DataStoreDriver {
String getDriverType();
DataObject create(DataObject obj);
DataObject copy(DataObject src, DataStore dest);
DataObject copy(DataObject src, DataObject dest);
DataObject move(DataObject src, DataObject dest);
Answer sendMessage(DataStoreEndPoint dsep, Command cmd);
boolean delete(DataObject obj);
}

View File

@ -1,5 +1,19 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface DataStoreEndPoint {
public class DataStoreEndPoint {
protected long hostId;
protected String privIp;
public DataStoreEndPoint(long host, String ip) {
hostId = host;
privIp = ip;
}
public long getHostId() {
return hostId;
}
public String getPrivateIp() {
return privIp;
}
}

View File

@ -3,5 +3,5 @@ package org.apache.cloudstack.platform.subsystem.api.storage;
import java.util.List;
public interface DataStoreEndPointSelector {
List<DataStoreEndPoint> getEndPoints(DataStore ds);
List<DataStoreEndPoint> getEndPoints();
}

View File

@ -5,7 +5,7 @@ public interface DataStoreLifeCycle {
HOSTUP,
HOSTDOWN,
}
void create();
void add();
void delete();
void enable();
void disable();

View File

@ -7,13 +7,14 @@ import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.StoragePool;
import com.cloud.utils.component.Adapter;
public interface StorageProvider {
public interface StorageProvider extends Adapter {
List<HypervisorType> supportedHypervisors();
String getProviderName();
StoreType supportedStoreType();
void configure(Map<String, String> storeProviderInfo);
DataStore createDataStore(HypervisorType hypervisor, DataStoreConfigurator dsc);
DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params);
DataStore getDataStore(StoragePool pool);
Map<HypervisorType, Map<String,DataStoreConfigurator>> getDataStoreConfigs();
}

View File

@ -1,6 +1,38 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cloud</groupId>
<artifactId>cloud-platform-storage</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Apache CloudStack Platform Storage</name>
<parent>
<groupId>com.cloud</groupId>
<artifactId>cloud-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.cloud</groupId>
<artifactId>cloud-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.cloud</groupId>
<artifactId>cloud-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.cloud</groupId>
<artifactId>cloud-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.cloud</groupId>
<artifactId>cloud-platform-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<!-- <testSourceDirectory>test</testSourceDirectory> -->
</build>
</project>

View File

@ -7,8 +7,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
import org.apache.cloudstack.storage.datastoreconfigurator.NfsDataStoreConfigurator;
@ -31,13 +34,8 @@ import com.cloud.utils.component.Inject;
public class DefaultPrimaryStorageProvider implements StorageProvider {
private String _name = DefaultPrimaryStorageProvider.class.toString();
static Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols;
@Inject
protected DataCenterDao _dcDao;
@Inject
protected ClusterDao _clusterDao;
@Inject
protected StoragePoolDao _storagePoolDao;
public List<HypervisorType> supportedHypervisors() {
List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
@ -61,61 +59,6 @@ public class DefaultPrimaryStorageProvider implements StorageProvider {
// TODO Auto-generated method stub
}
public DataStore createDataStore(HypervisorType hypervisor,
long dcId,
long podId,
long clusterId,
String name,
String url,
Map<String, String> extra) {
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
throw new InvalidParameterValueException("invalide url" + url);
}
String protocol = uri.getScheme();
if (protocol == null) {
throw new InvalidParameterValueException("the protocol can't be null");
}
Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(hypervisor);
if (dscs.isEmpty()) {
throw new InvalidParameterValueException("Doesn't support this hypervisor");
}
DataStoreConfigurator dsc = dscs.get(protocol);
if (dsc == null) {
throw new InvalidParameterValueException("Doesn't support this protocol");
}
Map<String, String> configs = dsc.getConfigs(uri, extra);
dsc.validate(configs);
StoragePoolVO spool = (StoragePoolVO)dsc.getStoragePool(configs);
DataCenterVO zone = _dcDao.findById(dcId);
if (zone == null) {
throw new InvalidParameterValueException("unable to find zone by id " + dcId);
}
StoragePoolVO existingPool = _storagePoolDao.findPoolByUUID(spool.getUuid());
if (existingPool != null) {
throw new InvalidParameterValueException("The same storage pool was added already");
}
long poolId = _storagePoolDao.getNextInSequence(Long.class, "id");
spool.setId(poolId);
spool.setDataCenterId(dcId);
spool.setPodId(podId);
spool.setName(name);
spool.setClusterId(clusterId);
spool.setStatus(StoragePoolStatus.Up);
spool = _storagePoolDao.persist(spool, extra);
DataStore ds = dsc.getDataStore(spool);
return ds;
}
public Map<HypervisorType, Map<String,DataStoreConfigurator>> getDataStoreConfigs() {
return _supportedProtocols;
@ -130,7 +73,7 @@ public class DefaultPrimaryStorageProvider implements StorageProvider {
// TODO Auto-generated method stub
return null;
}
public DataStore getDataStore(StoragePool pool) {
ClusterVO clu = _clusterDao.findById(pool.getClusterId());
HypervisorType hy = clu.getHypervisorType();
@ -139,4 +82,56 @@ public class DefaultPrimaryStorageProvider implements StorageProvider {
return dsc.getDataStore(pool);
}
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
// TODO Auto-generated method stub
return false;
}
public String getName() {
// TODO Auto-generated method stub
return null;
}
public boolean start() {
// TODO Auto-generated method stub
return false;
}
public boolean stop() {
// TODO Auto-generated method stub
return false;
}
public DataStore addDataStore(StoragePool spool, String url, Map<String, String> params) {
URI uri;
try {
uri = new URI(url);
} catch (URISyntaxException e) {
throw new InvalidParameterValueException("invalide url" + url);
}
String protocol = uri.getScheme();
if (protocol == null) {
throw new InvalidParameterValueException("the protocol can't be null");
}
ClusterVO cluster = _clusterDao.findById(spool.getClusterId());
Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(cluster.getHypervisorType());
if (dscs.isEmpty()) {
throw new InvalidParameterValueException("Doesn't support this hypervisor");
}
DataStoreConfigurator dsc = dscs.get(protocol);
if (dsc == null) {
throw new InvalidParameterValueException("Doesn't support this protocol");
}
Map<String, String> configs = dsc.getConfigs(uri, params);
dsc.validate(configs);
DataStore ds = dsc.getDataStore(spool);
return ds;
}
}

View File

@ -5,7 +5,11 @@ import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
public class XenDataStoreDriver implements DataStoreDriver {
protected DataStore _ds;
public XenDataStoreDriver(DataStore ds) {
_ds = ds;
}
public String getDriverType() {
// TODO Auto-generated method stub
return null;

View File

@ -10,6 +10,7 @@ import java.util.UUID;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.Storage.StoragePoolType;
@ -48,19 +49,12 @@ public abstract class NfsDataStoreConfigurator implements DataStoreConfigurator
}
public boolean validate(Map<String, String> configs) {
// TODO Auto-generated method stub
return false;
}
public StoragePoolVO getStoragePool(Map<String, String> configs) {
String nfsServer = configs.get(NfsConfigName.SERVER.toString());
String nfsPath = configs.get(NfsConfigName.PATH.toString());
String uuid = UUID.nameUUIDFromBytes(new String(nfsServer + nfsPath).getBytes()).toString();
StoragePoolVO pool = new StoragePoolVO(StoragePoolType.NetworkFilesystem,
nfsServer, -1,
nfsPath);
pool.setUuid(uuid);
return pool;
String uriHost = configs.get(NfsConfigName.SERVER.toString());
String uriPath = configs.get(NfsConfigName.PATH.toString());
if (uriHost == null || uriPath == null || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
throw new InvalidParameterValueException("host or path is null, should be nfs://hostname/path");
}
return true;
}
public DataStore getDataStore(StoragePool pool) {

View File

@ -1,12 +1,14 @@
package org.apache.cloudstack.storage.datastoreconfigurator;
import java.util.Map;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
import org.apache.cloudstack.storage.datastore.DefaultDataStore;
import org.apache.cloudstack.storage.datastore.XenDataStoreDriver;
import org.apache.cloudstack.storage.epselector.DefaultPrimaryEndpointSelector;
import org.apache.cloudstack.storage.filesystem.DefaultFileSystem;
import org.apache.cloudstack.storage.lifecycle.DefaultDataStoreLifeCycle;
import org.apache.cloudstack.storage.lifecycle.DefaultPrimaryDataStoreLifeCycle;
import org.apache.cloudstack.storage.strategy.XenBackupStrategy;
import org.apache.cloudstack.storage.strategy.XenSnapshotStrategy;
import org.apache.cloudstack.storage.strategy.XenVolumeStrategy;
@ -17,17 +19,21 @@ public class XenNfsDataStoreConfigurator extends NfsDataStoreConfigurator {
@Override
public DataStore getDataStore(StoragePool pool) {
DefaultDataStore ds = new DefaultDataStore();
ds.setBackupStrategy(new XenBackupStrategy());
ds.setVolumeStrategy(new XenVolumeStrategy());
ds.setSnapshotStrategy(new XenSnapshotStrategy());
ds.setEndPointSelector(new DefaultPrimaryEndpointSelector());
ds.setFileSystem(new DefaultFileSystem());
ds.setEndPointSelector(new DefaultPrimaryEndpointSelector(ds));
ds.setId(pool.getId());
ds.setType(StoreType.Primary);
ds.setURI(pool.getHostAddress() + "/" + pool.getPath());
ds.setUUID(pool.getUuid());
ds.setDataStoreDriver(new XenDataStoreDriver());
ds.setLifeCycle(new DefaultDataStoreLifeCycle(ds));
ds.setDataStoreDriver(new XenDataStoreDriver(ds));
ds.setBackupStrategy(new XenBackupStrategy(ds));
ds.setVolumeStrategy(new XenVolumeStrategy(ds));
ds.setSnapshotStrategy(new XenSnapshotStrategy(ds));
ds.setLifeCycle(new DefaultPrimaryDataStoreLifeCycle(ds));
return ds;
}
public StoragePool getStoragePool(Map<String, String> configs) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,17 +1,34 @@
package org.apache.cloudstack.storage.epselector;
import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPointSelector;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.resource.ResourceManager;
import com.cloud.utils.component.Inject;
public class DefaultPrimaryEndpointSelector implements
DataStoreEndPointSelector {
public List<DataStoreEndPoint> getEndPoints(DataStore ds) {
// TODO Auto-generated method stub
return null;
protected DataStore _ds;
@Inject
protected ResourceManager _resourceMgr;
public DefaultPrimaryEndpointSelector(DataStore ds) {
_ds = ds;
}
public List<DataStoreEndPoint> getEndPoints() {
List<HostVO> allHosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, _ds.getCluterId(), _ds.getPodId(), _ds.getZoneId());
List<DataStoreEndPoint> dseps = new ArrayList<DataStoreEndPoint>();
for (HostVO host : allHosts) {
dseps.add(new DataStoreEndPoint(host.getId(), host.getPrivateIpAddress()));
}
return dseps;
}
}

View File

@ -1,38 +0,0 @@
package org.apache.cloudstack.storage.lifecycle;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
public class DefaultDataStoreLifeCycle implements DataStoreLifeCycle {
private DataStore _ds;
public DefaultDataStoreLifeCycle(DataStore ds) {
this._ds = ds;
}
public void create() {
// TODO Auto-generated method stub
}
public void delete() {
// TODO Auto-generated method stub
}
public void enable() {
// TODO Auto-generated method stub
}
public void disable() {
// TODO Auto-generated method stub
}
public void processEvent(DataStoreEvent event, Object... objs) {
// TODO Auto-generated method stub
}
}

View File

@ -1,7 +1,11 @@
package org.apache.cloudstack.storage.strategy;
import org.apache.cloudstack.platform.subsystem.api.storage.BackupStrategy;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
public class XenBackupStrategy implements BackupStrategy {
protected DataStore _ds;
public XenBackupStrategy(DataStore ds) {
_ds = ds;
}
}

View File

@ -1,7 +1,11 @@
package org.apache.cloudstack.storage.strategy;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotStrategy;
public class XenSnapshotStrategy implements SnapshotStrategy {
protected DataStore _ds;
public XenSnapshotStrategy(DataStore ds) {
_ds = ds;
}
}

View File

@ -1,12 +1,17 @@
package org.apache.cloudstack.storage.strategy;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.Snapshot;
import org.apache.cloudstack.platform.subsystem.api.storage.Template;
import org.apache.cloudstack.platform.subsystem.api.storage.Volume;
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeStrategy;
public class XenVolumeStrategy implements VolumeStrategy {
protected DataStore _ds;
public XenVolumeStrategy(DataStore ds) {
_ds = ds;
}
public Volume createVolume(Volume vol) {
// TODO Auto-generated method stub
return null;