Search in sources :

Example 1 with SyncVolumePathCommand

use of org.apache.cloudstack.storage.command.SyncVolumePathCommand in project cloudstack by apache.

the class StorageManagerImpl method handleRemoveChildStoragePoolFromDatastoreCluster.

private void handleRemoveChildStoragePoolFromDatastoreCluster(Set<String> childDatastoreUUIDs) {
    for (String childDatastoreUUID : childDatastoreUUIDs) {
        StoragePoolVO dataStoreVO = _storagePoolDao.findPoolByUUID(childDatastoreUUID);
        List<VolumeVO> allVolumes = _volumeDao.findByPoolId(dataStoreVO.getId());
        allVolumes.removeIf(volumeVO -> volumeVO.getInstanceId() == null);
        allVolumes.removeIf(volumeVO -> volumeVO.getState() != Volume.State.Ready);
        for (VolumeVO volume : allVolumes) {
            VMInstanceVO vmInstance = _vmInstanceDao.findById(volume.getInstanceId());
            if (vmInstance == null) {
                continue;
            }
            long volumeId = volume.getId();
            Long hostId = vmInstance.getHostId();
            if (hostId == null) {
                hostId = vmInstance.getLastHostId();
            }
            HostVO hostVO = _hostDao.findById(hostId);
            // Prepare for the syncvolumepath command
            DataTO volTO = volFactory.getVolume(volume.getId()).getTO();
            DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType());
            Map<String, String> details = new HashMap<String, String>();
            details.put(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
            disk.setDetails(details);
            s_logger.debug(String.format("Attempting to process SyncVolumePathCommand for the volume %d on the host %d with state %s", volumeId, hostId, hostVO.getResourceState()));
            SyncVolumePathCommand cmd = new SyncVolumePathCommand(disk);
            final Answer answer = _agentMgr.easySend(hostId, cmd);
            // validate answer
            if (answer == null) {
                throw new CloudRuntimeException("Unable to get an answer to the SyncVolumePath command for volume " + volumeId);
            }
            if (!answer.getResult()) {
                throw new CloudRuntimeException("Unable to process SyncVolumePathCommand for the volume" + volumeId + " to the host " + hostId + " due to " + answer.getDetails());
            }
            assert (answer instanceof SyncVolumePathAnswer) : "Well, now why won't you actually return the SyncVolumePathAnswer when it's SyncVolumePathCommand? volume=" + volume.getUuid() + "Host=" + hostId;
            // check for the changed details of volume and update database
            VolumeVO volumeVO = _volumeDao.findById(volumeId);
            String datastoreName = answer.getContextParam("datastoreName");
            if (datastoreName != null) {
                StoragePoolVO storagePoolVO = _storagePoolDao.findByUuid(datastoreName);
                if (storagePoolVO != null) {
                    volumeVO.setPoolId(storagePoolVO.getId());
                } else {
                    s_logger.warn(String.format("Unable to find datastore %s while updating the new datastore of the volume %d", datastoreName, volumeId));
                }
            }
            String volumePath = answer.getContextParam("volumePath");
            if (volumePath != null) {
                volumeVO.setPath(volumePath);
            }
            String chainInfo = answer.getContextParam("chainInfo");
            if (chainInfo != null) {
                volumeVO.setChainInfo(chainInfo);
            }
            _volumeDao.update(volumeVO.getId(), volumeVO);
        }
        dataStoreVO.setParent(0L);
        _storagePoolDao.update(dataStoreVO.getId(), dataStoreVO);
    }
}
Also used : HashMap(java.util.HashMap) VMInstanceVO(com.cloud.vm.VMInstanceVO) SyncVolumePathCommand(org.apache.cloudstack.storage.command.SyncVolumePathCommand) HostVO(com.cloud.host.HostVO) SyncVolumePathAnswer(org.apache.cloudstack.storage.command.SyncVolumePathAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) GetVolumeStatsAnswer(com.cloud.agent.api.GetVolumeStatsAnswer) Answer(com.cloud.agent.api.Answer) SyncVolumePathAnswer(org.apache.cloudstack.storage.command.SyncVolumePathAnswer) GetStoragePoolCapabilitiesAnswer(com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) DataTO(com.cloud.agent.api.to.DataTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) DiskTO(com.cloud.agent.api.to.DiskTO)

Aggregations

Answer (com.cloud.agent.api.Answer)1 GetStoragePoolCapabilitiesAnswer (com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer)1 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)1 GetVolumeStatsAnswer (com.cloud.agent.api.GetVolumeStatsAnswer)1 ModifyStoragePoolAnswer (com.cloud.agent.api.ModifyStoragePoolAnswer)1 DataTO (com.cloud.agent.api.to.DataTO)1 DiskTO (com.cloud.agent.api.to.DiskTO)1 HostVO (com.cloud.host.HostVO)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 HashMap (java.util.HashMap)1 SyncVolumePathAnswer (org.apache.cloudstack.storage.command.SyncVolumePathAnswer)1 SyncVolumePathCommand (org.apache.cloudstack.storage.command.SyncVolumePathCommand)1 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)1