<commit_before>/**
 * Copyright ${year} imperial
 * Contact: imperial <<EMAIL>>
 *
 *    Licensed under the BSD 3-Clause License (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://opensource.org/licenses/BSD-3-Clause
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package imperial.modaclouds.monitoring.datacollectors.monitors;


import imperial.modaclouds.monitoring.datacollectors.basic.AbstractMonitor;
import imperial.modaclouds.monitoring.datacollectors.basic.DataCollectorAgent;
import imperial.modaclouds.monitoring.datacollectors.demo.ofbiz.OFBizLogFileMonitor;

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

import javax.xml.parsers.ParserConfigurationException;

import org.restlet.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

/**
 * Main class.
 */
public class ModacloudsMonitor extends Application
{	
	private static final Logger logger = LoggerFactory.getLogger(ModacloudsMonitor.class);
	
	/**
	 * Index of the monitors.
	 */
	private static Map<String,Integer> dcIndex;

	/**
	 * The list of the monitors.
	 */
	private static List<AbstractMonitor> monitors;

	/**
	 * The name of the running monitors.
	 */
	private static List<String> runningMonitors;

	/**
	 * The static class of ModacloudsMonitor.
	 */
	private static ModacloudsMonitor modacloudsMonitor;

	/**
	 * DDa connector.
	 */
//	private static DDAConnector ddaConnector;

	/**
	 * URI of the DC.
	 */
//	private static String ownURI;	

	/**
	 * mode of the DC.
	 */
	private static String mode;

	/**
	 * Knowledge base connector.
	 */
//	private static KBConnector kbConnector;

	/**
	 * The mapp
	 */
	private static Map<String,String> metricCollectorMapping;

	/**
	 * Object store connector.
	 */
//	private static ObjectStoreConnector objectStoreConnector;

	/**
	 * Initial setup of the monitor.
	 */
	public static void initSetup() throws ParserConfigurationException, SAXException, IOException
	{		
		dcIndex = new HashMap<String,Integer>();
		dcIndex.put("jmx", 1);
		dcIndex.put("collectl", 2);
		dcIndex.put("sigar", 3);
		dcIndex.put("ofbiz", 4);
		dcIndex.put("logFile", 5);
		dcIndex.put("mysql", 6);
		dcIndex.put("cloudwatch", 7);
		dcIndex.put("flexiant", 8);
		dcIndex.put("ec2-spotPrice", 9);
		dcIndex.put("startupTime", 10);
		dcIndex.put("cost", 11);
		dcIndex.put("vmavailability", 12);
		dcIndex.put("detailedCost", 13);
		dcIndex.put("haproxy", 14);
		dcIndex.put("appavailability", 12);

		monitors = new ArrayList<AbstractMonitor>();
		runningMonitors = new ArrayList<String>();
	}


	/**
	 * run monitoring given the collector index.
	 * 
	 * @param index: monitoring collector index
	 * 
	 */
	public static void runMonitoring (String[] index) {

		int[] intArray = new int[index.length];
		for(int i = 0; i < index.length; i++) {
			if (dcIndex.get(index[i]) == null) {
				logger.warn("Cannot recognise collector: {}", index[i]);
			}
			else {
				intArray[i] = dcIndex.get(index[i]);
			}
		}

		for(int i = 0; i < index.length; i++) {
			if (runningMonitors.contains(index[i])) {
				logger.warn("Collector {} has already started!", index[i]);
				continue;
			}

			runningMonitors.add(index[i]);<commit_msg>bug fix<commit_after>/**
 * Copyright ${year} imperial
 * Contact: imperial <<EMAIL>>
 *
 *    Licensed under the BSD 3-Clause License (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://opensource.org/licenses/BSD-3-Clause
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package imperial.modaclouds.monitoring.datacollectors.monitors;


import imperial.modaclouds.monitoring.datacollectors.basic.AbstractMonitor;
import imperial.modaclouds.monitoring.datacollectors.basic.DataCollectorAgent;
import imperial.modaclouds.monitoring.datacollectors.demo.ofbiz.OFBizLogFileMonitor;

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

import javax.xml.parsers.ParserConfigurationException;

import org.restlet.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

/**
 * Main class.
 */
public class ModacloudsMonitor extends Application
{	
	private static final Logger logger = LoggerFactory.getLogger(ModacloudsMonitor.class);
	
	/**
	 * Index of the monitors.
	 */
	private static Map<String,Integer> dcIndex;

	/**
	 * The list of the monitors.
	 */
	private static List<AbstractMonitor> monitors;

	/**
	 * The name of the running monitors.
	 */
	private static List<String> runningMonitors;

	/**
	 * The static class of ModacloudsMonitor.
	 */
	private static ModacloudsMonitor modacloudsMonitor;

	/**
	 * DDa connector.
	 */
//	private static DDAConnector ddaConnector;

	/**
	 * URI of the DC.
	 */
//	private static String ownURI;	

	/**
	 * mode of the DC.
	 */
	private static String mode;

	/**
	 * Knowledge base connector.
	 */
//	private static KBConnector kbConnector;

	/**
	 * The mapp
	 */
	private static Map<String,String> metricCollectorMapping;

	/**
	 * Object store connector.
	 */
//	private static ObjectStoreConnector objectStoreConnector;

	/**
	 * Initial setup of the monitor.
	 */
	public static void initSetup() throws ParserConfigurationException, SAXException, IOException
	{		
		dcIndex = new HashMap<String,Integer>();
		dcIndex.put("jmx", 1);
		dcIndex.put("collectl", 2);
		dcIndex.put("sigar", 3);
		dcIndex.put("ofbiz", 4);
		dcIndex.put("logFile", 5);
		dcIndex.put("mysql", 6);
		dcIndex.put("cloudwatch", 7);
		dcIndex.put("flexiant", 8);
		dcIndex.put("ec2-spotPrice", 9);
		dcIndex.put("startupTime", 10);
		dcIndex.put("cost", 11);
		dcIndex.put("vmavailability", 12);
		dcIndex.put("detailedCost", 13);
		dcIndex.put("haproxy", 14);
		dcIndex.put("appavailability", 15);

		monitors = new ArrayList<AbstractMonitor>();
		runningMonitors = new ArrayList<String>();
	}


	/**
	 * run monitoring given the collector index.
	 * 
	 * @param index: monitoring collector index
	 * 
	 */
	public static void runMonitoring (String[] index) {

		int[] intArray = new int[index.length];
		for(int i = 0; i < index.length; i++) {
			if (dcIndex.get(index[i]) == null) {
				logger.warn("Cannot recognise collector: {}", index[i]);
			}
			else {
				intArray[i] = dcIndex.get(index[i]);
			}
		}

		for(int i = 0; i < index.length; i++) {
			if (runningMonitors.contains(index[i])) {
				logger.warn("Collector {} has already started!", index[i]);
				continue;
			}

			runningMonitors.add(index[i]);
{'fraction_non_alphanumeric': 0.12674132750614586, 'fraction_numerical': 0.0076481835564053535, 'mean_word_length': 3.8304749340369395, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4906828', 'n_tokens_mistral': 2506, 'n_tokens_neox': 2233, 'n_words': 614}