mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
add image skeleton
This commit is contained in:
parent
6dd2318b44
commit
17c82b7270
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 class ImageMotionServiceImpl implements ImageMotionService {
|
||||
|
||||
@Override
|
||||
public boolean copyTemplate(String templateUri, String destTemplateUri) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean copyIso(String isoUri, String destIsoUri) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,15 +22,16 @@ import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
|
||||
import org.apache.cloudstack.storage.image.manager.ImageDataStoreManager;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public class ImageServiceImpl implements ImageService {
|
||||
|
||||
@Inject
|
||||
ImageDataStoreManager imageStoreMgr;
|
||||
ImageDataStoreProviderManager imageStoreProviderMgr;
|
||||
@Override
|
||||
public boolean registerTemplate(long templateId, long imageStoreId) {
|
||||
ImageDataStore ids = imageStoreMgr.getImageDataStore(imageStoreId);
|
||||
ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId);
|
||||
Template template = ids.registerTemplate(templateId);
|
||||
if (ids.needDownloadToCacheStorage()) {
|
||||
ImageDownloader imageDl = ids.getImageDownloader();
|
||||
@ -59,8 +60,8 @@ public class ImageServiceImpl implements ImageService {
|
||||
|
||||
@Override
|
||||
public String grantTemplateAccess(long templateId, long endpointId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
ImageDataStore ids = imageStoreProviderMgr.getDataStoreFromTemplateId(templateId);
|
||||
return ids.grantAccess(templateId, endpointId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -32,5 +32,13 @@ public class Template {
|
||||
public ImageDataStore getImageDataStore() {
|
||||
return this.dataStore;
|
||||
}
|
||||
|
||||
public void setImageDataStoreId(long dataStoreId) {
|
||||
imageVO.setImageDataStoreId(dataStoreId);
|
||||
}
|
||||
|
||||
public long getImageDataStoreId() {
|
||||
return imageVO.getImageDataStoreId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +20,6 @@ package org.apache.cloudstack.storage.image.db;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDaoStoreDao {
|
||||
public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDataStoreDao {
|
||||
|
||||
}
|
||||
|
||||
@ -20,6 +20,6 @@ package org.apache.cloudstack.storage.image.db;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface ImageDaoStoreDao extends GenericDao<ImageDataStoreVO, Long> {
|
||||
public interface ImageDataStoreDao extends GenericDao<ImageDataStoreVO, Long> {
|
||||
|
||||
}
|
||||
@ -18,6 +18,32 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.db;
|
||||
|
||||
public interface ImageDataStoreProviderVO {
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
@Entity
|
||||
@Table(name="image_data_store_provider")
|
||||
public class ImageDataStoreProviderVO {
|
||||
@Id
|
||||
@TableGenerator(name="image_data_store_provider_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="image_data_store_provider_seq", allocationSize=1)
|
||||
@Column(name="id", nullable = false)
|
||||
private long id;
|
||||
|
||||
@Column(name="name", nullable = false)
|
||||
private String name;
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,6 +129,9 @@ public class ImageDataVO implements Identity {
|
||||
@Column(name="enable_sshkey")
|
||||
private boolean enableSshKey;
|
||||
|
||||
@Column(name="image_data_store_id")
|
||||
private long imageDataStoreId;
|
||||
|
||||
@Transient
|
||||
Map details;
|
||||
|
||||
@ -377,5 +380,13 @@ public class ImageDataVO implements Identity {
|
||||
public void setEnableSshKey(boolean enable) {
|
||||
enableSshKey = enable;
|
||||
}
|
||||
|
||||
public long getImageDataStoreId() {
|
||||
return this.imageDataStoreId;
|
||||
}
|
||||
|
||||
public void setImageDataStoreId(long dataStoreId) {
|
||||
this.imageDataStoreId = dataStoreId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,7 +21,9 @@ package org.apache.cloudstack.storage.image.driver;
|
||||
import org.apache.cloudstack.storage.image.Template;
|
||||
|
||||
public class ImageDataStoreDriverImpl implements ImageDataStoreDriver {
|
||||
|
||||
|
||||
public ImageDataStoreDriverImpl() {
|
||||
}
|
||||
@Override
|
||||
public boolean registerTemplate(Template template) {
|
||||
//TODO: check the availability of template
|
||||
|
||||
@ -21,14 +21,14 @@ package org.apache.cloudstack.storage.image.manager;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDaoStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public class ImageDataStoreManagerImpl implements ImageDataStoreManager {
|
||||
@Inject
|
||||
ImageDaoStoreDao dataStoreDao;
|
||||
ImageDataStoreDao dataStoreDao;
|
||||
@Inject
|
||||
ImageDataDao imageDataDao;
|
||||
@Override
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.provider;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreImpl;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
|
||||
private final String providerName = "DefaultProvider";
|
||||
@Inject
|
||||
ImageDataStoreProviderDao providerDao;
|
||||
@Inject
|
||||
ImageDataStoreDao imageStoreDao;
|
||||
|
||||
@Override
|
||||
public ImageDataStore getImageDataStore(long imageStoreId) {
|
||||
ImageDataStoreVO idsv = imageStoreDao.findById(imageStoreId);
|
||||
ImageDataStoreDriver driver = new ImageDataStoreDriverImpl();
|
||||
ImageDataStore ids = new ImageDataStoreImpl(idsv, driver, false, null);
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,4 +22,5 @@ import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public interface ImageDataStoreProvider {
|
||||
ImageDataStore getImageDataStore(long imageStoreId);
|
||||
public String getName();
|
||||
}
|
||||
|
||||
@ -18,6 +18,10 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.provider;
|
||||
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public interface ImageDataStoreProviderManager {
|
||||
public ImageDataStoreProvider getProvider(long providerId);
|
||||
public ImageDataStore getDataStore(long dataStoreId);
|
||||
public ImageDataStore getDataStoreFromTemplateId(long templateId);
|
||||
}
|
||||
|
||||
@ -18,20 +18,56 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
@Component
|
||||
public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProviderManager {
|
||||
|
||||
@Inject
|
||||
ImageDataStoreProviderDao providerDao;
|
||||
@Inject
|
||||
ImageDataStoreDao dataStoreDao;
|
||||
@Inject
|
||||
ImageDataDao imageDataDao;
|
||||
@Inject
|
||||
List<ImageDataStoreProvider> providers;
|
||||
@Override
|
||||
public ImageDataStoreProvider getProvider(long providerId) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ImageDataStoreProvider getProvider(String name) {
|
||||
for (ImageDataStoreProvider provider : providers) {
|
||||
if (provider.getName().equalsIgnoreCase(name)) {
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStore getDataStore(long dataStoreId) {
|
||||
ImageDataStoreVO idsv = dataStoreDao.findById(dataStoreId);
|
||||
long providerId = idsv.getProvider();
|
||||
ImageDataStoreProviderVO idspv = providerDao.findById(providerId);
|
||||
ImageDataStoreProvider provider = getProvider(idspv.getName());
|
||||
return provider.getImageDataStore(dataStoreId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ImageDataStore getDataStoreFromTemplateId(long templateId) {
|
||||
ImageDataVO iddv = imageDataDao.findById(templateId);
|
||||
return getDataStore(iddv.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@ import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.Template;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
|
||||
@ -31,13 +33,15 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
ImageDataDao imageDao;
|
||||
ImageDataStoreDriver driver;
|
||||
ImageDownloader downloader;
|
||||
ImageDataStoreVO imageDataStoreVO;
|
||||
boolean needDownloadToCacheStorage = false;
|
||||
|
||||
|
||||
public ImageDataStoreImpl(ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) {
|
||||
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) {
|
||||
this.driver = driver;
|
||||
this.needDownloadToCacheStorage = needDownloadToCacheStorage;
|
||||
this.downloader = downloader;
|
||||
this.imageDataStoreVO = dataStoreVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -45,6 +49,7 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
ImageDataVO idv = imageDao.findById(templateId);
|
||||
Template template = new Template(this, idv);
|
||||
if (driver.registerTemplate(template)) {
|
||||
template.setImageDataStoreId(imageDataStoreVO.getId());
|
||||
return template;
|
||||
} else {
|
||||
return null;
|
||||
@ -53,8 +58,8 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
|
||||
@Override
|
||||
public String grantAccess(long templateId, long endPointId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
ImageDataVO idv = imageDao.findById(templateId);
|
||||
return idv.getUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user