From 7c9e30a6ea2de0880cebec401f5e28799d77c2a8 Mon Sep 17 00:00:00 2001 From: Edison Su Date: Fri, 2 Nov 2012 17:44:28 -0700 Subject: [PATCH] add more files --- .../storage/image/ImageService.java | 2 +- .../storage/image/ImageServiceImpl.java | 19 +++++- .../cloudstack/storage/image/Template.java | 7 +++ .../storage/image/db/ImageDaoStoreDao.java | 25 ++++++++ .../image/db/ImageDaoStoreDaoImpl.java | 25 ++++++++ .../image/db/ImageDataStoreProviderDao.java | 25 ++++++++ .../db/ImageDataStoreProviderDaoImpl.java | 26 ++++++++ .../image/db/ImageDataStoreProviderVO.java} | 4 +- .../storage/image/db/ImageDataStoreVO.java | 60 +++++++++++++++++++ .../image/downloader/ImageDownloader.java | 25 ++++++++ .../driver/ImageDataStoreDriverImpl.java | 4 +- .../manager/ImageDataStoreManagerImpl.java | 12 +++- .../ImageDataStoreProviderManager.java | 23 +++++++ .../ImageDataStoreProviderManagerImpl.java | 37 ++++++++++++ .../storage/image/store/ImageDataStore.java | 3 + .../image/store/ImageDataStoreImpl.java | 40 ++++++++++++- 16 files changed, 325 insertions(+), 12 deletions(-) create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDao.java create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDaoImpl.java rename platform/{api/src/org/apache/cloudstack/platform/subsystem/api/storage/Template.java => storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java} (88%) create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java create mode 100644 platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/ImageService.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageService.java index 3ff020e0a66..ebdc594f151 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/image/ImageService.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageService.java @@ -19,7 +19,7 @@ package org.apache.cloudstack.storage.image; public interface ImageService { - long registerTemplate(String templateUrl, long accountId); + boolean registerTemplate(long templateId, long imageStoreId); boolean deleteTemplate(long templateId); long registerIso(String isoUrl, long accountId); boolean deleteIso(long isoId); diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java index 119a25549eb..68491922f3a 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java @@ -18,12 +18,25 @@ */ package org.apache.cloudstack.storage.image; +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.store.ImageDataStore; + public class ImageServiceImpl implements ImageService { + @Inject + ImageDataStoreManager imageStoreMgr; @Override - public long registerTemplate(String templateUrl, long accountId) { - // TODO Auto-generated method stub - return 0; + public boolean registerTemplate(long templateId, long imageStoreId) { + ImageDataStore ids = imageStoreMgr.getImageDataStore(imageStoreId); + Template template = ids.registerTemplate(templateId); + if (ids.needDownloadToCacheStorage()) { + ImageDownloader imageDl = ids.getImageDownloader(); + imageDl.downloadImage(template); + } + return true; } @Override diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/Template.java b/platform/storage/src/org/apache/cloudstack/storage/image/Template.java index 8191550daad..4fc6b53b305 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/image/Template.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/Template.java @@ -28,4 +28,11 @@ public class Template { this.dataStore = dataStore; this.imageVO = imageVO; } + + public ImageDataStore getImageDataStore() { + return this.dataStore; + } + + public String getTemplate + } diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDao.java b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDao.java new file mode 100644 index 00000000000..3e1a951e295 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDao.java @@ -0,0 +1,25 @@ +/* + * 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.db; + +import com.cloud.utils.db.GenericDao; + +public interface ImageDaoStoreDao extends GenericDao { + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java new file mode 100644 index 00000000000..01dd62ede43 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java @@ -0,0 +1,25 @@ +/* + * 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.db; + +import com.cloud.utils.db.GenericDaoBase; + +public class ImageDaoStoreDaoImpl extends GenericDaoBase implements ImageDaoStoreDao { + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java new file mode 100644 index 00000000000..466afa296f4 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java @@ -0,0 +1,25 @@ +/* + * 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.db; + +import com.cloud.utils.db.GenericDao; + +public interface ImageDataStoreProviderDao extends GenericDao { + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDaoImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDaoImpl.java new file mode 100644 index 00000000000..cb075bea1ee --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDaoImpl.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.db; + +import com.cloud.utils.db.GenericDaoBase; + + +public class ImageDataStoreProviderDaoImpl extends GenericDaoBase implements ImageDataStoreProviderDao { + +} diff --git a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/Template.java b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java similarity index 88% rename from platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/Template.java rename to platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java index efa7538abf4..b8ecdccaa81 100644 --- a/platform/api/src/org/apache/cloudstack/platform/subsystem/api/storage/Template.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.cloudstack.platform.subsystem.api.storage; +package org.apache.cloudstack.storage.image.db; -public interface Template extends DataObject { +public interface ImageDataStoreProviderVO { } diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java new file mode 100644 index 00000000000..7177203aa75 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java @@ -0,0 +1,60 @@ +/* + * 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.db; + +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") +public class ImageDataStoreVO { + @Id + @TableGenerator(name="image_data_store_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="image_data_store_seq", allocationSize=1) + @Column(name="id", nullable = false) + private long id; + + @Column(name="name", nullable = false) + private String name; + + @Column(name="image_provider", nullable = false) + private long provider; + + public long getId() { + return this.id; + } + + public String getName() { + return this.name; + } + + public long getProvider() { + return this.provider; + } + + public void setName(String name) { + this.name = name; + } + + public void setProvider(long provider) { + this.provider = provider; + } +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java b/platform/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java new file mode 100644 index 00000000000..123df61e48c --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java @@ -0,0 +1,25 @@ +/* + * 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.downloader; + +import org.apache.cloudstack.storage.image.Template; + +public interface ImageDownloader { + public void downloadImage(Template template); +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java index 55a8920770c..a88e6695e18 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java @@ -24,8 +24,8 @@ public class ImageDataStoreDriverImpl implements ImageDataStoreDriver { @Override public boolean registerTemplate(Template template) { - // TODO Auto-generated method stub - return false; + //TODO: check the availability of template + return true; } @Override diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java index 6f8a58f8a8a..3b09fcbe521 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java @@ -18,12 +18,22 @@ */ 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.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; + @Inject + ImageDataDao imageDataDao; @Override public ImageDataStore getImageDataStore(long dataStoreId) { + ImageDataStoreVO dataStore = dataStoreDao.findById(dataStoreId); // TODO Auto-generated method stub return null; } diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java b/platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java new file mode 100644 index 00000000000..1f9c956ce68 --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java @@ -0,0 +1,23 @@ +/* + * 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; + +public interface ImageDataStoreProviderManager { + public ImageDataStoreProvider getProvider(long providerId); +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java new file mode 100644 index 00000000000..0325311df5c --- /dev/null +++ b/platform/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java @@ -0,0 +1,37 @@ +/* + * 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.ImageDataStoreProviderDao; + + +public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProviderManager { + + @Inject + ImageDataStoreProviderDao providerDao; + @Override + public ImageDataStoreProvider getProvider(long providerId) { + + return null; + } + + +} diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java b/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java index 2faead9bd19..60d1e84dc05 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java @@ -19,10 +19,13 @@ package org.apache.cloudstack.storage.image.store; import org.apache.cloudstack.storage.image.Template; +import org.apache.cloudstack.storage.image.downloader.ImageDownloader; public interface ImageDataStore { Template registerTemplate(long templateId); String grantAccess(long templateId, long endPointId); boolean revokeAccess(long templateId, long endPointId); boolean deleteTemplate(long templateId); + boolean needDownloadToCacheStorage(); + ImageDownloader getImageDownloader(); } diff --git a/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java b/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java index 5986378c5cb..925e1525879 100644 --- a/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java +++ b/platform/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java @@ -18,14 +18,37 @@ */ package org.apache.cloudstack.storage.image.store; +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.ImageDataVO; +import org.apache.cloudstack.storage.image.downloader.ImageDownloader; +import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver; public class ImageDataStoreImpl implements ImageDataStore { - + @Inject + ImageDataDao imageDao; + ImageDataStoreDriver driver; + ImageDownloader downloader; + boolean needDownloadToCacheStorage = false; + + + public ImageDataStoreImpl(ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) { + this.driver = driver; + this.needDownloadToCacheStorage = needDownloadToCacheStorage; + this.downloader = downloader; + } + @Override public Template registerTemplate(long templateId) { - // TODO Auto-generated method stub - return null; + ImageDataVO idv = imageDao.findById(templateId); + Template template = new Template(this, idv); + if (driver.registerTemplate(template)) { + return template; + } else { + return null; + } } @Override @@ -46,4 +69,15 @@ public class ImageDataStoreImpl implements ImageDataStore { return false; } + @Override + public boolean needDownloadToCacheStorage() { + // TODO Auto-generated method stub + return false; + } + + @Override + public ImageDownloader getImageDownloader() { + return this.downloader; + } + }