remodel storeage

This commit is contained in:
Edison Su 2012-08-27 00:00:45 -07:00
parent e07f8449f4
commit 6701d6bec2
33 changed files with 726 additions and 60 deletions

View File

@ -1,23 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface DataMigrationSubSystem {
void migrate(String volume, String storagePool, String reservationId);
}

View File

@ -1,23 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface DistributedFileSystem {
}

View File

@ -1,13 +0,0 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
import java.net.URI;
import com.cloud.org.Grouping;
public interface StorageSubSystem {
String getType();
Class<? extends Grouping> getScope();
URI grantAccess(String vol, String reservationId);
URI RemoveAccess(String vol, String reservationId);
}

View File

@ -0,0 +1,5 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface BackupStrategy {
}

View File

@ -42,6 +42,11 @@ public interface DataStore {
StoreType getType();
StoreScope getScope();
Long getId();
DataStoreDriverRef getDataStoreDriver();
DataStoreDriver getDataStoreDriver();
void setEndPointSelector(DataStoreEndPointSelector selector);
FileSystem getFileSystem();
VolumeStrategy getVolumeStrategy();
SnapshotStrategy getSnapshotStrategy();
BackupStrategy getBackupStrategy();
DataStoreLifeCycle getLifeCycle();
}

View File

@ -0,0 +1,16 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
import java.net.URI;
import java.util.List;
import java.util.Map;
import com.cloud.storage.StoragePool;
public interface DataStoreConfigurator {
String getProtocol();
StoragePool getStoragePool(Map<String, String> configs);
List<String> getConfigNames();
Map<String, String> getConfigs(URI uri, Map<String, String> extras);
boolean validate(Map<String, String> configs);
DataStore getDataStore(StoragePool pool);
}

View File

@ -0,0 +1,5 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface DataStoreEndPoint {
}

View File

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

View File

@ -0,0 +1,5 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface DataStoreExtendedAttribute {
}

View File

@ -0,0 +1,13 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface DataStoreLifeCycle {
public enum DataStoreEvent {
HOSTUP,
HOSTDOWN,
}
void create();
void delete();
void enable();
void disable();
void processEvent(DataStoreEvent event, Object... objs);
}

View File

@ -28,4 +28,5 @@ public interface FileSystem {
String getFileType();
boolean isWritable(DataObject obj);
boolean contains(DataObject obj);
DataObject ioctl(DataObject obj, Object... objects);
}

View File

@ -0,0 +1,5 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface SnapshotStrategy {
}

View File

@ -0,0 +1,19 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
import java.util.List;
import java.util.Map;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.StoragePool;
public interface StorageProvider {
List<HypervisorType> supportedHypervisors();
String getProviderName();
StoreType supportedStoreType();
void configure(Map<String, String> storeProviderInfo);
DataStore createDataStore(HypervisorType hypervisor, DataStoreConfigurator dsc);
DataStore getDataStore(StoragePool pool);
Map<HypervisorType, Map<String,DataStoreConfigurator>> getDataStoreConfigs();
}

View File

@ -0,0 +1,5 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface TemplateStrategy {
}

View File

@ -0,0 +1,10 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
public interface VolumeStrategy {
Volume createVolume(Volume vol);
Volume copyVolume(Volume srcVol, Volume destVol);
Volume createVolumeFromSnapshot(Volume vol, Snapshot snapshot);
Volume createVolumeFromTemplate(Volume vol, Template template);
Volume migrateVolume(Volume srcVol, Volume destVol);
boolean deleteVolume(Volume vol);
}

View File

@ -0,0 +1,142 @@
package org.apache.cloudstack.storage;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.StorageProvider;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
import org.apache.cloudstack.storage.datastoreconfigurator.NfsDataStoreConfigurator;
import org.apache.cloudstack.storage.datastoreconfigurator.XenNfsDataStoreConfigurator;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StoragePoolStatus;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.dao.StoragePoolDao;
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>();
hypervisors.add(Hypervisor.HypervisorType.XenServer);
return hypervisors;
}
public DefaultPrimaryStorageProvider() {
Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
DataStoreConfigurator nfsdc = new XenNfsDataStoreConfigurator();
dscs.put(nfsdc.getProtocol(), nfsdc);
_supportedProtocols.put(HypervisorType.XenServer, dscs);
}
public StoreType supportedStoreType() {
return StoreType.Primary;
}
public void configure(Map<String, String> storeProviderInfo) {
// 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;
}
public String getProviderName() {
return _name;
}
public DataStore createDataStore(HypervisorType hypervisor,
DataStoreConfigurator dsc) {
// TODO Auto-generated method stub
return null;
}
public DataStore getDataStore(StoragePool pool) {
ClusterVO clu = _clusterDao.findById(pool.getClusterId());
HypervisorType hy = clu.getHypervisorType();
Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(hy);
DataStoreConfigurator dsc = dscs.get(pool.getPoolType().toString());
return dsc.getDataStore(pool);
}
}

View File

@ -0,0 +1,7 @@
package org.apache.cloudstack.storage;
import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
public interface StorageProviderManager {
StorageProvider getProvider(String uuid);
}

View File

@ -0,0 +1,39 @@
package org.apache.cloudstack.storage;
import java.util.Map;
import javax.naming.ConfigurationException;
import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
import com.cloud.utils.component.Manager;
public class StorageProviderManagerImpl implements StorageProviderManager, Manager {
public StorageProvider getProvider(String uuid) {
// TODO Auto-generated method stub
return null;
}
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
// TODO Auto-generated method stub
return false;
}
public boolean start() {
// TODO Auto-generated method stub
return false;
}
public boolean stop() {
// TODO Auto-generated method stub
return false;
}
public String getName() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,130 @@
package org.apache.cloudstack.storage.datastore;
import org.apache.cloudstack.platform.subsystem.api.storage.BackupStrategy;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPointSelector;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
import org.apache.cloudstack.platform.subsystem.api.storage.FileSystem;
import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotStrategy;
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeStrategy;
public class DefaultDataStore implements DataStore {
protected VolumeStrategy _volumeStrategy;
protected SnapshotStrategy _snapshotStrategy;
protected BackupStrategy _backupStrategy;
protected String _uri;
protected String _uuid;
protected StoreType _type;
protected StoreScope _scope;
protected long _poolId;
protected DataStoreDriver _driverRef;
protected DataStoreEndPointSelector _selector;
protected FileSystem _fs;
protected VolumeStrategy _volumeSt;
protected SnapshotStrategy _snapshotSt;
protected BackupStrategy _backupSt;
protected long _id;
protected DataStoreLifeCycle _dslf;
public DefaultDataStore(
) {
}
public String getURI() {
// TODO Auto-generated method stub
return null;
}
public void setURI(String uri) {
this._uri = uri;
}
public String getUUID() {
return this._uuid;
}
public void setUUID(String uuid) {
this._uuid = uuid;
}
public StoreType getType() {
return this._type;
}
public void setType(StoreType type) {
this._type = type;
}
public StoreScope getScope() {
return this._scope;
}
public void setScope(StoreScope scope) {
this._scope = scope;
}
public Long getId() {
return this._id;
}
public void setId(long id) {
this._id = id;
}
public DataStoreDriver getDataStoreDriver() {
return this._driverRef;
}
public void setDataStoreDriver(DataStoreDriver drv) {
this._driverRef = drv;
}
public void setEndPointSelector(DataStoreEndPointSelector selector) {
this._selector = selector;
}
public DataStoreEndPointSelector getSelector() {
return this._selector;
}
public FileSystem getFileSystem() {
return this._fs;
}
public void setFileSystem(FileSystem fs) {
this._fs = fs;
}
public VolumeStrategy getVolumeStrategy() {
return this._volumeSt;
}
public void setVolumeStrategy(VolumeStrategy vs) {
this._volumeSt = vs;
}
public SnapshotStrategy getSnapshotStrategy() {
return this._snapshotSt;
}
public void setSnapshotStrategy(SnapshotStrategy ss) {
this._snapshotSt = ss;
}
public BackupStrategy getBackupStrategy() {
return this._backupSt;
}
public void setBackupStrategy(BackupStrategy bs) {
this._backupSt = bs;
}
public DataStoreLifeCycle getLifeCycle() {
return this._dslf;
}
public void setLifeCycle(DataStoreLifeCycle lf) {
this._dslf = lf;
}
}

View File

@ -0,0 +1,39 @@
package org.apache.cloudstack.storage.datastore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataObject;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
public class XenDataStoreDriver implements DataStoreDriver {
public String getDriverType() {
// TODO Auto-generated method stub
return null;
}
public DataObject create(DataObject obj) {
// TODO Auto-generated method stub
return null;
}
public DataObject copy(DataObject src, DataStore dest) {
// TODO Auto-generated method stub
return null;
}
public DataObject copy(DataObject src, DataObject dest) {
// TODO Auto-generated method stub
return null;
}
public DataObject move(DataObject src, DataObject dest) {
// TODO Auto-generated method stub
return null;
}
public boolean delete(DataObject obj) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -0,0 +1,71 @@
package org.apache.cloudstack.storage.datastoreconfigurator;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.storage.StoragePool;
import com.cloud.storage.StoragePoolVO;
import com.cloud.storage.Storage.StoragePoolType;
public abstract class NfsDataStoreConfigurator implements DataStoreConfigurator {
private enum NfsConfigName {
SERVER,
PORT,
PATH;
}
public NfsDataStoreConfigurator() {
}
public String getProtocol() {
return "NFS";
}
public Map<String, String> getConfigs(URI uri, Map<String, String> extras) {
Map<String, String> configs = new HashMap<String, String>();
String storageHost = uri.getHost();
String hostPath = uri.getPath();
configs.put(NfsConfigName.SERVER.toString(), storageHost);
configs.put(NfsConfigName.PATH.toString(), hostPath);
configs.putAll(extras);
return configs;
}
public List<String> getConfigNames() {
List<String> names = new ArrayList<String>();
names.add(NfsConfigName.SERVER.toString());
names.add(NfsConfigName.PATH.toString());
return names;
}
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;
}
public DataStore getDataStore(StoragePool pool) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,33 @@
package org.apache.cloudstack.storage.datastoreconfigurator;
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.strategy.XenBackupStrategy;
import org.apache.cloudstack.storage.strategy.XenSnapshotStrategy;
import org.apache.cloudstack.storage.strategy.XenVolumeStrategy;
import com.cloud.storage.StoragePool;
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.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));
return ds;
}
}

View File

@ -0,0 +1,17 @@
package org.apache.cloudstack.storage.epselector;
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;
public class DefaultPrimaryEndpointSelector implements
DataStoreEndPointSelector {
public List<DataStoreEndPoint> getEndPoints(DataStore ds) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,59 @@
package org.apache.cloudstack.storage.filesystem;
import org.apache.cloudstack.platform.subsystem.api.storage.DataObject;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import org.apache.cloudstack.platform.subsystem.api.storage.FileSystem;
public class DefaultFileSystem implements FileSystem {
public DataObject create(DataObject obj) {
// TODO Auto-generated method stub
return null;
}
public DataObject copy(DataObject Obj, DataStore destStore) {
// TODO Auto-generated method stub
return null;
}
public DataObject copy(DataObject obj, DataObject destObj) {
// TODO Auto-generated method stub
return null;
}
public DataObject move(DataObject srcObj, DataObject destObj) {
// TODO Auto-generated method stub
return null;
}
public boolean delete(DataObject obj) {
// TODO Auto-generated method stub
return false;
}
public long getStats(DataObject obj) {
// TODO Auto-generated method stub
return 0;
}
public String getFileType() {
// TODO Auto-generated method stub
return null;
}
public boolean isWritable(DataObject obj) {
// TODO Auto-generated method stub
return false;
}
public boolean contains(DataObject obj) {
// TODO Auto-generated method stub
return false;
}
public DataObject ioctl(DataObject obj, Object... objects) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,38 @@
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

@ -0,0 +1,7 @@
package org.apache.cloudstack.storage.strategy;
import org.apache.cloudstack.platform.subsystem.api.storage.BackupStrategy;
public class XenBackupStrategy implements BackupStrategy {
}

View File

@ -0,0 +1,7 @@
package org.apache.cloudstack.storage.strategy;
import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotStrategy;
public class XenSnapshotStrategy implements SnapshotStrategy {
}

View File

@ -0,0 +1,40 @@
package org.apache.cloudstack.storage.strategy;
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 {
public Volume createVolume(Volume vol) {
// TODO Auto-generated method stub
return null;
}
public Volume copyVolume(Volume srcVol, Volume destVol) {
// TODO Auto-generated method stub
return null;
}
public Volume createVolumeFromSnapshot(Volume vol, Snapshot snapshot) {
// TODO Auto-generated method stub
return null;
}
public Volume createVolumeFromTemplate(Volume vol, Template template) {
// TODO Auto-generated method stub
return null;
}
public Volume migrateVolume(Volume srcVol, Volume destVol) {
// TODO Auto-generated method stub
return null;
}
public boolean deleteVolume(Volume vol) {
// TODO Auto-generated method stub
return false;
}
}