http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ef83f6db/server/src/com/cloud/storage/LocalStoragePoolListener.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/LocalStoragePoolListener.java b/server/src/com/cloud/storage/LocalStoragePoolListener.java index 8d5875e..a04c79c 100755 --- a/server/src/com/cloud/storage/LocalStoragePoolListener.java +++ b/server/src/com/cloud/storage/LocalStoragePoolListener.java @@ -16,8 +16,6 @@ // under the License. package com.cloud.storage; -import java.util.List; - import javax.inject.Inject; import org.apache.log4j.Logger; @@ -30,20 +28,14 @@ import com.cloud.agent.api.Command; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupStorageCommand; import com.cloud.agent.api.StoragePoolInfo; -import com.cloud.capacity.Capacity; -import com.cloud.capacity.CapacityVO; import com.cloud.capacity.dao.CapacityDao; -import com.cloud.dc.DataCenterVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.exception.ConnectionException; import com.cloud.host.HostVO; import com.cloud.host.Status; -import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; import com.cloud.utils.db.DB; -import com.cloud.utils.db.SearchCriteria; -import com.cloud.utils.db.Transaction; public class LocalStoragePoolListener implements Listener { private final static Logger s_logger = Logger.getLogger(LocalStoragePoolListener.class); @@ -91,63 +83,7 @@ public class LocalStoragePoolListener implements Listener { return; } - DataCenterVO dc = _dcDao.findById(host.getDataCenterId()); - if (dc == null || !dc.isLocalStorageEnabled()) { - return; - } - - try { - StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), pInfo.getHostPath(), pInfo.getUuid()); - if(pool == null && host.getHypervisorType() == HypervisorType.VMware) { - // perform run-time upgrade. In versions prior to 2.2.12, there is a bug that we don't save local datastore info (host path is empty), this will cause us - // not able to distinguish multiple local datastores that may be available on the host, to support smooth migration, we - // need to perform runtime upgrade here - if(pInfo.getHostPath().length() > 0) { - pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), "", pInfo.getUuid()); - } - } - - if (pool == null) { - - long poolId = _storagePoolDao.getNextInSequence(Long.class, "id"); - String name = cmd.getName() == null ? (host.getName() + " Local Storage") : cmd.getName(); - Transaction txn = Transaction.currentTxn(); - txn.start(); - pool = new StoragePoolVO(poolId, name, pInfo.getUuid(), pInfo.getPoolType(), host.getDataCenterId(), - host.getPodId(), pInfo.getAvailableBytes(), pInfo.getCapacityBytes(), pInfo.getHost(), 0, - pInfo.getHostPath()); - pool.setClusterId(host.getClusterId()); - pool.setStatus(StoragePoolStatus.Up); - _storagePoolDao.persist(pool, pInfo.getDetails()); - StoragePoolHostVO poolHost = new StoragePoolHostVO(pool.getId(), host.getId(), pInfo.getLocalPath()); - _storagePoolHostDao.persist(poolHost); - _storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getCapacityBytes() - pool.getAvailableBytes()); - - txn.commit(); - } else { - Transaction txn = Transaction.currentTxn(); - txn.start(); - pool.setPath(pInfo.getHostPath()); - pool.setAvailableBytes(pInfo.getAvailableBytes()); - pool.setCapacityBytes(pInfo.getCapacityBytes()); - _storagePoolDao.update(pool.getId(), pool); - if (pInfo.getDetails() != null) { - _storagePoolDao.updateDetails(pool.getId(), pInfo.getDetails()); - } - StoragePoolHostVO poolHost = _storagePoolHostDao.findByPoolHost(pool.getId(), host.getId()); - if (poolHost == null) { - poolHost = new StoragePoolHostVO(pool.getId(), host.getId(), pInfo.getLocalPath()); - _storagePoolHostDao.persist(poolHost); - } - - _storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, pool.getCapacityBytes() - pool.getAvailableBytes()); - - txn.commit(); - } - } catch (Exception e) { - s_logger.warn("Unable to setup the local storage pool for " + host, e); - throw new ConnectionException(true, "Unable to setup the local storage pool for " + host, e); - } + this._storageMgr.createLocalStorage(host, pInfo); }
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ef83f6db/server/src/com/cloud/storage/OCFS2ManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/OCFS2ManagerImpl.java b/server/src/com/cloud/storage/OCFS2ManagerImpl.java index 6bbeec4..5c526a6 100755 --- a/server/src/com/cloud/storage/OCFS2ManagerImpl.java +++ b/server/src/com/cloud/storage/OCFS2ManagerImpl.java @@ -25,6 +25,7 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ef83f6db/server/src/com/cloud/storage/RegisterVolumePayload.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/RegisterVolumePayload.java b/server/src/com/cloud/storage/RegisterVolumePayload.java new file mode 100644 index 0000000..142de18 --- /dev/null +++ b/server/src/com/cloud/storage/RegisterVolumePayload.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package com.cloud.storage; + +public class RegisterVolumePayload { + private final String url; + private final String checksum; + private final String format; + + public RegisterVolumePayload(String url, String checksum, String format) { + this.url = url; + this.checksum = checksum; + this.format = format; + } + + public String getUrl() { + return this.url; + } + + public String getChecksum() { + return this.checksum; + } + + public String getFormat() { + return this.format; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ef83f6db/server/src/com/cloud/storage/StorageManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/storage/StorageManager.java b/server/src/com/cloud/storage/StorageManager.java index 97853ac..9213b4b 100755 --- a/server/src/com/cloud/storage/StorageManager.java +++ b/server/src/com/cloud/storage/StorageManager.java @@ -17,50 +17,29 @@ package com.cloud.storage; import java.util.List; +import java.util.Set; + +import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; +import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; +import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; +import com.cloud.agent.api.StoragePoolInfo; import com.cloud.agent.manager.Commands; import com.cloud.capacity.CapacityVO; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; -import com.cloud.deploy.DeployDestination; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientStorageCapacityException; +import com.cloud.exception.ConnectionException; import com.cloud.exception.StorageUnavailableException; import com.cloud.host.Host; -import com.cloud.host.HostVO; import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.service.ServiceOfferingVO; import com.cloud.storage.Storage.ImageFormat; -import com.cloud.storage.Volume.Event; -import com.cloud.storage.Volume.Type; -import com.cloud.user.Account; import com.cloud.utils.Pair; -import com.cloud.utils.component.Manager; -import com.cloud.utils.fsm.NoTransitionException; import com.cloud.vm.DiskProfile; import com.cloud.vm.VMInstanceVO; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachineProfile; - -public interface StorageManager extends StorageService, Manager { - boolean canVmRestartOnAnotherServer(long vmId); - - /** Returns the absolute path of the specified ISO - * @param templateId - the ID of the template that represents the ISO - * @param datacenterId - * @return absolute ISO path - */ - public Pair<String, String> getAbsoluteIsoPath(long templateId, long dataCenterId); - - /** - * Returns the URL of the secondary storage host - * @param zoneId - * @return URL - */ - public String getSecondaryStorageURL(long zoneId); +public interface StorageManager extends StorageService { /** * Returns a comma separated list of tags for the specified storage pool * @param poolId @@ -68,67 +47,9 @@ public interface StorageManager extends StorageService, Manager { */ public String getStoragePoolTags(long poolId); - /** - * Returns the secondary storage host - * @param zoneId - * @return secondary storage host - */ - public HostVO getSecondaryStorageHost(long zoneId); - - /** - * Returns the secondary storage host - * @param zoneId - * @return secondary storage host - */ - public VMTemplateHostVO findVmTemplateHost(long templateId, StoragePool pool); - - /** - * Moves a volume from its current storage pool to a storage pool with enough capacity in the specified zone, pod, or cluster - * @param volume - * @param destPoolDcId - * @param destPoolPodId - * @param destPoolClusterId - * @return VolumeVO - * @throws ConcurrentOperationException - */ - VolumeVO moveVolume(VolumeVO volume, long destPoolDcId, Long destPoolPodId, Long destPoolClusterId, HypervisorType dataDiskHyperType) throws ConcurrentOperationException; - - /** - * Create a volume based on the given criteria - * @param volume - * @param vm - * @param template - * @param dc - * @param pod - * @param clusterId - * @param offering - * @param diskOffering - * @param avoids - * @param size - * @param hyperType - * @return volume VO if success, null otherwise - */ - VolumeVO createVolume(VolumeVO volume, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod, Long clusterId, - ServiceOfferingVO offering, DiskOfferingVO diskOffering, List<StoragePoolVO> avoids, long size, HypervisorType hyperType); - - /** - * Marks the specified volume as destroyed in the management server database. The expunge thread will delete the volume from its storage pool. - * @param volume - * @return - */ - boolean destroyVolume(VolumeVO volume) throws ConcurrentOperationException; + - /** Create capacity entries in the op capacity table - * @param storagePool - */ - public void createCapacityEntry(StoragePoolVO storagePool); - /** - * Checks that the volume is stored on a shared storage pool - * @param volume - * @return true if the volume is on a shared storage pool, false otherwise - */ - boolean volumeOnSharedStoragePool(VolumeVO volume); Answer sendToPool(long poolId, Command cmd) throws StorageUnavailableException; Answer sendToPool(StoragePool pool, Command cmd) throws StorageUnavailableException; @@ -138,17 +59,6 @@ public interface StorageManager extends StorageService, Manager { Pair<Long, Answer> sendToPool(StoragePool pool, long[] hostIdsToTryFirst, List<Long> hostIdsToAvoid, Command cmd) throws StorageUnavailableException; /** - * Checks that one of the following is true: - * 1. The volume is not attached to any VM - * 2. The volume is attached to a VM that is running on a host with the KVM hypervisor, and the VM is stopped - * 3. The volume is attached to a VM that is running on a host with the XenServer hypervisor (the VM can be stopped or running) - * @return true if one of the above conditions is true - */ - boolean volumeInactive(VolumeVO volume); - - String getVmNameOnVolume(VolumeVO volume); - - /** * Checks if a host has running VMs that are using its local storage pool. * @return true if local storage is active on the host */ @@ -162,31 +72,10 @@ public interface StorageManager extends StorageService, Manager { String getPrimaryStorageNameLabel(VolumeVO volume); - /** - * Allocates one volume. - * @param <T> - * @param type - * @param offering - * @param name - * @param size - * @param template - * @param vm - * @param account - * @return VolumeVO a persisted volume. - */ - <T extends VMInstanceVO> DiskProfile allocateRawVolume(Type type, String name, DiskOfferingVO offering, Long size, T vm, Account owner); - <T extends VMInstanceVO> DiskProfile allocateTemplatedVolume(Type type, String name, DiskOfferingVO offering, VMTemplateVO template, T vm, Account owner); void createCapacityEntry(StoragePoolVO storagePool, short capacityType, long allocated); - void prepare(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest) throws StorageUnavailableException, InsufficientStorageCapacityException, ConcurrentOperationException; - - void release(VirtualMachineProfile<? extends VMInstanceVO> profile); - - void cleanupVolumes(long vmId) throws ConcurrentOperationException; - - void prepareForMigration(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest); Answer sendToPool(StoragePool pool, long[] hostIdsToTryFirst, Command cmd) throws StorageUnavailableException; @@ -194,49 +83,41 @@ public interface StorageManager extends StorageService, Manager { CapacityVO getStoragePoolUsedStats(Long poolId, Long clusterId, Long podId, Long zoneId); - boolean createStoragePool(long hostId, StoragePoolVO pool); + List<StoragePoolVO> ListByDataCenterHypervisor(long datacenterId, HypervisorType type); - boolean delPoolFromHost(long hostId); - HostVO getSecondaryStorageHost(long zoneId, long tmpltId); + List<VMInstanceVO> listByStoragePool(long storagePoolId); - List<HostVO> getSecondaryStorageHosts(long zoneId); + StoragePoolVO findLocalStorageOnHost(long hostId); - List<StoragePoolVO> ListByDataCenterHypervisor(long datacenterId, HypervisorType type); + Host updateSecondaryStorage(long secStorageId, String newUrl); + List<Long> getUpHostsInPool(long poolId); - List<VMInstanceVO> listByStoragePool(long storagePoolId); + void cleanupSecondaryStorage(boolean recurring); - StoragePoolVO findLocalStorageOnHost(long hostId); - VMTemplateHostVO getTemplateHostRef(long zoneId, long tmpltId, boolean readyOnly); + HypervisorType getHypervisorTypeFromFormat(ImageFormat format); + + boolean storagePoolHasEnoughSpace(List<Volume> volume, StoragePool pool); - boolean StorageMigration( - VirtualMachineProfile<? extends VirtualMachine> vm, - StoragePool destPool) throws ConcurrentOperationException; + + boolean registerHostListener(String providerUuid, HypervisorHostListener listener); - boolean stateTransitTo(Volume vol, Event event) - throws NoTransitionException; + StoragePool findStoragePool(DiskProfile dskCh, DataCenterVO dc, + HostPodVO pod, Long clusterId, Long hostId, VMInstanceVO vm, + Set<StoragePool> avoid); - VolumeVO allocateDuplicateVolume(VolumeVO oldVol, Long templateId); - Host updateSecondaryStorage(long secStorageId, String newUrl); + void connectHostToSharedPool(long hostId, long poolId) + throws StorageUnavailableException; - List<Long> getUpHostsInPool(long poolId); + void createCapacityEntry(long poolId); - void cleanupSecondaryStorage(boolean recurring); - VolumeVO copyVolumeFromSecToPrimary(VolumeVO volume, VMInstanceVO vm, - VMTemplateVO template, DataCenterVO dc, HostPodVO pod, - Long clusterId, ServiceOfferingVO offering, - DiskOfferingVO diskOffering, List<StoragePoolVO> avoids, long size, - HypervisorType hyperType) throws NoTransitionException; - String getSupportedImageFormatForCluster(Long clusterId); - HypervisorType getHypervisorTypeFromFormat(ImageFormat format); - boolean storagePoolHasEnoughSpace(List<Volume> volume, StoragePool pool); + DataStore createLocalStorage(Host host, StoragePoolInfo poolInfo) throws ConnectionException; - boolean deleteVolume(long volumeId, Account caller) throws ConcurrentOperationException; }
