<commit_before>package org.ovirt.engine.core.bll.storage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
import org.ovirt.engine.core.bll.context.CommandContext;
import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.common.action.ExtendSANStorageDomainParameters;
import org.ovirt.engine.core.common.action.VdcReturnValueBase;
import org.ovirt.engine.core.common.businessentities.VDS;
import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
import org.ovirt.engine.core.common.businessentities.storage.LUNs;
import org.ovirt.engine.core.common.errors.EngineException;
import org.ovirt.engine.core.common.utils.Pair;
import org.ovirt.engine.core.common.vdscommands.GetDeviceListVDSCommandParameters;
import org.ovirt.engine.core.common.vdscommands.GetDevicesVisibilityVDSCommandParameters;
import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.utils.linq.LinqUtils;
import org.ovirt.engine.core.utils.linq.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("serial")
@NonTransactiveCommandAttribute
public class ConnectAllHostsToLunCommand<T extends ExtendSANStorageDomainParameters> extends
        StorageDomainCommandBase<T> {

    private static final Logger log = LoggerFactory.getLogger(ConnectAllHostsToLunCommand.class);

    public ConnectAllHostsToLunCommand(T parameters, CommandContext commandContext) {
        super(parameters, commandContext);
    }

    public ConnectAllHostsToLunCommand(T parameters) {
        this(parameters, null);
    }

    public static class ConnectAllHostsToLunCommandReturnValue extends VdcReturnValueBase {
        private VDS failedVds;
        private LUNs failedLun;

        public VDS getFailedVds() {
            return failedVds;
        }

        public void setFailedVds(VDS failedVds) {
            this.failedVds = failedVds;
        }

        public LUNs getFailedLun() {
            return failedLun;
        }

        public void setFailedLun(LUNs failedLun) {
            this.failedLun = failedLun;
        }
    }

    @Override
    protected ConnectAllHostsToLunCommandReturnValue createReturnValue() {
        return new ConnectAllHostsToLunCommandReturnValue();
    }

    private ConnectAllHostsToLunCommandReturnValue getResult() {
        return (ConnectAllHostsToLunCommandReturnValue) getReturnValue();
    }

    @Override
    protected void executeCommand() {
        VDS spmVds = LinqUtils.first(LinqUtils.filter(getAllRunningVdssInPool(), new Predicate<VDS>() {
            @Override
            public boolean eval(VDS vds) {
                return vds.getSpmStatus() == VdsSpmStatus.SPM;
            }
        }));

        final List<LUNs> luns = getHostLuns(spmVds);
        final Map<String, LUNs> lunsMap = new HashMap<>();
        for (LUNs lun : luns) {
            lunsMap.put(lun.getLUN_id(), lun);
        }
        final List<LUNs> processedLunsList = new ArrayList<>();
        for (String lunId : getParameters().getLunIds()) {
            LUNs lun = lunsMap.get(lunId);
            if (lun == null) {
                //fail
                handleFailure(spmVds, getDbFacade().getLunDao().get(lunId));
                return;
            }

            lun.setvolume_group_id(getStorageDomain().getStorage());
            processedLunsList.add(lun);
        }
        // connect all vds in pool (except spm) to lun and getDeviceList
        Pair<Boolean, Map<String, List<Guid>>> result = connectVdsToLun(processedLunsList);
        if (result.getFirst()) {
            getReturnValue().setActionReturnValue(processedLunsList);
            setCommandShouldBeLogged(false);
            setSucceeded(true);
        } else {<commit_msg>core: ConnectAllHostsToLunCommand lambdas<commit_after>package org.ovirt.engine.core.bll.storage;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
import org.ovirt.engine.core.bll.context.CommandContext;
import org.ovirt.engine.core.common.AuditLogType;
import org.ovirt.engine.core.common.action.ExtendSANStorageDomainParameters;
import org.ovirt.engine.core.common.action.VdcReturnValueBase;
import org.ovirt.engine.core.common.businessentities.VDS;
import org.ovirt.engine.core.common.businessentities.VdsSpmStatus;
import org.ovirt.engine.core.common.businessentities.storage.LUNs;
import org.ovirt.engine.core.common.errors.EngineException;
import org.ovirt.engine.core.common.utils.Pair;
import org.ovirt.engine.core.common.vdscommands.GetDeviceListVDSCommandParameters;
import org.ovirt.engine.core.common.vdscommands.GetDevicesVisibilityVDSCommandParameters;
import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
import org.ovirt.engine.core.compat.Guid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("serial")
@NonTransactiveCommandAttribute
public class ConnectAllHostsToLunCommand<T extends ExtendSANStorageDomainParameters> extends
        StorageDomainCommandBase<T> {

    private static final Logger log = LoggerFactory.getLogger(ConnectAllHostsToLunCommand.class);

    public ConnectAllHostsToLunCommand(T parameters, CommandContext commandContext) {
        super(parameters, commandContext);
    }

    public ConnectAllHostsToLunCommand(T parameters) {
        this(parameters, null);
    }

    public static class ConnectAllHostsToLunCommandReturnValue extends VdcReturnValueBase {
        private VDS failedVds;
        private LUNs failedLun;

        public VDS getFailedVds() {
            return failedVds;
        }

        public void setFailedVds(VDS failedVds) {
            this.failedVds = failedVds;
        }

        public LUNs getFailedLun() {
            return failedLun;
        }

        public void setFailedLun(LUNs failedLun) {
            this.failedLun = failedLun;
        }
    }

    @Override
    protected ConnectAllHostsToLunCommandReturnValue createReturnValue() {
        return new ConnectAllHostsToLunCommandReturnValue();
    }

    private ConnectAllHostsToLunCommandReturnValue getResult() {
        return (ConnectAllHostsToLunCommandReturnValue) getReturnValue();
    }

    @Override
    protected void executeCommand() {
        VDS spmVds = getAllRunningVdssInPool().stream()
                .filter(vds -> vds.getSpmStatus() == VdsSpmStatus.SPM).findFirst().orElse(null);

        final List<LUNs> luns = getHostLuns(spmVds);
        final Map<String, LUNs> lunsMap = new HashMap<>();
        for (LUNs lun : luns) {
            lunsMap.put(lun.getLUN_id(), lun);
        }
        final List<LUNs> processedLunsList = new ArrayList<>();
        for (String lunId : getParameters().getLunIds()) {
            LUNs lun = lunsMap.get(lunId);
            if (lun == null) {
                //fail
                handleFailure(spmVds, getDbFacade().getLunDao().get(lunId));
                return;
            }

            lun.setvolume_group_id(getStorageDomain().getStorage());
            processedLunsList.add(lun);
        }
        // connect all vds in pool (except spm) to lun and getDeviceList
        Pair<Boolean, Map<String, List<Guid>>> result = connectVdsToLun(processedLunsList);
        if (result.getFirst()) {
            getReturnValue().setActionReturnValue(processedLunsList);
            setCommandShouldBeLogged(false);
            setSucceeded(true);
        } else {
{'fraction_non_alphanumeric': 0.09487516425755585, 'fraction_numerical': 0.0005256241787122207, 'mean_word_length': 3.2472098214285716, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7493492', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2288, 'n_words': 383}