Search in sources :

Example 81 with StorageServerConnections

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

the class AbstractDiskVmCommand method performPlugCommand.

protected void performPlugCommand(VDSCommandType commandType, Disk disk, VmDevice vmDevice) {
    if (disk.getDiskStorageType() == DiskStorageType.LUN) {
        LunDisk lunDisk = (LunDisk) disk;
        if (commandType == VDSCommandType.HotPlugDisk) {
            LUNs lun = lunDisk.getLun();
            updateLUNConnectionsInfo(lun);
            lun.getLunConnections().stream().map(StorageServerConnections::getStorageType).distinct().forEach(t -> {
                if (!getStorageHelper(t).connectStorageToLunByVdsId(null, getVm().getRunOnVds(), lun, getVm().getStoragePoolId())) {
                    throw new EngineException(EngineError.StorageServerConnectionError);
                }
            });
        }
    } else if (disk.getDiskStorageType() == DiskStorageType.CINDER) {
        CinderDisk cinderDisk = (CinderDisk) disk;
        setStorageDomainId(cinderDisk.getStorageIds().get(0));
        getCinderBroker().updateConnectionInfoForDisk(cinderDisk);
    }
    Map<String, String> diskAddressMap = getDiskAddressMap(vmDevice, getDiskVmElement().getDiskInterface());
    runVdsCommand(commandType, new HotPlugDiskVDSParameters(getVm().getRunOnVds(), getVm(), disk, vmDevice, diskAddressMap, getDiskVmElement().getDiskInterface(), getDiskVmElement().isPassDiscard()));
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) EngineException(org.ovirt.engine.core.common.errors.EngineException) CinderDisk(org.ovirt.engine.core.common.businessentities.storage.CinderDisk) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) HotPlugDiskVDSParameters(org.ovirt.engine.core.common.vdscommands.HotPlugDiskVDSParameters)

Example 82 with StorageServerConnections

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

the class ISCSIStorageHelper method filterConnectionsUsedByOthers.

@SuppressWarnings("unchecked")
@Override
protected List<StorageServerConnections> filterConnectionsUsedByOthers(List<StorageServerConnections> connections, String vgId, final String lunId) {
    // if we have lun id then filter by this lun
    // else get vg's luns from db
    List<String> lunsByVgWithNoDisks = new ArrayList<>();
    if (lunId.isEmpty()) {
        List<String> lunsByVg = lunDao.getAllForVolumeGroup(vgId).stream().map(LUNs::getLUNId).collect(Collectors.toList());
        // at that case they should left at db
        for (String lunIdByVg : lunsByVg) {
            if (diskLunMapDao.getDiskIdByLunId(lunIdByVg) == null) {
                lunsByVgWithNoDisks.add(lunIdByVg);
            }
        }
    } else {
        lunsByVgWithNoDisks.add(lunId);
    }
    List<StorageServerConnections> toRemove = new ArrayList<>();
    for (StorageServerConnections connection : connections) {
        fillConnectionDetailsIfNeeded(connection);
        if (connection.getId() != null) {
            List<String> list = lunDao.getAllForStorageServerConnection(connection.getId()).stream().map(LUNs::getLUNId).collect(Collectors.toList());
            if (0 < CollectionUtils.subtract(list, lunsByVgWithNoDisks).size()) {
                toRemove.add(connection);
            }
        }
    }
    return (List<StorageServerConnections>) CollectionUtils.subtract(connections, toRemove);
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 83 with StorageServerConnections

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

the class ISCSIStorageHelper method updateIfaces.

public List<StorageServerConnections> updateIfaces(List<StorageServerConnections> conns, Guid vdsId) {
    List<StorageServerConnections> res = new ArrayList<>(conns);
    for (StorageServerConnections conn : conns) {
        // Get list of endpoints (nics or vlans) that will initiate iscsi sessions.
        // Targets are represented by StorageServerConnections object (connection, iqn, port, portal).
        List<VdsNetworkInterface> ifaces = interfaceDao.getIscsiIfacesByHostIdAndStorageTargetId(vdsId, conn.getId());
        if (!ifaces.isEmpty()) {
            VdsNetworkInterface removedInterface = ifaces.remove(0);
            setInterfaceProperties(conn, removedInterface);
            // from more than one endpoint(initiator) we have to clone this connection per endpoint.
            for (VdsNetworkInterface iface : ifaces) {
                StorageServerConnections newConn = StorageServerConnections.copyOf(conn);
                newConn.setId(Guid.newGuid().toString());
                setInterfaceProperties(newConn, iface);
                res.add(newConn);
            }
        }
    }
    return res;
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) ArrayList(java.util.ArrayList) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface)

Example 84 with StorageServerConnections

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

the class ISCSIStorageHelper method isConnectSucceeded.

@Override
public boolean isConnectSucceeded(final Map<String, String> returnValue, List<StorageServerConnections> connections) {
    boolean result = true;
    List<String> failedConnectionsList = returnValue.keySet().stream().filter(a -> !"0".equals(returnValue.get(a))).collect(Collectors.toList());
    for (String failedConnection : failedConnectionsList) {
        List<LUNs> failedLuns = lunDao.getAllForStorageServerConnection(failedConnection);
        if (!failedLuns.isEmpty()) {
            for (LUNs lun : failedLuns) {
                // TODO: check if LUNs in the same pool.
                List<String> strings = storageServerConnectionLunMapDao.getAll(lun.getLUNId()).stream().map(LUNStorageServerConnectionMap::getStorageServerConnection).collect(Collectors.toList());
                if (CollectionUtils.subtract(strings, failedConnectionsList).size() == 0) {
                    // At case of failure the appropriate log message will be
                    // added
                    log.info("The lun with id '{}' was reported as problematic", lun.getPhysicalVolumeId());
                    for (String connectionFailed : failedConnectionsList) {
                        String connectionField = addToAuditLogErrorMessage(connectionFailed, returnValue.get(connectionFailed), connections, lun);
                        printLog(log, connectionField, returnValue.get(connectionFailed));
                    }
                    return false;
                }
            }
        } else {
            result = false;
            printLog(log, failedConnection, returnValue.get(failedConnection));
        }
    }
    return result;
}
Also used : ConnectHostToStoragePoolServersParameters(org.ovirt.engine.core.common.action.ConnectHostToStoragePoolServersParameters) Guid(org.ovirt.engine.core.compat.Guid) StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) LoggerFactory(org.slf4j.LoggerFactory) Singleton(javax.inject.Singleton) VdsNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface) ArrayList(java.util.ArrayList) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) Inject(javax.inject.Inject) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionType(org.ovirt.engine.core.common.action.ActionType) CollectionUtils(org.apache.commons.collections.CollectionUtils) StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) Map(java.util.Map) LUNStorageServerConnectionMap(org.ovirt.engine.core.common.businessentities.storage.LUNStorageServerConnectionMap) Pair(org.ovirt.engine.core.common.utils.Pair) StorageServerConnectionLunMapDao(org.ovirt.engine.core.dao.StorageServerConnectionLunMapDao) StorageType(org.ovirt.engine.core.common.businessentities.storage.StorageType) SyncLunsInfoForBlockStorageDomainParameters(org.ovirt.engine.core.common.action.SyncLunsInfoForBlockStorageDomainParameters) Logger(org.slf4j.Logger) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) HostStoragePoolParametersBase(org.ovirt.engine.core.common.action.HostStoragePoolParametersBase) StorageServerConnectionManagementVDSParameters(org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters) VDSCommandType(org.ovirt.engine.core.common.vdscommands.VDSCommandType) InterfaceDao(org.ovirt.engine.core.dao.network.InterfaceDao) Collections(java.util.Collections) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs) LUNs(org.ovirt.engine.core.common.businessentities.storage.LUNs)

Example 85 with StorageServerConnections

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

the class ISCSIStorageHelper method runConnectionStorageToDomain.

@SuppressWarnings("unchecked")
@Override
protected Pair<Boolean, EngineFault> runConnectionStorageToDomain(StorageDomain storageDomain, Guid vdsId, int type, LUNs lun, Guid storagePoolId) {
    boolean isSuccess = true;
    VDSReturnValue returnValue = null;
    List<StorageServerConnections> list = (lun == null) ? storageServerConnectionDao.getAllForVolumeGroup(storageDomain.getStorage()) : lun.getLunConnections();
    if (list.size() != 0) {
        if (VDSCommandType.forValue(type) == VDSCommandType.DisconnectStorageServer) {
            list = filterConnectionsUsedByOthers(list, storageDomain.getStorage(), lun != null ? lun.getLUNId() : "");
        } else if (VDSCommandType.forValue(type) == VDSCommandType.ConnectStorageServer) {
            list = updateIfaces(list, vdsId);
        }
        Guid poolId = storagePoolId;
        if (storageDomain != null && storageDomain.getStoragePoolId() != null) {
            poolId = storageDomain.getStoragePoolId();
        }
        returnValue = backend.getResourceManager().runVdsCommand(VDSCommandType.forValue(type), new StorageServerConnectionManagementVDSParameters(vdsId, poolId, StorageType.ISCSI, list));
        isSuccess = returnValue.getSucceeded();
        if (isSuccess && VDSCommandType.forValue(type) == VDSCommandType.ConnectStorageServer) {
            isSuccess = isConnectSucceeded((Map<String, String>) returnValue.getReturnValue(), list);
        }
    }
    EngineFault engineFault = null;
    if (!isSuccess && returnValue.getVdsError() != null) {
        engineFault = new EngineFault();
        engineFault.setError(returnValue.getVdsError().getCode());
    }
    return new Pair<>(isSuccess, engineFault);
}
Also used : StorageServerConnections(org.ovirt.engine.core.common.businessentities.StorageServerConnections) StorageServerConnectionManagementVDSParameters(org.ovirt.engine.core.common.vdscommands.StorageServerConnectionManagementVDSParameters) EngineFault(org.ovirt.engine.core.common.errors.EngineFault) Guid(org.ovirt.engine.core.compat.Guid) Map(java.util.Map) LUNStorageServerConnectionMap(org.ovirt.engine.core.common.businessentities.storage.LUNStorageServerConnectionMap) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

StorageServerConnections (org.ovirt.engine.core.common.businessentities.StorageServerConnections)181 Test (org.junit.Test)83 ArrayList (java.util.ArrayList)43 Guid (org.ovirt.engine.core.compat.Guid)39 LUNs (org.ovirt.engine.core.common.businessentities.storage.LUNs)33 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)32 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)19 List (java.util.List)18 StorageType (org.ovirt.engine.core.common.businessentities.storage.StorageType)17 VDS (org.ovirt.engine.core.common.businessentities.VDS)16 StorageServerConnectionParametersBase (org.ovirt.engine.core.common.action.StorageServerConnectionParametersBase)15 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)15 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)14 HashSet (java.util.HashSet)13 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)11 ActionType (org.ovirt.engine.core.common.action.ActionType)11 Set (java.util.Set)10 StorageConnection (org.ovirt.engine.api.model.StorageConnection)10 StorageDomainType (org.ovirt.engine.core.common.businessentities.StorageDomainType)10 QueryType (org.ovirt.engine.core.common.queries.QueryType)10