You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2012/09/03 04:27:44 UTC
[1/2] git commit: add secondary storage provider
Updated Branches:
refs/heads/javelin 7d92c1dc2 -> 73cc47415
add secondary storage provider
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/73cc4741
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/73cc4741
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/73cc4741
Branch: refs/heads/javelin
Commit: 73cc474157c2f3a2c47f5932f6fc652dc1939fec
Parents: 7d92c1d
Author: Edison Su <su...@gmail.com>
Authored: Sun Sep 2 19:26:20 2012 -0700
Committer: Edison Su <su...@gmail.com>
Committed: Sun Sep 2 19:26:20 2012 -0700
----------------------------------------------------------------------
.../platform/subsystem/api/storage/DataStore.java | 5 +-
.../subsystem/api/storage/DataStoreDriver.java | 2 +
.../subsystem/api/storage/StorageEvent.java | 1 +
.../subsystem/api/storage/StorageProvider.java | 2 +-
.../subsystem/api/storage/TemplateProfile.java | 72 ----
.../subsystem/api/storage/TemplateStrategy.java | 7 +
.../storage/DefaultPrimaryStorageProvider.java | 137 --------
.../storage/StorageOrchestratorImpl.java | 7 +-
.../NfsSecondaryStorageConfigurator.java | 55 +++
.../storage/driver/AbstractStorageDriver.java | 30 ++-
.../storage/driver/DefaultNfsSecondaryDriver.java | 79 +++++
.../DefaultNfsSecondaryEndPointSelector.java | 38 +++
.../cloudstack/storage/image/ImageManager.java | 32 ++
.../cloudstack/storage/image/ImageManagerImpl.java | 167 ++++++++++
.../storage/image/ImageOrchestrator.java | 26 ++
.../storage/image/ImageOrchestratorImpl.java | 78 +++++
.../lifecycle/DefaultNfsSecondaryLifeCycle.java | 54 +++
.../storage/manager/SecondaryStorageManager.java | 3 +
.../manager/SecondaryStorageManagerImpl.java | 28 ++
.../storage/manager/TemplateManager.java | 33 --
.../storage/manager/TemplateManagerImpl.java | 91 -----
.../DefaultNfsSecondaryStorageProvider.java | 131 ++++++++
.../provider/DefaultPrimaryStorageProvider.java | 139 ++++++++
.../storage/provider/HttpImageStoreProvider.java | 91 +++++
.../provider/S3SecondaryStorageProvider.java | 91 +++++
.../provider/SwiftSecondaryStorageProvider.java | 91 +++++
.../storage/strategy/DefaultTemplateStratey.java | 113 ++++++-
.../cloud/baremetal/BareMetalTemplateAdapter.java | 4 +-
.../cloud/baremetal/BareMetalVmManagerImpl.java | 2 +-
.../cloud/template/HyervisorTemplateAdapter.java | 5 +-
server/src/com/cloud/template/TemplateAdapter.java | 1 +
.../com/cloud/template/TemplateAdapterBase.java | 1 +
.../com/cloud/template/TemplateManagerImpl.java | 1 +
server/src/com/cloud/template/TemplateProfile.java | 255 ---------------
34 files changed, 1255 insertions(+), 617 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java
index 20a16e5..d18c7a3 100644
--- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java
+++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java
@@ -21,6 +21,7 @@ package org.apache.cloudstack.platform.subsystem.api.storage;
import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.storage.Snapshot;
import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.TemplateProfile;
import com.cloud.storage.Volume;
import com.cloud.template.VirtualMachineTemplate;
@@ -35,6 +36,7 @@ public interface DataStore {
public enum StoreType {
Primary,
+ Image,
Backup;
}
public class StoreScope {
@@ -55,6 +57,7 @@ public interface DataStore {
boolean isSharedStorage();
Long getId();
DataStoreDriver getDataStoreDriver();
+ StorageProvider getProvider();
DataStoreEndPointSelector getEndPointSelector();
FileSystem getFileSystem();
VolumeStrategy getVolumeStrategy();
@@ -65,7 +68,7 @@ public interface DataStore {
VolumeProfile prepareVolume(Volume volume, DataStore destStore);
SnapshotProfile prepareSnapshot(Snapshot snapshot, DataStore destStore);
- TemplateProfile prepareTemplate(VirtualMachineTemplate template, DataStore destStore);
+ TemplateProfile prepareTemplate(long templateId, DataStore destStore);
boolean contains(Volume volume);
boolean contains(Snapshot snapshot);
boolean contains(TemplateProfile template);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java
index 61ff967..400d883 100644
--- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java
+++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java
@@ -20,11 +20,13 @@ package org.apache.cloudstack.platform.subsystem.api.storage;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
+import com.cloud.storage.TemplateProfile;
import com.cloud.vm.DiskProfile;
public interface DataStoreDriver {
String getDriverType();
TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep);
+ TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep);
DiskProfile createVolumeFromTemplate(DiskProfile volProfile, TemplateProfile tp, DataStoreEndPoint ep);
DataObject create(DataObject obj);
DataObject copy(DataObject src, DataStore dest);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java
index 7ff4a76..34cfb2a 100644
--- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java
+++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java
@@ -20,5 +20,6 @@ package org.apache.cloudstack.platform.subsystem.api.storage;
public enum StorageEvent {
DownloadTemplateToPrimary,
+ RegisterTemplate,
CreateVolumeFromTemplate;
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java
index 95391c3..7bc7e30 100644
--- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java
+++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java
@@ -12,7 +12,7 @@ import com.cloud.utils.component.Adapter;
public interface StorageProvider extends Adapter {
List<HypervisorType> supportedHypervisors();
String getProviderName();
- StoreType supportedStoreType();
+ List<StoreType> supportedStoreTypes();
void configure(Map<String, String> storeProviderInfo);
DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params);
DataStore getDataStore(StoragePool pool);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java
deleted file mode 100644
index 39da9d3..0000000
--- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java
+++ /dev/null
@@ -1,72 +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;
-
-import com.cloud.storage.Storage;
-
-public class TemplateProfile {
- private String _uri;
- private String _imageStorageUri;
- private String _localPath;
- private long _id;
- private long _templatePoolRefId;
- public String getURI() {
- return _uri;
- }
-
- public long getId() {
- return _id;
- }
-
- public String getLocalPath() {
- return _localPath;
- }
-
- public void setLocalPath(String path) {
- _localPath = path;
- }
-
- public void setTemplatePoolRefId(long id) {
- this._templatePoolRefId = id;
- }
-
- public long getTemplatePoolRefId() {
- return this._templatePoolRefId;
- }
-
- public String getImageStorageUri() {
- return _imageStorageUri;
- }
-
- public String getUniqueName() {
- return null;
- }
-
- public Storage.ImageFormat getFormat() {
- return null;
- }
-
- public String getInstallPath() {
- return null;
- }
-
- public long getTemplateSize() {
- return 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java
----------------------------------------------------------------------
diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java
index a76f17d..00daf0c 100644
--- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java
+++ b/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java
@@ -1,7 +1,14 @@
package org.apache.cloudstack.platform.subsystem.api.storage;
+import com.cloud.agent.api.storage.DownloadCommand.Proxy;
+import com.cloud.storage.TemplateProfile;
+
public interface TemplateStrategy {
TemplateProfile install(TemplateProfile tp);
TemplateProfile get(long templateId);
+ TemplateProfile register(TemplateProfile tp);
+ boolean canRegister(long templateId);
int getDownloadWait();
+ long getMaxTemplateSizeInBytes();
+ Proxy getHttpProxy();
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/DefaultPrimaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/DefaultPrimaryStorageProvider.java b/platform/storage/src/org/apache/cloudstack/storage/DefaultPrimaryStorageProvider.java
deleted file mode 100644
index ea2dfe3..0000000
--- a/platform/storage/src/org/apache/cloudstack/storage/DefaultPrimaryStorageProvider.java
+++ /dev/null
@@ -1,137 +0,0 @@
-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 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;
-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 ClusterDao _clusterDao;
-
- 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 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);
- }
-
- 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java b/platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
index e53cb0b..00e6eae 100644
--- a/platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
+++ b/platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java
@@ -28,8 +28,8 @@ import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile;
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile;
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeStrategy;
import org.apache.cloudstack.storage.db.VolumeHostVO;
+import org.apache.cloudstack.storage.image.ImageManager;
import org.apache.cloudstack.storage.manager.BackupStorageManager;
-import org.apache.cloudstack.storage.manager.TemplateManager;
import org.apache.cloudstack.storage.manager.SecondaryStorageManager;
import org.apache.cloudstack.storage.volume.VolumeManager;
import org.apache.log4j.Logger;
@@ -76,7 +76,7 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
@Inject
SecondaryStorageManager _secondaryStorageMgr;
@Inject
- TemplateManager _templateMgr;
+ ImageManager _templateMgr;
@Inject
VMTemplateDao _templateDao;
@@ -169,9 +169,8 @@ public class StorageOrchestratorImpl implements StorageOrchestrator {
volume = _volumeMgr.processEvent(volume, Volume.Event.CreateRequested);
if (volume.getTemplateId() != null) {
- VirtualMachineTemplate template = _templateDao.findById(volume.getTemplateId());
DataStore ds = _secondaryStorageMgr.getImageStore(destStore);
- TemplateProfile tp = ds.prepareTemplate(template, destStore);
+ TemplateProfile tp = ds.prepareTemplate(volume.getTemplateId(), destStore);
if (!destStore.contains(tp)) {
tp = _templateMgr.AssociateTemplateStoragePool(tp, destStore);
tp = destStore.getTemplateStrategy().install(tp);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/datastoreconfigurator/NfsSecondaryStorageConfigurator.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/datastoreconfigurator/NfsSecondaryStorageConfigurator.java b/platform/storage/src/org/apache/cloudstack/storage/datastoreconfigurator/NfsSecondaryStorageConfigurator.java
new file mode 100644
index 0000000..a69b6a6
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/datastoreconfigurator/NfsSecondaryStorageConfigurator.java
@@ -0,0 +1,55 @@
+/*
+ * 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.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.driver.DefaultNfsSecondaryDriver;
+import org.apache.cloudstack.storage.epselector.DefaultNfsSecondaryEndPointSelector;
+
+import org.apache.cloudstack.storage.lifecycle.DefaultNfsSecondaryLifeCycle;
+
+import org.apache.cloudstack.storage.strategy.DefaultTemplateStratey;
+
+
+import com.cloud.storage.StoragePool;
+
+public class NfsSecondaryStorageConfigurator extends NfsDataStoreConfigurator {
+ @Override
+ public DataStore getDataStore(StoragePool pool) {
+ DefaultDataStore ds = new DefaultDataStore();
+ ds.setEndPointSelector(new DefaultNfsSecondaryEndPointSelector(ds));
+ ds.setId(pool.getId());
+ ds.setType(StoreType.Image);
+ ds.setURI(pool.getHostAddress() + "/" + pool.getPath());
+ ds.setUUID(pool.getUuid());
+ ds.setDataStoreDriver(new DefaultNfsSecondaryDriver(ds));
+ ds.setTemplateStrategy(new DefaultTemplateStratey(ds));
+ ds.setLifeCycle(new DefaultNfsSecondaryLifeCycle(ds));
+ return ds;
+ }
+ public StoragePool getStoragePool(Map<String, String> configs) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java b/platform/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java
index 10b39c0..125874e 100644
--- a/platform/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java
+++ b/platform/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java
@@ -23,14 +23,17 @@ import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile;
-import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile;
import org.apache.cloudstack.platform.subsystem.api.storage.TemplateStrategy;
-
+import com.cloud.agent.api.storage.DownloadProgressCommand;
+import com.cloud.agent.api.storage.DownloadProgressCommand.RequestType;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.storage.CreateAnswer;
import com.cloud.agent.api.storage.CreateCommand;
+import com.cloud.agent.api.storage.DownloadCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer;
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
import com.cloud.agent.api.to.VolumeTO;
+import com.cloud.storage.TemplateProfile;
import com.cloud.vm.DiskProfile;
@@ -45,18 +48,29 @@ public abstract class AbstractStorageDriver implements DataStoreDriver {
}
public TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep) {
- PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getUniqueName(), tp.getURI(), tp.getFormat(),
+ PrimaryStorageDownloadCommand dcmd = new PrimaryStorageDownloadCommand(tp.getName(), tp.getUrl(), tp.getFormat(),
0, _ds.getId(), _ds.getUUID(), _ts.getDownloadWait());
dcmd.setSecondaryStorageUrl(tp.getImageStorageUri());
dcmd.setPrimaryStorageUrl(_ds.getURI());
- Answer asw = ep.sendCommand(dcmd);
+ PrimaryStorageDownloadAnswer asw = (PrimaryStorageDownloadAnswer)ep.sendCommand(dcmd);
- TemplateProfile tpn = new TemplateProfile();
- tpn.setLocalPath("/mnt/test");
- tpn.setTemplatePoolRefId(tp.getTemplatePoolRefId());
- return tpn;
+ tp.setLocalPath(asw.getInstallPath());
+ return tp;
}
+ public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep, boolean freshDownload) {
+
+ DownloadCommand dcmd =
+ new DownloadCommand(_ds.getURI(), tp.getTemplate(), _ts.getMaxTemplateSizeInBytes());
+ dcmd.setProxy(_ts.getHttpProxy());
+ if (!freshDownload) {
+ dcmd = new DownloadProgressCommand(dcmd, tp.getJobId(), RequestType.GET_OR_RESTART);
+ }
+
+ ep.sendCommand(dcmd);
+ return tp;
+ }
+
public DiskProfile createVolumeFromTemplate(DiskProfile volProfile, TemplateProfile tp, DataStoreEndPoint ep) {
CreateCommand cmd = new CreateCommand(volProfile, tp.getLocalPath(), _ds.getTO());
CreateAnswer ans = (CreateAnswer)ep.sendCommand(cmd);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java b/platform/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java
new file mode 100644
index 0000000..6983978
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java
@@ -0,0 +1,79 @@
+/*
+ * 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.storage.driver;
+
+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.DataStoreEndPoint;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.storage.TemplateProfile;
+
+public class DefaultNfsSecondaryDriver extends AbstractStorageDriver {
+
+ /**
+ * @param ds
+ */
+ public DefaultNfsSecondaryDriver(DataStore ds) {
+ super(ds);
+ // TODO Auto-generated constructor stub
+ }
+
+ public String getDriverType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep) {
+ // 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 Answer sendMessage(DataStoreEndPoint dsep, Command cmd) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean delete(DataObject obj) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/epselector/DefaultNfsSecondaryEndPointSelector.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/epselector/DefaultNfsSecondaryEndPointSelector.java b/platform/storage/src/org/apache/cloudstack/storage/epselector/DefaultNfsSecondaryEndPointSelector.java
new file mode 100644
index 0000000..b9de406
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/epselector/DefaultNfsSecondaryEndPointSelector.java
@@ -0,0 +1,38 @@
+/*
+ * 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.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;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageEvent;
+
+public class DefaultNfsSecondaryEndPointSelector implements DataStoreEndPointSelector {
+ protected DataStore _ds;
+ public DefaultNfsSecondaryEndPointSelector(DataStore ds) {
+ _ds = ds;
+ }
+ public List<DataStoreEndPoint> getEndPoints(StorageEvent event) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/image/ImageManager.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/ImageManager.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManager.java
new file mode 100644
index 0000000..29845a1
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManager.java
@@ -0,0 +1,32 @@
+/*
+ * 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.storage.image;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+
+
+import com.cloud.api.commands.RegisterTemplateCmd;
+
+import com.cloud.storage.TemplateProfile;
+
+public interface ImageManager {
+ TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds);
+ TemplateProfile getProfile(long templateId);
+ com.cloud.storage.TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java
new file mode 100644
index 0000000..83f331f
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java
@@ -0,0 +1,167 @@
+/*
+ * 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.storage.image;
+
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.log4j.Logger;
+
+import com.cloud.api.commands.RegisterTemplateCmd;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.Storage.TemplateType;
+import com.cloud.storage.TemplateProfile;
+import com.cloud.storage.VMTemplateHostVO;
+import com.cloud.storage.VMTemplateStoragePoolVO;
+import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.storage.dao.VMTemplatePoolDao;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.utils.EnumUtils;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class ImageManagerImpl implements ImageManager {
+ private static final Logger s_logger = Logger.getLogger(ImageManagerImpl.class);
+ @Inject
+ VMTemplateDao _templateDao;
+ @Inject
+ VMTemplatePoolDao _templatePoolDao;
+ @Inject
+ DataCenterDao _dcDao;
+
+ public boolean contains(VirtualMachineTemplate template, DataStore ds) {
+ long templateId = template.getId();
+ long poolId = ds.getId();
+ VMTemplateStoragePoolVO templateStoragePoolRef = null;
+ templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
+ return templateStoragePoolRef == null ? false : true;
+ }
+
+ public TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds) {
+ long templateId = tp.getTemplateId();
+ long poolId = ds.getId();
+ VMTemplateStoragePoolVO templateStoragePoolRef = null;
+ long templateStoragePoolRefId;
+
+ templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
+ if (templateStoragePoolRef != null) {
+ templateStoragePoolRef.setMarkedForGC(false);
+ _templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
+
+ if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId);
+ }
+
+ tp.setLocalPath(templateStoragePoolRef.getInstallPath());
+ tp.setTemplatePoolRefId(templateStoragePoolRef.getId());
+ return tp;
+ }
+ }
+
+ if (templateStoragePoolRef == null) {
+ templateStoragePoolRef = new VMTemplateStoragePoolVO(poolId, templateId);
+ try {
+ templateStoragePoolRef = _templatePoolDao.persist(templateStoragePoolRef);
+ templateStoragePoolRefId = templateStoragePoolRef.getId();
+ } catch (Exception e) {
+ s_logger.debug("Assuming we're in a race condition: " + e.getMessage());
+ templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
+ if (templateStoragePoolRef == null) {
+ throw new CloudRuntimeException("Unable to persist a reference for pool " + poolId + " and template " + templateId);
+ }
+ templateStoragePoolRefId = templateStoragePoolRef.getId();
+ }
+ } else {
+ templateStoragePoolRefId = templateStoragePoolRef.getId();
+ }
+ tp.setTemplatePoolRefId(templateStoragePoolRefId);
+ return tp;
+ }
+
+ public TemplateProfile getProfile(long templateId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ protected TemplateProfile persistTemplate(TemplateProfile profile) {
+ Long zoneId = profile.getZoneId();
+ VMTemplateVO template = new VMTemplateVO(profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(),
+ profile.getFeatured(), profile.getIsExtractable(), TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(),
+ profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(),
+ profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(),
+ profile.getDetails(), profile.getSshKeyEnabled());
+
+ if (zoneId == null || zoneId.longValue() == -1) {
+ List<DataCenterVO> dcs = _dcDao.listAll();
+
+ if (dcs.isEmpty()) {
+ throw new CloudRuntimeException("No zones are present in the system, can't add template");
+ }
+
+ template.setCrossZones(true);
+ for (DataCenterVO dc: dcs) {
+ _templateDao.addTemplateToZone(template, dc.getId());
+ }
+ } else {
+ _templateDao.addTemplateToZone(template, zoneId);
+ }
+
+ return getProfile(template.getId());
+ }
+
+ protected boolean parameterCheck(RegisterTemplateCmd cmd) {
+ Long zoneId = cmd.getZoneId();
+ if (zoneId == -1) {
+ zoneId = null;
+ }
+
+ ImageFormat imgfmt = ImageFormat.valueOf(cmd.getFormat().toUpperCase());
+ if (imgfmt == null) {
+ throw new IllegalArgumentException("Image format is incorrect " + cmd.getFormat() + ". Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
+ }
+
+ // If a zoneId is specified, make sure it is valid
+ if (zoneId != null) {
+ DataCenterVO zone = _dcDao.findById(zoneId);
+ if (zone == null) {
+ throw new IllegalArgumentException("Please specify a valid zone.");
+ }
+ }
+
+ List<VMTemplateVO> systemvmTmplts = _templateDao.listAllSystemVMTemplates();
+ for (VMTemplateVO template : systemvmTmplts) {
+ if (template.getName().equalsIgnoreCase(cmd.getTemplateName()) || template.getDisplayText().equalsIgnoreCase(cmd.getDisplayText())) {
+ throw new IllegalArgumentException("Cannot use reserved names for templates");
+ }
+ }
+
+ return true;
+ }
+
+ public TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd) {
+ parameterCheck(cmd);
+ TemplateProfile tp = new TemplateProfile(cmd);
+ return persistTemplate(tp);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java
new file mode 100644
index 0000000..f759d6b
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java
@@ -0,0 +1,26 @@
+/*
+ * 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.storage.image;
+
+public interface ImageOrchestrator {
+ void registerTemplate(long templateId);
+ void registerSnapshot(long snapshotId);
+ void registerVolume(long volumeId);
+ void registerIso(long isoId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestratorImpl.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestratorImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestratorImpl.java
new file mode 100644
index 0000000..43c262d
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageOrchestratorImpl.java
@@ -0,0 +1,78 @@
+/*
+ * 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.storage.image;
+
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotProfile;
+import org.apache.cloudstack.platform.subsystem.api.storage.TemplateStrategy;
+import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile;
+import org.apache.cloudstack.storage.manager.SecondaryStorageManager;
+
+import com.cloud.storage.TemplateProfile;
+import com.cloud.storage.VMTemplateZoneVO;
+import com.cloud.storage.dao.VMTemplateZoneDao;
+import com.cloud.utils.component.Inject;
+
+public class ImageOrchestratorImpl implements ImageOrchestrator {
+ @Inject
+ SecondaryStorageManager _secStorageMgr;
+ @Inject
+ VMTemplateZoneDao _templateZoneDao;
+ public void registerTemplate(long templateId) {
+ List<VMTemplateZoneVO> tpZones = _templateZoneDao.listByTemplateId(templateId);
+
+ for (VMTemplateZoneVO tpZone : tpZones) {
+ DataStore imageStore = null;
+ List<DataStore> imageStores = _secStorageMgr.getImageStores(tpZone.getZoneId());
+ for (DataStore imgStore : imageStores) {
+ TemplateStrategy ts = imgStore.getTemplateStrategy();
+ if (ts.canRegister(templateId)) {
+ imageStore = imgStore;
+ break;
+ }
+ }
+
+ if (imageStore == null) {
+ continue;
+ }
+
+ TemplateStrategy ts = imageStore.getTemplateStrategy();
+ ts.register(ts.get(templateId));
+ }
+ }
+
+ public void registerSnapshot(long snapshotId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void registerVolume(long volumeId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void registerIso(long isoId) {
+ // TODO Auto-generated method stub
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java b/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java
new file mode 100644
index 0000000..d31935e
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java
@@ -0,0 +1,54 @@
+/*
+ * 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.storage.lifecycle;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
+
+public class DefaultNfsSecondaryLifeCycle implements DataStoreLifeCycle {
+ protected DataStore _ds;
+ public DefaultNfsSecondaryLifeCycle(DataStore ds) {
+ _ds = ds;
+ }
+ public void add() {
+ // 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
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java b/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java
index 2a80a96..cc9136e 100644
--- a/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java
+++ b/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java
@@ -18,6 +18,8 @@
*/
package org.apache.cloudstack.storage.manager;
+import java.util.List;
+
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
import com.cloud.storage.Snapshot;
@@ -27,5 +29,6 @@ import com.cloud.template.VirtualMachineTemplate;
public interface SecondaryStorageManager {
DataStore getStore(Volume volume);
DataStore getImageStore(DataStore destStore);
+ List<DataStore> getImageStores(long zoneId);
DataStore getStore(Snapshot snapshot);
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java
index 8694290..587f5d4 100644
--- a/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java
+++ b/platform/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java
@@ -18,6 +18,34 @@
*/
package org.apache.cloudstack.storage.manager;
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Volume;
+import com.cloud.storage.dao.VMTemplateZoneDao;
+import com.cloud.utils.component.Inject;
+
public class SecondaryStorageManagerImpl implements SecondaryStorageManager {
+ public DataStore getStore(Volume volume) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getImageStore(DataStore destStore) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<DataStore> getImageStores() {
+
+ return null;
+ }
+
+ public DataStore getStore(Snapshot snapshot) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManager.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManager.java b/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManager.java
deleted file mode 100644
index 916d795..0000000
--- a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManager.java
+++ /dev/null
@@ -1,33 +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.storage.manager;
-
-import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotProfile;
-import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile;
-import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile;
-
-import com.cloud.storage.Snapshot;
-import com.cloud.storage.Volume;
-import com.cloud.template.VirtualMachineTemplate;
-
-public interface TemplateManager {
- TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds);
- TemplateProfile getProfile(long templateId);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManagerImpl.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManagerImpl.java
deleted file mode 100644
index ba9cf0f..0000000
--- a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManagerImpl.java
+++ /dev/null
@@ -1,91 +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.storage.manager;
-
-import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile;
-import org.apache.log4j.Logger;
-
-import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateStoragePoolVO;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.dao.VMTemplatePoolDao;
-import com.cloud.template.VirtualMachineTemplate;
-import com.cloud.utils.component.Inject;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-public class TemplateManagerImpl implements TemplateManager {
- private static final Logger s_logger = Logger.getLogger(TemplateManagerImpl.class);
- @Inject
- VMTemplateDao _templateDao;
- @Inject
- VMTemplatePoolDao _templatePoolDao;
-
- public boolean contains(VirtualMachineTemplate template, DataStore ds) {
- long templateId = template.getId();
- long poolId = ds.getId();
- VMTemplateStoragePoolVO templateStoragePoolRef = null;
- templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
- return templateStoragePoolRef == null ? false : true;
- }
-
- public TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds) {
- long templateId = tp.getId();
- long poolId = ds.getId();
- VMTemplateStoragePoolVO templateStoragePoolRef = null;
- long templateStoragePoolRefId;
-
- templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
- if (templateStoragePoolRef != null) {
- templateStoragePoolRef.setMarkedForGC(false);
- _templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
-
- if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) {
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId);
- }
-
- tp.setLocalPath(templateStoragePoolRef.getInstallPath());
- tp.setTemplatePoolRefId(templateStoragePoolRef.getId());
- return tp;
- }
- }
-
- if (templateStoragePoolRef == null) {
- templateStoragePoolRef = new VMTemplateStoragePoolVO(poolId, templateId);
- try {
- templateStoragePoolRef = _templatePoolDao.persist(templateStoragePoolRef);
- templateStoragePoolRefId = templateStoragePoolRef.getId();
- } catch (Exception e) {
- s_logger.debug("Assuming we're in a race condition: " + e.getMessage());
- templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId);
- if (templateStoragePoolRef == null) {
- throw new CloudRuntimeException("Unable to persist a reference for pool " + poolId + " and template " + templateId);
- }
- templateStoragePoolRefId = templateStoragePoolRef.getId();
- }
- } else {
- templateStoragePoolRefId = templateStoragePoolRef.getId();
- }
- tp.setTemplatePoolRefId(templateStoragePoolRefId);
- return tp;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java b/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java
new file mode 100644
index 0000000..484b485
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java
@@ -0,0 +1,131 @@
+/*
+ * 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.storage.provider;
+
+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 java.util.Set;
+
+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.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+import org.apache.cloudstack.storage.datastoreconfigurator.NfsSecondaryStorageConfigurator;
+import org.apache.cloudstack.storage.datastoreconfigurator.XenNfsDataStoreConfigurator;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class DefaultNfsSecondaryStorageProvider implements StorageProvider {
+ private String _name = DefaultPrimaryStorageProvider.class.toString();
+ protected Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols;
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
+ DataStoreConfigurator nfsdc = new NfsSecondaryStorageConfigurator();
+ dscs.put(nfsdc.getProtocol(), nfsdc);
+
+ _supportedProtocols.put(HypervisorType.XenServer, dscs);
+ _supportedProtocols.put(HypervisorType.KVM, dscs);
+ _supportedProtocols.put(HypervisorType.VMware, dscs);
+ _supportedProtocols.put(HypervisorType.Ovm, dscs);
+ return true;
+ }
+
+ 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 List<HypervisorType> supportedHypervisors() {
+ List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
+ Set<HypervisorType> hyps = _supportedProtocols.keySet();
+
+ for (HypervisorType hy : hyps) {
+ hypervisors.add(hy);
+ }
+
+ return hypervisors;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, 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");
+ }
+
+ DataStoreConfigurator dscf = _supportedProtocols.get(HypervisorType.XenServer).get(protocol);
+ Map<String, String> configs = dscf.getConfigs(uri, params);
+ dscf.validate(configs);
+ DataStore ds = dscf.getDataStore(sp);
+ return ds;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ List<StoreType> types = new ArrayList<StoreType>();
+ types.add(StoreType.Image);
+ types.add(StoreType.Backup);
+ return types;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java b/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java
new file mode 100644
index 0000000..a416fa4
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java
@@ -0,0 +1,139 @@
+package org.apache.cloudstack.storage.provider;
+
+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 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;
+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 ClusterDao _clusterDao;
+
+ 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 List<StoreType> supportedStoreType() {
+ List<StoreType> type = new ArrayList<StoreType>();
+ type.add(StoreType.Primary);
+ return type;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ 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);
+ }
+
+ 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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java b/platform/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java
new file mode 100644
index 0000000..c98320b
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java
@@ -0,0 +1,91 @@
+/*
+ * 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.storage.provider;
+
+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.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class HttpImageStoreProvider implements StorageProvider {
+
+ 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 List<HypervisorType> supportedHypervisors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java b/platform/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java
new file mode 100644
index 0000000..d5c15b3
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java
@@ -0,0 +1,91 @@
+/*
+ * 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.storage.provider;
+
+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.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class S3SecondaryStorageProvider implements StorageProvider {
+
+ 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 List<HypervisorType> supportedHypervisors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java b/platform/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java
new file mode 100644
index 0000000..75bf74c
--- /dev/null
+++ b/platform/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java
@@ -0,0 +1,91 @@
+/*
+ * 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.storage.provider;
+
+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.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class SwiftSecondaryStorageProvider implements StorageProvider {
+
+ 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 List<HypervisorType> supportedHypervisors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/platform/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java
----------------------------------------------------------------------
diff --git a/platform/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java b/platform/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java
index e5701a1..d3867fc 100644
--- a/platform/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java
+++ b/platform/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java
@@ -19,6 +19,7 @@
package org.apache.cloudstack.storage.strategy;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
@@ -26,13 +27,21 @@ import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPointSelector;
import org.apache.cloudstack.platform.subsystem.api.storage.StorageEvent;
-import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
import org.apache.cloudstack.platform.subsystem.api.storage.TemplateStrategy;
-import org.apache.cloudstack.storage.manager.TemplateManager;
+import org.apache.cloudstack.storage.image.ImageManager;
import org.apache.log4j.Logger;
+import com.cloud.agent.api.storage.DownloadCommand.Proxy;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.TemplateProfile;
+import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStoragePoolVO;
+import com.cloud.storage.VMTemplateStorageResourceAssoc;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.dao.VMTemplatePoolDao;
import com.cloud.utils.component.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
@@ -47,7 +56,13 @@ public class DefaultTemplateStratey implements TemplateStrategy {
@Inject
VMTemplatePoolDao _templatePoolDao;
@Inject
- TemplateManager _templateMgr;
+ VMTemplateHostDao _templateImageStoreDao;
+ @Inject
+ ImageManager _templateMgr;
+
+ public DefaultTemplateStratey(DataStore ds) {
+ _ds = ds;
+ }
public TemplateProfile get(long templateId) {
return _templateMgr.getProfile(templateId);
@@ -71,17 +86,17 @@ public class DefaultTemplateStratey implements TemplateStrategy {
tp = _driver.install(tp, ep);
templateStoragePoolRef.setDownloadPercent(100);
templateStoragePoolRef.setDownloadState(Status.DOWNLOADED);
- templateStoragePoolRef.setLocalDownloadPath(tp.getInstallPath());
- templateStoragePoolRef.setInstallPath(tp.getInstallPath());
- templateStoragePoolRef.setTemplateSize(tp.getTemplateSize());
+ templateStoragePoolRef.setLocalDownloadPath(tp.getLocalPath());
+ templateStoragePoolRef.setInstallPath(tp.getLocalPath());
+ templateStoragePoolRef.setTemplateSize(tp.getSize());
_templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Template " + tp.getId() + " is installed via " + ep.getHostId());
+ s_logger.debug("Template " + tp.getTemplateId() + " is installed via " + ep.getHostId());
}
- return get(tp.getId());
+ return get(tp.getTemplateId());
} catch (CloudRuntimeException e) {
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Template " + tp.getId() + " download to pool " + _ds.getId() + " failed due to " + e.toString());
+ s_logger.debug("Template " + tp.getTemplateId() + " download to pool " + _ds.getId() + " failed due to " + e.toString());
}
}
}
@@ -90,8 +105,86 @@ public class DefaultTemplateStratey implements TemplateStrategy {
}
if (s_logger.isDebugEnabled()) {
- s_logger.debug("Template " + tp.getId() + " is not found on and can not be downloaded to pool " + _ds.getId());
+ s_logger.debug("Template " + tp.getTemplateId() + " is not found on and can not be downloaded to pool " + _ds.getId());
+ }
+ return null;
+ }
+
+ public TemplateProfile register(TemplateProfile tp) {
+
+ VMTemplateHostVO vmTemplateHost = _templateImageStoreDao.findByHostTemplate(_ds.getId(), tp.getTemplateId());
+ if (vmTemplateHost == null) {
+ vmTemplateHost = new VMTemplateHostVO(_ds.getId(), tp.getTemplateId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, tp.getUrl());
+ _templateImageStoreDao.persist(vmTemplateHost);
}
+
+ DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
+ List<DataStoreEndPoint> eps = dseps.getEndPoints(StorageEvent.RegisterTemplate);
+
+ Collections.shuffle(eps);
+ DataStoreEndPoint ep = eps.get(0);
+ _driver.register(tp, ep);
+
+ return null;
+ }
+
+ protected boolean checkHypervisor(HypervisorType hypervisor) {
+ StorageProvider sp = _ds.getProvider();
+ List<HypervisorType> spHys = sp.supportedHypervisors();
+ boolean checkHypervisor = false;
+ for (HypervisorType hy : spHys) {
+ if (hy == hypervisor) {
+ checkHypervisor = true;
+ }
+ }
+ return checkHypervisor;
+ }
+
+ protected boolean checkFormat(String url, String format) {
+ if ((!url.toLowerCase().endsWith("vhd")) && (!url.toLowerCase().endsWith("vhd.zip")) && (!url.toLowerCase().endsWith("vhd.bz2")) && (!url.toLowerCase().endsWith("vhd.gz"))
+ && (!url.toLowerCase().endsWith("qcow2")) && (!url.toLowerCase().endsWith("qcow2.zip")) && (!url.toLowerCase().endsWith("qcow2.bz2")) && (!url.toLowerCase().endsWith("qcow2.gz"))
+ && (!url.toLowerCase().endsWith("ova")) && (!url.toLowerCase().endsWith("ova.zip")) && (!url.toLowerCase().endsWith("ova.bz2")) && (!url.toLowerCase().endsWith("ova.gz"))
+ && (!url.toLowerCase().endsWith("img")) && (!url.toLowerCase().endsWith("raw"))) {
+ throw new InvalidParameterValueException("Please specify a valid " + format.toLowerCase());
+ }
+
+ if ((format.equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith(
+ "vhd.gz")))
+ || (format.equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url
+ .toLowerCase().endsWith("qcow2.gz")))
+ || (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase()
+ .endsWith("ova.gz"))) || (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
+ throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + format.toLowerCase());
+ }
+ return true;
+ }
+
+ public boolean canRegister(long templateId) {
+ TemplateProfile tp = get(templateId);
+
+ if (!checkHypervisor(tp.getHypervisorType())) {
+ return false;
+ }
+
+ if (!checkFormat(tp.getUrl(), tp.getFormat().toString())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int getDownloadWait() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getMaxTemplateSizeInBytes() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Proxy getHttpProxy() {
+ // TODO Auto-generated method stub
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java b/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
index e03cdda..f11c495 100755
--- a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
+++ b/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
@@ -37,11 +37,11 @@ import com.cloud.host.dao.HostDao;
import com.cloud.resource.ResourceManager;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.TemplateProfile;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VMTemplateZoneVO;
import com.cloud.template.TemplateAdapter;
import com.cloud.template.TemplateAdapterBase;
-import com.cloud.template.TemplateProfile;
import com.cloud.user.Account;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
@@ -131,7 +131,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements Tem
@Override @DB
public boolean delete(TemplateProfile profile) {
- VMTemplateVO template = profile.getTemplate();
+ VMTemplateVO template = (VMTemplateVO)profile.getTemplate();
Long templateId = template.getId();
boolean success = true;
String zoneName;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
index 3972728..c808113 100755
--- a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
+++ b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
@@ -66,11 +66,11 @@ import com.cloud.resource.ResourceManager;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.storage.Storage;
import com.cloud.storage.Storage.TemplateType;
+import com.cloud.storage.TemplateProfile;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume;
import com.cloud.template.TemplateAdapter;
import com.cloud.template.TemplateAdapter.TemplateAdapterType;
-import com.cloud.template.TemplateProfile;
import com.cloud.user.Account;
import com.cloud.user.AccountVO;
import com.cloud.user.SSHKeyPair;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/server/src/com/cloud/template/HyervisorTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/HyervisorTemplateAdapter.java b/server/src/com/cloud/template/HyervisorTemplateAdapter.java
index bdb89f6..b5af45b 100755
--- a/server/src/com/cloud/template/HyervisorTemplateAdapter.java
+++ b/server/src/com/cloud/template/HyervisorTemplateAdapter.java
@@ -45,6 +45,7 @@ import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.TemplateType;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.TemplateProfile;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.VMTemplateZoneVO;
import com.cloud.storage.download.DownloadMonitor;
@@ -150,7 +151,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
public boolean delete(TemplateProfile profile) {
boolean success = true;
- VMTemplateVO template = profile.getTemplate();
+ VMTemplateVO template = (VMTemplateVO)profile.getTemplate();
Long zoneId = profile.getZoneId();
Long templateId = template.getId();
@@ -267,7 +268,7 @@ public class HyervisorTemplateAdapter extends TemplateAdapterBase implements Tem
public TemplateProfile prepareDelete(DeleteTemplateCmd cmd) {
TemplateProfile profile = super.prepareDelete(cmd);
- VMTemplateVO template = profile.getTemplate();
+ VMTemplateVO template = (VMTemplateVO)profile.getTemplate();
Long zoneId = profile.getZoneId();
if (template.getTemplateType() == TemplateType.SYSTEM) {
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/server/src/com/cloud/template/TemplateAdapter.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateAdapter.java b/server/src/com/cloud/template/TemplateAdapter.java
index 26e10ee..0a1293b 100755
--- a/server/src/com/cloud/template/TemplateAdapter.java
+++ b/server/src/com/cloud/template/TemplateAdapter.java
@@ -24,6 +24,7 @@ import com.cloud.api.commands.RegisterIsoCmd;
import com.cloud.api.commands.RegisterTemplateCmd;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.TemplateProfile;
import com.cloud.storage.VMTemplateVO;
import com.cloud.user.Account;
import com.cloud.utils.component.Adapter;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/73cc4741/server/src/com/cloud/template/TemplateAdapterBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java
index 4a379b1..bd1a909 100755
--- a/server/src/com/cloud/template/TemplateAdapterBase.java
+++ b/server/src/com/cloud/template/TemplateAdapterBase.java
@@ -42,6 +42,7 @@ import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.org.Grouping;
import com.cloud.storage.GuestOS;
+import com.cloud.storage.TemplateProfile;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.TemplateType;
import com.cloud.storage.VMTemplateVO;