diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java index 9db205b12a5..86462472743 100644 --- a/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java +++ b/engine/storage/src/org/apache/cloudstack/storage/image/BaseImageStoreDriverImpl.java @@ -68,7 +68,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { return null; } - class CreateContext extends AsyncRpcContext { + protected class CreateContext extends AsyncRpcContext { final DataObject data; public CreateContext(AsyncCompletionCallback callback, DataObject data) { @@ -92,7 +92,7 @@ public abstract class BaseImageStoreDriverImpl implements ImageStoreDriver { } } - protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher callback, + protected Void createTemplateAsyncCallback(AsyncCallbackDispatcher callback, CreateContext 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 callback, + protected Void createVolumeAsyncCallback(AsyncCallbackDispatcher callback, CreateContext context) { DownloadAnswer answer = callback.getResult(); DataObject obj = context.data; diff --git a/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java b/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java index 8816fc2d9a3..d5fe8a18a82 100644 --- a/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java +++ b/plugins/storage/image/simulator/src/org/apache/cloudstack/storage/datastore/driver/SimulatorImageStoreDriverImpl.java @@ -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 extends AsyncRpcContext { - final DataObject data; - public CreateContext(AsyncCompletionCallback 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 callback) { + public void createAsync(DataStore store, DataObject data, AsyncCompletionCallback 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 callback) { CreateContext context = new CreateContext(callback, data); AsyncCallbackDispatcher 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 callback, - CreateContext 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 callback, - CreateContext 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 callback) { + CreateContext context = new CreateContext(callback, data); + AsyncCallbackDispatcher 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; } } \ No newline at end of file diff --git a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java index 1d00c973c97..ece7b260cd4 100644 --- a/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java +++ b/plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java @@ -54,16 +54,12 @@ public class SamplePrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver return null; } -<<<<<<< HEAD @Override public ChapInfo getChapInfo(VolumeInfo volumeInfo) { return null; } - private class CreateVolumeContext extends AsyncRpcConext { -======= private class CreateVolumeContext extends AsyncRpcContext { ->>>>>>> Fix typo in class name private final DataObject volume; public CreateVolumeContext(AsyncCompletionCallback callback, DataObject volume) { super(callback); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index ff323cbbedf..138c6d7d137 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -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 details = new HashMap(); - 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 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 extractApiParamAsMap(Map ds) { + Map details = new HashMap(); + 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) {