<commit_before>package de.unibi.cebitec.bibigrid.openstack;

import de.unibi.cebitec.bibigrid.core.model.*;
import de.unibi.cebitec.bibigrid.core.model.exceptions.ClientConnectionFailedException;
import org.openstack4j.api.OSClient;
import org.openstack4j.api.compute.ServerGroupService;
import org.openstack4j.api.exceptions.AuthenticationException;
import org.openstack4j.model.common.Identifier;
import org.openstack4j.model.compute.Image;
import org.openstack4j.model.storage.block.Volume;
import org.openstack4j.openstack.OSFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Implementation of abstract class Client.
 *
 * @author mfriedrichs(at)techfak.uni-bielefeld.de
 * @author jkrueger(at)cebitec.uni-bielefeld.de
 */
class ClientOpenstack extends Client {
    private static final Logger LOG = LoggerFactory.getLogger(ClientOpenstack.class);

    private final OSClient internalClient;

    ClientOpenstack(ConfigurationOpenstack config) throws ClientConnectionFailedException {
        OpenStackCredentials credentials = config.getOpenstackCredentials();
        try {
            OSFactory.enableHttpLoggingFilter(config.isDebugRequests());
            internalClient = buildOSClientV3(credentials);
            LOG.info("Openstack connection established.");
        } catch (AuthenticationException e) {
            if (Configuration.DEBUG) {
                e.printStackTrace();
            }
            throw new ClientConnectionFailedException(String.format("Connection failed: %s. " +
                    "Please make sure the supplied OpenStack credentials are valid.", e.getLocalizedMessage()), e);
        } catch (Exception e) {
            if (Configuration.DEBUG) {
                e.printStackTrace();
            }
            throw new ClientConnectionFailedException(String.format("Failed to connect openstack " +
                    "client: %s: %s", e.getClass().getSimpleName(), e.getLocalizedMessage()), e);
        }
    }

    private static OSClient buildOSClientV3(OpenStackCredentials credentials) {
        if (Configuration.DEBUG) {
            LOG.info(credentials.toString());
        }
        return OSFactory.builderV3()
                .endpoint(credentials.getEndpoint())
                .credentials(credentials.getUsername(), credentials.getPassword(), Identifier.byName(credentials.getUserDomain()))
                .scopeToProject(Identifier.byName(credentials.getProject()), Identifier.byId(credentials.getProjectDomainId()))
                .authenticate();
    }

    OSClient getInternal() {
        return internalClient;
    }
<commit_msg>Fixed single query of id / name instead of both<commit_after>package de.unibi.cebitec.bibigrid.openstack;

import de.unibi.cebitec.bibigrid.core.model.*;
import de.unibi.cebitec.bibigrid.core.model.exceptions.ClientConnectionFailedException;
import org.openstack4j.api.OSClient;
import org.openstack4j.api.compute.ServerGroupService;
import org.openstack4j.api.exceptions.AuthenticationException;
import org.openstack4j.model.common.Identifier;
import org.openstack4j.model.compute.Image;
import org.openstack4j.model.storage.block.Volume;
import org.openstack4j.openstack.OSFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Implementation of abstract class Client.
 *
 * @author mfriedrichs(at)techfak.uni-bielefeld.de
 * @author jkrueger(at)cebitec.uni-bielefeld.de
 */
class ClientOpenstack extends Client {
    private static final Logger LOG = LoggerFactory.getLogger(ClientOpenstack.class);

    private final OSClient internalClient;

    ClientOpenstack(ConfigurationOpenstack config) throws ClientConnectionFailedException {
        OpenStackCredentials credentials = config.getOpenstackCredentials();
        try {
            OSFactory.enableHttpLoggingFilter(config.isDebugRequests());
            internalClient = buildOSClientV3(credentials);
            LOG.info("Openstack connection established.");
        } catch (AuthenticationException e) {
            if (Configuration.DEBUG) {
                e.printStackTrace();
            }
            throw new ClientConnectionFailedException(String.format("Connection failed: %s. " +
                    "Please make sure the supplied OpenStack credentials are valid.", e.getLocalizedMessage()), e);
        } catch (Exception e) {
            if (Configuration.DEBUG) {
                e.printStackTrace();
            }
            throw new ClientConnectionFailedException(String.format("Failed to connect openstack " +
                    "client: %s: %s", e.getClass().getSimpleName(), e.getLocalizedMessage()), e);
        }
    }

    private static OSClient buildOSClientV3(OpenStackCredentials credentials) {
        if (Configuration.DEBUG) {
            LOG.info(credentials.toString());
        }
        Identifier project = getIdentifier(credentials.getProject(), credentials.getProjectId());
        Identifier userDomain = getIdentifier(credentials.getUserDomain(), credentials.getUserDomainId());
        Identifier projectDomain = getIdentifier(credentials.getProjectDomain(), credentials.getProjectDomainId());
        return OSFactory.builderV3()
                .endpoint(credentials.getEndpoint())
                .credentials(credentials.getUsername(), credentials.getPassword(), userDomain)
                .scopeToProject(project, projectDomain)
                .authenticate();
    }

    static Identifier getIdentifier(String name, String id) {
        if (name == null) {
            if (id == null) {
                LOG.error("No ProjectDomain provided. Cannot authenticate via Openstack API.");
            } else {
                return Identifier.byId(id);
            }
        } else {
            return Identifier.byName(name);
        }
        return null;
    }

    OSClient getInternal() {
        return internalClient;
    }

{'fraction_non_alphanumeric': 0.09904952476238119, 'fraction_numerical': 0.00400200100050025, 'mean_word_length': 3.0747282608695654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '987352', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1565, 'n_words': 301}