From a6df8a5b44dc575c5ba58516b8f4ac588b7bd44c Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 5 Nov 2012 09:14:14 -0800 Subject: [PATCH] Added engine --- engine/api/pom.xml | 42 + .../org/apache/cloudstack/platform/Rules.java | 85 ++ .../cloud/entity/api/BackupEntity.java | 29 + .../cloud/entity/api/EdgeService.java | 23 + .../cloud/entity/api/NetworkEntity.java | 39 + .../platform/cloud/entity/api/NicEntity.java | 29 + .../cloud/entity/api/SnapshotEntity.java | 49 + .../cloud/entity/api/TemplateEntity.java | 27 + .../entity/api/VirtualMachineEntity.java | 148 +++ .../cloud/entity/api/VolumeEntity.java | 74 ++ .../datacenter/entity/api/ClusterEntity.java | 25 + .../entity/api/DataCenterResourceEntity.java | 83 ++ .../entity/api/OrganizationScope.java | 23 + .../datacenter/entity/api/PodEntity.java | 30 + .../datacenter/entity/api/StorageEntity.java | 24 + .../datacenter/entity/api/ZoneEntity.java | 30 + .../platform/entity/api/CloudStackEntity.java | 96 ++ .../InsufficientCapacityException.java | 24 + .../service/api/DirectoryService.java | 34 + .../platform/service/api/EntityService.java | 45 + .../service/api/OperationsServices.java | 57 ++ .../service/api/OrchestrationService.java | 84 ++ .../service/api/ProvisioningService.java | 65 ++ .../api/hypervisor/ComputeSubsystem.java | 31 + .../api/network/NetworkServiceProvider.java | 47 + .../api/network/NetworkSubsystem.java | 35 + .../subsystem/api/storage/BackupStrategy.java | 5 + .../api/storage/DataMigrationSubSystem.java | 29 + .../subsystem/api/storage/DataObject.java | 42 + ...DataObjectBackupStorageOperationState.java | 58 ++ .../subsystem/api/storage/DataStore.java | 76 ++ .../api/storage/DataStoreConfigurator.java | 16 + .../api/storage/DataStoreDriver.java | 35 + .../api/storage/DataStoreEndPoint.java | 26 + .../storage/DataStoreEndPointSelector.java | 7 + .../storage/DataStoreExtendedAttribute.java | 5 + .../api/storage/DataStoreLifeCycle.java | 13 + .../subsystem/api/storage/FileSystem.java | 32 + .../subsystem/api/storage/Snapshot.java | 23 + .../api/storage/SnapshotProfile.java | 26 + .../api/storage/SnapshotStrategy.java | 5 + .../subsystem/api/storage/StorageEvent.java | 25 + .../api/storage/StorageProvider.java | 20 + .../api/storage/StorageSubSystem.java | 13 + .../api/storage/TemplateProfile.java | 287 ++++++ .../api/storage/TemplateStrategy.java | 13 + .../subsystem/api/storage/VolumeProfile.java | 34 + .../subsystem/api/storage/VolumeStrategy.java | 16 + engine/components-api/pom.xml | 47 + engine/compute/pom.xml | 52 + .../compute/ComputeOrchestrator.java | 37 + .../compute/ComputeOrchestratorImpl.java | 41 + engine/network/pom.xml | 52 + .../network/NetworkOrchestrator.java | 40 + engine/orchestration/pom.xml | 52 + .../orchestration/CloudOrchestrator.java | 82 ++ .../platform/planning/Concierge.java | 36 + engine/pom.xml | 44 + engine/schema/pom.xml | 52 + engine/storage/pom.xml | 85 ++ .../apache/cloudstack/storage/BaseType.java | 40 + .../apache/cloudstack/storage/EndPoint.java | 8 + .../storage/HypervisorHostEndPoint.java | 55 ++ .../storage/StorageOrchestrator.java | 59 ++ .../storage/StorageOrchestratorImpl.java | 315 ++++++ .../storage/StorageProviderManager.java | 11 + .../storage/StorageProviderManagerImpl.java | 55 ++ .../cloudstack/storage/VolumeBackupRef.java | 66 ++ .../storage/backup/BackupMotionService.java | 23 + .../storage/backup/BackupService.java | 24 + .../storage/command/CreateVolumeAnswer.java | 36 + .../storage/command/CreateVolumeCommand.java | 42 + .../storage/datastore/DataStoreStatus.java | 29 + .../storage/datastore/DefaultDataStore.java | 229 +++++ .../DefaultPrimaryDataStoreImpl.java | 118 +++ .../storage/datastore/PrimaryDataStore.java | 34 + .../datastore/PrimaryDataStoreInfo.java | 31 + .../datastore/PrimaryDataStoreInfoImpl.java | 68 ++ .../storage/datastore/db/DataStoreVO.java | 258 +++++ .../datastore/db/PrimaryDataStoreDao.java | 106 ++ .../datastore/db/PrimaryDataStoreDaoImpl.java | 377 +++++++ .../db/PrimaryDataStoreProviderDao.java | 25 + .../db/PrimaryDataStoreProviderDaoImpl.java | 28 + .../db/PrimaryDataStoreProviderVO.java | 38 + .../DefaultPrimaryDataStoreDriverImpl.java | 65 ++ .../driver/PrimaryDataStoreDriver.java | 11 + .../DefaultPrimaryDataStoreLifeCycleImpl.java | 70 ++ .../lifecycle/PrimaryDataStoreLifeCycle.java | 31 + .../DefaultPrimaryDataStoreManagerImpl.java | 55 ++ .../manager/PrimaryDataStoreManager.java | 27 + .../DefaultPrimaryDatastoreProviderImpl.java | 44 + .../provider/PrimaryDataStoreProvider.java | 9 + .../PrimaryDataStoreProviderManager.java | 5 + .../PrimaryDataStoreProviderManagerImpl.java | 32 + .../storage/datastore/type/DataStoreType.java | 23 + .../storage/datastore/type/ISCSI.java | 31 + .../datastore/type/NetworkFileSystem.java | 31 + .../storage/datastore/type/SharedMount.java | 29 + .../storage/driver/AbstractStorageDriver.java | 76 ++ .../driver/DefaultNfsSecondaryDriver.java | 90 ++ .../driver/XenServerStorageDriver.java | 81 ++ .../storage/image/ImageManager.java | 32 + .../storage/image/ImageManagerImpl.java | 167 ++++ .../storage/image/ImageMotionService.java | 24 + .../storage/image/ImageOrchestrator.java | 26 + .../storage/image/ImageOrchestratorImpl.java | 78 ++ .../storage/image/ImageService.java | 30 + .../storage/image/ImageServiceImpl.java | 84 ++ .../cloudstack/storage/image/Template.java | 36 + .../storage/image/db/ImageDaoStoreDao.java | 25 + .../image/db/ImageDaoStoreDaoImpl.java | 25 + .../storage/image/db/ImageDataDao.java | 71 ++ .../storage/image/db/ImageDataDaoImpl.java | 925 ++++++++++++++++++ .../image/db/ImageDataStoreProviderDao.java | 25 + .../db/ImageDataStoreProviderDaoImpl.java | 26 + .../image/db/ImageDataStoreProviderVO.java | 23 + .../storage/image/db/ImageDataStoreVO.java | 60 ++ .../storage/image/db/ImageDataVO.java | 381 ++++++++ .../image/downloader/ImageDownloader.java | 25 + .../image/driver/ImageDataStoreDriver.java | 28 + .../driver/ImageDataStoreDriverImpl.java | 51 + .../storage/image/format/BAREMETAL.java | 31 + .../cloudstack/storage/image/format/ISO.java | 31 + .../storage/image/format/ImageFormat.java | 23 + .../image/format/ImageFormatHelper.java | 44 + .../cloudstack/storage/image/format/OVA.java | 31 + .../storage/image/format/QCOW2.java | 31 + .../storage/image/format/Unknown.java | 32 + .../cloudstack/storage/image/format/VHD.java | 29 + .../image/manager/ImageDataStoreManager.java | 25 + .../manager/ImageDataStoreManagerImpl.java | 41 + .../provider/ImageDataStoreProvider.java | 25 + .../ImageDataStoreProviderManager.java | 23 + .../ImageDataStoreProviderManagerImpl.java | 37 + .../storage/image/store/ImageDataStore.java | 31 + .../image/store/ImageDataStoreImpl.java | 83 ++ .../DefaultNfsSecondaryLifeCycle.java | 54 + .../DefaultPrimaryDataStoreLifeCycle.java | 123 +++ .../storage/manager/BackupStorageManager.java | 39 + .../manager/BackupStorageManagerImpl.java | 66 ++ .../manager/PrimaryDataStoreManager.java | 42 + .../manager/PrimaryDataStoreManagerImpl.java | 142 +++ .../manager/SecondaryStorageManager.java | 34 + .../manager/SecondaryStorageManagerImpl.java | 56 ++ .../DefaultNfsSecondaryStorageProvider.java | 131 +++ .../DefaultPrimaryStorageProvider.java | 144 +++ .../provider/HttpImageStoreProvider.java | 91 ++ .../provider/S3SecondaryStorageProvider.java | 91 ++ .../SwiftSecondaryStorageProvider.java | 91 ++ .../storage/snapshot/SnapshotService.java | 24 + .../strategy/DefaultTemplateStratey.java | 191 ++++ .../strategy/DefaultVolumeStrategy.java | 90 ++ .../storage/strategy/XenBackupStrategy.java | 11 + .../storage/strategy/XenSnapshotStrategy.java | 11 + .../cloudstack/storage/volume/Volume.java | 101 ++ .../storage/volume/VolumeEvent.java | 34 + .../cloudstack/storage/volume/VolumeInfo.java | 76 ++ .../storage/volume/VolumeManager.java | 33 + .../storage/volume/VolumeManagerImpl.java | 70 ++ .../storage/volume/VolumeMotionService.java | 23 + .../storage/volume/VolumeService.java | 67 ++ .../storage/volume/VolumeServiceImpl.java | 79 ++ .../storage/volume/VolumeState.java | 73 ++ .../storage/volume/db/VolumeDao.java | 82 ++ .../storage/volume/db/VolumeDaoImpl.java | 427 ++++++++ .../storage/volume/db/VolumeVO.java | 425 ++++++++ .../storage/volume/disktype/QCOW2.java | 10 + .../storage/volume/disktype/Unknown.java | 7 + .../storage/volume/disktype/VHD.java | 10 + .../storage/volume/disktype/VMDK.java | 10 + .../volume/disktype/VolumeDiskType.java | 4 + .../volume/disktype/VolumeDiskTypeBase.java | 34 + .../volume/disktype/VolumeDiskTypeHelper.java | 29 + .../storage/volume/type/DataDisk.java | 10 + .../cloudstack/storage/volume/type/Iso.java | 10 + .../storage/volume/type/RootDisk.java | 10 + .../storage/volume/type/Unknown.java | 8 + .../storage/volume/type/VolumeType.java | 22 + .../storage/volume/type/VolumeTypeBase.java | 31 + .../storage/volume/type/VolumeTypeHelper.java | 28 + .../cloudstack/storage/test/AllTests.java | 29 + .../cloudstack/storage/test/AopTest.java | 14 + .../storage/test/AopTestAdvice.java | 20 + .../storage/test/StorageFactoryBean.java | 42 + .../storage/test/storageContext.xml | 67 ++ .../storage/test/volumeServiceTest.java | 128 +++ 186 files changed, 11592 insertions(+) create mode 100644 engine/api/pom.xml create mode 100755 engine/api/src/org/apache/cloudstack/platform/Rules.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/BackupEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/EdgeService.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NicEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/SnapshotEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/TemplateEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VolumeEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ClusterEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/DataCenterResourceEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/OrganizationScope.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/PodEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/StorageEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ZoneEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/entity/api/CloudStackEntity.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/exception/InsufficientCapacityException.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/service/api/DirectoryService.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/service/api/EntityService.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/service/api/OperationsServices.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/service/api/ProvisioningService.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/hypervisor/ComputeSubsystem.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkServiceProvider.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/BackupStrategy.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObject.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObjectBackupStorageOperationState.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreConfigurator.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPoint.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPointSelector.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreExtendedAttribute.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreLifeCycle.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/FileSystem.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/Snapshot.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotProfile.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotStrategy.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java create mode 100755 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeProfile.java create mode 100644 engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeStrategy.java create mode 100644 engine/components-api/pom.xml create mode 100644 engine/compute/pom.xml create mode 100755 engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.java create mode 100755 engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestratorImpl.java create mode 100644 engine/network/pom.xml create mode 100755 engine/network/src/org/apache/cloudstack/network/NetworkOrchestrator.java create mode 100755 engine/orchestration/pom.xml create mode 100755 engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java create mode 100755 engine/planning/src/org/apache/cloudstack/platform/planning/Concierge.java create mode 100644 engine/pom.xml create mode 100644 engine/schema/pom.xml create mode 100644 engine/storage/pom.xml create mode 100644 engine/storage/src/org/apache/cloudstack/storage/BaseType.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/EndPoint.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPoint.java create mode 100755 engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/StorageProviderManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/StorageProviderManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/VolumeBackupRef.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/backup/BackupMotionService.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/backup/BackupService.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeAnswer.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreStatus.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultDataStore.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfo.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfoImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/db/DataStoreVO.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDao.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDaoImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderVO.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/PrimaryDataStoreLifeCycle.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/type/DataStoreType.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/type/ISCSI.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/type/NetworkFileSystem.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/datastore/type/SharedMount.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/driver/XenServerStorageDriver.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/ImageManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/ImageMotionService.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/ImageOrchestratorImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/Template.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDao.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDaoImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultVolumeStrategy.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/strategy/XenBackupStrategy.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/strategy/XenSnapshotStrategy.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/Volume.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEvent.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManager.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManagerImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeMotionService.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/VolumeState.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/disktype/QCOW2.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/disktype/Unknown.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VHD.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VMDK.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskType.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeBase.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeHelper.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/type/DataDisk.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/type/Iso.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/type/RootDisk.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java create mode 100644 engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java create mode 100644 engine/storage/test/org/apache/cloudstack/storage/test/AllTests.java create mode 100644 engine/storage/test/org/apache/cloudstack/storage/test/AopTest.java create mode 100644 engine/storage/test/org/apache/cloudstack/storage/test/AopTestAdvice.java create mode 100644 engine/storage/test/org/apache/cloudstack/storage/test/StorageFactoryBean.java create mode 100644 engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml create mode 100644 engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java diff --git a/engine/api/pom.xml b/engine/api/pom.xml new file mode 100644 index 00000000000..88b3b380b5f --- /dev/null +++ b/engine/api/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + cloud-engine-api + Apache CloudStack Cloud Engine API + + org.apache.cloudstack + cloud-engine + 4.1.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-api + ${project.version} + + + + install + src + test + + diff --git a/engine/api/src/org/apache/cloudstack/platform/Rules.java b/engine/api/src/org/apache/cloudstack/platform/Rules.java new file mode 100755 index 00000000000..61e0c3c0071 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/Rules.java @@ -0,0 +1,85 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; + +import com.cloud.utils.StringUtils; + +/** + * Rules specifies all rules about developing and using CloudStack Orchestration + * Platforms APIs. This class is not actually used in CloudStack Orchestration + * Platform but must be read by all who wants to use and develop against + * CloudStack Orchestration Platform. + * + * Make sure to make changes here when there are changes to how the APIs should + * be used and developed. + * + * Changes to this class must be approved by the maintainer of this project. + * + */ +public class Rules { + public static List whenUsing() { + List rules = new ArrayList(); + rules.add("Always be prepared to handle RuntimeExceptions."); + return rules; + } + + public static List whenWritingNewApis() { + List rules = new ArrayList(); + rules.add("You may think you're the greatest developer in the " + + "world but every change to the API must be reviewed and approved. "); + rules.add("Every API must have unit tests written against it. And not it's unit tests"); + rules.add(""); + + + return rules; + } + + private static void printRule(String rule) { + System.out.print("API Rule: "); + String skip = ""; + int brk = 0; + while (true) { + int stop = StringUtils.formatForOutput(rule, brk, 75 - skip.length(), ' '); + if (stop < 0) { + break; + } + System.out.print(skip); + skip = " "; + System.out.println(rule.substring(brk, stop).trim()); + brk = stop; + } + } + + public static void main(String[] args) { + System.out.println("When developing against the CloudStack Orchestration Platform, you must following the following rules:"); + for (String rule : whenUsing()) { + printRule(rule); + } + System.out.println(""); + System.out.println("When writing APIs, you must follow these rules:"); + for (String rule : whenWritingNewApis()) { + printRule(rule); + } + } + +} + diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/BackupEntity.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/BackupEntity.java new file mode 100755 index 00000000000..9bf39a87ee3 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/BackupEntity.java @@ -0,0 +1,29 @@ +/* + * 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.cloud.entity.api; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +/** + * @author ahuang + * + */ +public interface BackupEntity extends CloudStackEntity { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/EdgeService.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/EdgeService.java new file mode 100755 index 00000000000..8dceb746431 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/EdgeService.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.platform.cloud.entity.api; + +public interface EdgeService { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java new file mode 100755 index 00000000000..12d32a29036 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NetworkEntity.java @@ -0,0 +1,39 @@ +/* + * 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.cloud.entity.api; + +import java.util.List; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +import com.cloud.network.Network; + +public interface NetworkEntity extends CloudStackEntity, Network { + void routeTo(NetworkEntity network); + + List listEdgeServicesTo(); + + List listVirtualMachineUuids(); + + List listVirtualMachines(); + + List listNics(); + + void addIpRange(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NicEntity.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NicEntity.java new file mode 100755 index 00000000000..4da66ccf385 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/NicEntity.java @@ -0,0 +1,29 @@ +/* + * 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.cloud.entity.api; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +/** + * @author ahuang + * + */ +public interface NicEntity extends CloudStackEntity { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/SnapshotEntity.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/SnapshotEntity.java new file mode 100755 index 00000000000..efe9b1c74ce --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/SnapshotEntity.java @@ -0,0 +1,49 @@ +/* + * 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.cloud.entity.api; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +import com.cloud.storage.Snapshot; + +public interface SnapshotEntity extends CloudStackEntity, Snapshot { + /** + * Make a reservation for backing up this snapshot + * @param expiration time in seconds to expire the reservation + * @return reservation token + */ + String reserveForBackup(int expiration); + + /** + * Perform the backup according to the reservation token + * @param reservationToken token returned by reserveForBackup + */ + void backup(String reservationToken); + + /** + * restore this snapshot to this vm. + * @param vm + */ + void restore(String vm); + + /** + * Destroy this snapshot. + */ + void destroy(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/TemplateEntity.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/TemplateEntity.java new file mode 100755 index 00000000000..75623ccb108 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/TemplateEntity.java @@ -0,0 +1,27 @@ +/* + * 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.cloud.entity.api; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +import com.cloud.template.VirtualMachineTemplate; + +public interface TemplateEntity extends CloudStackEntity, VirtualMachineTemplate { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java new file mode 100755 index 00000000000..0e1d3d92191 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VirtualMachineEntity.java @@ -0,0 +1,148 @@ +/* + * 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.cloud.entity.api; + +import java.util.List; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeploymentPlanner.ExcludeList; +import com.cloud.vm.VirtualMachine; + +/** + * VirtualMachineEntity represents a Virtual Machine in Cloud Orchestration + * Platform. + * + */ +public interface VirtualMachineEntity extends VirtualMachine, CloudStackEntity { + + /** + * @return List of uuids for volumes attached to this virtual machine. + */ + List listVolumeUuids(); + + /** + * @return List of volumes attached to this virtual machine. + */ + List listVolumes(); + + /** + * @return List of uuids for nics attached to this virtual machine. + */ + List listNicUuids(); + + /** + * @return List of nics attached to this virtual machine. + */ + List listNics(); + + /** + * @return the template this virtual machine is based off. + */ + TemplateEntity getTemplate(); + + /** + * @return the list of tags associated with the virtual machine + */ + List listTags(); + + void addTag(); + + void delTag(); + + /** + * Start the virtual machine with a given deploy destination + * @param plannerToUse the Deployment Planner that should be used + * @param dest destination to which to deploy the machine + * @param exclude list of areas to exclude + * @return a reservation id + */ + String reserve(String plannerToUse, DeployDestination dest, ExcludeList exclude); + + /** + * Migrate this VM to a certain destination. + * + * @param reservationId reservation id from reserve call. + */ + void migrateTo(String reservationId); + + /** + * Deploy this virtual machine according to the reservation from before. + * @param reservationId reservation id from reserve call. + * + */ + void deploy(String reservationId); + + /** + * Stop the virtual machine + * + */ + void stop(); + + /** + * Cleans up after any botched starts. CloudStack Orchestration Platform + * will attempt a best effort to actually shutdown any resource but + * even if it cannot, it releases the resource from its database. + */ + void cleanup(); + + /** + * Destroys the VM. + */ + void destroy(); + + /** + * Duplicate this VM in the database so that it will start new + * @param externalId + * @return a new VirtualMachineEntity + */ + VirtualMachineEntity duplicate(String externalId); + + /** + * Take a VM snapshot + */ + SnapshotEntity takeSnapshotOf(); + + /** + * Attach volume to this VM + * @param volume volume to attach + * @param deviceId deviceId to use + */ + void attach(VolumeEntity volume, short deviceId); + + /** + * Detach the volume from this VM + * @param volume volume to detach + */ + void detach(VolumeEntity volume); + + /** + * Connect the VM to a network + * @param network network to attach + * @param deviceId device id to use when a nic is created + */ + void connectTo(NetworkEntity network, short nicId); + + /** + * Disconnect the VM from this network + * @param netowrk network to disconnect from + */ + void disconnectFrom(NetworkEntity netowrk, short nicId); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VolumeEntity.java b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VolumeEntity.java new file mode 100755 index 00000000000..d7e5f381bf4 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/cloud/entity/api/VolumeEntity.java @@ -0,0 +1,74 @@ +/* + * 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.cloud.entity.api; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +import com.cloud.storage.Volume; + +public interface VolumeEntity extends CloudStackEntity, Volume { + + /** + * Take a snapshot of the volume + */ + SnapshotEntity takeSnapshotOf(boolean full); + + /** + * Make a reservation to do storage migration + * + * @param expirationTime time in seconds the reservation is cancelled + * @return reservation token + */ + String reserveForMigration(long expirationTime); + + /** + * Migrate using a reservation. + * @param reservationToken reservation token + */ + void migrate(String reservationToken); + + /** + * Setup for a copy of this volume. + * @return destination to copy to + */ + VolumeEntity setupForCopy(); + + /** + * Perform the copy + * @param dest copy to this volume + */ + void copy(VolumeEntity dest); + + /** + * Attach to the vm + * @param vm vm to attach to + * @param deviceId device id to use + */ + void attachTo(String vm, long deviceId); + + /** + * Detach from the vm + */ + void detachFrom(); + + /** + * Destroy the volume + */ + void destroy(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ClusterEntity.java b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ClusterEntity.java new file mode 100755 index 00000000000..83789098d24 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ClusterEntity.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.platform.datacenter.entity.api; + +import com.cloud.org.Cluster; + +public interface ClusterEntity extends DataCenterResourceEntity, Cluster, OrganizationScope { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/DataCenterResourceEntity.java b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/DataCenterResourceEntity.java new file mode 100755 index 00000000000..5ca27c54f69 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/DataCenterResourceEntity.java @@ -0,0 +1,83 @@ +/* + * 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.datacenter.entity.api; + +import org.apache.cloudstack.platform.entity.api.CloudStackEntity; + +import com.cloud.utils.fsm.StateMachine2; +import com.cloud.utils.fsm.StateObject; + +/** + * This interface specifies the states and operations all physical + * and virtual resources in the data center must implement. + */ +public interface DataCenterResourceEntity extends CloudStackEntity, StateObject { + + /** + * This is the state machine for how CloudStack should interact with + * + */ + public enum State { + Disabled("The resource is disabled so CloudStack should not use it. This is the initial state of all resources added to CloudStack."), + Enabled("The resource is now enabled for CloudStack to use."), + Deactivated("The resource is disactivated so CloudStack should not use it for new resource needs."); + + String _description; + + private State(String description) { + _description = description; + } + + public enum Event { + EnableRequest, + DisableRequest, + DeactivateRequest, + ActivatedRequest + } + + protected static final StateMachine2 s_fsm = new StateMachine2(); + static { + s_fsm.addTransition(Disabled, Event.EnableRequest, Enabled); + s_fsm.addTransition(Enabled, Event.DisableRequest, Disabled); + s_fsm.addTransition(Enabled, Event.DeactivateRequest, Deactivated); + s_fsm.addTransition(Deactivated, Event.ActivatedRequest, Enabled); + } + + } + /** + * Prepare the resource to take new on new demands. + */ + boolean enable(); + + /** + * Disables the resource. Cleanup. Prepare for the resource to be removed. + */ + boolean disable(); + + /** + * Do not use the resource for new demands. + */ + boolean deactivate(); + + /** + * Reactivates a deactivated resource. + */ + boolean reactivate(); + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/OrganizationScope.java b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/OrganizationScope.java new file mode 100755 index 00000000000..0fa64976808 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/OrganizationScope.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.platform.datacenter.entity.api; + +public interface OrganizationScope { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/PodEntity.java b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/PodEntity.java new file mode 100755 index 00000000000..e4743008f20 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/PodEntity.java @@ -0,0 +1,30 @@ +/* + * 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.datacenter.entity.api; + +import java.util.List; + +import com.cloud.dc.Pod; +import com.cloud.org.Cluster; + +public interface PodEntity extends DataCenterResourceEntity, Pod { + + List listClusters(); + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/StorageEntity.java b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/StorageEntity.java new file mode 100755 index 00000000000..2d222324d2a --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/StorageEntity.java @@ -0,0 +1,24 @@ +/* + * 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.datacenter.entity.api; + +import com.cloud.storage.StoragePool; + +public interface StorageEntity extends DataCenterResourceEntity, StoragePool { +} diff --git a/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ZoneEntity.java b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ZoneEntity.java new file mode 100755 index 00000000000..48940fae4e0 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/datacenter/entity/api/ZoneEntity.java @@ -0,0 +1,30 @@ +/* + * 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.datacenter.entity.api; + +import java.util.List; + +import com.cloud.dc.DataCenter; + +/** + * Describes a zone and operations that can be done in a zone. + */ +public interface ZoneEntity extends DataCenterResourceEntity, DataCenter { + List listPods(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/entity/api/CloudStackEntity.java b/engine/api/src/org/apache/cloudstack/platform/entity/api/CloudStackEntity.java new file mode 100755 index 00000000000..1aa70b6c124 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/entity/api/CloudStackEntity.java @@ -0,0 +1,96 @@ +/* + * 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.entity.api; + +import java.lang.reflect.Method; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * All entities returned by the Cloud Orchestration Platform must implement + * this interface. CloudValueEntity is an immutable representation of + * an entity exposed by Cloud Orchestration Platform. For each object, it + * defines two ids: uuid, generated by CloudStack Orchestration Platform, and + * an external id that is set by the caller when the entity is created. All + * ids must be unique for that entity. CloudValueEntity also can be converted + * to a CloudActionableEntity which contains actions the object can perform. + */ +public interface CloudStackEntity { + /** + * @return the uuid of the object. + */ + String getUuid(); + + /** + * @return the id which is often the database id. + */ + long getId(); + + /** + * @return external id set by the caller + */ + String getExternalId(); + + /** + * @return current state for the entity + */ + String getCurrentState(); + + /** + * @return desired state for the entity + */ + String getDesiredState(); + + /** + * Get the time the entity was created + */ + Date getCreatedTime(); + + /** + * Get the time the entity was last updated + */ + Date getLastUpdatedTime(); + + /** + * @return reference to the owner of this entity + */ + String getOwner(); + + /** + * @return details stored for this entity when created. + */ + Map getDetails(String source); + + /** + * @return a list of sources that have added to the details. + */ + List getDetailSources(); + + void addDetail(String source, String name, String value); + + void delDetail(String source, String name, String value); + + void updateDetail(String source, String name, String value); + + /** + * @return list of actions that can be performed on the object in its current state + */ + List getApplicableActions(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/exception/InsufficientCapacityException.java b/engine/api/src/org/apache/cloudstack/platform/exception/InsufficientCapacityException.java new file mode 100755 index 00000000000..d2f9112aaef --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/exception/InsufficientCapacityException.java @@ -0,0 +1,24 @@ +/* + * 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.exception; + +public class InsufficientCapacityException { + + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/service/api/DirectoryService.java b/engine/api/src/org/apache/cloudstack/platform/service/api/DirectoryService.java new file mode 100755 index 00000000000..e789613444a --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/service/api/DirectoryService.java @@ -0,0 +1,34 @@ +/* + * 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.service.api; + +import java.net.URI; +import java.util.List; + +import com.cloud.utils.component.PluggableService; + +public interface DirectoryService { + void registerService(String serviceName, URI endpoint); + void unregisterService(String serviceName, URI endpoint); + List getEndPoints(String serviceName); + URI getLoadBalancedEndPoint(String serviceName); + + List listServices(); + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/service/api/EntityService.java b/engine/api/src/org/apache/cloudstack/platform/service/api/EntityService.java new file mode 100755 index 00000000000..6983d28ec16 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/service/api/EntityService.java @@ -0,0 +1,45 @@ +/* + * 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.service.api; + +import java.util.List; + +import com.cloud.network.Network; +import com.cloud.storage.Volume; +import com.cloud.vm.VirtualMachine; + +/** + * Service to retrieve CloudStack entities + * very likely to change + */ +public interface EntityService { + List listVirtualMachines(); + List listVolumes(); + List listNetworks(); + List listNics(); + List listSnapshots(); + List listTemplates(); + List listStoragePools(); + List listHosts(); + + VirtualMachine getVirtualMachine(String vm); + Volume getVolume(String volume); + Network getNetwork(String network); + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/service/api/OperationsServices.java b/engine/api/src/org/apache/cloudstack/platform/service/api/OperationsServices.java new file mode 100755 index 00000000000..5cf7bc6059f --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/service/api/OperationsServices.java @@ -0,0 +1,57 @@ +/* + * 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.service.api; + +import java.net.URL; +import java.util.List; + +import com.cloud.alert.Alert; +import com.cloud.async.AsyncJob; + +public interface OperationsServices { + List listJobs(); + + List listJobsInProgress(); + + List listJobsCompleted(); + + List listJobsCompleted(Long from); + + List listJobsInWaiting(); + + void cancelJob(String job); + + List listAlerts(); + + Alert getAlert(String uuid); + + void cancelAlert(String alert); + + void registerForAlerts(); + + String registerForEventNotifications(String type, String topic, URL url); + + boolean deregisterForEventNotifications(String notificationId); + + /** + * @return the list of event topics someone can register for + */ + List listEventTopics(); + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java b/engine/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java new file mode 100755 index 00000000000..87c2fe0e1f9 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/service/api/OrchestrationService.java @@ -0,0 +1,84 @@ +/* + * 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.service.api; + +import java.net.URL; +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.platform.cloud.entity.api.NetworkEntity; +import org.apache.cloudstack.platform.cloud.entity.api.TemplateEntity; +import org.apache.cloudstack.platform.cloud.entity.api.VirtualMachineEntity; +import org.apache.cloudstack.platform.cloud.entity.api.VolumeEntity; + +import com.cloud.hypervisor.Hypervisor; + +public interface OrchestrationService { + /** + * creates a new virtual machine + * + * @param uuid externally unique name to reference the virtual machine + * @param template reference to the template + * @param hostName name of the host + * @param cpu # of cpu cores + * @param speed speed of the cpu core + * @param memory memory to allocate in bytes + * @param networks networks that this VM belongs in + * @param rootDiskTags tags for the root disk + * @param computeTags tags for the compute + * @param details extra details to store for the VM + * @return VirtualMachine + */ + VirtualMachineEntity createVirtualMachine(String name, + String template, + String hostName, + int cpu, + int speed, + long memory, + List networks, + List rootDiskTags, + List computeTags, + Map details, + String owner); + + VirtualMachineEntity createVirtualMachineFromScratch(String uuid, + String iso, + String os, + String hypervisor, + String hostName, + int cpu, + int speed, + long memory, + List networks, + List computeTags, + Map details, + String owner); + + NetworkEntity createNetwork(String externaId, String name, String cidr, String gateway); + + void destroyNetwork(String networkUuid); + + VolumeEntity createVolume(); + + void destroyVolume(String volumeEntity); + + TemplateEntity registerTemplate(String name, URL path, String os, Hypervisor hypervisor); + + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/service/api/ProvisioningService.java b/engine/api/src/org/apache/cloudstack/platform/service/api/ProvisioningService.java new file mode 100755 index 00000000000..0032a258786 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/service/api/ProvisioningService.java @@ -0,0 +1,65 @@ +/* + * 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.service.api; + +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.platform.datacenter.entity.api.ZoneEntity; + +import com.cloud.dc.DataCenter; +import com.cloud.dc.Pod; +import com.cloud.host.Host; +import com.cloud.host.Status; +import com.cloud.storage.StoragePool; + + +/** + * ProvisioningService registers and deregisters physical and virtual + * resources that the management server can use. + */ +public interface ProvisioningService { + + String registerStorage(String name, List tags, Map details); + ZoneEntity registerZone(String name, List tags, Map details); + String registerPod(String name, List tags, Map details); + String registerCluster(String name, List tags, Map details); + String registerHost(String name, List tags, Map details); + + + + void deregisterStorage(String uuid); + void deregisterZone(); + void deregisterPod(); + void deregisterCluster(); + void deregisterHost(); + + void changeState(String type, String entity, Status state); + + List listHosts(); + + List listPods(); + + List listZones(); + + + + List listStorage(); + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/hypervisor/ComputeSubsystem.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/hypervisor/ComputeSubsystem.java new file mode 100644 index 00000000000..b9f8a87686f --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/hypervisor/ComputeSubsystem.java @@ -0,0 +1,31 @@ +/* + * 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.hypervisor; + + +public interface ComputeSubsystem { + + void start(String vm, String reservationId); + + void cancel(String reservationId); + + void stop(String vm, String reservationId); + + void migrate(String vm, String reservationId); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkServiceProvider.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkServiceProvider.java new file mode 100755 index 00000000000..a66a4f54db5 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkServiceProvider.java @@ -0,0 +1,47 @@ +/* + * 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.network; + +public interface NetworkServiceProvider { + /** + * Plug your network elements into this network + * @param network + * @param reservationId + */ + void plugInto(String network, String reservationId); + + /** + * Unplug your network elements from this network + * @param network + * @param reservationId + */ + void unplugFrom(String network, String reservationId); + + /** + * Cancel a previous work + * @param reservationId + */ + void cancel(String reservationId); + + void provideServiceTo(String vm, String network, String reservationId); + + void removeServiceFrom(String vm, String network, String reservationId); + + void cleanUp(String network, String reservationId); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java new file mode 100755 index 00000000000..6a373821c23 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/network/NetworkSubsystem.java @@ -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.platform.subsystem.api.network; + +public interface NetworkSubsystem { + String create(); + + String start(String network, String reservationId); + + void shutdown(String nework, String reservationId); + + void prepare(String vm, String network, String reservationId); + + void release(String vm, String network, String reservationId); + + void cancel(String reservationId); + + void destroy(String network, String reservationId); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/BackupStrategy.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/BackupStrategy.java new file mode 100644 index 00000000000..b5aecd7a810 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/BackupStrategy.java @@ -0,0 +1,5 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +public interface BackupStrategy { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java new file mode 100755 index 00000000000..edb15a64ed2 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataMigrationSubSystem.java @@ -0,0 +1,29 @@ +/* + * 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 java.net.URI; + +import com.cloud.org.Grouping; + +public interface DataMigrationSubSystem { + + Class getScopeCoverage(); + void migrate(URI source, URI dest, String reservationId); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObject.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObject.java new file mode 100644 index 00000000000..c861bc40a2a --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObject.java @@ -0,0 +1,42 @@ +/* + * 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 java.util.List; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.DataStoreRef; + +/* + * Logic entity + */ +public interface DataObject { + String getURI(); + String getUUID(); + DataStoreRef getStoreRef(); + long getSize(); + //volume/snapshot/template + String getType(); + //db id + Long getId(); + DataObject getParent(); + void setParent(DataObject obj); + List getChidren(); + boolean lock(); + boolean unlock(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObjectBackupStorageOperationState.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObjectBackupStorageOperationState.java new file mode 100644 index 00000000000..a565036b627 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataObjectBackupStorageOperationState.java @@ -0,0 +1,58 @@ +/* + * 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.utils.fsm.StateMachine; + +public enum DataObjectBackupStorageOperationState { + Copying, + Deleting, + Ready, + NonOperational; + + public enum Event { + Initial("Init state machine"), + CopyingRequested("Copy operation is requested"), + DeleteRequested("Delete operation is requested"), + OperationSuccess("Operation successed"), + OperationFailed("Operation failed"); + + private final String _msg; + + private Event(String msg) { + _msg = msg; + } + } + + public DataObjectBackupStorageOperationState getNextState(Event a) { + return s_fsm.getNextState(this, a); + } + + protected static final StateMachine s_fsm = new StateMachine(); + static { + s_fsm.addTransition(null, Event.Initial, DataObjectBackupStorageOperationState.Ready); + s_fsm.addTransition(DataObjectBackupStorageOperationState.Ready, Event.CopyingRequested, DataObjectBackupStorageOperationState.Copying); + s_fsm.addTransition(DataObjectBackupStorageOperationState.Copying, Event.CopyingRequested, DataObjectBackupStorageOperationState.Copying); + s_fsm.addTransition(DataObjectBackupStorageOperationState.Copying, Event.OperationFailed, DataObjectBackupStorageOperationState.Ready); + s_fsm.addTransition(DataObjectBackupStorageOperationState.Copying, Event.OperationSuccess, DataObjectBackupStorageOperationState.Ready); + s_fsm.addTransition(DataObjectBackupStorageOperationState.Ready, Event.DeleteRequested, DataObjectBackupStorageOperationState.Deleting); + s_fsm.addTransition(DataObjectBackupStorageOperationState.Deleting, Event.OperationFailed, DataObjectBackupStorageOperationState.Ready); + s_fsm.addTransition(DataObjectBackupStorageOperationState.Deleting, Event.OperationSuccess, DataObjectBackupStorageOperationState.NonOperational); + } +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java new file mode 100644 index 00000000000..0d0f082abb0 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStore.java @@ -0,0 +1,76 @@ +/* + * 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.agent.api.to.StorageFilerTO; +import com.cloud.storage.Snapshot; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.storage.Volume; +import com.cloud.template.VirtualMachineTemplate; + +public interface DataStore { + public class DataStoreRef { + + } + + public class DataStoreDriverRef { + + } + + public enum StoreType { + Primary, + Image, + Backup; + } + public class StoreScope { + public long zoneId; + private long clusterId; + private long hostId; + } + + String getURI(); + String getUUID(); + long getCluterId(); + long getPodId(); + long getZoneId(); + String getPath(); + StoreType getType(); + StoragePoolType getPoolType(); + StoreScope getScope(); + boolean isSharedStorage(); + Long getId(); + DataStoreDriver getDataStoreDriver(); + StorageProvider getProvider(); + DataStoreEndPointSelector getEndPointSelector(); + FileSystem getFileSystem(); + VolumeStrategy getVolumeStrategy(); + SnapshotStrategy getSnapshotStrategy(); + BackupStrategy getBackupStrategy(); + TemplateStrategy getTemplateStrategy(); + DataStoreLifeCycle getLifeCycle(); + + VolumeProfile prepareVolume(Volume volume, DataStore destStore); + SnapshotProfile prepareSnapshot(Snapshot snapshot, DataStore destStore); + TemplateProfile prepareTemplate(long templateId, DataStore destStore); + boolean contains(Volume volume); + boolean contains(Snapshot snapshot); + boolean contains(TemplateProfile template); + TemplateProfile get(TemplateProfile template); + StorageFilerTO getTO(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreConfigurator.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreConfigurator.java new file mode 100644 index 00000000000..8d80d8d3f48 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreConfigurator.java @@ -0,0 +1,16 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +import com.cloud.storage.StoragePool; + +public interface DataStoreConfigurator { + String getProtocol(); + StoragePool getStoragePool(Map configs); + List getConfigNames(); + Map getConfigs(URI uri, Map extras); + boolean validate(Map configs); + DataStore getDataStore(StoragePool pool); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java new file mode 100644 index 00000000000..258f0a1f8d6 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreDriver.java @@ -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.platform.subsystem.api.storage; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; + +public interface DataStoreDriver { + String getDriverType(); + TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep); + TemplateProfile register(TemplateProfile tp, DataStoreEndPoint ep); + DataObject create(DataObject obj); + DataObject copy(DataObject src, DataStore dest); + DataObject copy(DataObject src, DataObject dest); + DataObject move(DataObject src, DataObject dest); + VolumeProfile createVolumeFromTemplate(VolumeProfile vol, TemplateProfile tp, DataStoreEndPoint dp); + Answer sendMessage(DataStoreEndPoint dsep, Command cmd); + boolean delete(DataObject obj); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPoint.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPoint.java new file mode 100644 index 00000000000..8029424a424 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPoint.java @@ -0,0 +1,26 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; + +public class DataStoreEndPoint { + protected long hostId; + protected String privIp; + + public DataStoreEndPoint(long host, String ip) { + hostId = host; + privIp = ip; + } + + public long getHostId() { + return hostId; + } + + public String getPrivateIp() { + return privIp; + } + + public Answer sendCommand(Command cmd) { + return new Answer(cmd); + } +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPointSelector.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPointSelector.java new file mode 100644 index 00000000000..30b597cb5cd --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreEndPointSelector.java @@ -0,0 +1,7 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +import java.util.List; + +public interface DataStoreEndPointSelector { + List getEndPoints(StorageEvent event); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreExtendedAttribute.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreExtendedAttribute.java new file mode 100644 index 00000000000..55af9d96513 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreExtendedAttribute.java @@ -0,0 +1,5 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +public interface DataStoreExtendedAttribute { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreLifeCycle.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreLifeCycle.java new file mode 100644 index 00000000000..46be5f5fc95 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/DataStoreLifeCycle.java @@ -0,0 +1,13 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +public interface DataStoreLifeCycle { + public enum DataStoreEvent { + HOSTUP, + HOSTDOWN, + } + void add(); + void delete(); + void enable(); + void disable(); + void processEvent(DataStoreEvent event, Object... objs); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/FileSystem.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/FileSystem.java new file mode 100644 index 00000000000..213829d7302 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/FileSystem.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.platform.subsystem.api.storage; + +public interface FileSystem { + DataObject create(DataObject obj); + DataObject copy(DataObject Obj, DataStore destStore); + DataObject copy(DataObject obj, DataObject destObj); + DataObject move(DataObject srcObj, DataObject destObj); + boolean delete(DataObject obj); + long getStats(DataObject obj); + String getFileType(); + boolean isWritable(DataObject obj); + boolean contains(DataObject obj); + DataObject ioctl(DataObject obj, Object... objects); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/Snapshot.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/Snapshot.java new file mode 100644 index 00000000000..5702e4c4717 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/Snapshot.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.platform.subsystem.api.storage; + +public interface Snapshot extends DataObject { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotProfile.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotProfile.java new file mode 100644 index 00000000000..bf07cec7a00 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotProfile.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.platform.subsystem.api.storage; + +public class SnapshotProfile { + private String _uri; + public String getURI() { + return _uri; + } +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotStrategy.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotStrategy.java new file mode 100644 index 00000000000..f627f5a3779 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/SnapshotStrategy.java @@ -0,0 +1,5 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +public interface SnapshotStrategy { + +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.java new file mode 100644 index 00000000000..34cfb2a50ae --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageEvent.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.platform.subsystem.api.storage; + +public enum StorageEvent { + DownloadTemplateToPrimary, + RegisterTemplate, + CreateVolumeFromTemplate; +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java new file mode 100644 index 00000000000..7bc7e30ebd1 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageProvider.java @@ -0,0 +1,20 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.StoragePool; +import com.cloud.utils.component.Adapter; + +public interface StorageProvider extends Adapter { + List supportedHypervisors(); + String getProviderName(); + List supportedStoreTypes(); + void configure(Map storeProviderInfo); + DataStore addDataStore(StoragePool sp, String uri, Map params); + DataStore getDataStore(StoragePool pool); + Map> getDataStoreConfigs(); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java new file mode 100755 index 00000000000..e12ff797ad4 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/StorageSubSystem.java @@ -0,0 +1,13 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +import java.net.URI; + +import com.cloud.org.Grouping; + +public interface StorageSubSystem { + String getType(); + Class getScope(); + + URI grantAccess(String vol, String reservationId); + URI RemoveAccess(String vol, String reservationId); +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java new file mode 100755 index 00000000000..11c7e64169c --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateProfile.java @@ -0,0 +1,287 @@ +// 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 java.util.Map; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.Storage.ImageFormat; +import com.cloud.template.VirtualMachineTemplate; + +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; + VirtualMachineTemplate 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, VirtualMachineTemplate 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 VirtualMachineTemplate getTemplate() { + return template; + } + public void setTemplate(VirtualMachineTemplate 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; + } + + public String getImageStorageUri() { + return null; + } + + public void setLocalPath(String path) { + + } + + public String getLocalPath() { + return null; + } + + public String getJobId() { + return null; + } + + public void setTemplatePoolRefId(long id) { + + } + + public long getId() { + return 0; + } + + public long getTemplatePoolRefId() { + return 0; + } + + public long getSize() { + return 0; + } +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java new file mode 100644 index 00000000000..61ea40a667f --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/TemplateStrategy.java @@ -0,0 +1,13 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + +import com.cloud.agent.api.storage.DownloadCommand.Proxy; + +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/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeProfile.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeProfile.java new file mode 100644 index 00000000000..236ebf592fb --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeProfile.java @@ -0,0 +1,34 @@ +/* + * 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; + +public class VolumeProfile { + private String _uri; + public String getURI() { + return _uri; + } + + public String getPath() { + return null; + } + + public long getSize() { + return 0; + } +} diff --git a/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeStrategy.java b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeStrategy.java new file mode 100644 index 00000000000..207bbba0eb6 --- /dev/null +++ b/engine/api/src/org/apache/cloudstack/platform/subsystem/api/storage/VolumeStrategy.java @@ -0,0 +1,16 @@ +package org.apache.cloudstack.platform.subsystem.api.storage; + + +import com.cloud.storage.Volume; + +public interface VolumeStrategy { + Volume createVolume(Volume vol); + Volume createDataVolume(Volume vol); + Volume copyVolumeFromBackup(VolumeProfile srcVol, Volume destVol); + Volume createVolumeFromSnapshot(SnapshotProfile snapshot, Volume vol); + Volume createVolumeFromTemplate(TemplateProfile template, Volume vol); + Volume migrateVolume(Volume srcVol, Volume destVol, DataStore destStore); + Volume createVolumeFromBaseTemplate(Volume destVol, TemplateProfile tp); + boolean deleteVolume(Volume vol); + VolumeProfile get(long volumeId); +} diff --git a/engine/components-api/pom.xml b/engine/components-api/pom.xml new file mode 100644 index 00000000000..a4f8a44fa2a --- /dev/null +++ b/engine/components-api/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + cloud-engine-components-api + Apache CloudStack Cloud Engine Internal Components API + + org.apache.cloudstack + cloud-engine + 4.1.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.apache.cloudstack + cloud-framework-ipc + ${project.version} + + + + install + src + test + + diff --git a/engine/compute/pom.xml b/engine/compute/pom.xml new file mode 100644 index 00000000000..8fb3ab4fb2b --- /dev/null +++ b/engine/compute/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + cloud-engine-compute + Apache CloudStack Cloud Engine Compute Component + + org.apache.cloudstack + cloud-engine + 4.1.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.apache.cloudstack + cloud-framework-ipc + ${project.version} + + + org.apache.cloudstack + cloud-engine-components-api + ${project.version} + + + + install + src + test + + diff --git a/engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.java b/engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.java new file mode 100755 index 00000000000..8c1c91b043f --- /dev/null +++ b/engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestrator.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.compute; + +import java.util.logging.Handler; + +public interface ComputeOrchestrator { + /** + * start the vm + * @param vm vm + * @param reservationId + */ + @Ipc(topic="cs.compute.start", response="cs.compute.start.response") + void start(@IpcParam String vm, @IpcParam String reservationId, Handler handler); + + @Ipc(topic="cs.compute.cancel") + void cancel(@IpcParam String reservationId); + + @Ipc(topic="cs.compute.stop") + void stop(@IpcParam String vm, @IpcParam String reservationId); +} diff --git a/engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestratorImpl.java b/engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestratorImpl.java new file mode 100755 index 00000000000..5030feb22f8 --- /dev/null +++ b/engine/compute/src/org/apache/cloudstack/compute/ComputeOrchestratorImpl.java @@ -0,0 +1,41 @@ +/* + * 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.compute; + + +public class ComputeOrchestratorImpl implements ComputeOrchestrator { + + @Override + public void start(String vm, String reservationId) { + // Retrieve the VM + // Locate the HypervisorGuru based on the VM type + // Call HypervisorGuru to start the VM + } + + @Override + public void cancel(String reservationId) { + } + + @Override + public void stop(String vm, String reservationId) { + // Retrieve the VM + // Locate the HypervisorGuru based on the VM type + // Call HypervisorGuru to stop the VM + } +} diff --git a/engine/network/pom.xml b/engine/network/pom.xml new file mode 100644 index 00000000000..f0680bc7ded --- /dev/null +++ b/engine/network/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + cloud-engine-network + Apache CloudStack Cloud Engine API + + org.apache.cloudstack + cloud-engine + 4.1.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.apache.cloudstack + cloud-engine-components-api + ${project.version} + + + org.apache.cloudstack + cloud-framework-ipc + ${project.version} + + + + install + src + test + + diff --git a/engine/network/src/org/apache/cloudstack/network/NetworkOrchestrator.java b/engine/network/src/org/apache/cloudstack/network/NetworkOrchestrator.java new file mode 100755 index 00000000000..82756ac8391 --- /dev/null +++ b/engine/network/src/org/apache/cloudstack/network/NetworkOrchestrator.java @@ -0,0 +1,40 @@ +/* + * 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.network; + +public interface NetworkOrchestrator { + + /** + * Prepares for a VM to join a network + * @param vm vm + * @param reservationId reservation id + */ + void prepare(String vm, String reservationId); + + /** + * Release all reservation + */ + void release(String vm, String reservationId); + + /** + * Cancel a previous reservation + * @param reservationId + */ + void cancel(String reservationId); +} diff --git a/engine/orchestration/pom.xml b/engine/orchestration/pom.xml new file mode 100755 index 00000000000..2f03547b676 --- /dev/null +++ b/engine/orchestration/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + cloud-engine-orchestration + Apache CloudStack Cloud Engine Orchestration Component + + org.apache.cloudstack + cloud-engine + 4.1.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.apache.cloudstack + cloud-framework-ipc + ${project.version} + + + org.apache.cloudstack + cloud-engine-components-api + ${project.version} + + + + install + src + test + + diff --git a/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java new file mode 100755 index 00000000000..34154ad3b7c --- /dev/null +++ b/engine/orchestration/src/org/apache/cloudstack/platform/orchestration/CloudOrchestrator.java @@ -0,0 +1,82 @@ +/* + * 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.orchestration; + +import java.net.URL; +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.platform.cloud.entity.api.VirtualMachineEntity; +import org.apache.cloudstack.platform.cloud.entity.api.VolumeEntity; +import org.apache.cloudstack.platform.service.api.OrchestrationService; + +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.hypervisor.Hypervisor; + + +public class CloudOrchestrator implements OrchestrationService { + + public VirtualMachineEntity create(String name, String template, String hostName, int cpu, int speed, long memory, List networks, List rootDiskTags, List computeTags, + Map details, String owner) { + // TODO Auto-generated method stub + return null; + } + + public VirtualMachineEntity createFromScratch(String uuid, String iso, String os, String hypervisor, String hostName, int cpu, int speed, long memory, List networks, List computeTags, + Map details, String owner) { + // TODO Auto-generated method stub + return null; + } + + public String reserve(String vm, String planner, Long until) throws InsufficientCapacityException { + // TODO Auto-generated method stub + return null; + } + + public String deploy(String reservationId) { + // TODO Auto-generated method stub + return null; + } + + public void joinNetwork(String network1, String network2) { + // TODO Auto-generated method stub + + } + + public void createNetwork() { + // TODO Auto-generated method stub + + } + + public void destroyNetwork() { + // TODO Auto-generated method stub + + } + + public VolumeEntity createVolume() { + // TODO Auto-generated method stub + return null; + } + + public void registerTemplate(String name, URL path, String os, Hypervisor hypervisor) { + // TODO Auto-generated method stub + + } + +} diff --git a/engine/planning/src/org/apache/cloudstack/platform/planning/Concierge.java b/engine/planning/src/org/apache/cloudstack/platform/planning/Concierge.java new file mode 100755 index 00000000000..97dfb2bbfe6 --- /dev/null +++ b/engine/planning/src/org/apache/cloudstack/platform/planning/Concierge.java @@ -0,0 +1,36 @@ +/* + * 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.planning; + +import org.apache.cloudstack.framework.ipc.Ipc; + +public interface Concierge { + @Ipc(topic="cs.concierge.reserve") + String reserve(String vm, String planner, Long until); + + @Ipc(topic="cs.concierge.cancel") + String cancel(String reservationId); + + @Ipc(topic="cs.concierge.claim") + String claim(String reservationId); + + @Ipc(topic="cs.concierge.reserveAnother") + String reserveAnother(String reservationId); + +} diff --git a/engine/pom.xml b/engine/pom.xml new file mode 100644 index 00000000000..ba8b738f57f --- /dev/null +++ b/engine/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + cloud-engine + Apache CloudStack Cloud Engine + pom + + org.apache.cloudstack + cloudstack + 4.1.0-SNAPSHOT + ../pom.xml + + + install + src + test + + + api + compute + orchestration + storage + components-api + schema + network + + diff --git a/engine/schema/pom.xml b/engine/schema/pom.xml new file mode 100644 index 00000000000..3e38a840571 --- /dev/null +++ b/engine/schema/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + cloud-engine-schema + Apache CloudStack Cloud Engine Schema Component + + org.apache.cloudstack + cloud-engine + 4.1.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.apache.cloudstack + cloud-framework-ipc + ${project.version} + + + org.apache.cloudstack + cloud-engine-components-api + ${project.version} + + + + install + src + test + + diff --git a/engine/storage/pom.xml b/engine/storage/pom.xml new file mode 100644 index 00000000000..f922a2183bd --- /dev/null +++ b/engine/storage/pom.xml @@ -0,0 +1,85 @@ + + + 4.0.0 + cloud-engine-storage + Apache CloudStack Engine Storage Component + + org.apache.cloudstack + cloud-engine + 4.1.0-SNAPSHOT + ../pom.xml + + + + org.apache.cloudstack + cloud-api + ${project.version} + + + org.apache.cloudstack + cloud-core + ${project.version} + + + org.apache.cloudstack + cloud-server + ${project.version} + + + org.apache.cloudstack + cloud-engine-components-api + ${project.version} + + + org.apache.cloudstack + cloud-engine-api + ${project.version} + + + org.apache.openjpa + openjpa + 2.2.0 + + + mysql + mysql-connector-java + ${cs.mysql.version} + provided + + + org.mockito + mockito-all + 1.9.5 + + + org.aspectj + aspectjrt + 1.7.1 + + + org.aspectj + aspectjweaver + 1.7.1 + + + javax.inject + javax.inject + 1 + + + + install + src + test + + diff --git a/engine/storage/src/org/apache/cloudstack/storage/BaseType.java b/engine/storage/src/org/apache/cloudstack/storage/BaseType.java new file mode 100644 index 00000000000..12acc7d65a9 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/BaseType.java @@ -0,0 +1,40 @@ +/* + * 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; + +public abstract class BaseType { + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that instanceof String) { + if (this.toString().equalsIgnoreCase((String)that)) { + return true; + } + } else if (that instanceof BaseType) { + BaseType th = (BaseType)that; + if (this.toString().equalsIgnoreCase(th.toString())) { + return true; + } + } else { + return false; + } + return false; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/EndPoint.java b/engine/storage/src/org/apache/cloudstack/storage/EndPoint.java new file mode 100644 index 00000000000..0a3dfa2d28d --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/EndPoint.java @@ -0,0 +1,8 @@ +package org.apache.cloudstack.storage; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; + +public interface EndPoint { + public Answer sendMessage(Command cmd); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPoint.java b/engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPoint.java new file mode 100644 index 00000000000..8bd51c7c580 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/HypervisorHostEndPoint.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; + +import javax.inject.Inject; + +import org.apache.log4j.Logger; + +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; +import com.cloud.exception.AgentUnavailableException; +import com.cloud.exception.OperationTimedoutException; + +public class HypervisorHostEndPoint implements EndPoint { + private static final Logger s_logger = Logger.getLogger(HypervisorHostEndPoint.class); + private long hostId; + @Inject + AgentManager agentMgr; + public HypervisorHostEndPoint(long hostId) { + this.hostId = hostId; + } + + @Override + public Answer sendMessage(Command cmd) { + Answer answer = null; + try { + answer = agentMgr.send(hostId, cmd); + } catch (AgentUnavailableException e) { + s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString()); + } catch (OperationTimedoutException e) { + s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString()); + } catch (Exception e) { + s_logger.debug("Unable to send command:" + cmd + ", due to: " + e.toString()); + } + return answer; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java b/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java new file mode 100755 index 00000000000..691c413b793 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestrator.java @@ -0,0 +1,59 @@ +/* + * 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; + +import java.util.List; + +import com.cloud.deploy.DeploymentPlan; + +public interface StorageOrchestrator { + + /** + * Prepares all storage ready for a VM to start + * @param vm + * @param reservationId + */ + void prepare(long vmId, DeploymentPlan plan, String reservationId); + + /** + * Releases all storage that were used for a VM shutdown + * @param vm + * @param disks + * @param reservationId + */ + void release(long vmId, String reservationId); + + /** + * Destroy all disks + * @param disks + * @param reservationId + */ + void destroy(List disks, String reservationId); + + /** + * Cancel a reservation + * @param reservationId reservation to + */ + void cancel(String reservationId); + + /** + * If attaching a volume in allocated state to a running vm, need to create this volume + */ + void prepareAttachDiskToVM(long diskId, long vmId, String reservationId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java b/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java new file mode 100644 index 00000000000..7c88cae04da --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/StorageOrchestratorImpl.java @@ -0,0 +1,315 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataObjectBackupStorageOperationState; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider; +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.image.ImageManager; +import org.apache.cloudstack.storage.manager.BackupStorageManager; +import org.apache.cloudstack.storage.manager.SecondaryStorageManager; +import org.apache.cloudstack.storage.volume.VolumeManager; +import org.apache.log4j.Logger; + +import com.cloud.deploy.DeploymentPlan; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.offering.DiskOffering; +import com.cloud.storage.DiskOfferingVO; +import com.cloud.storage.StoragePool; +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeVO; +import com.cloud.storage.dao.DiskOfferingDao; +import com.cloud.storage.dao.StoragePoolDao; +import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.storage.dao.VolumeHostDao; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.utils.component.Inject; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.fsm.NoTransitionException; +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.dao.VMInstanceDao; + +public class StorageOrchestratorImpl implements StorageOrchestrator { + private static final Logger s_logger = Logger.getLogger(StorageOrchestratorImpl.class); + @Inject + StoragePoolDao _storagePoolDao; + @Inject + StorageProviderManager _spManager; + @Inject + VolumeDao _volumeDao; + @Inject + VMInstanceDao _vmDao; + @Inject + DiskOfferingDao _diskOfferingDao; + @Inject + VolumeHostDao _volumeHostDao; + @Inject + StorageProviderManager _storageProviderMgr; + @Inject + VolumeManager _volumeMgr; + @Inject + SecondaryStorageManager _secondaryStorageMgr; + @Inject + ImageManager _templateMgr; + @Inject + VMTemplateDao _templateDao; + + @DB + protected Volume copyVolumeFromBackupStorage(VolumeVO volume, DataStore destStore, String reservationId) throws NoTransitionException { + DataStore ds = _secondaryStorageMgr.getStore(volume); + if (!ds.contains(volume)) { + throw new CloudRuntimeException("volume: " + volume + "doesn't exist on backup storage"); + } + + VolumeProfile vp = ds.prepareVolume(volume, destStore); + + VolumeStrategy vs = destStore.getVolumeStrategy(); + + Transaction txn = Transaction.currentTxn(); + volume.setReservationId(reservationId); + _volumeMgr.processEvent(volume, Volume.Event.CopyRequested); + VolumeVO destVolume = _volumeMgr.allocateDuplicateVolume(volume); + destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested); + txn.commit(); + + vs.copyVolumeFromBackup(vp, destVolume); + + txn.start(); + volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); + destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded); + txn.commit(); + + return destVolume; + } + + @DB + protected Volume migrateVolume(VolumeVO volume, DataStore srcStore, DataStore destStore, String reservationId) throws NoTransitionException { + Transaction txn = Transaction.currentTxn(); + txn.start(); + volume.setReservationId(reservationId); + volume = _volumeMgr.processEvent(volume, Volume.Event.MigrationRequested); + Volume destVolume = _volumeMgr.allocateDuplicateVolume(volume); + destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested); + txn.commit(); + + VolumeStrategy vs = srcStore.getVolumeStrategy(); + vs.migrateVolume(volume, destVolume, destStore); + + txn.start(); + volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); + destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded); + txn.commit(); + + volume = _volumeMgr.processEvent(volume, Volume.Event.DestroyRequested); + + vs.deleteVolume(volume); + + _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); + return destVolume; + } + + @DB + protected Volume recreateVolume(VolumeVO srcVolume, DataStore destStore, String reservationId) throws NoTransitionException { + Transaction txn = Transaction.currentTxn(); + txn.start(); + srcVolume.setReservationId(reservationId); + srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.CopyRequested); + Volume destVolume = _volumeMgr.allocateDuplicateVolume(srcVolume); + destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.CreateRequested); + txn.commit(); + + DataStore srcStore = _storageProviderMgr.getDataStore(srcVolume.getPoolId()); + VolumeStrategy vs = srcStore.getVolumeStrategy(); + + vs.migrateVolume(srcVolume, destVolume, destStore); + + txn.start(); + srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.OperationSucceeded); + destVolume = _volumeMgr.processEvent(destVolume, Volume.Event.OperationSucceeded); + txn.commit(); + + srcVolume = _volumeMgr.processEvent(srcVolume, Volume.Event.DestroyRequested); + + vs.deleteVolume(srcVolume); + + _volumeMgr.processEvent(srcVolume, Volume.Event.OperationSucceeded); + + return destVolume; + } + + protected Volume createVolumeOnStorage(Volume volume, DataStore destStore, String reservationId) throws NoTransitionException { + VolumeStrategy vs = destStore.getVolumeStrategy(); + volume.setReservationId(reservationId); + volume = _volumeMgr.processEvent(volume, Volume.Event.CreateRequested); + + if (volume.getTemplateId() != null) { + DataStore ds = _secondaryStorageMgr.getImageStore(destStore); + TemplateProfile tp = ds.prepareTemplate(volume.getTemplateId(), destStore); + if (!destStore.contains(tp)) { + tp = _templateMgr.AssociateTemplateStoragePool(tp, destStore); + tp = destStore.getTemplateStrategy().install(tp); + } else { + tp = destStore.getTemplateStrategy().get(tp.getId()); + } + volume = vs.createVolumeFromBaseTemplate(volume, tp); + } else { + volume = vs.createDataVolume(volume); + } + + volume = _volumeMgr.processEvent(volume, Volume.Event.OperationSucceeded); + return volume; + } + + @DB + protected void prepareVolumes(List vols, Long destPoolId, String reservationId) throws NoTransitionException { + DataStore destStore = null; + if (destPoolId != null) { + destStore = _storageProviderMgr.getDataStore(destPoolId); + } + + for (VolumeVO volume : vols) { + if (volume.getPoolId() == null && destStore == null) { + throw new CloudRuntimeException("Volume has no pool associate and also no storage pool assigned in DeployDestination, Unable to create."); + } + if (destStore == null) { + continue; + } + + DataStore srcStore = _storageProviderMgr.getDataStore(volume.getPoolId()); + boolean needToCreateVolume = false; + boolean needToRecreateVolume = false; + boolean needToMigrateVolume = false; + boolean needToCopyFromSec = false; + + Volume.State state = volume.getState(); + if (state == Volume.State.Allocated) { + needToCreateVolume = true; + } else if (state == Volume.State.UploadOp) { + needToCopyFromSec = true; + } else if (destStore.getId() != srcStore.getId()) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Mismatch in storage pool " + destStore.getId() + " assigned by deploymentPlanner and the one associated with volume " + volume); + } + + if (volume.isRecreatable()) { + needToRecreateVolume = true; + } else { + if (Volume.Type.ROOT == volume.getVolumeType()) { + needToMigrateVolume = true; + } else { + if (destStore.getCluterId() != srcStore.getCluterId()) { + needToMigrateVolume = true; + } else if (!srcStore.isSharedStorage() && srcStore.getId() != destStore.getId()) { + needToMigrateVolume = true; + } else { + continue; + } + } + } + } else { + continue; + } + + + if (needToCreateVolume) { + createVolumeOnStorage(volume, destStore, reservationId); + } else if (needToMigrateVolume) { + migrateVolume(volume, srcStore, destStore, reservationId); + } else if (needToCopyFromSec) { + copyVolumeFromBackupStorage(volume, destStore, reservationId); + } else if (needToRecreateVolume) { + recreateVolume(volume, destStore, reservationId); + } + } + } + + public void prepare(long vmId, DeploymentPlan plan, String reservationId) { + VirtualMachine vm = _vmDao.findById(vmId); + + + List vols = _volumeDao.findUsableVolumesForInstance(vm.getId()); + if (s_logger.isDebugEnabled()) { + s_logger.debug("Prepare " + vols.size() + " volumes for " + vm.getInstanceName()); + } + + try { + prepareVolumes(vols, plan.getPoolId(), reservationId); + } catch (NoTransitionException e) { + s_logger.debug("Failed to prepare volume: " + e.toString()); + } + } + + + public void release(long vmId, String reservationId) { + // TODO Auto-generated method stub + + } + + public void destroy(List disks, String reservationId) { + // TODO Auto-generated method stub + + } + + public void cancel(String reservationId) { + // TODO Auto-generated method stub + + } + + public void prepareAttachDiskToVM(long diskId, long vmId, String reservationId) { + VirtualMachine vm = _vmDao.findById(vmId); + + if (vm == null || vm.getState() != VirtualMachine.State.Running) { + return; + } + + VolumeVO volume = _volumeDao.findById(diskId); + if (volume.getInstanceId() != null) { + if (volume.getInstanceId() != vmId) { + throw new InvalidParameterValueException("Volume " + volume + "already attached to " + volume.getInstanceId()); + } else { + return; + } + } + + List vols = new ArrayList(); + vols.add(volume); + + List rootDisks = _volumeDao.findByInstanceAndType(vmId, Volume.Type.ROOT); + VolumeVO rootDisk = rootDisks.get(0); + try { + prepareVolumes(vols, rootDisk.getPoolId(), reservationId); + } catch (NoTransitionException e) { + s_logger.debug("Failed to prepare volume: " + volume + ", due to" + e.toString()); + throw new CloudRuntimeException(e.toString()); + } + + volume = _volumeDao.findById(diskId); + volume.setInstanceId(vmId); + _volumeDao.update(volume.getId(), volume); + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/StorageProviderManager.java b/engine/storage/src/org/apache/cloudstack/storage/StorageProviderManager.java new file mode 100644 index 00000000000..e7b03a788ab --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/StorageProviderManager.java @@ -0,0 +1,11 @@ +package org.apache.cloudstack.storage; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider; + +public interface StorageProviderManager { + StorageProvider getProvider(String uuid); + StorageProvider getProvider(long poolId); + StorageProvider getBackupStorageProvider(long zoneId); + DataStore getDataStore(long poolId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/StorageProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/StorageProviderManagerImpl.java new file mode 100644 index 00000000000..6bfdf1dda32 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/StorageProviderManagerImpl.java @@ -0,0 +1,55 @@ +package org.apache.cloudstack.storage; + +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.StorageProvider; + +import com.cloud.utils.component.Manager; + +public class StorageProviderManagerImpl implements StorageProviderManager, Manager { + + public StorageProvider getProvider(String uuid) { + // TODO Auto-generated method stub + return null; + } + + public boolean configure(String name, Map params) + throws ConfigurationException { + // TODO Auto-generated method stub + return false; + } + + public boolean start() { + // TODO Auto-generated method stub + return false; + } + + public boolean stop() { + // TODO Auto-generated method stub + return false; + } + + public String getName() { + // TODO Auto-generated method stub + return null; + } + + public StorageProvider getProvider(long poolId) { + // TODO Auto-generated method stub + return null; + } + + public StorageProvider getBackupStorageProvider(long zoneId) { + // TODO Auto-generated method stub + return null; + } + + public DataStore getDataStore(long poolId) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/VolumeBackupRef.java b/engine/storage/src/org/apache/cloudstack/storage/VolumeBackupRef.java new file mode 100644 index 00000000000..64402d357f1 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/VolumeBackupRef.java @@ -0,0 +1,66 @@ +/* + * 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; + +import java.util.Date; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataObjectBackupStorageOperationState; + +import com.cloud.storage.Storage; +import com.cloud.storage.VMTemplateStorageResourceAssoc; +import com.cloud.storage.Storage.ImageFormat; +import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; + +public interface VolumeBackupRef { + public DataObjectBackupStorageOperationState getOperationState(); + + public String getInstallPath(); + + public long getHostId(); + + public long getVolumeId(); + + public long getZoneId(); + + public int getDownloadPercent(); + + public long getVolumeSize(); + + public Storage.ImageFormat getFormat(); + + public String getDownloadUrl(); + + public boolean getDestroyed(); + + public long getPhysicalSize(); + + public long getSize(); + + public String getLocalDownloadPath(); + + public String getChecksum(); + + public Status getDownloadState(); + + public Date getLastUpdated(); + + public Date getCreated(); + + public long getId(); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/backup/BackupMotionService.java b/engine/storage/src/org/apache/cloudstack/storage/backup/BackupMotionService.java new file mode 100644 index 00000000000..5105e25983e --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/backup/BackupMotionService.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.backup; + +public interface BackupMotionService { + boolean copySnapshot(String snapshotUri, String destSnapshotUri); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/backup/BackupService.java b/engine/storage/src/org/apache/cloudstack/storage/backup/BackupService.java new file mode 100644 index 00000000000..198247dec2a --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/backup/BackupService.java @@ -0,0 +1,24 @@ +/* + * 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.backup; + +public interface BackupService { + String grantAccessSnapshot(long snapshotId, long endpointId); + boolean revokeAccessSnapshot(long snapshotId, long endpointId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeAnswer.java b/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeAnswer.java new file mode 100644 index 00000000000..e75307c547d --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeAnswer.java @@ -0,0 +1,36 @@ +/* + * 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.command; + +import com.cloud.agent.api.Answer; + +public class CreateVolumeAnswer extends Answer { + private String volumeUuid; + protected CreateVolumeAnswer() { + super(); + } + + public CreateVolumeAnswer(String volumeUuid) { + this.volumeUuid = volumeUuid; + } + + public String getVolumeUuid() { + return this.volumeUuid; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java b/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java new file mode 100644 index 00000000000..243e0167da1 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/command/CreateVolumeCommand.java @@ -0,0 +1,42 @@ +/* + * 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.command; + +import org.apache.cloudstack.storage.volume.VolumeInfo; + +import com.cloud.agent.api.Command; + +public class CreateVolumeCommand extends Command { + protected VolumeInfo volumeInfo; + public CreateVolumeCommand(VolumeInfo volumeInfo) { + super(); + this.volumeInfo = volumeInfo; + } + + protected CreateVolumeCommand() { + super(); + } + + @Override + public boolean executeInSequence() { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreStatus.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreStatus.java new file mode 100644 index 00000000000..65f46b1e156 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DataStoreStatus.java @@ -0,0 +1,29 @@ +/* + * 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.datastore; + +public enum DataStoreStatus { + Creating, + Up, + PrepareForMaintenance, + ErrorInMaintenance, + CancelMaintenance, + Maintenance, + Removed; +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultDataStore.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultDataStore.java new file mode 100644 index 00000000000..0e7bb602feb --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultDataStore.java @@ -0,0 +1,229 @@ +package org.apache.cloudstack.storage.datastore; + +import org.apache.cloudstack.platform.subsystem.api.storage.BackupStrategy; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPointSelector; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle; +import org.apache.cloudstack.platform.subsystem.api.storage.FileSystem; +import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotProfile; +import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotStrategy; +import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider; +import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile; +import org.apache.cloudstack.platform.subsystem.api.storage.TemplateStrategy; +import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile; +import org.apache.cloudstack.platform.subsystem.api.storage.VolumeStrategy; + +import com.cloud.agent.api.to.StorageFilerTO; +import com.cloud.storage.Snapshot; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.storage.Volume; + +public class DefaultDataStore implements DataStore { + protected VolumeStrategy _volumeStrategy; + protected SnapshotStrategy _snapshotStrategy; + protected BackupStrategy _backupStrategy; + protected TemplateStrategy _templateStrategy; + protected String _uri; + protected String _uuid; + protected StoreType _type; + protected StoreScope _scope; + protected long _poolId; + protected DataStoreDriver _driverRef; + protected DataStoreEndPointSelector _selector; + protected FileSystem _fs; + protected VolumeStrategy _volumeSt; + protected SnapshotStrategy _snapshotSt; + protected BackupStrategy _backupSt; + protected long _id; + protected DataStoreLifeCycle _dslf; + + public DefaultDataStore( + ) { + } + + public String getURI() { + // TODO Auto-generated method stub + return null; + } + + public void setURI(String uri) { + this._uri = uri; + } + + public String getUUID() { + return this._uuid; + } + + public void setUUID(String uuid) { + this._uuid = uuid; + } + + public StoreType getType() { + return this._type; + } + + public void setType(StoreType type) { + this._type = type; + } + + public StoreScope getScope() { + return this._scope; + } + + public void setScope(StoreScope scope) { + this._scope = scope; + } + + public Long getId() { + return this._id; + } + + public void setId(long id) { + this._id = id; + } + + public DataStoreDriver getDataStoreDriver() { + return this._driverRef; + } + + public void setDataStoreDriver(DataStoreDriver drv) { + this._driverRef = drv; + } + + public void setEndPointSelector(DataStoreEndPointSelector selector) { + this._selector = selector; + } + + public DataStoreEndPointSelector getSelector() { + return this._selector; + } + + public FileSystem getFileSystem() { + return this._fs; + } + + public void setFileSystem(FileSystem fs) { + this._fs = fs; + } + + public VolumeStrategy getVolumeStrategy() { + return this._volumeSt; + } + + public void setVolumeStrategy(VolumeStrategy vs) { + this._volumeSt = vs; + } + + public SnapshotStrategy getSnapshotStrategy() { + return this._snapshotSt; + } + + public void setSnapshotStrategy(SnapshotStrategy ss) { + this._snapshotSt = ss; + } + + public BackupStrategy getBackupStrategy() { + return this._backupSt; + } + + public void setBackupStrategy(BackupStrategy bs) { + this._backupSt = bs; + } + + public TemplateStrategy getTemplateStrategy() { + return this._templateStrategy; + } + + public void setTemplateStrategy(TemplateStrategy ts) { + this._templateStrategy = ts; + } + + public DataStoreLifeCycle getLifeCycle() { + return this._dslf; + } + + public void setLifeCycle(DataStoreLifeCycle lf) { + this._dslf = lf; + } + + public long getCluterId() { + // TODO Auto-generated method stub + return 0; + } + + public long getPodId() { + // TODO Auto-generated method stub + return 0; + } + + public long getZoneId() { + // TODO Auto-generated method stub + return 0; + } + + public String getPath() { + // TODO Auto-generated method stub + return null; + } + + public StoragePoolType getPoolType() { + // TODO Auto-generated method stub + return null; + } + + public boolean isSharedStorage() { + // TODO Auto-generated method stub + return false; + } + + public StorageProvider getProvider() { + // TODO Auto-generated method stub + return null; + } + + public DataStoreEndPointSelector getEndPointSelector() { + // TODO Auto-generated method stub + return null; + } + + public VolumeProfile prepareVolume(Volume volume, DataStore destStore) { + // TODO Auto-generated method stub + return null; + } + + public SnapshotProfile prepareSnapshot(Snapshot snapshot, DataStore destStore) { + // TODO Auto-generated method stub + return null; + } + + public TemplateProfile prepareTemplate(long templateId, DataStore destStore) { + // TODO Auto-generated method stub + return null; + } + + public boolean contains(Volume volume) { + // TODO Auto-generated method stub + return false; + } + + public boolean contains(Snapshot snapshot) { + // TODO Auto-generated method stub + return false; + } + + public boolean contains(TemplateProfile template) { + // TODO Auto-generated method stub + return false; + } + + public TemplateProfile get(TemplateProfile template) { + // TODO Auto-generated method stub + return null; + } + + public StorageFilerTO getTO() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java new file mode 100644 index 00000000000..ea22b2314cd --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/DefaultPrimaryDataStoreImpl.java @@ -0,0 +1,118 @@ +package org.apache.cloudstack.storage.datastore; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.inject.Inject; + +import org.apache.cloudstack.storage.EndPoint; +import org.apache.cloudstack.storage.HypervisorHostEndPoint; +import org.apache.cloudstack.storage.datastore.db.DataStoreVO; +import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver; +import org.apache.cloudstack.storage.volume.Volume; +import org.apache.cloudstack.storage.volume.VolumeEvent; +import org.apache.cloudstack.storage.volume.db.VolumeDao; +import org.apache.cloudstack.storage.volume.db.VolumeVO; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.log4j.Logger; + +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.utils.component.ComponentInject; +import com.cloud.utils.exception.CloudRuntimeException; + +import edu.emory.mathcs.backport.java.util.Collections; + +public class DefaultPrimaryDataStoreImpl implements PrimaryDataStore { + private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreImpl.class); + protected PrimaryDataStoreDriver driver; + protected DataStoreVO pdsv; + protected PrimaryDataStoreInfo pdsInfo; + @Inject + private VolumeDao volumeDao; + @Inject + private HostDao hostDao; + public DefaultPrimaryDataStoreImpl(PrimaryDataStoreDriver driver, DataStoreVO pdsv, PrimaryDataStoreInfo pdsInfo) { + this.driver = driver; + this.pdsv = pdsv; + this.pdsInfo = pdsInfo; + } + + @Override + public Volume getVolume(long id) { + VolumeVO volumeVO = volumeDao.findById(id); + Volume vol = new Volume(this, volumeVO); + return vol; + } + + @Override + public List getVolumes() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean deleteVolume(long id) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Volume createVolume(long id, VolumeDiskType diskType) { + Volume vol = this.getVolume(id); + if (vol == null) { + return null; + } + + if (!pdsInfo.isVolumeDiskTypeSupported(diskType)) { + return null; + } + + boolean result = vol.stateTransit(VolumeEvent.CreateRequested); + if (!result) { + return null; + } + + try { + vol.setVolumeDiskType(diskType); + result = this.driver.createVolume(vol); + vol.update(); + return vol; + } catch (Exception e) { + result = false; + s_logger.debug("Failed to create volume: " + e.toString()); + throw new CloudRuntimeException(e.toString()); + } finally { + if (result == true) { + vol.stateTransit(VolumeEvent.OperationSucceeded); + } else { + vol.stateTransit(VolumeEvent.OperationFailed); + } + } + + } + + @Override + public List getEndPoints() { + Long clusterId = pdsv.getClusterId(); + if (clusterId == null) { + return null; + } + List endpoints = new ArrayList(); + List hosts = hostDao.findHypervisorHostInCluster(clusterId); + for (HostVO host : hosts) { + HypervisorHostEndPoint ep = new HypervisorHostEndPoint(host.getId()); + ComponentInject.inject(ep); + endpoints.add(ep); + } + Collections.shuffle(endpoints); + return endpoints; + } + + @Override + public PrimaryDataStoreInfo getDataStoreInfo() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java new file mode 100644 index 00000000000..7efa56177ea --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java @@ -0,0 +1,34 @@ +/* + * 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.datastore; + +import java.util.List; + +import org.apache.cloudstack.storage.EndPoint; +import org.apache.cloudstack.storage.volume.Volume; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; + +public interface PrimaryDataStore { + Volume getVolume(long id); + List getVolumes(); + boolean deleteVolume(long id); + Volume createVolume(long id, VolumeDiskType diskType); + List getEndPoints(); + PrimaryDataStoreInfo getDataStoreInfo(); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfo.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfo.java new file mode 100644 index 00000000000..d30a5c8d221 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfo.java @@ -0,0 +1,31 @@ +/* + * 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.datastore; + +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; + +public interface PrimaryDataStoreInfo { + public boolean isHypervisorSupported(HypervisorType hypervisor); + public boolean isLocalStorageSupported(); + public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType); + public long getCapacity(); + public long getAvailableCapacity(); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfoImpl.java new file mode 100644 index 00000000000..c453d33e93b --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStoreInfoImpl.java @@ -0,0 +1,68 @@ +/* + * 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.datastore; + +import java.util.List; + +import org.apache.cloudstack.storage.datastore.db.DataStoreVO; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; + +public class PrimaryDataStoreInfoImpl implements PrimaryDataStoreInfo { + protected List supportedHypervs; + protected List supportedDiskTypes; + protected long caapcity; + protected long avail; + protected boolean localStorage; + + public PrimaryDataStoreInfoImpl(List hypers, List diskTypes, + long capacity, long avail, boolean localStorage) { + this.avail = avail; + this.caapcity = capacity; + this.localStorage = localStorage; + this.supportedDiskTypes = diskTypes; + this.supportedHypervs = hypers; + } + + @Override + public boolean isHypervisorSupported(HypervisorType hypervisor) { + return this.supportedHypervs.contains(hypervisor) ? true : false; + } + + @Override + public boolean isLocalStorageSupported() { + return this.localStorage; + } + + @Override + public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType) { + return this.supportedDiskTypes.contains(diskType) ? true : false; + } + + @Override + public long getCapacity() { + return this.caapcity; + } + + @Override + public long getAvailableCapacity() { + return this.avail; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/DataStoreVO.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/DataStoreVO.java new file mode 100644 index 00000000000..52f3bbf1e74 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/DataStoreVO.java @@ -0,0 +1,258 @@ +/* + * 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.datastore.db; + +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import org.apache.cloudstack.storage.datastore.DataStoreStatus; + +import com.cloud.api.Identity; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name="storage_pool") +public class DataStoreVO implements Identity { + @Id + @TableGenerator(name="storage_pool_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="storage_pool_seq", allocationSize=1) + @Column(name="id", updatable=false, nullable = false) + private long id; + + @Column(name="name", updatable=false, nullable=false, length=255) + private String name = null; + + @Column(name="uuid", length=255) + private String uuid = null; + + @Column(name="pool_type", updatable=false, nullable=false, length=32) + private String protocol; + + @Column(name=GenericDao.CREATED_COLUMN) + Date created; + + @Column(name=GenericDao.REMOVED_COLUMN) + private Date removed; + + @Column(name="update_time", updatable=true) + @Temporal(value=TemporalType.TIMESTAMP) + private Date updateTime; + + @Column(name="data_center_id", updatable=true, nullable=false) + private long dataCenterId; + + @Column(name="pod_id", updatable=true) + private Long podId; + + @Column(name="available_bytes", updatable=true, nullable=true) + private long availableBytes; + + @Column(name="capacity_bytes", updatable=true, nullable=true) + private long capacityBytes; + + @Column(name="status", updatable=true, nullable=false) + @Enumerated(value=EnumType.STRING) + private DataStoreStatus status; + + @Column(name="storage_provider", updatable=true, nullable=false) + private Long storageProvider; + + @Column(name="storage_type", nullable=false) + private String storageType; + + @Column(name="host_address") + private String hostAddress; + + @Column(name="path") + private String path; + + @Column(name="port") + private int port; + + @Column(name="user_info") + private String userInfo; + + @Column(name="cluster_id") + private Long clusterId; + + public long getId() { + return id; + } + + public DataStoreStatus getStatus() { + return status; + } + + public DataStoreVO() { + // TODO Auto-generated constructor stub + } + + public String getName() { + return name; + } + + public String getUuid() { + return uuid; + } + + + public String getPoolType() { + return protocol; + } + + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } + + public Date getUpdateTime() { + return updateTime; + } + + public long getDataCenterId() { + return dataCenterId; + } + + public long getAvailableBytes() { + return availableBytes; + } + + public Long getStorageProviderId() { + return storageProvider; + } + + public void setStorageProviderId(Long provider) { + storageProvider = provider; + } + + public String getStorageType() { + return storageType; + } + + public void setStorageType(String type) { + storageType = type; + } + + public long getCapacityBytes() { + return capacityBytes; + } + + public void setAvailableBytes(long available) { + availableBytes = available; + } + + public void setCapacityBytes(long capacity) { + capacityBytes = capacity; + } + + + public Long getClusterId() { + return clusterId; + } + + public void setClusterId(Long clusterId) { + this.clusterId = clusterId; + } + + public String getHostAddress() { + return hostAddress; + } + + public String getPath() { + return path; + } + + public String getUserInfo() { + return userInfo; + } + + public void setStatus(DataStoreStatus status) + { + this.status = status; + } + + public void setId(long id) { + this.id = id; + } + + public void setDataCenterId(long dcId) { + this.dataCenterId = dcId; + } + + public void setPodId(Long podId) { + this.podId = podId; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setPath(String path) { + this.path = path; + } + + public void setUserInfo(String userInfo) { + this.userInfo = userInfo; + } + + public int getPort() { + return port; + } + + public Long getPodId() { + return podId; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof DataStoreVO) || obj == null) { + return false; + } + DataStoreVO that = (DataStoreVO)obj; + return this.id == that.id; + } + + @Override + public int hashCode() { + return new Long(id).hashCode(); + } + + @Override + public String toString() { + return new StringBuilder("Pool[").append(id).append("|").append(protocol).append("]").toString(); + } +} \ No newline at end of file diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java new file mode 100644 index 00000000000..8016559a6b9 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java @@ -0,0 +1,106 @@ +/* + * 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.datastore.db; + +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.storage.datastore.DataStoreStatus; + +import com.cloud.utils.db.GenericDao; + + +public interface PrimaryDataStoreDao extends GenericDao { + + /** + * @param datacenterId -- the id of the datacenter (availability zone) + */ + List listByDataCenterId(long datacenterId); + + /** + * @param datacenterId -- the id of the datacenter (availability zone) + */ + List listBy(long datacenterId, long podId, Long clusterId); + + /** + * Set capacity of storage pool in bytes + * @param id pool id. + * @param capacity capacity in bytes + */ + void updateCapacity(long id, long capacity); + + /** + * Set available bytes of storage pool in bytes + * @param id pool id. + * @param available available capacity in bytes + */ + void updateAvailable(long id, long available); + + + DataStoreVO persist(DataStoreVO pool, Map details); + + /** + * Find pool by name. + * + * @param name name of pool. + * @return the single StoragePoolVO + */ + List findPoolByName(String name); + + /** + * Find pools by the pod that matches the details. + * + * @param podId pod id to find the pools in. + * @param details details to match. All must match for the pool to be returned. + * @return List of StoragePoolVO + */ + List findPoolsByDetails(long dcId, long podId, Long clusterId, Map details); + + List findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared); + + /** + * Find pool by UUID. + * + * @param uuid uuid of pool. + * @return the single StoragePoolVO + */ + DataStoreVO findPoolByUUID(String uuid); + + List listByStorageHost(String hostFqdnOrIp); + + DataStoreVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid); + + List listPoolByHostPath(String host, String path); + + void updateDetails(long poolId, Map details); + + Map getDetails(long poolId); + + List searchForStoragePoolDetails(long poolId, String value); + + List findIfDuplicatePoolsExistByUUID(String uuid); + + List listByStatus(DataStoreStatus status); + + long countPoolsByStatus(DataStoreStatus... statuses); + + List listByStatusInZone(long dcId, DataStoreStatus status); + + List listPoolsByCluster(long clusterId); +} \ No newline at end of file diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java new file mode 100644 index 00000000000..442949957ba --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java @@ -0,0 +1,377 @@ +/* + * 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.datastore.db; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.storage.datastore.DataStoreStatus; +import org.springframework.stereotype.Component; + +import com.cloud.storage.StoragePoolDetailVO; +import com.cloud.storage.dao.StoragePoolDetailsDao; +import com.cloud.storage.dao.StoragePoolDetailsDaoImpl; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.exception.CloudRuntimeException; + +@Component +public class PrimaryDataStoreDaoImpl extends GenericDaoBase implements PrimaryDataStoreDao { + protected final SearchBuilder AllFieldSearch; + protected final SearchBuilder DcPodSearch; + protected final SearchBuilder DcPodAnyClusterSearch; + protected final SearchBuilder DeleteLvmSearch; + protected final GenericSearchBuilder StatusCountSearch; + + + + protected final StoragePoolDetailsDao _detailsDao; + + private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and ("; + private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?"; + private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?"; + + protected PrimaryDataStoreDaoImpl() { + AllFieldSearch = createSearchBuilder(); + AllFieldSearch.and("name", AllFieldSearch.entity().getName(), SearchCriteria.Op.EQ); + AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ); + AllFieldSearch.and("datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + AllFieldSearch.and("hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ); + AllFieldSearch.and("status",AllFieldSearch.entity().getStatus(),SearchCriteria.Op.EQ); + AllFieldSearch.and("path", AllFieldSearch.entity().getPath(), SearchCriteria.Op.EQ); + AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ); + AllFieldSearch.and("clusterId", AllFieldSearch.entity().getClusterId(), Op.EQ); + AllFieldSearch.done(); + + DcPodSearch = createSearchBuilder(); + DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + DcPodSearch.and().op("nullpod", DcPodSearch.entity().getPodId(), SearchCriteria.Op.NULL); + DcPodSearch.or("podId", DcPodSearch.entity().getPodId(), SearchCriteria.Op.EQ); + DcPodSearch.cp(); + DcPodSearch.and().op("nullcluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.NULL); + DcPodSearch.or("cluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.EQ); + DcPodSearch.cp(); + DcPodSearch.done(); + + DcPodAnyClusterSearch = createSearchBuilder(); + DcPodAnyClusterSearch.and("datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + DcPodAnyClusterSearch.and().op("nullpod", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.NULL); + DcPodAnyClusterSearch.or("podId", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.EQ); + DcPodAnyClusterSearch.cp(); + DcPodAnyClusterSearch.done(); + + DeleteLvmSearch = createSearchBuilder(); + DeleteLvmSearch.and("ids", DeleteLvmSearch.entity().getId(), SearchCriteria.Op.IN); + DeleteLvmSearch.and().op("LVM", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ); + DeleteLvmSearch.or("Filesystem", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ); + DeleteLvmSearch.cp(); + DeleteLvmSearch.done(); + + + + StatusCountSearch = createSearchBuilder(Long.class); + StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN); + StatusCountSearch.select(null, Func.COUNT, null); + StatusCountSearch.done(); + + _detailsDao = ComponentLocator.inject(StoragePoolDetailsDaoImpl.class); + } + + @Override + public List findPoolByName(String name) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("name", name); + return listIncludingRemovedBy(sc); + } + + + @Override + public DataStoreVO findPoolByUUID(String uuid) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("uuid", uuid); + return findOneIncludingRemovedBy(sc); + } + + + + @Override + public List findIfDuplicatePoolsExistByUUID(String uuid) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("uuid", uuid); + return listBy(sc); + } + + + @Override + public List listByDataCenterId(long datacenterId) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("datacenterId", datacenterId); + return listBy(sc); + } + + + @Override + public void updateAvailable(long id, long available) { + DataStoreVO pool = createForUpdate(id); + pool.setAvailableBytes(available); + update(id, pool); + } + + + @Override + public void updateCapacity(long id, long capacity) { + DataStoreVO pool = createForUpdate(id); + pool.setCapacityBytes(capacity); + update(id, pool); + + } + + @Override + public List listByStorageHost(String hostFqdnOrIp) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("hostAddress", hostFqdnOrIp); + return listIncludingRemovedBy(sc); + } + + @Override + public List listByStatus(DataStoreStatus status){ + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("status", status); + return listBy(sc); + } + + @Override + public List listByStatusInZone(long dcId, DataStoreStatus status){ + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("status", status); + sc.setParameters("datacenterId", dcId); + return listBy(sc); + } + + @Override + public DataStoreVO findPoolByHostPath(long datacenterId, Long podId, String host, String path, String uuid) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("hostAddress", host); + sc.setParameters("path", path); + sc.setParameters("datacenterId", datacenterId); + sc.setParameters("podId", podId); + sc.setParameters("uuid", uuid); + + return findOneBy(sc); + } + + @Override + public List listBy(long datacenterId, long podId, Long clusterId) { + if (clusterId != null) { + SearchCriteria sc = DcPodSearch.create(); + sc.setParameters("datacenterId", datacenterId); + sc.setParameters("podId", podId); + + sc.setParameters("cluster", clusterId); + return listBy(sc); + } else { + SearchCriteria sc = DcPodAnyClusterSearch.create(); + sc.setParameters("datacenterId", datacenterId); + sc.setParameters("podId", podId); + return listBy(sc); + } + } + + @Override + public List listPoolByHostPath(String host, String path) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("hostAddress", host); + sc.setParameters("path", path); + + return listBy(sc); + } + + public DataStoreVO listById(Integer id) + { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("id", id); + + return findOneIncludingRemovedBy(sc); + } + + @Override @DB + public DataStoreVO persist(DataStoreVO pool, Map details) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + pool = super.persist(pool); + if (details != null) { + for (Map.Entry detail : details.entrySet()) { + StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue()); + _detailsDao.persist(vo); + } + } + txn.commit(); + return pool; + } + + @DB + @Override + public List findPoolsByDetails(long dcId, long podId, Long clusterId, Map details) { + StringBuilder sql = new StringBuilder(DetailsSqlPrefix); + if (clusterId != null) { + sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND ("); + } + for (Map.Entry detail : details.entrySet()) { + sql.append("((storage_pool_details.name='").append(detail.getKey()).append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR "); + } + sql.delete(sql.length() - 4, sql.length()); + sql.append(DetailsSqlSuffix); + Transaction txn = Transaction.currentTxn(); + PreparedStatement pstmt = null; + try { + pstmt = txn.prepareAutoCloseStatement(sql.toString()); + int i = 1; + pstmt.setLong(i++, dcId); + pstmt.setLong(i++, podId); + if (clusterId != null) { + pstmt.setLong(i++, clusterId); + } + pstmt.setInt(i++, details.size()); + ResultSet rs = pstmt.executeQuery(); + List pools = new ArrayList(); + while (rs.next()) { + pools.add(toEntityBean(rs, false)); + } + return pools; + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to execute " + pstmt, e); + } + } + + protected Map tagsToDetails(String[] tags) { + Map details = new HashMap(tags.length); + for (String tag: tags) { + details.put(tag, "true"); + } + return details; + } + + @Override + public List findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) { + List storagePools = null; + if (tags == null || tags.length == 0) { + storagePools = listBy(dcId, podId, clusterId); + } else { + Map details = tagsToDetails(tags); + storagePools = findPoolsByDetails(dcId, podId, clusterId, details); + } + + if (shared == null) { + return storagePools; + } else { + List filteredStoragePools = new ArrayList(storagePools); + for (DataStoreVO pool : storagePools) { + /* + if (shared != pool.isShared()) { + filteredStoragePools.remove(pool); + }*/ + } + + return filteredStoragePools; + } + } + + @Override + @DB + public List searchForStoragePoolDetails(long poolId, String value){ + + StringBuilder sql = new StringBuilder(FindPoolTagDetails); + + Transaction txn = Transaction.currentTxn(); + PreparedStatement pstmt = null; + try { + pstmt = txn.prepareAutoCloseStatement(sql.toString()); + pstmt.setLong(1, poolId); + pstmt.setString(2, value); + + ResultSet rs = pstmt.executeQuery(); + List tags = new ArrayList(); + + while (rs.next()) { + tags.add(rs.getString("name")); + } + return tags; + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e); + } + + } + + @Override + public void updateDetails(long poolId, Map details) { + if (details != null) { + _detailsDao.update(poolId, details); + } + } + + @Override + public Map getDetails(long poolId) { + return _detailsDao.getDetails(poolId); + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + super.configure(name, params); + _detailsDao.configure("DetailsDao", params); + return true; + } + + + + @Override + public long countPoolsByStatus( DataStoreStatus... statuses) { + SearchCriteria sc = StatusCountSearch.create(); + + sc.setParameters("status", (Object[])statuses); + + List rs = customSearchIncludingRemoved(sc, null); + if (rs.size() == 0) { + return 0; + } + + return rs.get(0); + } + + @Override + public List listPoolsByCluster(long clusterId) { + SearchCriteria sc = AllFieldSearch.create(); + sc.setParameters("clusterId", clusterId); + + return listBy(sc); + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDao.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDao.java new file mode 100644 index 00000000000..cebcacf3bdc --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDao.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.datastore.db; + +import com.cloud.utils.db.GenericDao; + +public interface PrimaryDataStoreProviderDao extends GenericDao { + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDaoImpl.java new file mode 100644 index 00000000000..bd0571d6be0 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderDaoImpl.java @@ -0,0 +1,28 @@ +/* + * 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.datastore.db; + +import org.springframework.stereotype.Component; + +import com.cloud.utils.db.GenericDaoBase; + +@Component +class PrimaryDataStoreProviderDaoImpl extends GenericDaoBase implements PrimaryDataStoreProviderDao { + +} \ No newline at end of file diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderVO.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderVO.java new file mode 100644 index 00000000000..0d155802464 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreProviderVO.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.datastore.db; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.TableGenerator; + +@Entity +@Table(name="data_store_provider") +public class PrimaryDataStoreProviderVO { + @Id + @TableGenerator(name="data_store_provider_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="data_store_provider_seq", allocationSize=1) + @Column(name="id", updatable=false, nullable = false) + private long id; + + public long getId() { + return id; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java new file mode 100644 index 00000000000..935f2140b86 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/DefaultPrimaryDataStoreDriverImpl.java @@ -0,0 +1,65 @@ +package org.apache.cloudstack.storage.datastore.driver; + +import java.util.List; + +import org.apache.cloudstack.storage.EndPoint; +import org.apache.cloudstack.storage.command.CreateVolumeAnswer; +import org.apache.cloudstack.storage.command.CreateVolumeCommand; +import org.apache.cloudstack.storage.volume.Volume; +import org.apache.cloudstack.storage.volume.VolumeInfo; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.agent.api.Answer; + +@Component +public class DefaultPrimaryDataStoreDriverImpl implements + PrimaryDataStoreDriver { + private static final Logger s_logger = Logger.getLogger(DefaultPrimaryDataStoreDriverImpl.class); + @Override + public boolean createVolume(Volume vol) { + //The default driver will send createvolume command to one of hosts which can access its datastore + List endPoints = vol.getDataStore().getEndPoints(); + int retries = 3; + VolumeInfo volInfo = new VolumeInfo(vol); + CreateVolumeCommand createCmd = new CreateVolumeCommand(volInfo); + Answer answer = null; + int i = 0; + boolean result = false; + + for (EndPoint ep : endPoints) { + answer = ep.sendMessage(createCmd); + if (answer == null) { + if (i < retries) { + s_logger.debug("create volume failed, retrying: " + i); + } + i++; + } else { + CreateVolumeAnswer volAnswer = (CreateVolumeAnswer)answer; + vol.setUuid(volAnswer.getVolumeUuid()); + result = true; + } + } + + return result; + } + + @Override + public boolean deleteVolume(Volume vo) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String grantAccess(Volume vol, EndPoint ep) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean revokeAccess(Volume vol, EndPoint ep) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java new file mode 100644 index 00000000000..a35118a97b6 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/driver/PrimaryDataStoreDriver.java @@ -0,0 +1,11 @@ +package org.apache.cloudstack.storage.datastore.driver; + +import org.apache.cloudstack.storage.EndPoint; +import org.apache.cloudstack.storage.volume.Volume; + +public interface PrimaryDataStoreDriver { + boolean createVolume(Volume vol); + boolean deleteVolume(Volume vo); + String grantAccess(Volume vol, EndPoint ep); + boolean revokeAccess(Volume vol, EndPoint ep); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java new file mode 100644 index 00000000000..fe4562c9102 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/DefaultPrimaryDataStoreLifeCycleImpl.java @@ -0,0 +1,70 @@ +/* + * 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.datastore.lifecycle; + +import java.util.Map; + +import org.springframework.stereotype.Component; + +@Component +public class DefaultPrimaryDataStoreLifeCycleImpl implements PrimaryDataStoreLifeCycle { + + @Override + public boolean registerDataStore(Map dsInfos) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean attach(long scope) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean dettach(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean unmanaged(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean maintain(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean cancelMaintain(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean deleteDataStore(long dataStoreId) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/PrimaryDataStoreLifeCycle.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/PrimaryDataStoreLifeCycle.java new file mode 100644 index 00000000000..2e41a62ee4a --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/lifecycle/PrimaryDataStoreLifeCycle.java @@ -0,0 +1,31 @@ +/* + * 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.datastore.lifecycle; + +import java.util.Map; + +public interface PrimaryDataStoreLifeCycle { + public boolean registerDataStore(Map dsInfos); + public boolean attach(long scope); + public boolean dettach(long dataStoreId); + public boolean unmanaged(long dataStoreId); + public boolean maintain(long dataStoreId); + public boolean cancelMaintain(long dataStoreId); + public boolean deleteDataStore(long dataStoreId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.java new file mode 100644 index 00000000000..4949b2faf67 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/DefaultPrimaryDataStoreManagerImpl.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.datastore.manager; + +import javax.inject.Inject; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.db.DataStoreVO; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreProviderDao; +import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle; +import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider; +import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager; +import org.springframework.stereotype.Component; + +@Component +public class DefaultPrimaryDataStoreManagerImpl implements PrimaryDataStoreManager { + @Inject + PrimaryDataStoreProviderDao dataStoreProviderDao; + @Inject + PrimaryDataStoreProviderManager providerManager; + @Inject + PrimaryDataStoreDao dataStoreDao; + @Override + public PrimaryDataStore getPrimaryDataStore(long dataStoreId) { + DataStoreVO dataStoreVO = dataStoreDao.findById(dataStoreId); + Long providerId = dataStoreVO.getStorageProviderId(); + PrimaryDataStoreProvider provider = providerManager.getDataStoreProvider(providerId); + PrimaryDataStore dataStore = provider.getDataStore(dataStoreId); + return dataStore; + } + + @Override + public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java new file mode 100644 index 00000000000..b6ac34d3d76 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/manager/PrimaryDataStoreManager.java @@ -0,0 +1,27 @@ +/* + * 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.datastore.manager; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.lifecycle.PrimaryDataStoreLifeCycle; + +public interface PrimaryDataStoreManager { + public PrimaryDataStore getPrimaryDataStore(long dataStoreId); + public PrimaryDataStoreLifeCycle getPrimaryDataStoreLifeCycle(long dataStoreId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java new file mode 100644 index 00000000000..7ca9000d281 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/DefaultPrimaryDatastoreProviderImpl.java @@ -0,0 +1,44 @@ +package org.apache.cloudstack.storage.datastore.provider; + +import javax.inject.Inject; + +import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl; +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.PrimaryDataStoreInfo; +import org.apache.cloudstack.storage.datastore.db.DataStoreVO; +import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; +import org.apache.cloudstack.storage.datastore.driver.DefaultPrimaryDataStoreDriverImpl; +import org.apache.cloudstack.storage.datastore.driver.PrimaryDataStoreDriver; +import org.springframework.stereotype.Component; + +import com.cloud.utils.component.ComponentInject; + +@Component +public class DefaultPrimaryDatastoreProviderImpl implements + PrimaryDataStoreProvider { + protected PrimaryDataStoreDriver driver; + @Inject + public PrimaryDataStoreDao dataStoreDao; + + public DefaultPrimaryDatastoreProviderImpl() { + this.driver = new DefaultPrimaryDataStoreDriverImpl(); + } + @Override + public PrimaryDataStore getDataStore(long dataStoreId) { + DataStoreVO dsv = dataStoreDao.findById(dataStoreId); + if (dsv == null) { + return null; + } + + PrimaryDataStore pds = new DefaultPrimaryDataStoreImpl(driver, dsv, null); + pds = ComponentInject.inject(pds); + return pds; + } + + @Override + public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java new file mode 100644 index 00000000000..a346d3206dc --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProvider.java @@ -0,0 +1,9 @@ +package org.apache.cloudstack.storage.datastore.provider; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.PrimaryDataStoreInfo; + +public interface PrimaryDataStoreProvider { + public PrimaryDataStore getDataStore(long dataStoreId); + public PrimaryDataStoreInfo getDataStoreInfo(long dataStoreId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java new file mode 100644 index 00000000000..4ef9a5c75ee --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManager.java @@ -0,0 +1,5 @@ +package org.apache.cloudstack.storage.datastore.provider; + +public interface PrimaryDataStoreProviderManager { + public PrimaryDataStoreProvider getDataStoreProvider(Long providerId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java new file mode 100644 index 00000000000..08755530c11 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/provider/PrimaryDataStoreProviderManagerImpl.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.datastore.provider; + +import org.springframework.stereotype.Component; + +@Component +public class PrimaryDataStoreProviderManagerImpl implements PrimaryDataStoreProviderManager { + + @Override + public PrimaryDataStoreProvider getDataStoreProvider(Long providerId) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/type/DataStoreType.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/DataStoreType.java new file mode 100644 index 00000000000..8f3fe8ca8ca --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/DataStoreType.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.datastore.type; + +public interface DataStoreType { + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/type/ISCSI.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/ISCSI.java new file mode 100644 index 00000000000..26d36def426 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/ISCSI.java @@ -0,0 +1,31 @@ +/* + * 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.datastore.type; + +import org.apache.cloudstack.storage.BaseType; +import org.springframework.stereotype.Component; + +@Component +public class ISCSI extends BaseType implements DataStoreType { + private final String type = "iscsi"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/type/NetworkFileSystem.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/NetworkFileSystem.java new file mode 100644 index 00000000000..9340975f87c --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/NetworkFileSystem.java @@ -0,0 +1,31 @@ +/* + * 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.datastore.type; + +import org.apache.cloudstack.storage.BaseType; +import org.springframework.stereotype.Component; + +@Component +public class NetworkFileSystem extends BaseType implements DataStoreType { + private final String type = "nfs"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/datastore/type/SharedMount.java b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/SharedMount.java new file mode 100644 index 00000000000..c97a8939833 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/datastore/type/SharedMount.java @@ -0,0 +1,29 @@ +/* + * 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.datastore.type; + +import org.apache.cloudstack.storage.BaseType; + +public class SharedMount extends BaseType implements DataStoreType { + private final String type = "SharedMountPoint"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java b/engine/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java new file mode 100644 index 00000000000..245af06f79f --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/driver/AbstractStorageDriver.java @@ -0,0 +1,76 @@ +/* + * 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.DataStore; +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.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.storage.DownloadCommand; +import com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer; +import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; + +public abstract class AbstractStorageDriver implements DataStoreDriver { + protected DataStore _ds; + protected TemplateStrategy _ts; + + public AbstractStorageDriver(DataStore ds) { + _ds = ds; + _ts = ds.getTemplateStrategy(); + } + + public TemplateProfile install(TemplateProfile tp, DataStoreEndPoint ep) { + 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()); + PrimaryStorageDownloadAnswer asw = (PrimaryStorageDownloadAnswer)ep.sendCommand(dcmd); + + 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 VolumeProfile createVolumeFromTemplate(VolumeProfile volProfile, TemplateProfile tp, DataStoreEndPoint ep) { + CreateCommand cmd = new CreateCommand(volProfile, tp.getLocalPath(), _ds.getTO()); + CreateAnswer ans = (CreateAnswer)ep.sendCommand(cmd); + VolumeTO created = ans.getVolume(); + DiskProfile diskProfile = new VolumeProfile(volProfile); + diskProfile.setPath(created.getPath()); + diskProfile.setSize(created.getSize()); + return diskProfile; + return null; + }*/ +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java b/engine/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java new file mode 100644 index 00000000000..8e6fa1d8b3d --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/driver/DefaultNfsSecondaryDriver.java @@ -0,0 +1,90 @@ +/* + * 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 org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile; + +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; + } + + public org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile register(org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint ep) { + // TODO Auto-generated method stub + return null; + } + + public VolumeProfile createVolumeFromTemplate(VolumeProfile vol, org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint dp) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/driver/XenServerStorageDriver.java b/engine/storage/src/org/apache/cloudstack/storage/driver/XenServerStorageDriver.java new file mode 100644 index 00000000000..811b4c7f787 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/driver/XenServerStorageDriver.java @@ -0,0 +1,81 @@ +/* + * 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 org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; + + +public class XenServerStorageDriver extends AbstractStorageDriver { + protected DataStore _ds; + public XenServerStorageDriver(DataStore ds) { + super(ds); + _ds = ds; + } + + public String getDriverType() { + // 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; + } + + public org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile register(org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint ep) { + // TODO Auto-generated method stub + return null; + } + + public VolumeProfile createVolumeFromTemplate(VolumeProfile vol, org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile tp, DataStoreEndPoint dp) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageManager.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageManager.java new file mode 100644 index 00000000000..ffe0efe48cd --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/ImageManager.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.image; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile; + + +import com.cloud.api.commands.RegisterTemplateCmd; + + +public interface ImageManager { + TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds); + TemplateProfile getProfile(long templateId); + TemplateProfile allocateTemplateInDB(RegisterTemplateCmd cmd); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java new file mode 100644 index 00000000000..7c956da6914 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/ImageManagerImpl.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.image; + +import java.util.List; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +import org.apache.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.VMTemplateHostVO; +import com.cloud.storage.VMTemplateStoragePoolVO; +import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; +import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.dao.VMTemplateDao; +import com.cloud.storage.dao.VMTemplatePoolDao; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.utils.EnumUtils; +import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; + +public class ImageManagerImpl implements ImageManager { + private static final Logger s_logger = Logger.getLogger(ImageManagerImpl.class); + @Inject + VMTemplateDao _templateDao; + @Inject + VMTemplatePoolDao _templatePoolDao; + @Inject + DataCenterDao _dcDao; + + public boolean contains(VirtualMachineTemplate template, DataStore ds) { + long templateId = template.getId(); + long poolId = ds.getId(); + VMTemplateStoragePoolVO templateStoragePoolRef = null; + templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId); + return templateStoragePoolRef == null ? false : true; + } + + public TemplateProfile AssociateTemplateStoragePool(TemplateProfile tp, DataStore ds) { + long templateId = tp.getTemplateId(); + long poolId = ds.getId(); + VMTemplateStoragePoolVO templateStoragePoolRef = null; + long templateStoragePoolRefId; + + templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId); + if (templateStoragePoolRef != null) { + templateStoragePoolRef.setMarkedForGC(false); + _templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef); + + if (templateStoragePoolRef.getDownloadState() == Status.DOWNLOADED) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Template " + templateId + " has already been downloaded to pool " + poolId); + } + + tp.setLocalPath(templateStoragePoolRef.getInstallPath()); + tp.setTemplatePoolRefId(templateStoragePoolRef.getId()); + return tp; + } + } + + if (templateStoragePoolRef == null) { + templateStoragePoolRef = new VMTemplateStoragePoolVO(poolId, templateId); + try { + templateStoragePoolRef = _templatePoolDao.persist(templateStoragePoolRef); + templateStoragePoolRefId = templateStoragePoolRef.getId(); + } catch (Exception e) { + s_logger.debug("Assuming we're in a race condition: " + e.getMessage()); + templateStoragePoolRef = _templatePoolDao.findByPoolTemplate(poolId, templateId); + if (templateStoragePoolRef == null) { + throw new CloudRuntimeException("Unable to persist a reference for pool " + poolId + " and template " + templateId); + } + templateStoragePoolRefId = templateStoragePoolRef.getId(); + } + } else { + templateStoragePoolRefId = templateStoragePoolRef.getId(); + } + tp.setTemplatePoolRefId(templateStoragePoolRefId); + return tp; + } + + public TemplateProfile getProfile(long templateId) { + // TODO Auto-generated method stub + return null; + } + + protected TemplateProfile persistTemplate(TemplateProfile profile) { + Long zoneId = profile.getZoneId(); + VMTemplateVO template = new VMTemplateVO(profile.getTemplateId(), profile.getName(), profile.getFormat(), profile.getIsPublic(), + profile.getFeatured(), profile.getIsExtractable(), TemplateType.USER, profile.getUrl(), profile.getRequiresHVM(), + profile.getBits(), profile.getAccountId(), profile.getCheckSum(), profile.getDisplayText(), + profile.getPasswordEnabled(), profile.getGuestOsId(), profile.getBootable(), profile.getHypervisorType(), profile.getTemplateTag(), + profile.getDetails(), profile.getSshKeyEnabled()); + + if (zoneId == null || zoneId.longValue() == -1) { + List 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(null); + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageMotionService.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageMotionService.java new file mode 100644 index 00000000000..dd35e5d70c4 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/ImageMotionService.java @@ -0,0 +1,24 @@ +/* + * 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 ImageMotionService { + boolean copyTemplate(String templateUri, String destTemplateUri); + boolean copyIso(String isoUri, String destIsoUri); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageOrchestrator.java new file mode 100644 index 00000000000..f759d6b130f --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/ImageOrchestratorImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageOrchestratorImpl.java new file mode 100644 index 00000000000..43c262da227 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java new file mode 100644 index 00000000000..ebdc594f151 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/ImageService.java @@ -0,0 +1,30 @@ +/* + * 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 ImageService { + boolean registerTemplate(long templateId, long imageStoreId); + boolean deleteTemplate(long templateId); + long registerIso(String isoUrl, long accountId); + boolean deleteIso(long isoId); + String grantTemplateAccess(long templateId, long endpointId); + boolean revokeTemplateAccess(long templateId, long endpointId); + String grantIsoAccess(long isoId, long endpointId); + boolean revokeIsoAccess(long isoId, long endpointId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java new file mode 100644 index 00000000000..68491922f3a --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java @@ -0,0 +1,84 @@ +/* + * 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 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 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 + public boolean deleteTemplate(long templateId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public long registerIso(String isoUrl, long accountId) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean deleteIso(long isoId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String grantTemplateAccess(long templateId, long endpointId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean revokeTemplateAccess(long templateId, long endpointId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String grantIsoAccess(long isoId, long endpointId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean revokeIsoAccess(long isoId, long endpointId) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/Template.java b/engine/storage/src/org/apache/cloudstack/storage/image/Template.java new file mode 100644 index 00000000000..1a71d827553 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/Template.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.image; + +import org.apache.cloudstack.storage.image.db.ImageDataVO; +import org.apache.cloudstack.storage.image.store.ImageDataStore; + +public class Template { + protected ImageDataVO imageVO; + protected ImageDataStore dataStore; + public Template(ImageDataStore dataStore, ImageDataVO imageVO) { + this.dataStore = dataStore; + this.imageVO = imageVO; + } + + public ImageDataStore getImageDataStore() { + return this.dataStore; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDao.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDao.java new file mode 100644 index 00000000000..3e1a951e295 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDaoStoreDaoImpl.java new file mode 100644 index 00000000000..01dd62ede43 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java new file mode 100644 index 00000000000..b336ffa2db5 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDao.java @@ -0,0 +1,71 @@ +/* + * 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 java.util.List; +import java.util.Map; +import java.util.Set; + +import com.cloud.domain.DomainVO; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.projects.Project.ListProjectResourcesCriteria; +import com.cloud.template.VirtualMachineTemplate.TemplateFilter; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import com.cloud.utils.db.GenericDao; + +public interface ImageDataDao extends GenericDao { + public List listByPublic(); + public ImageDataVO findByName(String templateName); + public ImageDataVO findByTemplateName(String templateName); + + //public void update(ImageDataVO template); + + + public List listAllSystemVMTemplates(); + + public List listDefaultBuiltinTemplates(); + public String getRoutingTemplateUniqueName(); + public List findIsosByIdAndPath(Long domainId, Long accountId, String path); + public List listReadyTemplates(); + public List listByAccountId(long accountId); + public Set> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, + List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, Long zoneId, + HypervisorType hyperType, boolean onlyReady, boolean showDomr, List permittedAccounts, Account caller, + ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags); + + public Set> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, + boolean isIso, List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, + Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List permittedAccounts, Account caller, Map tags); + + public long addTemplateToZone(ImageDataVO tmplt, long zoneId); + public List listAllInZone(long dataCenterId); + + public List listByHypervisorType(List hyperTypes); + public List publicIsoSearch(Boolean bootable, boolean listRemoved, Map tags); + public List userIsoSearch(boolean listRemoved); + ImageDataVO findSystemVMTemplate(long zoneId); + ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType); + + ImageDataVO findRoutingTemplate(HypervisorType type); + List listPrivateTemplatesByHost(Long hostId); + public Long countTemplatesForAccount(long accountId); + +} + diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java new file mode 100644 index 00000000000..8ba557593b6 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataDaoImpl.java @@ -0,0 +1,925 @@ +/* + * 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 java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.storage.image.format.ISO; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.api.BaseCmd; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.domain.DomainVO; +import com.cloud.domain.dao.DomainDao; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.projects.Project.ListProjectResourcesCriteria; +import com.cloud.server.ResourceTag.TaggedResourceType; +import com.cloud.storage.Storage; +import com.cloud.storage.VMTemplateZoneVO; +import com.cloud.storage.Storage.TemplateType; +import com.cloud.storage.VMTemplateStorageResourceAssoc.Status; +import com.cloud.storage.dao.VMTemplateDaoImpl; +import com.cloud.storage.dao.VMTemplateDetailsDao; +import com.cloud.storage.dao.VMTemplateZoneDao; +import com.cloud.tags.ResourceTagVO; +import com.cloud.tags.dao.ResourceTagsDaoImpl; +import com.cloud.template.VirtualMachineTemplate.TemplateFilter; +import com.cloud.user.Account; +import com.cloud.utils.Pair; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.component.Inject; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.Filter; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.JoinBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.exception.CloudRuntimeException; + +@Component +public class ImageDataDaoImpl extends GenericDaoBase implements ImageDataDao { + private static final Logger s_logger = Logger.getLogger(VMTemplateDaoImpl.class); + + @Inject + VMTemplateZoneDao _templateZoneDao; + @Inject + VMTemplateDetailsDao _templateDetailsDao; + + @Inject + ConfigurationDao _configDao; + @Inject + HostDao _hostDao; + @Inject + DomainDao _domainDao; + @Inject + DataCenterDao _dcDao; + private final String SELECT_TEMPLATE_HOST_REF = "SELECT t.id, h.data_center_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " + + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t"; + + private final String SELECT_TEMPLATE_ZONE_REF = "SELECT t.id, tzr.zone_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " + + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) "; + + private final String SELECT_TEMPLATE_SWIFT_REF = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " + + "t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t"; + protected SearchBuilder TemplateNameSearch; + protected SearchBuilder UniqueNameSearch; + protected SearchBuilder tmpltTypeSearch; + protected SearchBuilder tmpltTypeHyperSearch; + protected SearchBuilder tmpltTypeHyperSearch2; + + protected SearchBuilder AccountIdSearch; + protected SearchBuilder NameSearch; + protected SearchBuilder TmpltsInZoneSearch; + private SearchBuilder PublicSearch; + private SearchBuilder NameAccountIdSearch; + private SearchBuilder PublicIsoSearch; + private SearchBuilder UserIsoSearch; + private GenericSearchBuilder CountTemplatesByAccount; + + ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class); + + + private String routerTmpltName; + private String consoleProxyTmpltName; + + protected ImageDataDaoImpl() { + } + + @Override + public List listByPublic() { + SearchCriteria sc = PublicSearch.create(); + sc.setParameters("public", 1); + return listBy(sc); + } + + @Override + public ImageDataVO findByName(String templateName) { + SearchCriteria sc = UniqueNameSearch.create(); + sc.setParameters("uniqueName", templateName); + return findOneIncludingRemovedBy(sc); + } + + @Override + public ImageDataVO findByTemplateName(String templateName) { + SearchCriteria sc = NameSearch.create(); + sc.setParameters("name", templateName); + return findOneIncludingRemovedBy(sc); + } + + @Override + public List publicIsoSearch(Boolean bootable, boolean listRemoved, Map tags){ + + SearchBuilder sb = null; + if (tags == null || tags.isEmpty()) { + sb = PublicIsoSearch; + } else { + sb = createSearchBuilder(); + sb.and("public", sb.entity().isPublicTemplate(), SearchCriteria.Op.EQ); + sb.and("format", sb.entity().getFormat(), SearchCriteria.Op.EQ); + sb.and("type", sb.entity().getTemplateType(), SearchCriteria.Op.EQ); + sb.and("bootable", sb.entity().isBootable(), SearchCriteria.Op.EQ); + sb.and("removed", sb.entity().getRemoved(), SearchCriteria.Op.EQ); + + SearchBuilder tagSearch = _tagsDao.createSearchBuilder(); + for (int count=0; count < tags.size(); count++) { + tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ); + tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ); + tagSearch.cp(); + } + tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ); + sb.groupBy(sb.entity().getId()); + sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); + } + + SearchCriteria sc = sb.create(); + + sc.setParameters("public", 1); + sc.setParameters("format", "ISO"); + sc.setParameters("type", TemplateType.PERHOST.toString()); + if (bootable != null) { + sc.setParameters("bootable", bootable); + } + + if (!listRemoved) { + sc.setParameters("removed", (Object)null); + } + + if (tags != null && !tags.isEmpty()) { + int count = 0; + sc.setJoinParameters("tagSearch", "resourceType", TaggedResourceType.ISO.toString()); + for (String key : tags.keySet()) { + sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key); + sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key)); + count++; + } + } + + return listBy(sc); + } + + @Override + public List userIsoSearch(boolean listRemoved){ + + SearchBuilder sb = null; + sb = UserIsoSearch; + SearchCriteria sc = sb.create(); + + sc.setParameters("format", Storage.ImageFormat.ISO); + sc.setParameters("type", TemplateType.USER.toString()); + + if (!listRemoved) { + sc.setParameters("removed", (Object)null); + } + + return listBy(sc); + } + @Override + public List listAllSystemVMTemplates() { + SearchCriteria sc = tmpltTypeSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + + Filter filter = new Filter(ImageDataVO.class, "id", false, null, null); + return listBy(sc, filter); + } + + @Override + public List listPrivateTemplatesByHost(Long hostId) { + + String sql = "select * from template_host_ref as thr INNER JOIN vm_template as t ON t.id=thr.template_id " + + "where thr.host_id=? and t.public=0 and t.featured=0 and t.type='USER' and t.removed is NULL"; + + List l = new ArrayList(); + + Transaction txn = Transaction.currentTxn(); + + PreparedStatement pstmt = null; + try { + pstmt = txn.prepareAutoCloseStatement(sql); + pstmt.setLong(1, hostId); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + l.add(rs.getLong(1)); + } + } catch (SQLException e) { + } catch (Throwable e) { + } + return l; + } + + @Override + public List listReadyTemplates() { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("ready", SearchCriteria.Op.EQ, true); + sc.addAnd("format", SearchCriteria.Op.NEQ, Storage.ImageFormat.ISO); + return listIncludingRemovedBy(sc); + } + + @Override + public List findIsosByIdAndPath(Long domainId, Long accountId, String path) { + SearchCriteria sc = createSearchCriteria(); + sc.addAnd("iso", SearchCriteria.Op.EQ, true); + if (domainId != null) { + sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); + } + if (accountId != null) { + sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); + } + if (path != null) { + sc.addAnd("path", SearchCriteria.Op.EQ, path); + } + return listIncludingRemovedBy(sc); + } + + @Override + public List listByAccountId(long accountId) { + SearchCriteria sc = AccountIdSearch.create(); + sc.setParameters("accountId", accountId); + return listBy(sc); + } + + @Override + public List listByHypervisorType(List hyperTypes) { + SearchCriteria sc = createSearchCriteria(); + hyperTypes.add(HypervisorType.None); + sc.addAnd("hypervisorType", SearchCriteria.Op.IN, hyperTypes.toArray()); + return listBy(sc); + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + boolean result = super.configure(name, params); + + PublicSearch = createSearchBuilder(); + PublicSearch.and("public", PublicSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ); + + routerTmpltName = (String)params.get("routing.uniquename"); + + s_logger.debug("Found parameter routing unique name " + routerTmpltName); + if (routerTmpltName==null) { + routerTmpltName="routing"; + } + + consoleProxyTmpltName = (String)params.get("consoleproxy.uniquename"); + if(consoleProxyTmpltName == null) { + consoleProxyTmpltName = "routing"; + } + if(s_logger.isDebugEnabled()) { + s_logger.debug("Use console proxy template : " + consoleProxyTmpltName); + } + + UniqueNameSearch = createSearchBuilder(); + UniqueNameSearch.and("uniqueName", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ); + NameSearch = createSearchBuilder(); + NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ); + + NameAccountIdSearch = createSearchBuilder(); + NameAccountIdSearch.and("name", NameAccountIdSearch.entity().getName(), SearchCriteria.Op.EQ); + NameAccountIdSearch.and("accountId", NameAccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + + PublicIsoSearch = createSearchBuilder(); + PublicIsoSearch.and("public", PublicIsoSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ); + PublicIsoSearch.and("format", PublicIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ); + PublicIsoSearch.and("type", PublicIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); + PublicIsoSearch.and("bootable", PublicIsoSearch.entity().isBootable(), SearchCriteria.Op.EQ); + PublicIsoSearch.and("removed", PublicIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ); + + UserIsoSearch = createSearchBuilder(); + UserIsoSearch.and("format", UserIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ); + UserIsoSearch.and("type", UserIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); + UserIsoSearch.and("removed", UserIsoSearch.entity().getRemoved(), SearchCriteria.Op.EQ); + + tmpltTypeHyperSearch = createSearchBuilder(); + tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); + SearchBuilder hostHyperSearch = _hostDao.createSearchBuilder(); + hostHyperSearch.and("type", hostHyperSearch.entity().getType(), SearchCriteria.Op.EQ); + hostHyperSearch.and("zoneId", hostHyperSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); + hostHyperSearch.groupBy(hostHyperSearch.entity().getHypervisorType()); + + tmpltTypeHyperSearch.join("tmplHyper", hostHyperSearch, hostHyperSearch.entity().getHypervisorType(), tmpltTypeHyperSearch.entity().getHypervisorType(), JoinBuilder.JoinType.INNER); + hostHyperSearch.done(); + tmpltTypeHyperSearch.done(); + + tmpltTypeHyperSearch2 = createSearchBuilder(); + tmpltTypeHyperSearch2.and("templateType", tmpltTypeHyperSearch2.entity().getTemplateType(), SearchCriteria.Op.EQ); + tmpltTypeHyperSearch2.and("hypervisorType", tmpltTypeHyperSearch2.entity().getHypervisorType(), SearchCriteria.Op.EQ); + + + tmpltTypeSearch = createSearchBuilder(); + tmpltTypeSearch.and("removed", tmpltTypeSearch.entity().getRemoved(), SearchCriteria.Op.NULL); + tmpltTypeSearch.and("templateType", tmpltTypeSearch.entity().getTemplateType(), SearchCriteria.Op.EQ); + + AccountIdSearch = createSearchBuilder(); + AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); + AccountIdSearch.and("publicTemplate", AccountIdSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ); + AccountIdSearch.done(); + + SearchBuilder tmpltZoneSearch = _templateZoneDao.createSearchBuilder(); + tmpltZoneSearch.and("removed", tmpltZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL); + tmpltZoneSearch.and("zoneId", tmpltZoneSearch.entity().getZoneId(), SearchCriteria.Op.EQ); + + TmpltsInZoneSearch = createSearchBuilder(); + TmpltsInZoneSearch.and("removed", TmpltsInZoneSearch.entity().getRemoved(), SearchCriteria.Op.NULL); + TmpltsInZoneSearch.and().op("avoidtype", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NEQ); + TmpltsInZoneSearch.or("templateType", TmpltsInZoneSearch.entity().getTemplateType(), SearchCriteria.Op.NULL); + TmpltsInZoneSearch.cp(); + TmpltsInZoneSearch.join("tmpltzone", tmpltZoneSearch, tmpltZoneSearch.entity().getTemplateId(), TmpltsInZoneSearch.entity().getId(), JoinBuilder.JoinType.INNER); + tmpltZoneSearch.done(); + TmpltsInZoneSearch.done(); + + CountTemplatesByAccount = createSearchBuilder(Long.class); + CountTemplatesByAccount.select(null, Func.COUNT, null); + CountTemplatesByAccount.and("account", CountTemplatesByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); + CountTemplatesByAccount.and("removed", CountTemplatesByAccount.entity().getRemoved(), SearchCriteria.Op.NULL); + CountTemplatesByAccount.done(); + + return result; + } + + @Override + public String getRoutingTemplateUniqueName() { + return routerTmpltName; + } + + @Override + public Set> searchSwiftTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, List hypers, Boolean bootable, DomainVO domain, + Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr, List permittedAccounts, Account caller, Map tags) { + + StringBuilder builder = new StringBuilder(); + if (!permittedAccounts.isEmpty()) { + for (Account permittedAccount : permittedAccounts) { + builder.append(permittedAccount.getAccountId() + ","); + } + } + + String permittedAccountsStr = builder.toString(); + + if (permittedAccountsStr.length() > 0) { + // chop the "," off + permittedAccountsStr = permittedAccountsStr.substring(0, permittedAccountsStr.length() - 1); + } + + Transaction txn = Transaction.currentTxn(); + txn.start(); + + Set> templateZonePairList = new HashSet>(); + PreparedStatement pstmt = null; + ResultSet rs = null; + String sql = SELECT_TEMPLATE_SWIFT_REF; + try { + String joinClause = ""; + String whereClause = " WHERE t.removed IS NULL"; + + if (isIso) { + whereClause += " AND t.format = 'ISO'"; + if (!hyperType.equals(HypervisorType.None)) { + joinClause = " INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id) INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) "; + whereClause += " AND goh.hypervisor_type = '" + hyperType.toString() + "'"; + } + } else { + whereClause += " AND t.format <> 'ISO'"; + if (hypers.isEmpty()) { + return templateZonePairList; + } else { + StringBuilder relatedHypers = new StringBuilder(); + for (HypervisorType hyper : hypers) { + relatedHypers.append("'"); + relatedHypers.append(hyper.toString()); + relatedHypers.append("'"); + relatedHypers.append(","); + } + relatedHypers.setLength(relatedHypers.length() - 1); + whereClause += " AND t.hypervisor_type IN (" + relatedHypers + ")"; + } + } + joinClause += " INNER JOIN template_swift_ref tsr on (t.id = tsr.template_id)"; + if (keyword != null) { + whereClause += " AND t.name LIKE \"%" + keyword + "%\""; + } else if (name != null) { + whereClause += " AND t.name LIKE \"%" + name + "%\""; + } + + if (bootable != null) { + whereClause += " AND t.bootable = " + bootable; + } + + if (!showDomr) { + whereClause += " AND t.type != '" + Storage.TemplateType.SYSTEM.toString() + "'"; + } + + if (templateFilter == TemplateFilter.featured) { + whereClause += " AND t.public = 1 AND t.featured = 1"; + } else if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { + if (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) { + joinClause += " INNER JOIN account a on (t.account_id = a.id) INNER JOIN domain d on (a.domain_id = d.id)"; + whereClause += " AND d.path LIKE '" + domain.getPath() + "%'"; + } else { + whereClause += " AND t.account_id IN (" + permittedAccountsStr + ")"; + } + } else if (templateFilter == TemplateFilter.sharedexecutable && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { + if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) { + joinClause += " LEFT JOIN launch_permission lp ON t.id = lp.template_id WHERE" + " (t.account_id IN (" + permittedAccountsStr + ") OR" + " lp.account_id IN (" + + permittedAccountsStr + "))"; + } else { + joinClause += " INNER JOIN account a on (t.account_id = a.id) "; + } + } else if (templateFilter == TemplateFilter.executable && !permittedAccounts.isEmpty()) { + whereClause += " AND (t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))"; + } else if (templateFilter == TemplateFilter.community) { + whereClause += " AND t.public = 1 AND t.featured = 0"; + } else if (templateFilter == TemplateFilter.all && caller.getType() == Account.ACCOUNT_TYPE_ADMIN) { + } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN) { + return templateZonePairList; + } + + sql += joinClause + whereClause + getOrderByLimit(pageSize, startIndex); + pstmt = txn.prepareStatement(sql); + rs = pstmt.executeQuery(); + while (rs.next()) { + Pair templateZonePair = new Pair(rs.getLong(1), -1L); + templateZonePairList.add(templateZonePair); + } + + } catch (Exception e) { + s_logger.warn("Error listing templates", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + txn.commit(); + } catch (SQLException sqle) { + s_logger.warn("Error in cleaning up", sqle); + } + } + + return templateZonePairList; + } + + + @Override + public Set> searchTemplates(String name, String keyword, TemplateFilter templateFilter, + boolean isIso, List hypers, Boolean bootable, DomainVO domain, Long pageSize, Long startIndex, + Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr,List permittedAccounts, + Account caller, ListProjectResourcesCriteria listProjectResourcesCriteria, Map tags) { + StringBuilder builder = new StringBuilder(); + if (!permittedAccounts.isEmpty()) { + for (Account permittedAccount : permittedAccounts) { + builder.append(permittedAccount.getAccountId() + ","); + } + } + + String permittedAccountsStr = builder.toString(); + + if (permittedAccountsStr.length() > 0) { + //chop the "," off + permittedAccountsStr = permittedAccountsStr.substring(0, permittedAccountsStr.length()-1); + } + + Transaction txn = Transaction.currentTxn(); + txn.start(); + + /* Use LinkedHashSet here to guarantee iteration order */ + Set> templateZonePairList = new LinkedHashSet>(); + PreparedStatement pstmt = null; + ResultSet rs = null; + StringBuilder relatedDomainIds = new StringBuilder(); + String sql = SELECT_TEMPLATE_ZONE_REF; + String groupByClause = ""; + try { + //short accountType; + //String accountId = null; + String guestOSJoin = ""; + StringBuilder templateHostRefJoin = new StringBuilder(); + String dataCenterJoin = "", lpjoin = ""; + String tagsJoin = ""; + + if (isIso && !hyperType.equals(HypervisorType.None)) { + guestOSJoin = " INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id) INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) "; + } + if (onlyReady){ + templateHostRefJoin.append(" INNER JOIN template_host_ref thr on (t.id = thr.template_id) INNER JOIN host h on (thr.host_id = h.id)"); + sql = SELECT_TEMPLATE_HOST_REF; + groupByClause = " GROUP BY t.id, h.data_center_id "; + } + if ((templateFilter == TemplateFilter.featured) || (templateFilter == TemplateFilter.community)) { + dataCenterJoin = " INNER JOIN data_center dc on (h.data_center_id = dc.id)"; + } + + if (templateFilter == TemplateFilter.sharedexecutable){ + lpjoin = " INNER JOIN launch_permission lp ON t.id = lp.template_id "; + } + + if (tags != null && !tags.isEmpty()) { + tagsJoin = " INNER JOIN resource_tags r ON t.id = r.resource_id "; + } + + sql += guestOSJoin + templateHostRefJoin + dataCenterJoin + lpjoin + tagsJoin; + String whereClause = ""; + + //All joins have to be made before we start setting the condition settings + if ((listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources + || (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.featured))) && + !(caller.getType() != Account.ACCOUNT_TYPE_NORMAL && templateFilter == TemplateFilter.all)) { + whereClause += " INNER JOIN account a on (t.account_id = a.id)"; + if ((templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) && (caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN)) { + whereClause += " INNER JOIN domain d on (a.domain_id = d.id) WHERE d.path LIKE '" + domain.getPath() + "%'"; + if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) { + whereClause += " AND a.type != " + Account.ACCOUNT_TYPE_PROJECT; + } + } else + if (listProjectResourcesCriteria == ListProjectResourcesCriteria.SkipProjectResources) { + whereClause += " WHERE a.type != " + Account.ACCOUNT_TYPE_PROJECT; + } + } + + if (!permittedAccounts.isEmpty()) { + for (Account account : permittedAccounts) { + //accountType = account.getType(); + //accountId = Long.toString(account.getId()); + DomainVO accountDomain = _domainDao.findById(account.getDomainId()); + + // get all parent domain ID's all the way till root domain + DomainVO domainTreeNode = accountDomain; + while (true) { + relatedDomainIds.append(domainTreeNode.getId()); + relatedDomainIds.append(","); + if (domainTreeNode.getParent() != null) { + domainTreeNode = _domainDao.findById(domainTreeNode.getParent()); + } else { + break; + } + } + + // get all child domain ID's + if (isAdmin(account.getType()) ) { + List allChildDomains = _domainDao.findAllChildren(accountDomain.getPath(), accountDomain.getId()); + for (DomainVO childDomain : allChildDomains) { + relatedDomainIds.append(childDomain.getId()); + relatedDomainIds.append(","); + } + } + relatedDomainIds.setLength(relatedDomainIds.length()-1); + } + } + + String attr = " AND "; + if (whereClause.endsWith(" WHERE ")) { + attr += " WHERE "; + } + + if (!isIso) { + if ( hypers.isEmpty() ) { + return templateZonePairList; + } else { + StringBuilder relatedHypers = new StringBuilder(); + for (HypervisorType hyper : hypers ) { + relatedHypers.append("'"); + relatedHypers.append(hyper.toString()); + relatedHypers.append("'"); + relatedHypers.append(","); + } + relatedHypers.setLength(relatedHypers.length()-1); + whereClause += attr + " t.hypervisor_type IN (" + relatedHypers + ")"; + } + } + + if (!permittedAccounts.isEmpty() && !(templateFilter == TemplateFilter.featured || + templateFilter == TemplateFilter.community || templateFilter == TemplateFilter.executable) && !isAdmin(caller.getType()) ) { + whereClause += attr + "t.account_id IN (" + permittedAccountsStr + ")"; + } + + if (templateFilter == TemplateFilter.featured) { + whereClause += attr + "t.public = 1 AND t.featured = 1"; + if (!permittedAccounts.isEmpty()) { + whereClause += attr + "(dc.domain_id IN (" + relatedDomainIds + ") OR dc.domain_id is NULL)"; + } + } else if (templateFilter == TemplateFilter.self || templateFilter == TemplateFilter.selfexecutable) { + whereClause += " AND t.account_id IN (" + permittedAccountsStr + ")"; + } else if (templateFilter == TemplateFilter.sharedexecutable) { + whereClause += " AND " + + " (t.account_id IN (" + permittedAccountsStr + ") OR" + + " lp.account_id IN (" + permittedAccountsStr + "))"; + } else if (templateFilter == TemplateFilter.executable && !permittedAccounts.isEmpty()) { + whereClause += attr + "(t.public = 1 OR t.account_id IN (" + permittedAccountsStr + "))"; + } else if (templateFilter == TemplateFilter.community) { + whereClause += attr + "t.public = 1 AND t.featured = 0"; + if (!permittedAccounts.isEmpty()) { + whereClause += attr + "(dc.domain_id IN (" + relatedDomainIds + ") OR dc.domain_id is NULL)"; + } + } else if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && !isIso) { + return templateZonePairList; + } + + if (tags != null && !tags.isEmpty()) { + whereClause += " AND ("; + boolean first = true; + for (String key : tags.keySet()) { + if (!first) { + whereClause += " OR "; + } + whereClause += "(r.key=\"" + key + "\" and r.value=\"" + tags.get(key) + "\")"; + first = false; + } + whereClause += ")"; + } + + if (whereClause.equals("")) { + whereClause += " WHERE "; + } else if (!whereClause.equals(" WHERE ")) { + whereClause += " AND "; + } + + sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId, + onlyReady, showDomr) + groupByClause + getOrderByLimit(pageSize, startIndex); + + pstmt = txn.prepareStatement(sql); + rs = pstmt.executeQuery(); + + while (rs.next()) { + Pair templateZonePair = new Pair(rs.getLong(1), rs.getLong(2)); + templateZonePairList.add(templateZonePair); + } + //for now, defaulting pageSize to a large val if null; may need to revisit post 2.2RC2 + if(isIso && templateZonePairList.size() < (pageSize != null ? pageSize : 500) + && templateFilter != TemplateFilter.community + && !(templateFilter == TemplateFilter.self && !BaseCmd.isRootAdmin(caller.getType())) ){ //evaluates to true If root admin and filter=self + + List publicIsos = publicIsoSearch(bootable, false, tags); + List userIsos = userIsoSearch(false); + + //Listing the ISOs according to the page size.Restricting the total no. of ISOs on a page + //to be less than or equal to the pageSize parameter + + int i=0; + + if (startIndex > userIsos.size()) { + i=(int) (startIndex - userIsos.size()); + } + + for (; i < publicIsos.size(); i++) { + if(templateZonePairList.size() >= pageSize){ + break; + } else { + if (keyword != null && publicIsos.get(i).getName().contains(keyword)) { + templateZonePairList.add(new Pair(publicIsos.get(i).getId(), null)); + continue; + } else if (name != null && publicIsos.get(i).getName().contains(name)) { + templateZonePairList.add(new Pair(publicIsos.get(i).getId(), null)); + continue; + } else if (keyword == null && name == null){ + templateZonePairList.add(new Pair(publicIsos.get(i).getId(), null)); + } + } + } + } + } catch (Exception e) { + s_logger.warn("Error listing templates", e); + } finally { + try { + if (rs != null) { + rs.close(); + } + if (pstmt != null) { + pstmt.close(); + } + txn.commit(); + } catch( SQLException sqle) { + s_logger.warn("Error in cleaning up", sqle); + } + } + + return templateZonePairList; + } + + private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr) { + String sql = ""; + if (keyword != null) { + sql += " t.name LIKE \"%" + keyword + "%\" AND"; + } else if (name != null) { + sql += " t.name LIKE \"%" + name + "%\" AND"; + } + + if (isIso) { + sql += " t.format = 'ISO'"; + if (!hyperType.equals(HypervisorType.None)) { + sql += " AND goh.hypervisor_type = '" + hyperType.toString() + "'"; + } + } else { + sql += " t.format <> 'ISO'"; + if (!hyperType.equals(HypervisorType.None)) { + sql += " AND t.hypervisor_type = '" + hyperType.toString() + "'"; + } + } + + if (bootable != null) { + sql += " AND t.bootable = " + bootable; + } + + if (onlyReady){ + sql += " AND thr.download_state = '" +Status.DOWNLOADED.toString() + "'" + " AND thr.destroyed=0 "; + if (zoneId != null){ + sql += " AND h.data_center_id = " +zoneId; + } + }else if (zoneId != null){ + sql += " AND tzr.zone_id = " +zoneId+ " AND tzr.removed is null" ; + }else{ + sql += " AND tzr.removed is null "; + } + if (!showDomr){ + sql += " AND t.type != '" +Storage.TemplateType.SYSTEM.toString() + "'"; + } + + sql += " AND t.removed IS NULL"; + + return sql; + } + + private String getOrderByLimit(Long pageSize, Long startIndex) { + Boolean isAscending = Boolean.parseBoolean(_configDao.getValue("sortkey.algorithm")); + isAscending = (isAscending == null ? true : isAscending); + + String sql; + if (isAscending) { + sql = " ORDER BY t.sort_key ASC"; + } else { + sql = " ORDER BY t.sort_key DESC"; + } + + if ((pageSize != null) && (startIndex != null)) { + sql += " LIMIT " + startIndex.toString() + "," + pageSize.toString(); + } + return sql; + } + + @Override + @DB + public long addTemplateToZone(ImageDataVO tmplt, long zoneId) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + ImageDataVO tmplt2 = findById(tmplt.getId()); + if (tmplt2 == null){ + if (persist(tmplt) == null) { + throw new CloudRuntimeException("Failed to persist the template " + tmplt); + } + if(tmplt.getDetails() != null) { + _templateDetailsDao.persist(tmplt.getId(), tmplt.getDetails()); + } + } + VMTemplateZoneVO tmpltZoneVO = _templateZoneDao.findByZoneTemplate(zoneId, tmplt.getId()); + if (tmpltZoneVO == null ) { + tmpltZoneVO = new VMTemplateZoneVO(zoneId, tmplt.getId(), new Date()); + _templateZoneDao.persist(tmpltZoneVO); + } else { + tmpltZoneVO.setRemoved(null); + tmpltZoneVO.setLastUpdated(new Date()); + _templateZoneDao.update(tmpltZoneVO.getId(), tmpltZoneVO); + } + txn.commit(); + + return tmplt.getId(); + } + + @Override + @DB + public List listAllInZone(long dataCenterId) { + SearchCriteria sc = TmpltsInZoneSearch.create(); + sc.setParameters("avoidtype", TemplateType.PERHOST.toString()); + sc.setJoinParameters("tmpltzone", "zoneId", dataCenterId); + return listBy(sc); + } + + @Override + public List listDefaultBuiltinTemplates() { + SearchCriteria sc = tmpltTypeSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.BUILTIN); + return listBy(sc); + } + + @Override + public ImageDataVO findSystemVMTemplate(long zoneId) { + SearchCriteria sc = tmpltTypeHyperSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing); + sc.setJoinParameters("tmplHyper", "zoneId", zoneId); + + //order by descending order of id and select the first (this is going to be the latest) + List tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, 1l)); + + if (tmplts.size() > 0) { + return tmplts.get(0); + } else { + return null; + } + } + + public ImageDataVO findSystemVMTemplate(long zoneId, HypervisorType hType) { + SearchCriteria sc = tmpltTypeHyperSearch.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + sc.setJoinParameters("tmplHyper", "type", Host.Type.Routing); + sc.setJoinParameters("tmplHyper", "zoneId", zoneId); + + //order by descending order of id + List tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, null)); + + for (ImageDataVO tmplt: tmplts) { + if (tmplt.getHypervisorType() == hType) { + return tmplt; + } + } + if (tmplts.size() > 0 && hType == HypervisorType.Any) { + return tmplts.get(0); + } + return null; + } + + @Override + public ImageDataVO findRoutingTemplate(HypervisorType hType) { + SearchCriteria sc = tmpltTypeHyperSearch2.create(); + sc.setParameters("templateType", Storage.TemplateType.SYSTEM); + sc.setParameters("hypervisorType", hType); + + //order by descending order of id and select the first (this is going to be the latest) + List tmplts = listBy(sc, new Filter(ImageDataVO.class, "id", false, null, 1l)); + + if (tmplts.size() > 0) { + return tmplts.get(0); + } else { + return null; + } + } + + @Override + public Long countTemplatesForAccount(long accountId) { + SearchCriteria sc = CountTemplatesByAccount.create(); + sc.setParameters("account", accountId); + return customSearch(sc, null).get(0); + } + + @Override + @DB + public boolean remove(Long id) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + ImageDataVO template = createForUpdate(); + template.setRemoved(new Date()); + + ImageDataVO vo = findById(id); + if (vo != null) { + if (vo.getFormat().equalsIgnoreCase(new ISO().toString())) { + _tagsDao.removeByIdAndType(id, TaggedResourceType.ISO); + } else { + _tagsDao.removeByIdAndType(id, TaggedResourceType.Template); + } + } + + boolean result = update(id, template); + txn.commit(); + return result; + } + + private boolean isAdmin(short accountType) { + return ((accountType == Account.ACCOUNT_TYPE_ADMIN) || + (accountType == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) || + (accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || + (accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN)); + } + +} \ No newline at end of file diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDao.java new file mode 100644 index 00000000000..466afa296f4 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderDaoImpl.java new file mode 100644 index 00000000000..cb075bea1ee --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.java new file mode 100644 index 00000000000..b8ecdccaa81 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreProviderVO.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.db; + +public interface ImageDataStoreProviderVO { + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataStoreVO.java new file mode 100644 index 00000000000..7177203aa75 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java new file mode 100644 index 00000000000..d50be8867d1 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/db/ImageDataVO.java @@ -0,0 +1,381 @@ +/* + * 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 java.util.Date; +import java.util.Map; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.Transient; + +import com.cloud.api.Identity; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.Storage; +import com.cloud.storage.VMTemplateVO; +import com.cloud.storage.Storage.TemplateType; +import com.cloud.utils.db.GenericDao; + +@Entity +@Table(name="vm_template") +public class ImageDataVO implements Identity { + @Id + @TableGenerator(name="vm_template_sq", table="sequence", pkColumnName="name", valueColumnName="value", pkColumnValue="vm_template_seq", allocationSize=1) + @Column(name="id", nullable = false) + private long id; + + @Column(name="format") + private String format; + + @Column(name="unique_name") + private String uniqueName; + + @Column(name="name") + private String name = null; + + @Column(name="public") + private boolean publicTemplate = true; + + @Column(name="featured") + private boolean featured; + + @Column(name="type") + private Storage.TemplateType templateType; + + @Column(name="url") + private String url = null; + + @Column(name="hvm") + private boolean requiresHvm; + + @Column(name="bits") + private int bits; + + @Temporal(value=TemporalType.TIMESTAMP) + @Column(name=GenericDao.CREATED_COLUMN) + private Date created = null; + + @Column(name=GenericDao.REMOVED) + @Temporal(TemporalType.TIMESTAMP) + private Date removed; + + @Column(name="account_id") + private long accountId; + + @Column(name="checksum") + private String checksum; + + @Column(name="display_text", length=4096) + private String displayText; + + @Column(name="enable_password") + private boolean enablePassword; + + @Column(name="guest_os_id") + private long guestOSId; + + @Column(name="bootable") + private boolean bootable = true; + + @Column(name="prepopulate") + private boolean prepopulate = false; + + @Column(name="cross_zones") + private boolean crossZones = false; + + @Column(name="hypervisor_type") + @Enumerated(value=EnumType.STRING) + private HypervisorType hypervisorType; + + @Column(name="extractable") + private boolean extractable = true; + + @Column(name="source_template_id") + private Long sourceTemplateId; + + @Column(name="template_tag") + private String templateTag; + + @Column(name="uuid") + private String uuid; + + @Column(name="sort_key") + private int sortKey; + + @Column(name="enable_sshkey") + private boolean enableSshKey; + + @Transient + Map details; + + + public String getUniqueName() { + return uniqueName; + } + + public void setUniqueName(String uniqueName) { + this.uniqueName = uniqueName; + } + + protected ImageDataVO() { + this.uuid = UUID.randomUUID().toString(); + } + + public boolean getEnablePassword() { + return enablePassword; + } + + public String getFormat() { + return format; + } + + public void setEnablePassword(boolean enablePassword) { + this.enablePassword = enablePassword; + } + + public void setFormat(String format) { + this.format = format; + } + + public long getId() { + return id; + } + + public TemplateType getTemplateType() { + return templateType; + } + + public void setTemplateType(TemplateType type) { + this.templateType = type; + } + + public boolean requiresHvm() { + return requiresHvm; + } + + public int getBits() { + return bits; + } + + public void setBits(int bits) { + this.bits = bits; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getRemoved() { + return removed; + } + + public boolean isPublicTemplate() { + return publicTemplate; + } + + public void setPublicTemplate(boolean publicTemplate) { + this.publicTemplate = publicTemplate; + } + + public boolean isFeatured() { + return featured; + } + + public void setFeatured(boolean featured) { + this.featured = featured; + } + + public Date getCreated() { + return created; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public long getAccountId() { + return accountId; + } + + public String getChecksum() { + return checksum; + } + + public void setChecksum(String checksum) { + this.checksum = checksum; + } + + public String getDisplayText() { + return displayText; + } + + public void setDisplayText(String displayText) { + this.displayText = displayText; + } + + public long getGuestOSId() { + return guestOSId; + } + + public void setGuestOSId(long guestOSId) { + this.guestOSId = guestOSId; + } + + public boolean isBootable() { + return bootable; + } + + public void setBootable(boolean bootable) { + this.bootable = bootable; + } + + public void setPrepopulate(boolean prepopulate) { + this.prepopulate = prepopulate; + } + + public boolean isPrepopulate() { + return prepopulate; + } + + public void setCrossZones(boolean crossZones) { + this.crossZones = crossZones; + } + + public boolean isCrossZones() { + return crossZones; + } + + public HypervisorType getHypervisorType() { + return hypervisorType; + } + + public void setHypervisorType(HypervisorType hyperType) { + hypervisorType = hyperType; + } + + public boolean isExtractable() { + return extractable; + } + + public void setExtractable(boolean extractable) { + this.extractable = extractable; + } + + public Long getSourceTemplateId() { + return sourceTemplateId; + } + + public void setSourceTemplateId(Long sourceTemplateId) { + this.sourceTemplateId = sourceTemplateId; + } + + public String getTemplateTag() { + return templateTag; + } + + public void setTemplateTag(String templateTag) { + this.templateTag = templateTag; + } + + public long getDomainId() { + return -1; + } + + @Override + public String getUuid() { + return this.uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public Map getDetails() { + return this.details; + } + + public void setDetails(Map details) { + this.details = details; + } + + @Override + public boolean equals(Object that) { + if (this == that ) { + return true; + } + if (!(that instanceof VMTemplateVO)){ + return false; + } + VMTemplateVO other = (VMTemplateVO)that; + + return ((this.getUniqueName().equals(other.getUniqueName()))); + } + + @Override + public int hashCode() { + return uniqueName.hashCode(); + } + + @Transient + String toString; + @Override + public String toString() { + if (toString == null) { + toString = new StringBuilder("Tmpl[").append(id).append("-").append(format).append("-").append(uniqueName).toString(); + } + return toString; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public void setSortKey(int key) { + sortKey = key; + } + + public int getSortKey() { + return sortKey; + } + + public boolean getEnableSshKey() { + return enableSshKey; + } + + public void setEnableSshKey(boolean enable) { + enableSshKey = enable; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java b/engine/storage/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java new file mode 100644 index 00000000000..123df61e48c --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java new file mode 100644 index 00000000000..1a45bd9048c --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java @@ -0,0 +1,28 @@ +/* + * 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.driver; + +import org.apache.cloudstack.storage.image.Template; + +public interface ImageDataStoreDriver { + boolean registerTemplate(Template template); + String grantAccess(long templateId, long endPointId); + boolean revokeAccess(long templateId, long endPointId); + boolean deleteTemplate(Template template); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java new file mode 100644 index 00000000000..a88e6695e18 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java @@ -0,0 +1,51 @@ +/* + * 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.driver; + +import org.apache.cloudstack.storage.image.Template; + +public class ImageDataStoreDriverImpl implements ImageDataStoreDriver { + + @Override + public boolean registerTemplate(Template template) { + //TODO: check the availability of template + return true; + } + + @Override + public String grantAccess(long templateId, long endPointId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean revokeAccess(long templateId, long endPointId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean deleteTemplate(Template template) { + // TODO Auto-generated method stub + return false; + } + + + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java new file mode 100644 index 00000000000..c3de2f1a31d --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java @@ -0,0 +1,31 @@ +/* + * 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.format; + +import org.apache.cloudstack.storage.BaseType; +import org.springframework.stereotype.Component; + +@Component +public class BAREMETAL extends BaseType implements ImageFormat { + private final String type = "BAREMETAL"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java new file mode 100644 index 00000000000..f27d16b178a --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java @@ -0,0 +1,31 @@ +/* + * 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.format; + +import org.apache.cloudstack.storage.BaseType; +import org.springframework.stereotype.Component; + +@Component +public class ISO extends BaseType implements ImageFormat { + private final String type = "ISO"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.java new file mode 100644 index 00000000000..f02694a7195 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.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.format; + +public interface ImageFormat { + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java new file mode 100644 index 00000000000..6ecb9b05d43 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java @@ -0,0 +1,44 @@ +/* + * 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.format; + +import java.util.List; + +import javax.inject.Inject; + +import org.springframework.stereotype.Component; + +@Component +public class ImageFormatHelper { + private static List formats; + private static final ImageFormat defaultFormat = new Unknown(); + @Inject + public void setFormats(List formats) { + ImageFormatHelper.formats = formats; + } + + public static ImageFormat getFormat(String format) { + for(ImageFormat fm : formats) { + if (fm.equals(format)) { + return fm; + } + } + return ImageFormatHelper.defaultFormat; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.java new file mode 100644 index 00000000000..46f77a00be2 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.java @@ -0,0 +1,31 @@ +/* + * 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.format; + +import org.apache.cloudstack.storage.BaseType; +import org.springframework.stereotype.Component; + +@Component +public class OVA extends BaseType implements ImageFormat { + private final String type = "OVA"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.java new file mode 100644 index 00000000000..9e13ebb62c8 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.java @@ -0,0 +1,31 @@ +/* + * 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.format; + +import org.apache.cloudstack.storage.BaseType; +import org.springframework.stereotype.Component; + +@Component("imageformat_qcow2") +public class QCOW2 extends BaseType implements ImageFormat { + private final String type = "QCOW2"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java new file mode 100644 index 00000000000..341be646b6b --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.image.format; + +import org.apache.cloudstack.storage.BaseType; +import org.springframework.stereotype.Component; + +@Component +public class Unknown extends BaseType implements ImageFormat { + private final String type = "Unknown"; + + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.java new file mode 100644 index 00000000000..4a02e5fe893 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.java @@ -0,0 +1,29 @@ +/* + * 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.format; + +import org.apache.cloudstack.storage.BaseType; + +public class VHD extends BaseType implements ImageFormat { + private final String type = "VHD"; + @Override + public String toString() { + return type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.java b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.java new file mode 100644 index 00000000000..878e394c9f9 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.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.manager; + +import org.apache.cloudstack.storage.image.store.ImageDataStore; + +public interface ImageDataStoreManager { + ImageDataStore getImageDataStore(long dataStoreId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java new file mode 100644 index 00000000000..3b09fcbe521 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java @@ -0,0 +1,41 @@ +/* + * 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.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/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.java b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.java new file mode 100644 index 00000000000..42933f440b9 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.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.provider; + +import org.apache.cloudstack.storage.image.store.ImageDataStore; + +public interface ImageDataStoreProvider { + ImageDataStore getImageDataStore(long imageStoreId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java new file mode 100644 index 00000000000..1f9c956ce68 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java new file mode 100644 index 00000000000..0325311df5c --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java new file mode 100644 index 00000000000..60d1e84dc05 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java @@ -0,0 +1,31 @@ +/* + * 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.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/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java new file mode 100644 index 00000000000..925e1525879 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java @@ -0,0 +1,83 @@ +/* + * 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.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) { + ImageDataVO idv = imageDao.findById(templateId); + Template template = new Template(this, idv); + if (driver.registerTemplate(template)) { + return template; + } else { + return null; + } + } + + @Override + public String grantAccess(long templateId, long endPointId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean revokeAccess(long templateId, long endPointId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean deleteTemplate(long templateId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean needDownloadToCacheStorage() { + // TODO Auto-generated method stub + return false; + } + + @Override + public ImageDownloader getImageDownloader() { + return this.downloader; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java new file mode 100644 index 00000000000..d31935e1a47 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java new file mode 100644 index 00000000000..dbf8589ad64 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java @@ -0,0 +1,123 @@ +package org.apache.cloudstack.storage.lifecycle; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +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.DataStoreLifeCycle; +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.CreateStoragePoolCommand; +import com.cloud.agent.api.ModifyStoragePoolAnswer; +import com.cloud.agent.api.ModifyStoragePoolCommand; +import com.cloud.alert.AlertManager; +import com.cloud.exception.StorageUnavailableException; +import com.cloud.host.HostVO; +import com.cloud.storage.StoragePoolHostVO; +import com.cloud.storage.StoragePoolVO; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.storage.dao.StoragePoolDao; +import com.cloud.storage.dao.StoragePoolHostDao; +import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; + +public class DefaultPrimaryDataStoreLifeCycle implements DataStoreLifeCycle { + private static final Logger s_logger = Logger.getLogger(DataStoreLifeCycle.class); + private DataStore _ds; + @Inject + StoragePoolDao _storagePoolDao; + @Inject + StoragePoolHostDao _poolHostDao; + public DefaultPrimaryDataStoreLifeCycle(DataStore ds) { + this._ds = ds; + } + + + protected boolean createStoragePool(DataStoreEndPoint ep, StoragePoolVO pool) { + DataStoreDriver dsDriver = _ds.getDataStoreDriver(); + CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool); + final Answer answer = dsDriver.sendMessage(ep, cmd); + if (answer != null && answer.getResult()) { + return true; + } else { + throw new CloudRuntimeException(answer.getDetails()); + } + } + + protected void connectHostToSharedPool(DataStoreEndPoint ep, StoragePoolVO pool) throws StorageUnavailableException { + DataStoreDriver dsDriver = _ds.getDataStoreDriver(); + long hostId = ep.getHostId(); + ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool); + final Answer answer = dsDriver.sendMessage(ep, cmd); + + if (answer == null) { + throw new StorageUnavailableException("Unable to get an answer to the modify storage pool command", pool.getId()); + } + + if (!answer.getResult()) { + throw new StorageUnavailableException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails(), pool.getId()); + } + + assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId(); + ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer; + + StoragePoolHostVO poolHost = _poolHostDao.findByPoolHost(pool.getId(), hostId); + if (poolHost == null) { + poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/")); + _poolHostDao.persist(poolHost); + } else { + poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/")); + } + pool.setAvailableBytes(mspAnswer.getPoolInfo().getAvailableBytes()); + pool.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes()); + _storagePoolDao.update(pool.getId(), pool); + } + + public void add() { + DataStoreEndPointSelector dseps = _ds.getEndPointSelector(); + List dsep = dseps.getEndPoints(null); + boolean success = false; + StoragePoolVO spool = _storagePoolDao.findById(_ds.getId()); + for (DataStoreEndPoint ep : dsep) { + success = createStoragePool(ep, spool); + if (success) { + break; + } + } + + List poolHosts = new ArrayList(); + for (DataStoreEndPoint ep : dsep) { + try { + connectHostToSharedPool(ep, spool); + poolHosts.add(ep); + } catch (Exception e) { + s_logger.debug("Failed to add storage on this ep: " + ep.getHostId()); + } + } + } + + 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/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java new file mode 100644 index 00000000000..f8388c937ec --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.manager; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataObjectBackupStorageOperationState; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; + +import com.cloud.storage.Snapshot; +import com.cloud.storage.Volume; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.utils.fsm.NoTransitionException; + +public interface BackupStorageManager { + boolean contains(Volume vol); + boolean contains(Snapshot snapshot); + boolean contains(VirtualMachineTemplate template); + + DataStore getBackupDataStore(Volume vol); + DataStore getBackupDataStore(Snapshot snapshot); + DataStore getBackupDataStore(VirtualMachineTemplate template); + + boolean updateOperationState(Volume vol, DataObjectBackupStorageOperationState.Event event) throws NoTransitionException; +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java new file mode 100644 index 00000000000..500763c774f --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.manager; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataObjectBackupStorageOperationState.Event; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; + +import com.cloud.storage.Snapshot; +import com.cloud.storage.Volume; +import com.cloud.template.VirtualMachineTemplate; +import com.cloud.utils.fsm.NoTransitionException; + +public class BackupStorageManagerImpl implements BackupStorageManager { + + public boolean contains(Volume vol) { + // TODO Auto-generated method stub + return false; + } + + public boolean contains(Snapshot snapshot) { + // TODO Auto-generated method stub + return false; + } + + public boolean contains(VirtualMachineTemplate template) { + // TODO Auto-generated method stub + return false; + } + + public DataStore getBackupDataStore(Volume vol) { + // TODO Auto-generated method stub + return null; + } + + public DataStore getBackupDataStore(Snapshot snapshot) { + // TODO Auto-generated method stub + return null; + } + + public DataStore getBackupDataStore(VirtualMachineTemplate template) { + // TODO Auto-generated method stub + return null; + } + + public boolean updateOperationState(Volume vol, Event event) throws NoTransitionException { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java new file mode 100644 index 00000000000..6292ab8b553 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.manager; + +import java.util.List; +import java.util.Map; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.StoragePool; + +public interface PrimaryDataStoreManager { + PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, + String URI, + String storageType, + String poolName, + String storageProviderName, + Map params); + void deleteStoragePool(long poolId); + void enableStoragePool(long poolId); + void disableStoragePool(long poolId); + Map> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor); + Map> getSupportedSecondaryStorages(long zoneId); + PrimaryDataStore getDataStore(String id); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java new file mode 100644 index 00000000000..2cae6a8c7ac --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.manager; + +import java.util.Iterator; +import java.util.List; +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.platform.subsystem.api.storage.DataStoreLifeCycle; +import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider; +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; + +import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.dao.ClusterDao; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.dc.dao.HostPodDao; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.StoragePool; +import com.cloud.storage.StoragePoolStatus; +import com.cloud.storage.StoragePoolVO; +import com.cloud.storage.dao.StoragePoolDao; +import com.cloud.utils.component.Adapters; +import com.cloud.utils.component.Inject; +import com.cloud.utils.exception.CloudRuntimeException; + +public class PrimaryDataStoreManagerImpl implements PrimaryDataStoreManager { + @Inject(adapter = StorageProvider.class) + protected Adapters _storageProviders; + @Inject + protected DataCenterDao _dcDao; + @Inject + protected HostPodDao _podDao; + @Inject + protected ClusterDao _clusterDao; + @Inject + protected StoragePoolDao _storagePoolDao; + + public void deleteStoragePool(long poolId) { + StoragePool spool = _storagePoolDao.findById(poolId); + StorageProvider sp = findStorageProvider(spool.getStorageProvider()); + DataStore ds = sp.getDataStore(spool); + DataStoreLifeCycle dslc = ds.getLifeCycle(); + dslc.delete(); + } + + public void enableStoragePool(long poolId) { + // TODO Auto-generated method stub + + } + + public void disableStoragePool(long poolId) { + // TODO Auto-generated method stub + + } + + public Map> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor) { + // TODO Auto-generated method stub + return null; + } + + public Map> getSupportedSecondaryStorages(long zoneId) { + // TODO Auto-generated method stub + return null; + } + + protected StorageProvider findStorageProvider(String name) { + Iterator spIter = _storageProviders.iterator(); + StorageProvider sp = null; + while (spIter.hasNext()) { + sp = spIter.next(); + if (sp.getProviderName().equalsIgnoreCase(name)) { + break; + } + } + + return sp; + } + + public StoragePool addStoragePool(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map params) { + StoragePoolVO spool = new StoragePoolVO(); + long poolId = _storagePoolDao.getNextInSequence(Long.class, "id"); + spool.setId(poolId); + spool.setDataCenterId(zoneId); + spool.setPodId(podId); + spool.setName(poolName); + spool.setClusterId(clusterId); + spool.setStorageProvider(storageProviderName); + spool.setStorageType(storageType); + spool.setStatus(StoragePoolStatus.Creating); + spool = _storagePoolDao.persist(spool); + + StorageProvider sp = findStorageProvider(storageProviderName); + DataStore ds = sp.addDataStore((StoragePool)spool, URI, params); + + DataStoreLifeCycle dslc = ds.getLifeCycle(); + try { + dslc.add(); + } catch (CloudRuntimeException e) { + _storagePoolDao.remove(spool.getId()); + throw e; + } + + spool.setPath(ds.getURI()); + spool.setUuid(ds.getUUID()); + spool.setStatus(StoragePoolStatus.Up); + _storagePoolDao.update(spool.getId(), spool); + spool = _storagePoolDao.findById(spool.getId()); + return spool; + } + + @Override + public PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map params) { + // TODO Auto-generated method stub + return null; + } + + @Override + public PrimaryDataStore getDataStore(String id) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java new file mode 100644 index 00000000000..cc9136e5fd1 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.manager; + +import 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.template.VirtualMachineTemplate; + +public interface SecondaryStorageManager { + DataStore getStore(Volume volume); + DataStore getImageStore(DataStore destStore); + List getImageStores(long zoneId); + DataStore getStore(Snapshot snapshot); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java new file mode 100644 index 00000000000..dd4ed68e047 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cloudstack.storage.manager; + +import 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; + } + + public List getImageStores(long zoneId) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java new file mode 100644 index 00000000000..484b4851062 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java new file mode 100644 index 00000000000..a5579d07726 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java @@ -0,0 +1,144 @@ +package org.apache.cloudstack.storage.provider; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle; +import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType; +import org.apache.cloudstack.storage.datastoreconfigurator.NfsDataStoreConfigurator; +import org.apache.cloudstack.storage.datastoreconfigurator.XenNfsDataStoreConfigurator; + +import com.cloud.dc.ClusterVO; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.HostPodVO; +import com.cloud.dc.dao.ClusterDao; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.hypervisor.Hypervisor; +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.StoragePool; +import com.cloud.storage.StoragePoolStatus; +import com.cloud.storage.StoragePoolVO; +import com.cloud.storage.dao.StoragePoolDao; +import com.cloud.utils.component.Inject; + +public class DefaultPrimaryStorageProvider implements StorageProvider { + private String _name = DefaultPrimaryStorageProvider.class.toString(); + static Map> _supportedProtocols; + @Inject + protected ClusterDao _clusterDao; + + public List supportedHypervisors() { + List hypervisors = new ArrayList(); + hypervisors.add(Hypervisor.HypervisorType.XenServer); + return hypervisors; + } + + public DefaultPrimaryStorageProvider() { + Map dscs = new HashMap(); + DataStoreConfigurator nfsdc = new XenNfsDataStoreConfigurator(); + dscs.put(nfsdc.getProtocol(), nfsdc); + + _supportedProtocols.put(HypervisorType.XenServer, dscs); + } + + public List supportedStoreType() { + List type = new ArrayList(); + type.add(StoreType.Primary); + return type; + } + + public void configure(Map storeProviderInfo) { + // TODO Auto-generated method stub + + } + + public Map> getDataStoreConfigs() { + return _supportedProtocols; + } + + public String getProviderName() { + return _name; + } + + public DataStore createDataStore(HypervisorType hypervisor, + DataStoreConfigurator dsc) { + // TODO Auto-generated method stub + return null; + } + + public DataStore getDataStore(StoragePool pool) { + ClusterVO clu = _clusterDao.findById(pool.getClusterId()); + HypervisorType hy = clu.getHypervisorType(); + Map dscs = _supportedProtocols.get(hy); + DataStoreConfigurator dsc = dscs.get(pool.getPoolType().toString()); + return dsc.getDataStore(pool); + } + + 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 DataStore addDataStore(StoragePool spool, 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"); + } + + ClusterVO cluster = _clusterDao.findById(spool.getClusterId()); + + Map dscs = _supportedProtocols.get(cluster.getHypervisorType()); + if (dscs.isEmpty()) { + throw new InvalidParameterValueException("Doesn't support this hypervisor"); + } + + DataStoreConfigurator dsc = dscs.get(protocol); + if (dsc == null) { + throw new InvalidParameterValueException("Doesn't support this protocol"); + } + + Map configs = dsc.getConfigs(uri, params); + dsc.validate(configs); + DataStore ds = dsc.getDataStore(spool); + + return ds; + } + + public List supportedStoreTypes() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java new file mode 100644 index 00000000000..c98320ba300 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java new file mode 100644 index 00000000000..d5c15b3ccb6 --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java new file mode 100644 index 00000000000..75bf74c02ae --- /dev/null +++ b/engine/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/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.java b/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.java new file mode 100644 index 00000000000..6adab006a6e --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.java @@ -0,0 +1,24 @@ +/* + * 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.snapshot; + +public interface SnapshotService { + long takeSnapshot(long volumeId); + boolean deleteSnapshot(long snapshotId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java b/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java new file mode 100644 index 00000000000..2c6eaa3bcaa --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java @@ -0,0 +1,191 @@ +/* + * 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.strategy; + +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +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.StorageProvider; +import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile; +import org.apache.cloudstack.platform.subsystem.api.storage.TemplateStrategy; +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.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; + +public class DefaultTemplateStratey implements TemplateStrategy { + private static final Logger s_logger = Logger.getLogger(DefaultTemplateStratey.class); + protected DataStore _ds; + protected DataStoreDriver _driver; + protected int _primaryStorageDownloadWait; + protected int _installTries = 3; + protected int _storagePoolMaxWaitSeconds = 3600; + @Inject + VMTemplatePoolDao _templatePoolDao; + @Inject + VMTemplateHostDao _templateImageStoreDao; + @Inject + ImageManager _templateMgr; + + public DefaultTemplateStratey(DataStore ds) { + _ds = ds; + } + + public TemplateProfile get(long templateId) { + return _templateMgr.getProfile(templateId); + } + + public TemplateProfile install(TemplateProfile tp) { + DataStoreEndPointSelector dseps = _ds.getEndPointSelector(); + List eps = dseps.getEndPoints(StorageEvent.DownloadTemplateToPrimary); + int tries = Math.min(eps.size(), _installTries); + + VMTemplateStoragePoolVO templateStoragePoolRef = _templatePoolDao.acquireInLockTable(tp.getTemplatePoolRefId(), _storagePoolMaxWaitSeconds); + if (templateStoragePoolRef == null) { + throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + tp.getTemplatePoolRefId()); + } + + try { + for (int retry = 0; retry < tries; retry++) { + Collections.shuffle(eps); + DataStoreEndPoint ep = eps.get(0); + try { + tp = _driver.install(tp, ep); + templateStoragePoolRef.setDownloadPercent(100); + templateStoragePoolRef.setDownloadState(Status.DOWNLOADED); + 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.getTemplateId() + " is installed via " + ep.getHostId()); + } + return get(tp.getTemplateId()); + } catch (CloudRuntimeException e) { + if (s_logger.isDebugEnabled()) { + s_logger.debug("Template " + tp.getTemplateId() + " download to pool " + _ds.getId() + " failed due to " + e.toString()); + } + } + } + } finally { + _templatePoolDao.releaseFromLockTable(tp.getTemplatePoolRefId()); + } + + if (s_logger.isDebugEnabled()) { + 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/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultVolumeStrategy.java b/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultVolumeStrategy.java new file mode 100644 index 00000000000..35e284f1c70 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultVolumeStrategy.java @@ -0,0 +1,90 @@ +package org.apache.cloudstack.storage.strategy; + +import java.util.List; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +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.SnapshotProfile; +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.VolumeProfile; +import org.apache.cloudstack.platform.subsystem.api.storage.VolumeStrategy; +import org.apache.cloudstack.storage.volume.VolumeManager; + +import org.apache.log4j.Logger; + + +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeVO; +import com.cloud.utils.component.Inject; + + +public class DefaultVolumeStrategy implements VolumeStrategy { + private static final Logger s_logger = Logger.getLogger(DefaultVolumeStrategy.class); + protected DataStore _ds; + protected DataStoreDriver _driver; + @Inject + VolumeManager _volumeMgr; + + public VolumeProfile get(long volumeId) { + return _volumeMgr.getProfile(volumeId); + } + + public DefaultVolumeStrategy(DataStore ds) { + _ds = ds; + } + public Volume createVolume(Volume vol) { + // TODO Auto-generated method stub + return null; + } + public Volume createDataVolume(Volume vol) { + // TODO Auto-generated method stub + return null; + } + public Volume copyVolumeFromBackup(VolumeProfile srcVol, Volume destVol) { + // TODO Auto-generated method stub + return null; + } + public Volume createVolumeFromSnapshot(SnapshotProfile snapshot, Volume vol) { + // TODO Auto-generated method stub + return null; + } + public Volume createVolumeFromTemplate(TemplateProfile template, Volume vol) { + // TODO Auto-generated method stub + return null; + } + public Volume migrateVolume(Volume srcVol, Volume destVol, DataStore destStore) { + // TODO Auto-generated method stub + return null; + } + + public Volume createVolumeFromBaseTemplate(Volume volume, TemplateProfile tp) { + DataStoreEndPointSelector dsep = _ds.getEndPointSelector(); + List dseps = dsep.getEndPoints(StorageEvent.CreateVolumeFromTemplate); + DataStoreEndPoint dp = dseps.get(0); + + VolumeProfile vp = _driver.createVolumeFromTemplate(get(volume.getId()), tp, dp); + + VolumeVO vlvo = _volumeMgr.getVolume(volume.getId()); + + vlvo.setFolder(_ds.getPath()); + vlvo.setPath(vp.getPath()); + vlvo.setSize(vp.getSize()); + vlvo.setPoolType(_ds.getPoolType()); + vlvo.setPoolId(_ds.getId()); + vlvo.setPodId(_ds.getPodId()); + + return _volumeMgr.updateVolume(vlvo); + } + public boolean deleteVolume(Volume vol) { + // TODO Auto-generated method stub + return false; + } + + + + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/strategy/XenBackupStrategy.java b/engine/storage/src/org/apache/cloudstack/storage/strategy/XenBackupStrategy.java new file mode 100644 index 00000000000..5ac839d00e3 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/strategy/XenBackupStrategy.java @@ -0,0 +1,11 @@ +package org.apache.cloudstack.storage.strategy; + +import org.apache.cloudstack.platform.subsystem.api.storage.BackupStrategy; +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; + +public class XenBackupStrategy implements BackupStrategy { + protected DataStore _ds; + public XenBackupStrategy(DataStore ds) { + _ds = ds; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/strategy/XenSnapshotStrategy.java b/engine/storage/src/org/apache/cloudstack/storage/strategy/XenSnapshotStrategy.java new file mode 100644 index 00000000000..1b938806605 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/strategy/XenSnapshotStrategy.java @@ -0,0 +1,11 @@ +package org.apache.cloudstack.storage.strategy; + +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; +import org.apache.cloudstack.platform.subsystem.api.storage.SnapshotStrategy; + +public class XenSnapshotStrategy implements SnapshotStrategy { + protected DataStore _ds; + public XenSnapshotStrategy(DataStore ds) { + _ds = ds; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/Volume.java b/engine/storage/src/org/apache/cloudstack/storage/volume/Volume.java new file mode 100644 index 00000000000..35eaa3b9a16 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/Volume.java @@ -0,0 +1,101 @@ +package org.apache.cloudstack.storage.volume; + +import javax.inject.Inject; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.PrimaryDataStoreInfo; +import org.apache.cloudstack.storage.volume.db.VolumeDao; +import org.apache.cloudstack.storage.volume.db.VolumeVO; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper; +import org.apache.cloudstack.storage.volume.type.VolumeType; +import org.apache.cloudstack.storage.volume.type.VolumeTypeHelper; +import org.apache.log4j.Logger; + +import com.cloud.utils.fsm.NoTransitionException; +import com.cloud.utils.fsm.StateMachine2; + +public class Volume { + private static final Logger s_logger = Logger.getLogger(Volume.class); + protected VolumeVO volumeVO; + private StateMachine2 _volStateMachine; + protected PrimaryDataStore dataStore; + @Inject + VolumeDiskTypeHelper diskTypeHelper; + @Inject + VolumeTypeHelper volumeTypeHelper; + @Inject + VolumeDao volumeDao; + + public Volume(PrimaryDataStore dataStore, VolumeVO volumeVO) { + this.volumeVO = volumeVO; + this.dataStore = dataStore; + } + + public String getUuid() { + return volumeVO.getUuid(); + } + + public void setUuid(String uuid) { + volumeVO.setUuid(uuid); + } + + public String getPath() { + return volumeVO.getPath(); + } + + public String getTemplateUuid() { + return null; + } + + public String getTemplatePath() { + return null; + } + + public PrimaryDataStoreInfo getDataStoreInfo() { + return dataStore.getDataStoreInfo(); + } + + public VolumeState getState() { + return volumeVO.getState(); + } + + public PrimaryDataStore getDataStore() { + return dataStore; + } + + public long getSize() { + return volumeVO.getSize(); + } + + public VolumeDiskType getDiskType() { + return diskTypeHelper.getDiskType(volumeVO.getDiskType()); + } + + public VolumeType getType() { + return volumeTypeHelper.getType(volumeVO.getVolumeType()); + } + + public long getVolumeId() { + return volumeVO.getId(); + } + + public void setVolumeDiskType(VolumeDiskType type) { + volumeVO.setDiskType(type.toString()); + } + + public boolean stateTransit(VolumeEvent event) { + boolean result = false; + try { + result = _volStateMachine.transitTo(volumeVO, event, null, volumeDao); + } catch (NoTransitionException e) { + s_logger.debug("Failed to transit volume: " + this.getVolumeId() + ", due to: " + e.toString()); + } + return result; + } + + public void update() { + volumeDao.update(volumeVO.getId(), volumeVO); + volumeVO = volumeDao.findById(volumeVO.getId()); + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEvent.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEvent.java new file mode 100644 index 00000000000..33d1261ead9 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeEvent.java @@ -0,0 +1,34 @@ +/* + * 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.volume; + +public enum VolumeEvent { + CreateRequested, + CopyRequested, + CopySucceeded, + CopyFailed, + OperationFailed, + OperationSucceeded, + OperationRetry, + UploadRequested, + MigrationRequested, + SnapshotRequested, + DestroyRequested, + ExpungingRequested; +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java new file mode 100644 index 00000000000..0c6981a9401 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeInfo.java @@ -0,0 +1,76 @@ +/* + * 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.volume; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStoreInfo; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.cloudstack.storage.volume.type.VolumeType; + +public class VolumeInfo { + private long size; + private String uuid; + private String path; + private PrimaryDataStoreInfo dataStoreInfo; + private String baseTemplateUuid; + private String baseTemplatePath; + private VolumeType type; + private VolumeDiskType diskType; + + public VolumeInfo(Volume volume) { + this.size = volume.getSize(); + this.uuid = volume.getUuid(); + this.baseTemplatePath = volume.getTemplatePath(); + this.baseTemplateUuid = volume.getTemplateUuid(); + this.dataStoreInfo = volume.getDataStoreInfo(); + this.diskType = volume.getDiskType(); + this.type = volume.getType(); + } + + public long getSize() { + return this.size; + } + + public String getUuid() { + return this.uuid; + } + + public String getPath() { + return this.path; + } + + public PrimaryDataStoreInfo getDataStore() { + return this.dataStoreInfo; + } + + public String getTemplateUuid() { + return this.baseTemplateUuid; + } + + public String getTemplatePath() { + return this.baseTemplatePath; + } + + public VolumeType getType() { + return this.type; + } + + public VolumeDiskType getDiskType() { + return this.diskType; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManager.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManager.java new file mode 100644 index 00000000000..1b4bc93d75d --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManager.java @@ -0,0 +1,33 @@ +/* + * 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.volume; + +import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile; + +import com.cloud.storage.Volume; +import com.cloud.storage.VolumeVO; +import com.cloud.utils.fsm.NoTransitionException; + +public interface VolumeManager { + VolumeVO allocateDuplicateVolume(VolumeVO oldVol); + VolumeVO processEvent(Volume vol, Volume.Event event) throws NoTransitionException; + VolumeProfile getProfile(long volumeId); + VolumeVO getVolume(long volumeId); + VolumeVO updateVolume(VolumeVO volume); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManagerImpl.java new file mode 100644 index 00000000000..19e61a8fb33 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeManagerImpl.java @@ -0,0 +1,70 @@ +/* + * 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.volume; + +import org.apache.cloudstack.platform.subsystem.api.storage.VolumeProfile; + +import com.cloud.storage.VolumeVO; +import com.cloud.storage.Volume; +import com.cloud.storage.dao.VolumeDao; +import com.cloud.utils.component.Inject; +import com.cloud.utils.fsm.NoTransitionException; +import com.cloud.utils.fsm.StateMachine2; + +public class VolumeManagerImpl implements VolumeManager { + private StateMachine2 _volStateMachine; + @Inject + protected VolumeDao _volumeDao; + + + public VolumeVO allocateDuplicateVolume(VolumeVO oldVol) { + VolumeVO newVol = new VolumeVO(oldVol.getVolumeType(), oldVol.getName(), oldVol.getDataCenterId(), oldVol.getDomainId(), oldVol.getAccountId(), oldVol.getDiskOfferingId(), oldVol.getSize()); + newVol.setTemplateId(oldVol.getTemplateId()); + newVol.setDeviceId(oldVol.getDeviceId()); + newVol.setInstanceId(oldVol.getInstanceId()); + newVol.setRecreatable(oldVol.isRecreatable()); + newVol.setReservationId(oldVol.getReservationId()); + return null; + //return _volumeDao.persist(newVol); + } + + + public VolumeVO processEvent(Volume vol, Volume.Event event) throws NoTransitionException { + //_volStateMachine.transitTo(vol, event, null, _volumeDao); + return _volumeDao.findById(vol.getId()); + } + + + public VolumeProfile getProfile(long volumeId) { + // TODO Auto-generated method stub + return null; + } + + + public VolumeVO getVolume(long volumeId) { + // TODO Auto-generated method stub + return null; + } + + + public VolumeVO updateVolume(VolumeVO volume) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeMotionService.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeMotionService.java new file mode 100644 index 00000000000..9814ecb86ed --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeMotionService.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.volume; + +public interface VolumeMotionService { + boolean copyVolume(String volumeUri, String destVolumeUri); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java new file mode 100644 index 00000000000..63e247cc2a8 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeService.java @@ -0,0 +1,67 @@ +/* + * 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.volume; + +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.cloudstack.storage.volume.type.VolumeType; + +public interface VolumeService { + + /** + * + */ + Volume allocateVolumeInDb(long size, VolumeType type,String volName, Long templateId); + + /** + * Creates the volume based on the given criteria + * + * @param cmd + * + * @return the volume object + */ + Volume createVolume(long volumeId, long dataStoreId, VolumeDiskType diskType); + + /** + * Delete volume + * @param volumeId + * @return + * @throws ConcurrentOperationException + */ + boolean deleteVolume(long volumeId); + + /** + * + */ + boolean cloneVolume(long volumeId, long baseVolId); + + /** + * + */ + boolean createVolumeFromSnapshot(long volumeId, long snapshotId); + + /** + * + */ + String grantAccess(long volumeId, long endpointId); + + /** + * + */ + boolean rokeAccess(long volumeId, long endpointId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java new file mode 100644 index 00000000000..145813fda9b --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.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.volume; + +import javax.inject.Inject; + +import org.apache.cloudstack.storage.datastore.PrimaryDataStore; +import org.apache.cloudstack.storage.datastore.manager.PrimaryDataStoreManager; +import org.apache.cloudstack.storage.volume.db.VolumeDao; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.cloudstack.storage.volume.type.VolumeType; +import org.springframework.stereotype.Service; + +import com.cloud.utils.db.DB; + +@Service +public class VolumeServiceImpl implements VolumeService { + @Inject + VolumeDao volDao; + @Inject + PrimaryDataStoreManager dataStoreMgr; + @Override + public Volume createVolume(long volumeId, long dataStoreId, VolumeDiskType diskType) { + PrimaryDataStore dataStore = dataStoreMgr.getPrimaryDataStore(dataStoreId); + return dataStore.createVolume(volumeId, diskType); + } + + @DB + @Override + public boolean deleteVolume(long volumeId) { + return true; + } + + @Override + public boolean cloneVolume(long volumeId, long baseVolId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean createVolumeFromSnapshot(long volumeId, long snapshotId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public String grantAccess(long volumeId, long endpointId) { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean rokeAccess(long volumeId, long endpointId) { + // TODO Auto-generated method stub + return false; + } + + @Override + public Volume allocateVolumeInDb(long size, VolumeType type, String volName, Long templateId) { + volDao.allocVolume(size, type, volName, templateId); + return null; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeState.java b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeState.java new file mode 100644 index 00000000000..f2ebafa6690 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/VolumeState.java @@ -0,0 +1,73 @@ +/* + * 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.volume; + +import org.apache.cloudstack.storage.volume.db.VolumeVO; + +import com.cloud.utils.fsm.StateMachine2; + +public enum VolumeState { + Allocated("The volume is allocated but has not been created yet."), + Creating("The volume is being created. getPoolId() should reflect the pool where it is being created."), + Ready("The volume is ready to be used."), + Migrating("The volume is migrating to other storage pool"), + Snapshotting("There is a snapshot created on this volume, not backed up to secondary storage yet"), + Expunging("The volume is being expunging"), + Destroy("The volume is destroyed, and can't be recovered."), + UploadOp ("The volume upload operation is in progress or in short the volume is on secondary storage"); + + String _description; + + private VolumeState(String description) { + _description = description; + } + + public static StateMachine2 getStateMachine() { + return s_fsm; + } + + public String getDescription() { + return _description; + } + + private final static StateMachine2 s_fsm = new StateMachine2(); + static { + s_fsm.addTransition(Allocated, VolumeEvent.CreateRequested, Creating); + s_fsm.addTransition(Allocated, VolumeEvent.DestroyRequested, Destroy); + s_fsm.addTransition(Creating, VolumeEvent.OperationRetry, Creating); + s_fsm.addTransition(Creating, VolumeEvent.OperationFailed, Allocated); + s_fsm.addTransition(Creating, VolumeEvent.OperationSucceeded, Ready); + s_fsm.addTransition(Creating, VolumeEvent.DestroyRequested, Destroy); + s_fsm.addTransition(Creating, VolumeEvent.CreateRequested, Creating); + s_fsm.addTransition(Allocated, VolumeEvent.UploadRequested, UploadOp); + s_fsm.addTransition(UploadOp, VolumeEvent.CopyRequested, Creating);// CopyRequested for volume from sec to primary storage + s_fsm.addTransition(Creating, VolumeEvent.CopySucceeded, Ready); + s_fsm.addTransition(Creating, VolumeEvent.CopyFailed, UploadOp);// Copying volume from sec to primary failed. + s_fsm.addTransition(UploadOp, VolumeEvent.DestroyRequested, Destroy); + s_fsm.addTransition(Ready, VolumeEvent.DestroyRequested, Destroy); + s_fsm.addTransition(Destroy, VolumeEvent.ExpungingRequested, Expunging); + s_fsm.addTransition(Ready, VolumeEvent.SnapshotRequested, Snapshotting); + s_fsm.addTransition(Snapshotting, VolumeEvent.OperationSucceeded, Ready); + s_fsm.addTransition(Snapshotting, VolumeEvent.OperationFailed, Ready); + s_fsm.addTransition(Ready, VolumeEvent.MigrationRequested, Migrating); + s_fsm.addTransition(Migrating, VolumeEvent.OperationSucceeded, Ready); + s_fsm.addTransition(Migrating, VolumeEvent.OperationFailed, Ready); + s_fsm.addTransition(Destroy, VolumeEvent.OperationSucceeded, Destroy); + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java new file mode 100644 index 00000000000..0f297278fdf --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDao.java @@ -0,0 +1,82 @@ +// 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.volume.db; + +import java.util.List; + +import org.apache.cloudstack.storage.volume.Volume; +import org.apache.cloudstack.storage.volume.VolumeEvent; +import org.apache.cloudstack.storage.volume.VolumeState; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.cloudstack.storage.volume.type.VolumeType; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.storage.Storage.ImageFormat; +import com.cloud.utils.Pair; +import com.cloud.utils.db.GenericDao; +import com.cloud.utils.fsm.StateDao; + +public interface VolumeDao extends GenericDao, StateDao { + + List findDetachedByAccount(long accountId); + + List findByAccount(long accountId); + + Pair getCountAndTotalByPool(long poolId); + + Pair getNonDestroyedCountAndTotalByPool(long poolId); + + List findByInstance(long id); + + List findByInstanceAndType(long id, VolumeType vType); + + List findByInstanceIdDestroyed(long vmId); + + List findByAccountAndPod(long accountId, long podId); + + List findByTemplateAndZone(long templateId, long zoneId); + + void deleteVolumesByInstance(long instanceId); + + void attachVolume(long volumeId, long vmId, long deviceId); + + void detachVolume(long volumeId); + + boolean isAnyVolumeActivelyUsingTemplateOnPool(long templateId, long poolId); + + List findCreatedByInstance(long id); + + List findByPoolId(long poolId); + + List findByInstanceAndDeviceId(long instanceId, long deviceId); + + List findUsableVolumesForInstance(long instanceId); + + Long countAllocatedVolumesForAccount(long accountId); + + HypervisorType getHypervisorType(long volumeId); + + List listVolumesToBeDestroyed(); + + ImageFormat getImageFormat(Long volumeId); + + List findReadyRootVolumesByInstance(long instanceId); + + List listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId); + + VolumeVO allocVolume(long size, VolumeType type, String volName, Long templateId); +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java new file mode 100644 index 00000000000..ca51bac7866 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeDaoImpl.java @@ -0,0 +1,427 @@ +// 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.volume.db; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.ejb.Local; + +import org.apache.cloudstack.storage.volume.Volume; +import org.apache.cloudstack.storage.volume.VolumeEvent; +import org.apache.cloudstack.storage.volume.VolumeState; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.cloudstack.storage.volume.type.RootDisk; +import org.apache.cloudstack.storage.volume.type.VolumeType; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Component; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.server.ResourceTag.TaggedResourceType; +import com.cloud.storage.Storage.ImageFormat; +import com.cloud.tags.dao.ResourceTagsDaoImpl; +import com.cloud.utils.Pair; +import com.cloud.utils.component.ComponentLocator; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GenericSearchBuilder; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Func; +import com.cloud.utils.db.SearchCriteria.Op; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.db.UpdateBuilder; +import com.cloud.utils.exception.CloudRuntimeException; + +@Local(value=VolumeDao.class) +@Component +public class VolumeDaoImpl extends GenericDaoBase implements VolumeDao { + private static final Logger s_logger = Logger.getLogger(VolumeDaoImpl.class); + protected final SearchBuilder DetachedAccountIdSearch; + protected final SearchBuilder TemplateZoneSearch; + protected final GenericSearchBuilder TotalSizeByPoolSearch; + protected final GenericSearchBuilder ActiveTemplateSearch; + protected final SearchBuilder InstanceStatesSearch; + protected final SearchBuilder AllFieldsSearch; + protected GenericSearchBuilder CountByAccount; + ResourceTagsDaoImpl _tagsDao = ComponentLocator.inject(ResourceTagsDaoImpl.class); + + protected static final String SELECT_VM_SQL = "SELECT DISTINCT instance_id from volumes v where v.host_id = ? and v.mirror_state = ?"; + protected static final String SELECT_HYPERTYPE_FROM_VOLUME = "SELECT c.hypervisor_type from volumes v, storage_pool s, cluster c where v.pool_id = s.id and s.cluster_id = c.id and v.id = ?"; + + private static final String ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT = "SELECT pool.id, SUM(IF(vol.state='Ready' AND vol.account_id = ?, 1, 0)) FROM `cloud`.`storage_pool` pool LEFT JOIN `cloud`.`volumes` vol ON pool.id = vol.pool_id WHERE pool.data_center_id = ? " + + " AND pool.pod_id = ? AND pool.cluster_id = ? " + + " GROUP BY pool.id ORDER BY 2 ASC "; + + @Override + public List findDetachedByAccount(long accountId) { + SearchCriteria sc = DetachedAccountIdSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("destroyed", VolumeState.Destroy); + return listBy(sc); + } + + @Override + public List findByAccount(long accountId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("state", VolumeState.Ready); + return listBy(sc); + } + + @Override + public List findByInstance(long id) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", id); + return listBy(sc); + } + + @Override + public List findByInstanceAndDeviceId(long instanceId, long deviceId){ + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", instanceId); + sc.setParameters("deviceId", deviceId); + return listBy(sc); + } + + @Override + public List findByPoolId(long poolId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("poolId", poolId); + sc.setParameters("notDestroyed", VolumeState.Destroy); + sc.setParameters("vType", new RootDisk().toString()); + return listBy(sc); + } + + @Override + public List findCreatedByInstance(long id) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", id); + sc.setParameters("state", VolumeState.Ready); + return listBy(sc); + } + + @Override + public List findUsableVolumesForInstance(long instanceId) { + SearchCriteria sc = InstanceStatesSearch.create(); + sc.setParameters("instance", instanceId); + sc.setParameters("states", VolumeState.Creating, VolumeState.Ready, VolumeState.Allocated); + + return listBy(sc); + } + + @Override + public List findByInstanceAndType(long id, VolumeType vType) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", id); + sc.setParameters("vType", vType.toString()); + return listBy(sc); + } + + @Override + public List findByInstanceIdDestroyed(long vmId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", vmId); + sc.setParameters("destroyed", VolumeState.Destroy); + return listBy(sc); + } + + @Override + public List findReadyRootVolumesByInstance(long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", instanceId); + sc.setParameters("state", VolumeState.Ready); + sc.setParameters("vType", new RootDisk().toString()); + return listBy(sc); + } + + @Override + public List findByAccountAndPod(long accountId, long podId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("accountId", accountId); + sc.setParameters("pod", podId); + sc.setParameters("state", VolumeState.Ready); + + return listIncludingRemovedBy(sc); + } + + @Override + public List findByTemplateAndZone(long templateId, long zoneId) { + SearchCriteria sc = TemplateZoneSearch.create(); + sc.setParameters("template", templateId); + sc.setParameters("zone", zoneId); + + return listIncludingRemovedBy(sc); + } + + @Override + public boolean isAnyVolumeActivelyUsingTemplateOnPool(long templateId, long poolId) { + SearchCriteria sc = ActiveTemplateSearch.create(); + sc.setParameters("template", templateId); + sc.setParameters("pool", poolId); + + List results = customSearchIncludingRemoved(sc, null); + assert results.size() > 0 : "How can this return a size of " + results.size(); + + return results.get(0) > 0; + } + + @Override + public void deleteVolumesByInstance(long instanceId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("instanceId", instanceId); + expunge(sc); + } + + @Override + public void attachVolume(long volumeId, long vmId, long deviceId) { + VolumeVO volume = createForUpdate(volumeId); + volume.setInstanceId(vmId); + volume.setDeviceId(deviceId); + volume.setUpdated(new Date()); + volume.setAttached(new Date()); + update(volumeId, volume); + } + + @Override + public void detachVolume(long volumeId) { + VolumeVO volume = createForUpdate(volumeId); + volume.setInstanceId(null); + volume.setDeviceId(null); + volume.setUpdated(new Date()); + volume.setAttached(null); + update(volumeId, volume); + } + + @Override + @DB + public HypervisorType getHypervisorType(long volumeId) { + /*lookup from cluster of pool*/ + Transaction txn = Transaction.currentTxn(); + PreparedStatement pstmt = null; + + try { + String sql = SELECT_HYPERTYPE_FROM_VOLUME; + pstmt = txn.prepareAutoCloseStatement(sql); + pstmt.setLong(1, volumeId); + ResultSet rs = pstmt.executeQuery(); + if (rs.next()) { + return HypervisorType.getType(rs.getString(1)); + } + return HypervisorType.None; + } catch (SQLException e) { + throw new CloudRuntimeException("DB Exception on: " + SELECT_HYPERTYPE_FROM_VOLUME, e); + } catch (Throwable e) { + throw new CloudRuntimeException("Caught: " + SELECT_HYPERTYPE_FROM_VOLUME, e); + } + } + + @Override + public ImageFormat getImageFormat(Long volumeId) { + HypervisorType type = getHypervisorType(volumeId); + if ( type.equals(HypervisorType.KVM)) { + return ImageFormat.QCOW2; + } else if ( type.equals(HypervisorType.XenServer)) { + return ImageFormat.VHD; + } else if ( type.equals(HypervisorType.VMware)) { + return ImageFormat.OVA; + } else { + s_logger.warn("Do not support hypervisor " + type.toString()); + return null; + } + } + + protected VolumeDaoImpl() { + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("state", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("accountId", AllFieldsSearch.entity().getAccountId(), Op.EQ); + AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), Op.EQ); + AllFieldsSearch.and("instanceId", AllFieldsSearch.entity().getInstanceId(), Op.EQ); + AllFieldsSearch.and("deviceId", AllFieldsSearch.entity().getDeviceId(), Op.EQ); + AllFieldsSearch.and("poolId", AllFieldsSearch.entity().getPoolId(), Op.EQ); + AllFieldsSearch.and("vType", AllFieldsSearch.entity().getVolumeType(), Op.EQ); + AllFieldsSearch.and("id", AllFieldsSearch.entity().getId(), Op.EQ); + AllFieldsSearch.and("destroyed", AllFieldsSearch.entity().getState(), Op.EQ); + AllFieldsSearch.and("notDestroyed", AllFieldsSearch.entity().getState(), Op.NEQ); + AllFieldsSearch.and("updatedCount", AllFieldsSearch.entity().getUpdatedCount(), Op.EQ); + AllFieldsSearch.done(); + + DetachedAccountIdSearch = createSearchBuilder(); + DetachedAccountIdSearch.and("accountId", DetachedAccountIdSearch.entity().getAccountId(), Op.EQ); + DetachedAccountIdSearch.and("destroyed", DetachedAccountIdSearch.entity().getState(), Op.NEQ); + DetachedAccountIdSearch.and("instanceId", DetachedAccountIdSearch.entity().getInstanceId(), Op.NULL); + DetachedAccountIdSearch.done(); + + TemplateZoneSearch = createSearchBuilder(); + TemplateZoneSearch.and("template", TemplateZoneSearch.entity().getTemplateId(), Op.EQ); + TemplateZoneSearch.and("zone", TemplateZoneSearch.entity().getDataCenterId(), Op.EQ); + TemplateZoneSearch.done(); + + TotalSizeByPoolSearch = createSearchBuilder(SumCount.class); + TotalSizeByPoolSearch.select("sum", Func.SUM, TotalSizeByPoolSearch.entity().getSize()); + TotalSizeByPoolSearch.select("count", Func.COUNT, (Object[])null); + TotalSizeByPoolSearch.and("poolId", TotalSizeByPoolSearch.entity().getPoolId(), Op.EQ); + TotalSizeByPoolSearch.and("removed", TotalSizeByPoolSearch.entity().getRemoved(), Op.NULL); + TotalSizeByPoolSearch.and("state", TotalSizeByPoolSearch.entity().getState(), Op.NEQ); + TotalSizeByPoolSearch.done(); + + ActiveTemplateSearch = createSearchBuilder(Long.class); + ActiveTemplateSearch.and("pool", ActiveTemplateSearch.entity().getPoolId(), Op.EQ); + ActiveTemplateSearch.and("template", ActiveTemplateSearch.entity().getTemplateId(), Op.EQ); + ActiveTemplateSearch.and("removed", ActiveTemplateSearch.entity().getRemoved(), Op.NULL); + ActiveTemplateSearch.select(null, Func.COUNT, null); + ActiveTemplateSearch.done(); + + InstanceStatesSearch = createSearchBuilder(); + InstanceStatesSearch.and("instance", InstanceStatesSearch.entity().getInstanceId(), Op.EQ); + InstanceStatesSearch.and("states", InstanceStatesSearch.entity().getState(), Op.IN); + InstanceStatesSearch.done(); + + CountByAccount = createSearchBuilder(Long.class); + CountByAccount.select(null, Func.COUNT, null); + CountByAccount.and("account", CountByAccount.entity().getAccountId(), SearchCriteria.Op.EQ); + CountByAccount.and("state", CountByAccount.entity().getState(), SearchCriteria.Op.NIN); + CountByAccount.done(); + } + + @Override @DB(txn=false) + public Pair getCountAndTotalByPool(long poolId) { + SearchCriteria sc = TotalSizeByPoolSearch.create(); + sc.setParameters("poolId", poolId); + List results = customSearch(sc, null); + SumCount sumCount = results.get(0); + return new Pair(sumCount.count, sumCount.sum); + } + + @Override + public Long countAllocatedVolumesForAccount(long accountId) { + SearchCriteria sc = CountByAccount.create(); + sc.setParameters("account", accountId); + sc.setParameters("state", VolumeState.Destroy); + return customSearch(sc, null).get(0); + } + + public static class SumCount { + public long sum; + public long count; + public SumCount() { + } + } + + @Override + public List listVolumesToBeDestroyed() { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("state", VolumeState.Destroy); + + return listBy(sc); + } + + @Override + public boolean updateState(VolumeState currentState, + VolumeEvent event, VolumeState nextState, VolumeVO vo, + Object data) { + + Long oldUpdated = vo.getUpdatedCount(); + Date oldUpdatedTime = vo.getUpdated(); + + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("id", vo.getId()); + sc.setParameters("state", currentState); + sc.setParameters("updatedCount", vo.getUpdatedCount()); + + vo.incrUpdatedCount(); + + UpdateBuilder builder = getUpdateBuilder(vo); + builder.set(vo, "state", nextState); + builder.set(vo, "updated", new Date()); + + int rows = update((VolumeVO)vo, sc); + if (rows == 0 && s_logger.isDebugEnabled()) { + VolumeVO dbVol = findByIdIncludingRemoved(vo.getId()); + if (dbVol != null) { + StringBuilder str = new StringBuilder("Unable to update ").append(vo.toString()); + str.append(": DB Data={id=").append(dbVol.getId()).append("; state=").append(dbVol.getState()).append("; updatecount=").append(dbVol.getUpdatedCount()).append(";updatedTime=").append(dbVol.getUpdated()); + str.append(": New Data={id=").append(vo.getId()).append("; state=").append(nextState).append("; event=").append(event).append("; updatecount=").append(vo.getUpdatedCount()).append("; updatedTime=").append(vo.getUpdated()); + str.append(": stale Data={id=").append(vo.getId()).append("; state=").append(currentState).append("; event=").append(event).append("; updatecount=").append(oldUpdated).append("; updatedTime=").append(oldUpdatedTime); + } else { + s_logger.debug("Unable to update volume: id=" + vo.getId() + ", as there is no such volume exists in the database anymore"); + } + } + return rows > 0; + } + + @Override + public List listPoolIdsByVolumeCount(long dcId, Long podId, Long clusterId, long accountId) { + Transaction txn = Transaction.currentTxn(); + PreparedStatement pstmt = null; + List result = new ArrayList(); + try { + String sql = ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT; + pstmt = txn.prepareAutoCloseStatement(sql); + pstmt.setLong(1, accountId); + pstmt.setLong(2, dcId); + pstmt.setLong(3, podId); + pstmt.setLong(4, clusterId); + + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) { + result.add(rs.getLong(1)); + } + return result; + } catch (SQLException e) { + throw new CloudRuntimeException("DB Exception on: " + ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e); + } catch (Throwable e) { + throw new CloudRuntimeException("Caught: " + ORDER_POOLS_NUMBER_OF_VOLUMES_FOR_ACCOUNT, e); + } + } + + @Override @DB(txn=false) + public Pair getNonDestroyedCountAndTotalByPool(long poolId) { + SearchCriteria sc = TotalSizeByPoolSearch.create(); + sc.setParameters("poolId", poolId); + sc.setParameters("state", VolumeState.Destroy); + List results = customSearch(sc, null); + SumCount sumCount = results.get(0); + return new Pair(sumCount.count, sumCount.sum); + } + + @Override + @DB + public boolean remove(Long id) { + Transaction txn = Transaction.currentTxn(); + txn.start(); + VolumeVO entry = findById(id); + if (entry != null) { + _tagsDao.removeByIdAndType(id, TaggedResourceType.Volume); + } + boolean result = super.remove(id); + txn.commit(); + return result; + } + + @Override + @DB + public VolumeVO allocVolume(long size, VolumeType type, String volName, Long templateId) { + VolumeVO vol = new VolumeVO(size, type.toString(), volName, templateId); + vol = this.persist(vol); + return vol; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java new file mode 100644 index 00000000000..48da123ceef --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/db/VolumeVO.java @@ -0,0 +1,425 @@ +//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.volume.db; +import java.util.Date; +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.TableGenerator; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.cloudstack.storage.volume.VolumeState; +import org.apache.cloudstack.storage.volume.disktype.Unknown; +import org.apache.cloudstack.storage.volume.type.VolumeType; + +import com.cloud.api.Identity; +import com.cloud.storage.Storage.StoragePoolType; +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.db.GenericDao; +import com.cloud.utils.fsm.StateObject; + +@Entity +@Table(name = "volumes") +public class VolumeVO implements Identity, StateObject{ + @Id + @TableGenerator(name = "volume_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "volume_seq", allocationSize = 1) + @GeneratedValue(strategy = GenerationType.TABLE) + @Column(name = "id") + long id; + + @Column(name = "name") + String name; + + @Column(name = "pool_id") + Long poolId; + + @Column(name = "last_pool_id") + Long lastPoolId; + + @Column(name = "account_id") + long accountId; + + @Column(name = "domain_id") + long domainId; + + @Column(name = "instance_id") + Long instanceId = null; + + @Column(name = "device_id") + Long deviceId = null; + + @Column(name = "size") + long size; + + @Column(name = "folder") + String folder; + + @Column(name = "path") + String path; + + @Column(name = "pod_id") + Long podId; + + @Column(name = "created") + Date created; + + @Column(name = "attached") + @Temporal(value = TemporalType.TIMESTAMP) + Date attached; + + @Column(name = "data_center_id") + long dataCenterId; + + @Column(name = "host_ip") + String hostip; + + @Column(name = "disk_offering_id") + long diskOfferingId; + + @Column(name = "template_id") + Long templateId; + + @Column(name = "first_snapshot_backup_uuid") + String firstSnapshotBackupUuid; + + @Column(name = "volume_type") + String volumeType = "UNKNOWN"; + + @Column(name = "pool_type") + @Enumerated(EnumType.STRING) + StoragePoolType poolType; + + @Column(name = "disk_type") + String diskType = new Unknown().toString(); + + @Column(name = GenericDao.REMOVED_COLUMN) + Date removed; + + @Column(name = "updated") + @Temporal(value = TemporalType.TIMESTAMP) + Date updated; + + @Column(name="update_count", updatable = true, nullable=false) + protected long updatedCount; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code. + + @Column(name = "recreatable") + boolean recreatable; + + @Column(name = "state") + @Enumerated(value = EnumType.STRING) + private VolumeState state; + + @Column(name = "chain_info") + String chainInfo; + + @Column(name = "uuid") + String uuid; + + @Column(name="reservation") + String reservationId; + + // Real Constructor + public VolumeVO(long size, String type, String name, Long templateId) { + this.volumeType = type.toString(); + this.size = size; + this.name = name; + this.templateId = templateId; + this.uuid = UUID.randomUUID().toString(); + } + + // Copy Constructor + public VolumeVO(VolumeVO that) { + this(that.getSize(), that.getVolumeType(), that.getName(), that.getTemplateId()); + this.recreatable = that.isRecreatable(); + this.state = that.getState(); + this.size = that.getSize(); + this.diskOfferingId = that.getDiskOfferingId(); + this.poolId = that.getPoolId(); + this.attached = that.getAttached(); + this.chainInfo = that.getChainInfo(); + this.templateId = that.getTemplateId(); + this.deviceId = that.getDeviceId(); + this.uuid = UUID.randomUUID().toString(); + } + + public long getUpdatedCount() { + return this.updatedCount; + } + + public void incrUpdatedCount() { + this.updatedCount++; + } + + public void decrUpdatedCount() { + this.updatedCount--; + } + + public boolean isRecreatable() { + return recreatable; + } + + public void setRecreatable(boolean recreatable) { + this.recreatable = recreatable; + } + + public long getId() { + return id; + } + + + public Long getPodId() { + return podId; + } + + + public long getDataCenterId() { + return dataCenterId; + } + + public String getName() { + return name; + } + + public long getAccountId() { + return accountId; + } + + public void setPoolType(StoragePoolType poolType) { + this.poolType = poolType; + } + + public StoragePoolType getPoolType() { + return poolType; + } + + public long getDomainId() { + return domainId; + } + + public String getFolder() { + return folder; + } + + public String getPath() { + return path; + } + + protected VolumeVO() { + } + + public long getSize() { + return size; + } + + public void setSize(long size) { + this.size = size; + } + + public Long getInstanceId() { + return instanceId; + } + + public Long getDeviceId() { + return deviceId; + } + + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; + } + + public String getVolumeType() { + return volumeType; + } + + public void setName(String name) { + this.name = name; + } + + public void setFolder(String folder) { + this.folder = folder; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public void setDomainId(long domainId) { + this.domainId = domainId; + } + + public void setInstanceId(Long instanceId) { + this.instanceId = instanceId; + } + + public void setPath(String path) { + this.path = path; + } + + public String getHostIp() { + return hostip; + } + + public void setHostIp(String hostip) { + this.hostip = hostip; + } + + public void setPodId(Long podId) { + this.podId = podId; + } + + public void setDataCenterId(long dataCenterId) { + this.dataCenterId = dataCenterId; + } + + public void setVolumeType(String type) { + volumeType = type; + } + + public Date getCreated() { + return created; + } + + public Date getRemoved() { + return removed; + } + + public void setRemoved(Date removed) { + this.removed = removed; + } + + public long getDiskOfferingId() { + return diskOfferingId; + } + + public void setDiskOfferingId(long diskOfferingId) { + this.diskOfferingId = diskOfferingId; + } + + public Long getTemplateId() { + return templateId; + } + + public void setTemplateId(Long templateId) { + this.templateId = templateId; + } + + public String getFirstSnapshotBackupUuid() { + return firstSnapshotBackupUuid; + } + + public void setFirstSnapshotBackupUuid(String firstSnapshotBackupUuid) { + this.firstSnapshotBackupUuid = firstSnapshotBackupUuid; + } + + public Long getPoolId() { + return poolId; + } + + public void setPoolId(Long poolId) { + this.poolId = poolId; + } + + public Date getUpdated() { + return updated; + } + + public VolumeState getState() { + return state; + } + + public void setUpdated(Date updated) { + this.updated = updated; + } + + @Override + public String toString() { + return new StringBuilder("Vol[").append(id).append("|vm=").append(instanceId).append("|").append(volumeType).append("]").toString(); + } + + public Date getAttached() { + return this.attached; + } + + public void setAttached(Date attached) { + this.attached = attached; + } + + public String getChainInfo() { + return this.chainInfo; + } + + public void setChainInfo(String chainInfo) { + this.chainInfo = chainInfo; + } + + public Long getLastPoolId() { + return this.lastPoolId; + } + + public void setLastPoolId(Long poolId) { + this.lastPoolId = poolId; + } + + @Override + public int hashCode() { + return NumbersUtil.hash(id); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof VolumeVO) { + return id == ((VolumeVO) obj).id; + } else { + return false; + } + } + + public String getReservationId() { + return this.reservationId; + } + + public void setReservationId(String reserv) { + this.reservationId = reserv; + } + + @Override + public String getUuid() { + return this.uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public String getDiskType() { + return diskType; + } + + public void setDiskType(String type) { + diskType = type; + } +} + diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/QCOW2.java b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/QCOW2.java new file mode 100644 index 00000000000..105801cabf8 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/QCOW2.java @@ -0,0 +1,10 @@ +package org.apache.cloudstack.storage.volume.disktype; + +import org.springframework.stereotype.Component; + +@Component +public class QCOW2 extends VolumeDiskTypeBase { + public QCOW2() { + this.type = "QCOW2"; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/Unknown.java b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/Unknown.java new file mode 100644 index 00000000000..e22acce7a17 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/Unknown.java @@ -0,0 +1,7 @@ +package org.apache.cloudstack.storage.volume.disktype; + +public class Unknown extends VolumeDiskTypeBase { + public Unknown() { + this.type = "Unknown"; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VHD.java b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VHD.java new file mode 100644 index 00000000000..4535748b64b --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VHD.java @@ -0,0 +1,10 @@ +package org.apache.cloudstack.storage.volume.disktype; + +import org.springframework.stereotype.Component; + +@Component +public class VHD extends VolumeDiskTypeBase { + public VHD() { + this.type = "VHD"; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VMDK.java b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VMDK.java new file mode 100644 index 00000000000..10623ab4bcc --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VMDK.java @@ -0,0 +1,10 @@ +package org.apache.cloudstack.storage.volume.disktype; + +import org.springframework.stereotype.Component; + +@Component +public class VMDK extends VolumeDiskTypeBase { + public VMDK() { + this.type = "VMDK"; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskType.java b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskType.java new file mode 100644 index 00000000000..1832fe3483a --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskType.java @@ -0,0 +1,4 @@ +package org.apache.cloudstack.storage.volume.disktype; + +public interface VolumeDiskType { +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeBase.java b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeBase.java new file mode 100644 index 00000000000..083d49c6f2c --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeBase.java @@ -0,0 +1,34 @@ +package org.apache.cloudstack.storage.volume.disktype; + +public class VolumeDiskTypeBase implements VolumeDiskType { + protected String type = "Unknown"; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that instanceof String) { + if (getType().equalsIgnoreCase((String)that)) { + return true; + } + } else if (that instanceof VolumeDiskTypeBase) { + VolumeDiskTypeBase th = (VolumeDiskTypeBase)that; + if (this.getType().equalsIgnoreCase(th.getType())) { + return true; + } + } else { + return false; + } + return false; + } + + @Override + public String toString() { + return getType(); + } + + protected String getType() { + return this.type; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeHelper.java b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeHelper.java new file mode 100644 index 00000000000..c51e25fcf84 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/disktype/VolumeDiskTypeHelper.java @@ -0,0 +1,29 @@ +package org.apache.cloudstack.storage.volume.disktype; + +import java.util.List; + +import javax.inject.Inject; + +import org.springframework.stereotype.Component; + +@Component +public class VolumeDiskTypeHelper { + + static private List diskTypes; + static final private VolumeDiskType defaultType = new Unknown(); + + @Inject + public void setDiskTypes(List diskTypes) { + VolumeDiskTypeHelper.diskTypes = diskTypes; + } + + public static VolumeDiskType getDiskType(String type) { + for (VolumeDiskType diskType : diskTypes) { + if (diskType.equals(type)) { + return diskType; + } + } + + return VolumeDiskTypeHelper.defaultType; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/DataDisk.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/DataDisk.java new file mode 100644 index 00000000000..1e30768c05d --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/type/DataDisk.java @@ -0,0 +1,10 @@ +package org.apache.cloudstack.storage.volume.type; + +import org.springframework.stereotype.Component; + +@Component +public class DataDisk extends VolumeTypeBase { + public DataDisk() { + this.type = "DataDisk"; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/Iso.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/Iso.java new file mode 100644 index 00000000000..61e4e358eb7 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/type/Iso.java @@ -0,0 +1,10 @@ +package org.apache.cloudstack.storage.volume.type; + +import org.springframework.stereotype.Component; + +@Component +public class Iso extends VolumeTypeBase { + public Iso() { + this.type = "iso"; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/RootDisk.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/RootDisk.java new file mode 100644 index 00000000000..c616cea21a8 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/type/RootDisk.java @@ -0,0 +1,10 @@ +package org.apache.cloudstack.storage.volume.type; + +import org.springframework.stereotype.Component; + +@Component +public class RootDisk extends VolumeTypeBase { + public RootDisk() { + this.type = "Root"; + } +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java new file mode 100644 index 00000000000..c1a77b14ae4 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/type/Unknown.java @@ -0,0 +1,8 @@ +package org.apache.cloudstack.storage.volume.type; + +public class Unknown extends VolumeTypeBase { + public Unknown() { + this.type = "Unknown"; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java new file mode 100644 index 00000000000..e423a5e62ef --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeType.java @@ -0,0 +1,22 @@ +/* + * 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.volume.type; + +public interface VolumeType { +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java new file mode 100644 index 00000000000..830873cd2c2 --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeBase.java @@ -0,0 +1,31 @@ +package org.apache.cloudstack.storage.volume.type; + +public class VolumeTypeBase implements VolumeType { + protected String type = "Unknown"; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that instanceof String) { + if (this.toString().equalsIgnoreCase((String)that)) { + return true; + } + } else if (that instanceof VolumeTypeBase) { + VolumeTypeBase th = (VolumeTypeBase)that; + if (this.toString().equalsIgnoreCase(th.toString())) { + return true; + } + } else { + return false; + } + return false; + } + + @Override + public String toString() { + return type; + } + +} diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java new file mode 100644 index 00000000000..9443475e79a --- /dev/null +++ b/engine/storage/src/org/apache/cloudstack/storage/volume/type/VolumeTypeHelper.java @@ -0,0 +1,28 @@ +package org.apache.cloudstack.storage.volume.type; + +import java.util.List; + +import javax.inject.Inject; + +import org.springframework.stereotype.Component; + +@Component +public class VolumeTypeHelper { + static private List types; + private static VolumeType defaultType = new Unknown(); + + @Inject + public void setTypes(List types) { + VolumeTypeHelper.types = types; + } + + public static VolumeType getType(String type) { + for (VolumeType ty : types) { + if (ty.equals(type)) { + return ty; + } + } + return VolumeTypeHelper.defaultType; + } + +} diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/AllTests.java b/engine/storage/test/org/apache/cloudstack/storage/test/AllTests.java new file mode 100644 index 00000000000..dde4484db54 --- /dev/null +++ b/engine/storage/test/org/apache/cloudstack/storage/test/AllTests.java @@ -0,0 +1,29 @@ +/* + * 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.test; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(Suite.class) +@SuiteClasses({ volumeServiceTest.class }) +public class AllTests { + +} diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/AopTest.java b/engine/storage/test/org/apache/cloudstack/storage/test/AopTest.java new file mode 100644 index 00000000000..0c2a2adf061 --- /dev/null +++ b/engine/storage/test/org/apache/cloudstack/storage/test/AopTest.java @@ -0,0 +1,14 @@ +package org.apache.cloudstack.storage.test; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +public @interface AopTest { + +} diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/AopTestAdvice.java b/engine/storage/test/org/apache/cloudstack/storage/test/AopTestAdvice.java new file mode 100644 index 00000000000..9bdec741eb1 --- /dev/null +++ b/engine/storage/test/org/apache/cloudstack/storage/test/AopTestAdvice.java @@ -0,0 +1,20 @@ +package org.apache.cloudstack.storage.test; + +import org.aspectj.lang.ProceedingJoinPoint; + +import com.cloud.utils.db.Transaction; + +public class AopTestAdvice { + public Object AopTestMethod(ProceedingJoinPoint call) throws Throwable { + Transaction txn = Transaction.open(call.getSignature().getName()); + System.out.println(call.getSignature().getName()); + Object ret = null; + try { + ret = call.proceed(); + } finally { + txn.close(); + } + System.out.println("end"); + return ret; + } +} diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/StorageFactoryBean.java b/engine/storage/test/org/apache/cloudstack/storage/test/StorageFactoryBean.java new file mode 100644 index 00000000000..68952b17f9e --- /dev/null +++ b/engine/storage/test/org/apache/cloudstack/storage/test/StorageFactoryBean.java @@ -0,0 +1,42 @@ +package org.apache.cloudstack.storage.test; + + +import org.mockito.Mockito; +import org.springframework.beans.factory.FactoryBean; + +/** + * A {@link FactoryBean} for creating mocked beans based on Mockito so that they + * can be {@link @Autowired} into Spring test configurations. + * + * @author Mattias Severson, Jayway + * + * @see FactoryBean + * @see org.mockito.Mockito + */ +public class StorageFactoryBean implements FactoryBean { + + private Class classToBeMocked; + + /** + * Creates a Mockito mock instance of the provided class. + * @param classToBeMocked The class to be mocked. + */ + public StorageFactoryBean(Class classToBeMocked) { + this.classToBeMocked = classToBeMocked; + } + + @Override + public T getObject() throws Exception { + return Mockito.mock(classToBeMocked); + } + + @Override + public Class getObjectType() { + return classToBeMocked; + } + + @Override + public boolean isSingleton() { + return true; + } +} diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml b/engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml new file mode 100644 index 00000000000..c32004bb61d --- /dev/null +++ b/engine/storage/test/org/apache/cloudstack/storage/test/storageContext.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java b/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java new file mode 100644 index 00000000000..8771d02543e --- /dev/null +++ b/engine/storage/test/org/apache/cloudstack/storage/test/volumeServiceTest.java @@ -0,0 +1,128 @@ +/* + * 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.test; + +import static org.junit.Assert.*; + +import java.awt.List; +import java.util.LinkedList; + +import javax.inject.Inject; + +import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStoreImpl; +import org.apache.cloudstack.storage.datastore.provider.DefaultPrimaryDatastoreProviderImpl; +import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProvider; +import org.apache.cloudstack.storage.image.format.ISO; +import org.apache.cloudstack.storage.image.format.ImageFormat; +import org.apache.cloudstack.storage.image.format.ImageFormatHelper; +import org.apache.cloudstack.storage.image.format.OVA; +import org.apache.cloudstack.storage.image.format.Unknown; +import org.apache.cloudstack.storage.volume.VolumeMotionService; +import org.apache.cloudstack.storage.volume.VolumeService; +import org.apache.cloudstack.storage.volume.db.VolumeDao; +import org.apache.cloudstack.storage.volume.disktype.QCOW2; +import org.apache.cloudstack.storage.volume.disktype.VHD; +import org.apache.cloudstack.storage.volume.disktype.VMDK; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskType; +import org.apache.cloudstack.storage.volume.disktype.VolumeDiskTypeHelper; +import org.apache.cloudstack.storage.volume.type.Iso; +import org.apache.cloudstack.storage.volume.type.VolumeTypeHelper; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.mockito.Mockito.*; + + +import com.cloud.utils.component.ComponentInject; +import com.cloud.utils.db.DB; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations="storageContext.xml") +public class volumeServiceTest { + @Autowired + protected VolumeService volService; + @Inject + protected VolumeDao volumeDao; + @Autowired + protected VolumeMotionService vmotion; + @Before + public void setUp() { + Mockito.when(vmotion.copyVolume(null, null)).thenReturn(false); + } + + @DB + public void test() { + assertTrue(volService.deleteVolume(1) != false); + assertNotNull(volumeDao); + //VolumeVO vol = new VolumeVO(Volume.Type.DATADISK, "test", 1, 2, 2, 1, 1); + //volumeDao.persist(vol); + /* + VolumeVO volume = new VolumeVO(); + String name = "test"; + long size = 100; + volume.setName(name); + volume.setSize(size); + volumeDao.persist(volume); + VolumeVO newVol = volumeDao.getVolumeByName(name); + assertTrue(newVol.getSize() == volume.getSize()); + */ + + fail("Not yet implemented"); + } + + @Test + public void test1() { + System.out.println(VolumeTypeHelper.getType("Root")); + System.out.println(VolumeDiskTypeHelper.getDiskType("vmdk")); + System.out.println(ImageFormatHelper.getFormat("ova")); + assertFalse(new VMDK().equals(new VHD())); + VMDK vmdk = new VMDK(); + assertTrue(vmdk.equals(vmdk)); + VMDK newvmdk = new VMDK(); + assertTrue(vmdk.equals(newvmdk)); + + ImageFormat ova = new OVA(); + ImageFormat iso = new ISO(); + assertTrue(ova.equals(new OVA())); + assertFalse(ova.equals(iso)); + assertTrue(ImageFormatHelper.getFormat("test").equals(new Unknown())); + + VolumeDiskType qcow2 = new QCOW2(); + ImageFormat qcow2format = new org.apache.cloudstack.storage.image.format.QCOW2(); + assertFalse(qcow2.equals(qcow2format)); + + } + + //@Test + public void testStaticBean() { + DefaultPrimaryDatastoreProviderImpl provider = ComponentInject.inject(DefaultPrimaryDatastoreProviderImpl.class); + assertNotNull(provider.dataStoreDao); + + DefaultPrimaryDataStoreImpl dpdsi = new DefaultPrimaryDataStoreImpl(null, null, null); + ComponentInject.inject(dpdsi); + //assertNotNull(dpdsi.volumeDao); + } +}