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 20a16e587df..d18c7a389dd 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); 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 61ff9675d70..400d8834bf3 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); 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 7ff4a76208e..34cfb2a50ae 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; } 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 95391c30826..7bc7e30ebd1 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 supportedHypervisors(); String getProviderName(); - StoreType supportedStoreType(); + List supportedStoreTypes(); void configure(Map storeProviderInfo); DataStore addDataStore(StoragePool sp, String uri, Map params); DataStore getDataStore(StoragePool pool); 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 39da9d3753b..00000000000 --- 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; - } -} 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 a76f17d5dcc..00daf0cb860 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(); } diff --git a/platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java b/platform/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java index e53cb0bbb74..00e6eaee036 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); 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 00000000000..a69b6a6f56c --- /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 configs) { + // TODO Auto-generated method stub + return null; + } + +} 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 10b39c05a6e..125874e873e 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); 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 00000000000..69839782a59 --- /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; + } + +} 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 00000000000..b9de406dc20 --- /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 getEndPoints(StorageEvent event) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManager.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManager.java similarity index 70% rename from platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManager.java rename to platform/storage/src/org/apache/cloudstack/storage/image/ImageManager.java index 916d795f26e..29845a1560b 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManager.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManager.java @@ -16,18 +16,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cloudstack.storage.manager; +package org.apache.cloudstack.storage.image; 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 { +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); } diff --git a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java similarity index 51% rename from platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManagerImpl.java rename to platform/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java index ba9cf0ffdea..83f331f9896 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/manager/TemplateManagerImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java @@ -16,12 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cloudstack.storage.manager; +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.TemplateProfile; 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; @@ -29,15 +36,18 @@ 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 TemplateManagerImpl implements TemplateManager { - private static final Logger s_logger = Logger.getLogger(TemplateManagerImpl.class); +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(); @@ -48,7 +58,7 @@ public class TemplateManagerImpl implements TemplateManager { } public TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds) { - long templateId = tp.getId(); + long templateId = tp.getTemplateId(); long poolId = ds.getId(); VMTemplateStoragePoolVO templateStoragePoolRef = null; long templateStoragePoolRefId; @@ -88,4 +98,70 @@ public class TemplateManagerImpl implements TemplateManager { 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 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 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); + } } 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 00000000000..f759d6b130f --- /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); +} 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 00000000000..43c262da227 --- /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 tpZones = _templateZoneDao.listByTemplateId(templateId); + + for (VMTemplateZoneVO tpZone : tpZones) { + DataStore imageStore = null; + List 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 + + } + + +} 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 00000000000..d31935e1a47 --- /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 + + } + +} 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 2a80a963a87..cc9136e5fd1 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 getImageStores(long zoneId); DataStore getStore(Snapshot snapshot); } 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 86942905270..587f5d4867d 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 getImageStores() { + + return null; + } + + public DataStore getStore(Snapshot snapshot) { + // TODO Auto-generated method stub + return null; + } } 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 00000000000..484b4851062 --- /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> _supportedProtocols; + public boolean configure(String name, Map params) throws ConfigurationException { + Map dscs = new HashMap(); + 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 supportedHypervisors() { + List hypervisors = new ArrayList(); + Set 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 storeProviderInfo) { + // TODO Auto-generated method stub + + } + + public DataStore addDataStore(StoragePool sp, String url, Map 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 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> getDataStoreConfigs() { + // TODO Auto-generated method stub + return null; + } + + public List supportedStoreTypes() { + List types = new ArrayList(); + types.add(StoreType.Image); + types.add(StoreType.Backup); + return types; + } + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/DefaultPrimaryStorageProvider.java b/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java similarity index 95% rename from platform/storage/src/org/apache/cloudstack/storage/DefaultPrimaryStorageProvider.java rename to platform/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java index ea2dfe35458..a416fa49c0f 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/DefaultPrimaryStorageProvider.java +++ b/platform/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java @@ -1,4 +1,4 @@ -package org.apache.cloudstack.storage; +package org.apache.cloudstack.storage.provider; import java.net.URI; import java.net.URISyntaxException; @@ -51,8 +51,10 @@ public class DefaultPrimaryStorageProvider implements StorageProvider { _supportedProtocols.put(HypervisorType.XenServer, dscs); } - public StoreType supportedStoreType() { - return StoreType.Primary; + public List supportedStoreType() { + List type = new ArrayList(); + type.add(StoreType.Primary); + return type; } public void configure(Map storeProviderInfo) { 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 00000000000..c98320ba300 --- /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 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 supportedHypervisors() { + // TODO Auto-generated method stub + return null; + } + + public String getProviderName() { + // TODO Auto-generated method stub + return null; + } + + public List supportedStoreTypes() { + // TODO Auto-generated method stub + return null; + } + + public void configure(Map storeProviderInfo) { + // TODO Auto-generated method stub + + } + + public DataStore addDataStore(StoragePool sp, String uri, Map params) { + // TODO Auto-generated method stub + return null; + } + + public DataStore getDataStore(StoragePool pool) { + // TODO Auto-generated method stub + return null; + } + + public Map> getDataStoreConfigs() { + // TODO Auto-generated method stub + return null; + } + +} 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 00000000000..d5c15b3ccb6 --- /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 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 supportedHypervisors() { + // TODO Auto-generated method stub + return null; + } + + public String getProviderName() { + // TODO Auto-generated method stub + return null; + } + + public List supportedStoreTypes() { + // TODO Auto-generated method stub + return null; + } + + public void configure(Map storeProviderInfo) { + // TODO Auto-generated method stub + + } + + public DataStore addDataStore(StoragePool sp, String uri, Map params) { + // TODO Auto-generated method stub + return null; + } + + public DataStore getDataStore(StoragePool pool) { + // TODO Auto-generated method stub + return null; + } + + public Map> getDataStoreConfigs() { + // TODO Auto-generated method stub + return null; + } + +} 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 00000000000..75bf74c02ae --- /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 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 supportedHypervisors() { + // TODO Auto-generated method stub + return null; + } + + public String getProviderName() { + // TODO Auto-generated method stub + return null; + } + + public List supportedStoreTypes() { + // TODO Auto-generated method stub + return null; + } + + public void configure(Map storeProviderInfo) { + // TODO Auto-generated method stub + + } + + public DataStore addDataStore(StoragePool sp, String uri, Map params) { + // TODO Auto-generated method stub + return null; + } + + public DataStore getDataStore(StoragePool pool) { + // TODO Auto-generated method stub + return null; + } + + public Map> getDataStoreConfigs() { + // TODO Auto-generated method stub + return null; + } + +} 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 e5701a1199d..d3867fcd87d 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,9 +105,87 @@ 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 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 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; + } + } diff --git a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java b/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java index e03cddabbcb..f11c49513f7 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; diff --git a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java index 3972728d5db..c8081138e24 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; diff --git a/server/src/com/cloud/template/HyervisorTemplateAdapter.java b/server/src/com/cloud/template/HyervisorTemplateAdapter.java index bdb89f65f80..b5af45b8103 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) { diff --git a/server/src/com/cloud/template/TemplateAdapter.java b/server/src/com/cloud/template/TemplateAdapter.java index 26e10ee7e77..0a1293bca20 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; diff --git a/server/src/com/cloud/template/TemplateAdapterBase.java b/server/src/com/cloud/template/TemplateAdapterBase.java index 4a379b1e808..bd1a9097f79 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; diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 1e87de2fecb..61b2b944441 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -94,6 +94,7 @@ import com.cloud.storage.StoragePool; import com.cloud.storage.StoragePoolHostVO; import com.cloud.storage.StoragePoolStatus; import com.cloud.storage.StoragePoolVO; +import com.cloud.storage.TemplateProfile; import com.cloud.storage.Upload; import com.cloud.storage.Upload.Type; import com.cloud.storage.UploadVO; diff --git a/server/src/com/cloud/template/TemplateProfile.java b/server/src/com/cloud/template/TemplateProfile.java deleted file mode 100755 index b050f40accb..00000000000 --- a/server/src/com/cloud/template/TemplateProfile.java +++ /dev/null @@ -1,255 +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 com.cloud.template; - -import java.util.Map; - -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.storage.Storage.ImageFormat; -import com.cloud.storage.VMTemplateVO; - -public class TemplateProfile { - Long userId; - String name; - String displayText; - Integer bits; - Boolean passwordEnabled; - Boolean sshKeyEnbaled; - Boolean requiresHvm; - String url; - Boolean isPublic; - Boolean featured; - Boolean isExtractable; - ImageFormat format; - Long guestOsId; - Long zoneId; - HypervisorType hypervisorType; - String accountName; - Long domainId; - Long accountId; - String chksum; - Boolean bootable; - Long templateId; - VMTemplateVO template; - String templateTag; - Map details; - - public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm, - String url, Boolean isPublic, Boolean featured, Boolean isExtractable, ImageFormat format, Long guestOsId, Long zoneId, - HypervisorType hypervisorType, String accountName, Long domainId, Long accountId, String chksum, Boolean bootable, Map details, Boolean sshKeyEnabled) { - this.templateId = templateId; - this.userId = userId; - this.name = name; - this.displayText = displayText; - this.bits = bits; - this.passwordEnabled = passwordEnabled; - this.requiresHvm = requiresHvm; - this.url = url; - this.isPublic = isPublic; - this.featured = featured; - this.isExtractable = isExtractable; - this.format = format; - this.guestOsId = guestOsId; - this.zoneId = zoneId; - this.hypervisorType = hypervisorType; - this.accountName = accountName; - this.domainId = domainId; - this.accountId = accountId; - this.chksum = chksum; - this.bootable = bootable; - this.details = details; - this.sshKeyEnbaled = sshKeyEnabled; - } - - public TemplateProfile(Long userId, VMTemplateVO template, Long zoneId) { - this.userId = userId; - this.template = template; - this.zoneId = zoneId; - } - - public TemplateProfile(Long templateId, Long userId, String name, String displayText, Integer bits, Boolean passwordEnabled, Boolean requiresHvm, - String url, Boolean isPublic, Boolean featured, Boolean isExtractable, ImageFormat format, Long guestOsId, Long zoneId, - HypervisorType hypervisorType, String accountName, Long domainId, Long accountId, String chksum, Boolean bootable, String templateTag, Map details, Boolean sshKeyEnabled) { - this(templateId, userId, name, displayText, bits, passwordEnabled, requiresHvm, url, isPublic, featured, isExtractable, format, guestOsId, zoneId, - hypervisorType, accountName, domainId, accountId, chksum, bootable, details, sshKeyEnabled); - this.templateTag = templateTag; - } - - public Long getTemplateId() { - return templateId; - } - public void setTemplateId(Long id) { - this.templateId = id; - } - - public Long getUserId() { - return userId; - } - public void setUserId(Long userId) { - this.userId = userId; - } - - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - public String getDisplayText() { - return displayText; - } - public void setDisplayText(String text) { - this.displayText = text; - } - - public Integer getBits() { - return bits; - } - public void setBits(Integer bits) { - this.bits = bits; - } - - public Boolean getPasswordEnabled() { - return passwordEnabled; - } - public void setPasswordEnabled(Boolean enabled) { - this.passwordEnabled = enabled; - } - - public Boolean getRequiresHVM() { - return requiresHvm; - } - public void setRequiresHVM(Boolean hvm) { - this.requiresHvm = hvm; - } - - public String getUrl() { - return url; - } - public void setUrl(String url) { - this.url = url; - } - - public Boolean getIsPublic() { - return isPublic; - } - public void setIsPublic(Boolean is) { - this.isPublic = is; - } - - public Boolean getFeatured() { - return featured; - } - public void setFeatured(Boolean featured) { - this.featured = featured; - } - - public Boolean getIsExtractable() { - return isExtractable; - } - public void setIsExtractable(Boolean is) { - this.isExtractable = is; - } - - public ImageFormat getFormat() { - return format; - } - public void setFormat(ImageFormat format) { - this.format = format; - } - - public Long getGuestOsId() { - return guestOsId; - } - public void setGuestOsId(Long id) { - this.guestOsId = id; - } - - public Long getZoneId() { - return zoneId; - } - public void setZoneId(Long id) { - this.zoneId = id; - } - - public HypervisorType getHypervisorType() { - return hypervisorType; - } - public void setHypervisorType(HypervisorType type) { - this.hypervisorType = type; - } - - public Long getDomainId() { - return domainId; - } - public void setDomainId(Long id) { - this.domainId = id; - } - - public Long getAccountId() { - return accountId; - } - public void setAccountId(Long id) { - this.accountId = id; - } - - public String getCheckSum() { - return chksum; - } - public void setCheckSum(String chksum) { - this.chksum = chksum; - } - - public Boolean getBootable() { - return this.bootable; - } - public void setBootable(Boolean bootable) { - this.bootable = bootable; - } - - public VMTemplateVO getTemplate() { - return template; - } - public void setTemplate(VMTemplateVO template) { - this.template = template; - } - - public String getTemplateTag() { - return templateTag; - } - - public void setTemplateTag(String templateTag) { - this.templateTag = templateTag; - } - - public Map getDetails() { - return this.details; - } - - public void setDetails(Map details) { - this.details = details; - } - - public void setSshKeyEnabled(Boolean enabled) { - this.sshKeyEnbaled = enabled; - } - - public Boolean getSshKeyEnabled() { - return this.sshKeyEnbaled; - } -}