|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.cloudstack.storage.manager; |
| 20 | + |
| 21 | +import java.util.Iterator; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore; |
| 26 | +import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType; |
| 27 | +import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle; |
| 28 | +import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider; |
| 29 | + |
| 30 | +import com.cloud.dc.ClusterVO; |
| 31 | +import com.cloud.dc.DataCenterVO; |
| 32 | +import com.cloud.dc.dao.ClusterDao; |
| 33 | +import com.cloud.dc.dao.DataCenterDao; |
| 34 | +import com.cloud.dc.dao.HostPodDao; |
| 35 | +import com.cloud.hypervisor.Hypervisor.HypervisorType; |
| 36 | +import com.cloud.storage.StoragePool; |
| 37 | +import com.cloud.storage.StoragePoolStatus; |
| 38 | +import com.cloud.storage.StoragePoolVO; |
| 39 | +import com.cloud.storage.dao.StoragePoolDao; |
| 40 | +import com.cloud.utils.component.Adapters; |
| 41 | +import com.cloud.utils.component.Inject; |
| 42 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 43 | + |
| 44 | +public class StoragePoolManagerImpl implements StoragePoolService { |
| 45 | + @Inject(adapter = StorageProvider.class) |
| 46 | + protected Adapters<StorageProvider> _storageProviders; |
| 47 | + @Inject |
| 48 | + protected DataCenterDao _dcDao; |
| 49 | + @Inject |
| 50 | + protected HostPodDao _podDao; |
| 51 | + @Inject |
| 52 | + protected ClusterDao _clusterDao; |
| 53 | + @Inject |
| 54 | + protected StoragePoolDao _storagePoolDao; |
| 55 | + |
| 56 | + public void deleteStoragePool(long poolId) { |
| 57 | + StoragePool spool = _storagePoolDao.findById(poolId); |
| 58 | + StorageProvider sp = findStorageProvider(spool.getStorageProvider()); |
| 59 | + DataStore ds = sp.getDataStore(spool); |
| 60 | + DataStoreLifeCycle dslc = ds.getLifeCycle(); |
| 61 | + dslc.delete(); |
| 62 | + } |
| 63 | + |
| 64 | + public void enableStoragePool(long poolId) { |
| 65 | + // TODO Auto-generated method stub |
| 66 | + |
| 67 | + } |
| 68 | + |
| 69 | + public void disableStoragePool(long poolId) { |
| 70 | + // TODO Auto-generated method stub |
| 71 | + |
| 72 | + } |
| 73 | + |
| 74 | + public Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor) { |
| 75 | + // TODO Auto-generated method stub |
| 76 | + return null; |
| 77 | + } |
| 78 | + |
| 79 | + public Map<String, List<String>> getSupportedSecondaryStorages(long zoneId) { |
| 80 | + // TODO Auto-generated method stub |
| 81 | + return null; |
| 82 | + } |
| 83 | + |
| 84 | + protected StorageProvider findStorageProvider(String name) { |
| 85 | + Iterator<StorageProvider> spIter = _storageProviders.iterator(); |
| 86 | + StorageProvider sp = null; |
| 87 | + while (spIter.hasNext()) { |
| 88 | + sp = spIter.next(); |
| 89 | + if (sp.getProviderName().equalsIgnoreCase(name)) { |
| 90 | + break; |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + return sp; |
| 95 | + } |
| 96 | + |
| 97 | + public StoragePool addStoragePool(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params) { |
| 98 | + StoragePoolVO spool = new StoragePoolVO(); |
| 99 | + long poolId = _storagePoolDao.getNextInSequence(Long.class, "id"); |
| 100 | + spool.setId(poolId); |
| 101 | + spool.setDataCenterId(zoneId); |
| 102 | + spool.setPodId(podId); |
| 103 | + spool.setName(poolName); |
| 104 | + spool.setClusterId(clusterId); |
| 105 | + spool.setStorageProvider(storageProviderName); |
| 106 | + spool.setStorageType(storageType); |
| 107 | + spool.setStatus(StoragePoolStatus.Creating); |
| 108 | + spool = _storagePoolDao.persist(spool); |
| 109 | + |
| 110 | + StorageProvider sp = findStorageProvider(storageProviderName); |
| 111 | + DataStore ds = sp.addDataStore((StoragePool)spool, URI, params); |
| 112 | + |
| 113 | + DataStoreLifeCycle dslc = ds.getLifeCycle(); |
| 114 | + try { |
| 115 | + dslc.add(); |
| 116 | + } catch (CloudRuntimeException e) { |
| 117 | + _storagePoolDao.remove(spool.getId()); |
| 118 | + throw e; |
| 119 | + } |
| 120 | + |
| 121 | + spool.setPath(ds.getURI()); |
| 122 | + spool.setUuid(ds.getUUID()); |
| 123 | + spool.setStatus(StoragePoolStatus.Up); |
| 124 | + _storagePoolDao.update(spool.getId(), spool); |
| 125 | + spool = _storagePoolDao.findById(spool.getId()); |
| 126 | + return spool; |
| 127 | + } |
| 128 | + |
| 129 | +} |
0 commit comments