<commit_before>package com.dianping.cat;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.unidal.dal.jdbc.DalException;
import org.unidal.helper.Files;
import org.unidal.helper.Threads;
import org.unidal.helper.Threads.Task;
import org.unidal.lookup.annotation.Inject;
import org.unidal.webres.json.JsonArray;
import org.unidal.webres.json.JsonObject;

import com.dianping.cat.core.dal.Hostinfo;
import com.dianping.cat.core.dal.HostinfoDao;
import com.dianping.cat.core.dal.HostinfoEntity;
import com.dianping.cat.core.dal.Project;
import com.dianping.cat.core.dal.ProjectDao;
import com.dianping.cat.core.dal.ProjectEntity;

public class DomainManager implements Initializable, LogEnabled {

	@Inject
	private HostinfoDao m_hostInfoDao;

	@Inject
	private ProjectDao m_projectDao;

	@Inject
	private ServerConfigManager m_manager;

	private Map<String, String> m_ipDomains = new ConcurrentHashMap<String, String>();

	private Map<String, String> m_unknownIps = new ConcurrentHashMap<String, String>();

	private Map<String, String> m_cmdbs = new ConcurrentHashMap<String, String>();

	private Set<String> m_domainsInCat = new HashSet<String>();

	private Map<String, Hostinfo> m_ipsInCat = new ConcurrentHashMap<String, Hostinfo>();

	private Logger m_logger;

	private static final String UNKNOWN_IP = "UnknownIp";

	private static final String UNKNOWN_PROJECT = "UnknownProject";

	private static final String CMDB_URL = "http://cmdb.dp/cmdb/device/s?q=%s&fl=app&tidy=true";
	
	private static final long DURATION = 60 * 60 * 1000L; 

	public boolean containsDomainInCat(String domain) {
		return m_domainsInCat.contains(domain);
	}

	@Override
	public void enableLogging(Logger logger) {
		m_logger = logger;
	}

	@Override
	public void initialize() throws InitializationException {
		//if (!m_manager.isLocalMode()) {
			try {
				m_ipDomains.put(UNKNOWN_IP, UNKNOWN_PROJECT);
				List<Hostinfo> infos = m_hostInfoDao.findAllIp(HostinfoEntity.READSET_FULL);

				for (Hostinfo info : infos) {
					m_ipDomains.put(info.getIp(), info.getDomain());
					m_ipsInCat.put(info.getIp(), info);
				}

				List<Project> projects = m_projectDao.findAll(ProjectEntity.READSET_FULL);
				for (Project project : projects) {
					m_domainsInCat.add(project.getDomain());
				}
			} catch (DalException e) {
				Cat.logError(e);
			}
			Threads.forGroup("Cat").start(new ReloadDomainTask());
			Threads.forGroup("Cat").start(new UploadHostinfoDBTask());
		//}
	}

	public boolean insert(String domain, String ip) {
		try {
			Hostinfo info = m_hostInfoDao.createLocal();

			info.setDomain(domain);
			info.setIp(ip);
			m_hostInfoDao.insert(info);
			m_domainsInCat.add(domain);
			m_ipsInCat.put(ip, info);
			return true;
		} catch (DalException e) {
			Cat.logError(e);
		}
		return false;
	}

	public boolean insertDomain(String domain) {
		Project project = m_projectDao.createLocal();

		project.setDomain(domain);
		project.setProjectLine("Default");
		project.setDepartment("Default");
		try {
			m_projectDao.insert(project);
			m_domainsInCat.add(domain);
<commit_msg>add judge whether is localModel for DomainManager<commit_after>package com.dianping.cat;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import org.unidal.dal.jdbc.DalException;
import org.unidal.helper.Files;
import org.unidal.helper.Threads;
import org.unidal.helper.Threads.Task;
import org.unidal.lookup.annotation.Inject;
import org.unidal.webres.json.JsonArray;
import org.unidal.webres.json.JsonObject;

import com.dianping.cat.core.dal.Hostinfo;
import com.dianping.cat.core.dal.HostinfoDao;
import com.dianping.cat.core.dal.HostinfoEntity;
import com.dianping.cat.core.dal.Project;
import com.dianping.cat.core.dal.ProjectDao;
import com.dianping.cat.core.dal.ProjectEntity;

public class DomainManager implements Initializable, LogEnabled {

	@Inject
	private HostinfoDao m_hostInfoDao;

	@Inject
	private ProjectDao m_projectDao;

	@Inject
	private ServerConfigManager m_manager;

	private Map<String, String> m_ipDomains = new ConcurrentHashMap<String, String>();

	private Map<String, String> m_unknownIps = new ConcurrentHashMap<String, String>();

	private Map<String, String> m_cmdbs = new ConcurrentHashMap<String, String>();

	private Set<String> m_domainsInCat = new HashSet<String>();

	private Map<String, Hostinfo> m_ipsInCat = new ConcurrentHashMap<String, Hostinfo>();

	private Logger m_logger;

	private static final String UNKNOWN_IP = "UnknownIp";

	private static final String UNKNOWN_PROJECT = "UnknownProject";

	private static final String CMDB_URL = "http://cmdb.dp/cmdb/device/s?q=%s&fl=app&tidy=true";
	
	private static final long DURATION = 60 * 60 * 1000L; 

	public boolean containsDomainInCat(String domain) {
		return m_domainsInCat.contains(domain);
	}

	@Override
	public void enableLogging(Logger logger) {
		m_logger = logger;
	}

	@Override
	public void initialize() throws InitializationException {
		if (!m_manager.isLocalMode()) {
			try {
				m_ipDomains.put(UNKNOWN_IP, UNKNOWN_PROJECT);
				List<Hostinfo> infos = m_hostInfoDao.findAllIp(HostinfoEntity.READSET_FULL);

				for (Hostinfo info : infos) {
					m_ipDomains.put(info.getIp(), info.getDomain());
					m_ipsInCat.put(info.getIp(), info);
				}

				List<Project> projects = m_projectDao.findAll(ProjectEntity.READSET_FULL);
				for (Project project : projects) {
					m_domainsInCat.add(project.getDomain());
				}
			} catch (DalException e) {
				Cat.logError(e);
			}
			Threads.forGroup("Cat").start(new ReloadDomainTask());
			Threads.forGroup("Cat").start(new UploadHostinfoDBTask());
		}
	}

	public boolean insert(String domain, String ip) {
		try {
			Hostinfo info = m_hostInfoDao.createLocal();

			info.setDomain(domain);
			info.setIp(ip);
			m_hostInfoDao.insert(info);
			m_domainsInCat.add(domain);
			m_ipsInCat.put(ip, info);
			return true;
		} catch (DalException e) {
			Cat.logError(e);
		}
		return false;
	}

	public boolean insertDomain(String domain) {
		Project project = m_projectDao.createLocal();

		project.setDomain(domain);
		project.setProjectLine("Default");
		project.setDepartment("Default");
		try {
			m_projectDao.insert(project);
			m_domainsInCat.add(domain);

{'fraction_non_alphanumeric': 0.11570945945945946, 'fraction_numerical': 0.0022522522522522522, 'mean_word_length': 5.119724375538329, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '2139811', 'n_tokens_mistral': 2566, 'n_tokens_neox': 2364, 'n_words': 450}