mirror of https://github.com/apache/cloudstack.git
the plugin better not touch database
This commit is contained in:
parent
57641d85f7
commit
49ded7e4a3
|
|
@ -68,7 +68,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
|
|||
return null;
|
||||
}
|
||||
|
||||
class CreateContext<T> extends AsyncRpcContext<T> {
|
||||
protected class CreateContext<T> extends AsyncRpcContext<T> {
|
||||
final DataObject data;
|
||||
|
||||
public CreateContext(AsyncCompletionCallback<T> callback, DataObject data) {
|
||||
|
|
@ -92,7 +92,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
|
|||
}
|
||||
}
|
||||
|
||||
protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<BaseImageStoreDriverImpl, DownloadAnswer> callback,
|
||||
protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback,
|
||||
CreateContext<CreateCmdResult> context) {
|
||||
DownloadAnswer answer = callback.getResult();
|
||||
DataObject obj = context.data;
|
||||
|
|
@ -139,7 +139,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver {
|
|||
return null;
|
||||
}
|
||||
|
||||
protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<BaseImageStoreDriverImpl, DownloadAnswer> callback,
|
||||
protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<? extends BaseImageStoreDriverImpl, DownloadAnswer> callback,
|
||||
CreateContext<CreateCmdResult> context) {
|
||||
DownloadAnswer answer = callback.getResult();
|
||||
DataObject obj = context.data;
|
||||
|
|
|
|||
|
|
@ -26,28 +26,20 @@ import com.cloud.agent.api.to.DataStoreTO;
|
|||
import com.cloud.agent.api.to.NfsTO;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.framework.async.AsyncRpcContext;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.BaseImageStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SimulatorImageStoreDriverImpl extends BaseImageStoreDriverImpl {
|
||||
|
||||
|
|
@ -69,82 +61,46 @@ public class SimulatorImageStoreDriverImpl extends BaseImageStoreDriverImpl {
|
|||
return nfsTO;
|
||||
}
|
||||
|
||||
class CreateContext<T> extends AsyncRpcContext<T> {
|
||||
final DataObject data;
|
||||
|
||||
public CreateContext(AsyncCompletionCallback<T> callback, DataObject data) {
|
||||
super(callback);
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
public String createEntityExtractUrl(DataStore store, String installPath, Storage.ImageFormat format) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAsync(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
public void createAsync(DataStore store, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
if (data.getType() == DataObjectType.TEMPLATE) {
|
||||
this.createTemplate(data, callback);
|
||||
} else if (data.getType() == DataObjectType.VOLUME) {
|
||||
this.createVolume(data, callback);
|
||||
}
|
||||
}
|
||||
|
||||
protected void createTemplate(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
|
||||
AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher
|
||||
.create(this);
|
||||
caller.setContext(context);
|
||||
if (data.getType() == DataObjectType.TEMPLATE) {
|
||||
this.createTemplateAsyncCallback(caller, context);
|
||||
} else if (data.getType() == DataObjectType.VOLUME) {
|
||||
this.createVolumeAsyncCallback(caller, context);
|
||||
}
|
||||
caller.setCallback(caller.getTarget().createTemplateAsyncCallback(null, null));
|
||||
String path = UUID.randomUUID().toString();
|
||||
Long size = new Long(5 * 1024L * 1024L);
|
||||
DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
|
||||
path, path, size, size, null);
|
||||
caller.complete(answer);
|
||||
return;
|
||||
}
|
||||
|
||||
protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> callback,
|
||||
CreateContext<CreateCmdResult> context) {
|
||||
DataObject obj = context.data;
|
||||
DataStore store = obj.getDataStore();
|
||||
TemplateObjectTO templateTO = (TemplateObjectTO)context.data.getTO();
|
||||
|
||||
TemplateDataStoreVO tmpltStoreVO = _templateStoreDao.findByStoreTemplate(store.getId(), obj.getId());
|
||||
if (tmpltStoreVO != null) {
|
||||
TemplateDataStoreVO updateBuilder = _templateStoreDao.createForUpdate();
|
||||
updateBuilder.setDownloadPercent(100);
|
||||
updateBuilder.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
updateBuilder.setLastUpdated(new Date());
|
||||
updateBuilder.setSize(new Long(5 * 1024L * 1024L));
|
||||
updateBuilder.setPhysicalSize(new Long(5 * 1024L * 1024L));
|
||||
updateBuilder.setDownloadUrl(templateTO.getOrigUrl());
|
||||
updateBuilder.setInstallPath(templateTO.getPath());
|
||||
updateBuilder.setTemplateId(templateTO.getId());
|
||||
updateBuilder.setState(ObjectInDataStoreStateMachine.State.Ready);
|
||||
_templateStoreDao.update(tmpltStoreVO.getId(), updateBuilder);
|
||||
// update size in vm_template table
|
||||
VMTemplateVO tmlptUpdater = _templateDao.createForUpdate();
|
||||
tmlptUpdater.setSize(new Long(5 * 1024l * 1024l));
|
||||
_templateDao.update(obj.getId(), tmlptUpdater);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> callback,
|
||||
CreateContext<CreateCmdResult> context) {
|
||||
DataObject obj = context.data;
|
||||
DataStore store = obj.getDataStore();
|
||||
VolumeObjectTO volumeTO = (VolumeObjectTO) context.data.getTO();
|
||||
|
||||
VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(store.getId(), obj.getId());
|
||||
if (volStoreVO != null) {
|
||||
VolumeDataStoreVO updateBuilder = _volumeStoreDao.createForUpdate();
|
||||
updateBuilder.setDownloadPercent(100);
|
||||
updateBuilder.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOADED);
|
||||
updateBuilder.setLastUpdated(new Date());
|
||||
updateBuilder.setInstallPath(volumeTO.getPath());
|
||||
updateBuilder.setVolumeId(volumeTO.getVolumeId());
|
||||
updateBuilder.setSize(volumeTO.getSize());
|
||||
updateBuilder.setPhysicalSize(volumeTO.getSize());
|
||||
updateBuilder.setState(ObjectInDataStoreStateMachine.State.Ready);
|
||||
_volumeStoreDao.update(volStoreVO.getId(), updateBuilder);
|
||||
// update size in volume table
|
||||
VolumeVO volUpdater = _volumeDao.createForUpdate();
|
||||
volUpdater.setSize(volumeTO.getSize());
|
||||
_volumeDao.update(obj.getId(), volUpdater);
|
||||
}
|
||||
return null;
|
||||
protected void createVolume(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
CreateContext<CreateCmdResult> context = new CreateContext<CreateCmdResult>(callback, data);
|
||||
AsyncCallbackDispatcher<SimulatorImageStoreDriverImpl, DownloadAnswer> caller = AsyncCallbackDispatcher
|
||||
.create(this);
|
||||
caller.setContext(context);
|
||||
caller.setCallback(caller.getTarget().createVolumeAsyncCallback(null, null));
|
||||
String path = UUID.randomUUID().toString();
|
||||
Long size = new Long(5 * 1024L * 1024L);
|
||||
DownloadAnswer answer = new DownloadAnswer(null, 100, null, VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
|
||||
path, path, size, size, null);
|
||||
caller.complete(answer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -54,16 +54,12 @@ public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
|
|||
return null;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
@Override
|
||||
public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private class CreateVolumeContext<T> extends AsyncRpcConext<T> {
|
||||
=======
|
||||
private class CreateVolumeContext<T> extends AsyncRpcContext<T> {
|
||||
>>>>>>> Fix typo in class name
|
||||
private final DataObject volume;
|
||||
public CreateVolumeContext(AsyncCompletionCallback<T> callback, DataObject volume) {
|
||||
super(callback);
|
||||
|
|
|
|||
|
|
@ -570,7 +570,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
} else {
|
||||
s_logger.debug("Storage cleanup is not enabled, so the storage cleanup thread is not being scheduled.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -579,7 +578,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
if (_storageCleanupEnabled) {
|
||||
_executor.shutdown();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -591,7 +589,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
if (dc == null || !dc.isLocalStorageEnabled()) {
|
||||
return null;
|
||||
}
|
||||
DataStore store = null;
|
||||
DataStore store;
|
||||
try {
|
||||
StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), pInfo.getHostPath(),
|
||||
pInfo.getUuid());
|
||||
|
|
@ -693,21 +691,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
}
|
||||
}
|
||||
|
||||
Map ds = cmd.getDetails();
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
if (ds != null) {
|
||||
Collection detailsCollection = ds.values();
|
||||
Iterator it = detailsCollection.iterator();
|
||||
while (it.hasNext()) {
|
||||
HashMap d = (HashMap) it.next();
|
||||
Iterator it2 = d.entrySet().iterator();
|
||||
while (it2.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it2.next();
|
||||
details.put((String) entry.getKey(), (String) entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> details = extractApiParamAsMap(cmd.getDetails());
|
||||
DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
|
||||
if (zone == null) {
|
||||
throw new InvalidParameterValueException("unable to find zone by id " + zoneId);
|
||||
|
|
@ -732,10 +716,9 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
params.put("capacityIops", cmd.getCapacityIops());
|
||||
|
||||
DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
|
||||
DataStore store = null;
|
||||
DataStore store;
|
||||
try {
|
||||
store = lifeCycle.initialize(params);
|
||||
|
||||
if (scopeType == ScopeType.CLUSTER) {
|
||||
ClusterScope clusterScope = new ClusterScope(clusterId, podId, zoneId);
|
||||
lifeCycle.attachCluster(store, clusterScope);
|
||||
|
|
@ -751,6 +734,23 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
return (PrimaryDataStoreInfo) dataStoreMgr.getDataStore(store.getId(), DataStoreRole.Primary);
|
||||
}
|
||||
|
||||
private Map<String, String> extractApiParamAsMap(Map ds) {
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
if (ds != null) {
|
||||
Collection detailsCollection = ds.values();
|
||||
Iterator it = detailsCollection.iterator();
|
||||
while (it.hasNext()) {
|
||||
HashMap d = (HashMap) it.next();
|
||||
Iterator it2 = d.entrySet().iterator();
|
||||
while (it2.hasNext()) {
|
||||
Map.Entry entry = (Map.Entry) it2.next();
|
||||
details.put((String) entry.getKey(), (String) entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreInfo updateStoragePool(UpdateStoragePoolCmd cmd) throws IllegalArgumentException {
|
||||
// Input validation
|
||||
|
|
@ -1637,7 +1637,6 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
}
|
||||
|
||||
Long dcId = cmd.getZoneId();
|
||||
String url = cmd.getUrl();
|
||||
Map details = cmd.getDetails();
|
||||
ScopeType scopeType = ScopeType.ZONE;
|
||||
if (dcId == null) {
|
||||
|
|
@ -1686,7 +1685,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
params.put("role", DataStoreRole.Image);
|
||||
|
||||
DataStoreLifeCycle lifeCycle = storeProvider.getDataStoreLifeCycle();
|
||||
DataStore store = null;
|
||||
DataStore store;
|
||||
try {
|
||||
store = lifeCycle.initialize(params);
|
||||
} catch (Exception e) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue