mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
add backup/snapshot project
This commit is contained in:
parent
ac5622cc2a
commit
54f9a5de65
@ -18,8 +18,9 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.backup;
|
||||
|
||||
public interface BackupService {
|
||||
String grantAccessSnapshot(long snapshotId, long endpointId);
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
|
||||
boolean revokeAccessSnapshot(long snapshotId, long endpointId);
|
||||
public interface BackupService {
|
||||
public boolean backupSnapshot(SnapshotInfo snapshot, long backupStoreId);
|
||||
public SnapshotOnBackupStoreInfo getSnapshot(long snapshotId);
|
||||
}
|
||||
|
||||
@ -30,6 +30,8 @@ import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreImpl;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.DefaultImageDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
@ -47,7 +49,7 @@ public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
|
||||
public ImageDataStore getImageDataStore(long imageStoreId) {
|
||||
ImageDataStoreVO idsv = imageStoreDao.findById(imageStoreId);
|
||||
ImageDataStoreDriver driver = new ImageDataStoreDriverImpl();
|
||||
ImageDataStore ids = new ImageDataStoreImpl(idsv, driver, false, null);
|
||||
ImageDataStore ids = new ImageDataStoreImpl(idsv, driver, false);
|
||||
ids = ComponentInject.inject(ids);
|
||||
return ids;
|
||||
}
|
||||
@ -69,14 +71,7 @@ public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStore registerDataStore(String name, Map<String, String> params) {
|
||||
ImageDataStoreVO dataStore = imageStoreDao.findByName(name);
|
||||
if (dataStore == null) {
|
||||
dataStore = new ImageDataStoreVO();
|
||||
dataStore.setName(name);
|
||||
dataStore.setProvider(provider.getId());
|
||||
dataStore = imageStoreDao.persist(dataStore);
|
||||
}
|
||||
return getImageDataStore(dataStore.getId());
|
||||
public ImageDataStoreLifeCycle getLifeCycle() {
|
||||
return new DefaultImageDataStoreLifeCycle(this, provider, imageStoreDao);
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,10 +21,11 @@ package org.apache.cloudstack.storage.image.provider;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
|
||||
|
||||
public interface ImageDataStoreProvider extends ImageDataStoreLifeCycle {
|
||||
public interface ImageDataStoreProvider {
|
||||
ImageDataStore getImageDataStore(long imageStoreId);
|
||||
boolean register(long providerId);
|
||||
public String getName();
|
||||
ImageDataStoreLifeCycle getLifeCycle();
|
||||
/**
|
||||
* @param providerId
|
||||
* @return
|
||||
|
||||
@ -18,9 +18,7 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.store;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
|
||||
|
||||
public interface ImageDataStore extends ImageDataStoreInfo {
|
||||
TemplateObject registerTemplate(long templateId);
|
||||
@ -32,8 +30,6 @@ public interface ImageDataStore extends ImageDataStoreInfo {
|
||||
boolean deleteTemplate(long templateId);
|
||||
|
||||
boolean needDownloadToCacheStorage();
|
||||
|
||||
ImageDownloader getImageDownloader();
|
||||
|
||||
TemplateObject getTemplate(long templateId);
|
||||
}
|
||||
|
||||
@ -20,27 +20,22 @@ package org.apache.cloudstack.storage.image.store;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
|
||||
|
||||
public class ImageDataStoreImpl implements ImageDataStore {
|
||||
@Inject
|
||||
ImageDataDao imageDao;
|
||||
ImageDataStoreDriver driver;
|
||||
ImageDownloader downloader;
|
||||
ImageDataStoreVO imageDataStoreVO;
|
||||
boolean needDownloadToCacheStorage = false;
|
||||
|
||||
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) {
|
||||
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver driver, boolean needDownloadToCacheStorage) {
|
||||
this.driver = driver;
|
||||
this.needDownloadToCacheStorage = needDownloadToCacheStorage;
|
||||
this.downloader = downloader;
|
||||
this.imageDataStoreVO = dataStoreVO;
|
||||
}
|
||||
|
||||
@ -76,11 +71,6 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDownloader getImageDownloader() {
|
||||
return this.downloader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getImageDataStoreId() {
|
||||
return imageDataStoreVO.getId();
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
package org.apache.cloudstack.storage.image.store.lifecycle;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProvider;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public class DefaultImageDataStoreLifeCycle implements ImageDataStoreLifeCycle {
|
||||
protected ImageDataStoreProvider provider;
|
||||
protected ImageDataStoreProviderVO providerVO;
|
||||
protected ImageDataStoreDao imageStoreDao;
|
||||
@Override
|
||||
public ImageDataStore registerDataStore(String name,
|
||||
Map<String, String> params) {
|
||||
ImageDataStoreVO dataStore = imageStoreDao.findByName(name);
|
||||
if (dataStore == null) {
|
||||
dataStore = new ImageDataStoreVO();
|
||||
dataStore.setName(name);
|
||||
dataStore.setProvider(providerVO.getId());
|
||||
dataStore = imageStoreDao.persist(dataStore);
|
||||
}
|
||||
return provider.getImageDataStore(dataStore.getId());
|
||||
}
|
||||
|
||||
public DefaultImageDataStoreLifeCycle(ImageDataStoreProvider provider,
|
||||
ImageDataStoreProviderVO providerVO,
|
||||
ImageDataStoreDao dao) {
|
||||
this.provider = provider;
|
||||
this.providerVO = providerVO;
|
||||
this.imageStoreDao = dao;
|
||||
}
|
||||
|
||||
}
|
||||
@ -62,6 +62,7 @@ import org.apache.cloudstack.storage.image.format.Unknown;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProvider;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.volume.VolumeService;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeVO;
|
||||
@ -211,7 +212,8 @@ public class volumeServiceTest {
|
||||
imageProviderMgr.configure("image Provider", new HashMap<String, Object>());
|
||||
ImageDataVO image = createImageData();
|
||||
ImageDataStoreProvider defaultProvider = imageProviderMgr.getProvider("DefaultProvider");
|
||||
ImageDataStore store = defaultProvider.registerDataStore("defaultHttpStore", new HashMap<String, String>());
|
||||
ImageDataStoreLifeCycle lifeCycle = defaultProvider.getLifeCycle();
|
||||
ImageDataStore store = lifeCycle.registerDataStore("defaultHttpStore", new HashMap<String, String>());
|
||||
imageService.registerTemplate(image.getId(), store.getImageDataStoreId());
|
||||
TemplateEntity te = imageService.getTemplateEntity(image.getId());
|
||||
return te;
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SnapshotServiceImpl implements SnapshotService {
|
||||
|
||||
@Override
|
||||
public SnapshotEntity getSnapshotEntity(long snapshotId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean takeSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revertSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package org.apache.cloudstack.storage.snapshot.strategy;
|
||||
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotStrategy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class HypervisorBasedSnapshot implements SnapshotStrategy {
|
||||
|
||||
@Override
|
||||
public boolean takeSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revertSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package org.apache.cloudstack.storage.snapshot.strategy;
|
||||
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotStrategy;
|
||||
|
||||
public class StorageBasedSnapshot implements SnapshotStrategy {
|
||||
|
||||
@Override
|
||||
public boolean takeSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revertSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteSnapshot(SnapshotInfo snapshot) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package org.apache.cloudstack.storage.backup;
|
||||
|
||||
import org.apache.cloudstack.storage.backup.datastore.BackupStoreInfo;
|
||||
|
||||
public interface SnapshotOnBackupStoreInfo {
|
||||
public String getName();
|
||||
public BackupStoreInfo getBackupStore();
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package org.apache.cloudstack.storage.backup.datastore;
|
||||
|
||||
import org.apache.cloudstack.storage.backup.SnapshotOnBackupStoreInfo;
|
||||
|
||||
public interface BackupStoreInfo {
|
||||
public SnapshotOnBackupStoreInfo getSnapshot(long snapshotId);
|
||||
public boolean deleteSnapshot(SnapshotOnBackupStoreInfo snapshot);
|
||||
}
|
||||
@ -0,0 +1,182 @@
|
||||
package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
|
||||
public class SnapshotEntityImpl implements SnapshotEntity {
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentState() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDesiredState() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreatedTime() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getLastUpdatedTime() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOwner() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getDetails(String source) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDetailSources() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDetail(String source, String name, String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Method> getApplicableActions() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAccountId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getVolumeId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getCreated() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status getStatus() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecursive() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getsnapshotType() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDomainId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reserveForBackup(int expiration) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backup(String reservationToken) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restore(String vm) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
|
||||
public interface SnapshotInfo {
|
||||
public String getName();
|
||||
public SnapshotInfo getParent();
|
||||
public SnapshotInfo getChild();
|
||||
public VolumeInfo getBaseVolume();
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity;
|
||||
|
||||
public interface SnapshotService {
|
||||
public SnapshotEntity getSnapshotEntity(long snapshotId);
|
||||
public boolean takeSnapshot(SnapshotInfo snapshot);
|
||||
public boolean revertSnapshot(SnapshotInfo snapshot);
|
||||
public boolean deleteSnapshot(SnapshotInfo snapshot);
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
public interface SnapshotStrategy {
|
||||
public boolean takeSnapshot(SnapshotInfo snapshot);
|
||||
public boolean revertSnapshot(SnapshotInfo snapshot);
|
||||
public boolean deleteSnapshot(SnapshotInfo snapshot);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user