Search in sources :

Example 11 with StorageDevice

use of org.ovirt.engine.core.common.businessentities.gluster.StorageDevice in project ovirt-engine by oVirt.

the class GetGlusterStorageDevicesQuery method filterStorageDevices.

private List<StorageDevice> filterStorageDevices(List<StorageDevice> storageDevices) {
    List<StorageDevice> filteredStorageDevices = new ArrayList<>();
    Pattern mountPointsFilterPattern = Pattern.compile(getMountPointsFilterPattern());
    List<String> fsTypesToFilterOutList = getFsTypesFilter();
    // Filter out the devices which are not going to be used as storage device for gluster.
    for (StorageDevice device : storageDevices) {
        if ((device.getMountPoint() != null && mountPointsFilterPattern.matcher(device.getMountPoint()).matches()) || (device.getFsType() != null && fsTypesToFilterOutList.contains(device.getFsType()))) {
            continue;
        }
        if (device.getCanCreateBrick() || device.getMountPoint() != null || device.getFsType() != null) {
            filteredStorageDevices.add(device);
        }
    }
    return filteredStorageDevices;
}
Also used : Pattern(java.util.regex.Pattern) StorageDevice(org.ovirt.engine.core.common.businessentities.gluster.StorageDevice) ArrayList(java.util.ArrayList)

Example 12 with StorageDevice

use of org.ovirt.engine.core.common.businessentities.gluster.StorageDevice in project ovirt-engine by oVirt.

the class StorageDeviceSyncJobTest method getStorageDevice.

private StorageDevice getStorageDevice(String name, Guid id) {
    StorageDevice storageDevice = new StorageDevice();
    storageDevice.setCanCreateBrick(true);
    storageDevice.setDescription("Test Device" + name);
    storageDevice.setDevPath("/dev/" + name);
    storageDevice.setDevType("SCSI");
    storageDevice.setName(name);
    storageDevice.setSize(10000L);
    if (id == null) {
        storageDevice.setId(Guid.newGuid());
    } else {
        storageDevice.setId(id);
    }
    return storageDevice;
}
Also used : StorageDevice(org.ovirt.engine.core.common.businessentities.gluster.StorageDevice)

Example 13 with StorageDevice

use of org.ovirt.engine.core.common.businessentities.gluster.StorageDevice in project ovirt-engine by oVirt.

the class CreateBrickVDSCommand method executeVdsBrokerCommand.

@Override
protected void executeVdsBrokerCommand() {
    CreateBrickVDSParameters parameters = getParameters();
    Set<String> diskNames = new HashSet<>();
    for (StorageDevice storageDevice : parameters.getStorageDevices()) {
        diskNames.add(storageDevice.getName());
    }
    storageDeviceReturn = getBroker().glusterCreateBrick(parameters.getLvName(), parameters.getMountPoint(), parameters.getRaidParams(), parameters.getFsType(), diskNames.toArray(new String[0]));
    proceedProxyReturnValue();
    if (getVDSReturnValue().getSucceeded()) {
        StorageDevice storageDevice = storageDeviceReturn.getStorageDevice();
        storageDevice.setVdsId(getParameters().getVdsId());
        storageDevice.setId(Guid.newGuid());
        setReturnValue(storageDevice);
    }
}
Also used : CreateBrickVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.CreateBrickVDSParameters) StorageDevice(org.ovirt.engine.core.common.businessentities.gluster.StorageDevice) HashSet(java.util.HashSet)

Example 14 with StorageDevice

use of org.ovirt.engine.core.common.businessentities.gluster.StorageDevice in project ovirt-engine by oVirt.

the class StorageDeviceSyncJob method updateStorageDevices.

public void updateStorageDevices(VDS vds, List<StorageDevice> storageDevicesFromVdsm) {
    Set<String> deviceUuidsFromVdsm = new HashSet<>();
    Set<String> deviceNamesFromVdsm = new HashSet<>();
    List<StorageDevice> storageDevicesInDb = storageDeviceDao.getStorageDevicesInHost(vds.getId());
    Map<String, StorageDevice> nameToDeviceMap = new HashMap<>();
    Map<String, StorageDevice> deviceUuidToDeviceMap = new HashMap<>();
    // newly added and updated devices without looping over the same list again and again.
    for (StorageDevice storageDevice : storageDevicesInDb) {
        nameToDeviceMap.put(storageDevice.getName(), storageDevice);
        if (storageDevice.getDevUuid() != null && !storageDevice.getDevUuid().isEmpty()) {
            deviceUuidToDeviceMap.put(storageDevice.getDevUuid(), storageDevice);
        }
    }
    List<StorageDevice> storageDevicesToUpdate = new ArrayList<>();
    List<StorageDevice> storageDevicesToDelete = new ArrayList<>();
    for (StorageDevice storageDevice : storageDevicesFromVdsm) {
        // Create deviceName and deviceUuid set to use it while finding the deleted services.
        deviceNamesFromVdsm.add(storageDevice.getName());
        if (storageDevice.getDevUuid() != null) {
            deviceUuidsFromVdsm.add(storageDevice.getDevUuid());
        }
        // If DevUuid is already exits in the DB then its an existing devices
        // Assume device from vdsm doesn't have devUUID, but device name already exists in the DB
        // Following two cases possible:
        // 1. If device in DB doesn't have a devUUID
        // update the device if there is a change from vdsm.
        // 2. If device in DB has devUUID
        // Though name matches, its two different devices. So treat this device as new one.
        // Device in DB will be updated/removed by some other iteration in the loop
        StorageDevice storageDevByDevUuid = deviceUuidToDeviceMap.get(storageDevice.getDevUuid());
        StorageDevice storageDevByName = nameToDeviceMap.get(storageDevice.getName());
        if (storageDevByDevUuid != null) {
            storageDevice.setId(storageDevByDevUuid.getId());
            if (!Objects.equals(storageDevByDevUuid, storageDevice)) {
                storageDevicesToUpdate.add(storageDevice);
            }
        } else if (storageDevByName != null && StringUtils.isBlank(storageDevByName.getDevUuid())) {
            storageDevice.setId(storageDevByName.getId());
            if (!Objects.equals(storageDevByName, storageDevice)) {
                storageDevicesToUpdate.add(storageDevice);
            }
        } else {
            storageDevice.setId(Guid.newGuid());
            storageDevice.setVdsId(vds.getId());
            log.debug("detected new storage device '{}' for host '{}'", storageDevice.getName(), vds.getName());
            storageDeviceDao.save(storageDevice);
            logStorageDeviceMessage(AuditLogType.NEW_STORAGE_DEVICE_DETECTED, vds, storageDevice);
        }
    }
    for (StorageDevice storageDevice : storageDevicesInDb) {
        if ((storageDevice.getDevUuid() != null && !deviceUuidsFromVdsm.contains(storageDevice.getDevUuid())) || (storageDevice.getDevUuid() == null && !deviceNamesFromVdsm.contains(storageDevice.getName()))) {
            log.debug("storage device '{}' detected removed for the host '{}'", storageDevice.getName(), vds.getName());
            logStorageDeviceMessage(AuditLogType.STORAGE_DEVICE_REMOVED_FROM_THE_HOST, vds, storageDevice);
            storageDevicesToDelete.add(storageDevice);
        }
    }
    if (!storageDevicesToUpdate.isEmpty()) {
        storageDeviceDao.updateAllInBatch(storageDevicesToUpdate);
    }
    if (!storageDevicesToDelete.isEmpty()) {
        storageDeviceDao.removeAllInBatch(storageDevicesToDelete);
    }
}
Also used : StorageDevice(org.ovirt.engine.core.common.businessentities.gluster.StorageDevice) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 15 with StorageDevice

use of org.ovirt.engine.core.common.businessentities.gluster.StorageDevice in project ovirt-engine by oVirt.

the class SyncStorageDevicesCommand method executeCommand.

@Override
protected void executeCommand() {
    VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GetStorageDeviceList, new VdsIdVDSCommandParametersBase(getVds().getId()));
    if (returnValue.getSucceeded()) {
        List<StorageDevice> storageDevices = (List<StorageDevice>) returnValue.getReturnValue();
        getStorageDeviceSyncJobInstance().updateStorageDevices(getVds(), storageDevices);
        setSucceeded(true);
    } else {
        handleVdsError(returnValue);
        setSucceeded(false);
    }
}
Also used : VdsIdVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdVDSCommandParametersBase) StorageDevice(org.ovirt.engine.core.common.businessentities.gluster.StorageDevice) List(java.util.List) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Aggregations

StorageDevice (org.ovirt.engine.core.common.businessentities.gluster.StorageDevice)23 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 CreateBrickParameters (org.ovirt.engine.core.common.action.gluster.CreateBrickParameters)4 List (java.util.List)3 SizeUnit (org.ovirt.engine.core.common.utils.SizeConverter.SizeUnit)3 HashSet (java.util.HashSet)2 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)2 VDS (org.ovirt.engine.core.common.businessentities.VDS)2 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Pattern (java.util.regex.Pattern)1 HostValidator (org.ovirt.engine.core.bll.validator.HostValidator)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 ActionType (org.ovirt.engine.core.common.action.ActionType)1 SyncGlusterStorageDevicesParameter (org.ovirt.engine.core.common.action.gluster.SyncGlusterStorageDevicesParameter)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 RaidType (org.ovirt.engine.core.common.businessentities.RaidType)1 VDSStatus (org.ovirt.engine.core.common.businessentities.VDSStatus)1