<commit_before>package org.trustsoft.slastic.plugins.slasticImpl.monitoring.kieker.reconstruction;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.trustsoft.slastic.plugins.slasticImpl.ModelManager;
import org.trustsoft.slastic.plugins.slasticImpl.monitoring.kieker.filters.AbstractTransformationComponent;

import de.cau.se.slastic.metamodel.componentAssembly.AssemblyComponent;
import de.cau.se.slastic.metamodel.executionEnvironment.ExecutionContainer;
import de.cau.se.slastic.metamodel.executionEnvironment.ExecutionEnvironmentFactory;
import de.cau.se.slastic.metamodel.executionEnvironment.MemSwapResourceSpecification;
import de.cau.se.slastic.metamodel.executionEnvironment.Resource;
import de.cau.se.slastic.metamodel.executionEnvironment.ResourceSpecification;
import de.cau.se.slastic.metamodel.typeRepository.ComponentType;
import de.cau.se.slastic.metamodel.typeRepository.ExecutionContainerType;
import de.cau.se.slastic.metamodel.typeRepository.ResourceType;
import de.cau.se.slastic.metamodel.typeRepository.resourceTypes.CPUType;
import de.cau.se.slastic.metamodel.typeRepository.resourceTypes.GenericResourceType;
import de.cau.se.slastic.metamodel.typeRepository.resourceTypes.MemSwapType;

/**
 * 
 * @author <NAME>
 * 
 */
public abstract class AbstractModelReconstructionComponent extends
		AbstractTransformationComponent {

	private static final Log log = LogFactory
			.getLog(AbstractModelReconstructionComponent.class);

	public AbstractModelReconstructionComponent(final ModelManager modelManager) {
		super(modelManager);
	}

	private final static String CPU_RESOURCE_NAME_PREFX = "cpu";
	private final static String MEM_SWAP_RESOURCE_NAME = "memSwap";

	public static String createGenericResourceSpecName(final String name) {
		return name;
	}

	public static String createCPUResourceSpecName(final String cpuId) {
		return AbstractModelReconstructionComponent.CPU_RESOURCE_NAME_PREFX
				+ cpuId;
	}

	public static String createMemSwapResourceSpecName() {
		return AbstractModelReconstructionComponent.MEM_SWAP_RESOURCE_NAME;
	}

	/**
	 * 
	 * @param hostName
	 * @return
	 */
	protected ExecutionContainer lookupOrCreateExecutionContainerByName(
			final String hostName) {
		ExecutionContainer executionContainer;
		{
			/*
			 * Lookup execution container
			 */
			executionContainer =
					this.getExecutionEnvModelManager()
							.lookupExecutionContainer(hostName);
			if (executionContainer == null) {
				/* We need to create the execution container */
				executionContainer = this.createExecutionContainer(hostName);
			}
		}<commit_msg>hack to pass technical hostname to rconstruction filters<commit_after>package org.trustsoft.slastic.plugins.slasticImpl.monitoring.kieker.reconstruction;

import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.trustsoft.slastic.plugins.slasticImpl.ModelManager;
import org.trustsoft.slastic.plugins.slasticImpl.monitoring.kieker.filters.AbstractTransformationComponent;

import de.cau.se.slastic.metamodel.componentAssembly.AssemblyComponent;
import de.cau.se.slastic.metamodel.executionEnvironment.ExecutionContainer;
import de.cau.se.slastic.metamodel.executionEnvironment.ExecutionEnvironmentFactory;
import de.cau.se.slastic.metamodel.executionEnvironment.MemSwapResourceSpecification;
import de.cau.se.slastic.metamodel.executionEnvironment.Resource;
import de.cau.se.slastic.metamodel.executionEnvironment.ResourceSpecification;
import de.cau.se.slastic.metamodel.typeRepository.ComponentType;
import de.cau.se.slastic.metamodel.typeRepository.ExecutionContainerType;
import de.cau.se.slastic.metamodel.typeRepository.ResourceType;
import de.cau.se.slastic.metamodel.typeRepository.resourceTypes.CPUType;
import de.cau.se.slastic.metamodel.typeRepository.resourceTypes.GenericResourceType;
import de.cau.se.slastic.metamodel.typeRepository.resourceTypes.MemSwapType;

/**
 * 
 * @author <NAME>
 * 
 */
public abstract class AbstractModelReconstructionComponent extends
		AbstractTransformationComponent {

	private static final Log log = LogFactory
			.getLog(AbstractModelReconstructionComponent.class);

	public AbstractModelReconstructionComponent(final ModelManager modelManager) {
		super(modelManager);
	}

	private final static String CPU_RESOURCE_NAME_PREFX = "cpu";
	private final static String MEM_SWAP_RESOURCE_NAME = "memSwap";

	public static String createGenericResourceSpecName(final String name) {
		return name;
	}

	public static String createCPUResourceSpecName(final String cpuId) {
		return AbstractModelReconstructionComponent.CPU_RESOURCE_NAME_PREFX
				+ cpuId;
	}

	public static String createMemSwapResourceSpecName() {
		return AbstractModelReconstructionComponent.MEM_SWAP_RESOURCE_NAME;
	}

	/**
	 * TODO: Really DIRTY HACK: This information should be stored somewhere
	 * central, e.g., in the model manager.
	 * 
	 * Maps a technical hostname to the corresponding archiectural container
	 * name;
	 */
	public static final ConcurrentHashMap<String, ExecutionContainer> containerNameMapping =
			new ConcurrentHashMap<String, ExecutionContainer>();

	boolean reportedMatch = false;

	/**
	 * 
	 * @param hostName
	 * @return
	 */
	protected ExecutionContainer lookupOrCreateExecutionContainerByName(
			final String hostName) {

		ExecutionContainer executionContainer;

		{ /* HACK! */
			executionContainer =
					AbstractModelReconstructionComponent.containerNameMapping
							.get(hostName);
			if (executionContainer != null) {
				if (!this.reportedMatch) {
					AbstractModelReconstructionComponent.log
							.info("Found match: " + hostName + "->"
									+ executionContainer);
					this.reportedMatch = true;
				}
				return executionContainer;
			}
		}

		{
			/*
			 * Lookup execution container
			 */
			executionContainer =
					this.getExecutionEnvModelManager()
							.lookupExecutionContainer(hostName);
			if (executionContainer == null) {
				/* We need to create the execution container */
				executionContainer = this.createExecutionContainer(hostName);
			}
			// TODO: remove
			AbstractModelReconstructionComponent.containerNameMapping.put(
					hostName, executionContainer);
		}
{'fraction_non_alphanumeric': 0.08345300781873305, 'fraction_numerical': 0.0, 'mean_word_length': 5.481902792140641, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '1096101', 'n_tokens_mistral': 1979, 'n_tokens_neox': 1740, 'n_words': 306}