/**
* Analytica - beta version - Systems Monitoring Tool
*
* Copyright (C) 2013, KleeGroup, direction.technique@kleegroup.com (http://www.kleegroup.com)
* KleeGroup, Centre d'affaire la Boursidi�re - BP 159 - 92357 Le Plessis Robinson Cedex - France
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Foundation;
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program;
* if not, see <http://www.gnu.org/licenses>
*
* Linking this library statically or dynamically with other modules is making a combined work based on this library.
* Thus, the terms and conditions of the GNU General Public License cover the whole combination.
*
* As a special exception, the copyright holders of this library give you permission to link this library
* with independent modules to produce an executable, regardless of the license terms of these independent modules,
* and to copy and distribute the resulting executable under terms of your choice, provided that you also meet,
* for each linked independent module, the terms and conditions of the license of that module.
* An independent module is a module which is not derived from or based on this library.
* If you modify this library, you may extend this exception to your version of the library,
* but you are not obliged to do so.
* If you do not wish to do so, delete this exception statement from your version.
*/
package io.analytica.spies.imp.javassist;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
/**
* Configuration du JavassistSpy, qui d�finie les points d'encrage et les sp�cificit�s du branchement de l'agent.
* @author npiedeloup
* @version $Id: MemoryLeakTransformer.java,v 1.1 2011/05/12 10:16:05 prahmoune Exp $
*/
public final class AnalyticaSpyConf {
private final String collectorName;
private final Map<String, String> collectorParams;
private final String systemName;
private final String[] systemLocation;
private final List<String> fastExcludedPackages;
private final List<String> fastIncludedPackages;
private final List<AnalyticaSpyHookPoint> hookPoints;
private final Map<String, String> localVariables;
private final List<String> methodBefore;
private final List<String> methodAfter;
private final Map<String, List<String>> methodCatchs;
private final List<String> methodFinally;
/**
* Constructeur.
* @param collectorName Nom du plugin a utiliser
* @param collectorParams Param�tres du plugin
* @param systemName Nom du syst�me
* @param systemLocation Emplacement du syst�me support $hostName
* @param excludedPackages Liste de package � exclure
* @param includedPackages Liste de package � inclure
* @param hookPoints Liste de point d'accroche de l'agent
* @param localVariables Liste de variables locales (Nom => Class)
* @param methodBefore Code ins�r� en before
* @param methodAfter Code ins�r� en after
* @param methodCatchs Liste des catchs (ExceptionClass => code)
* @param methodFinally Code ins�r� en finally
*/
public AnalyticaSpyConf(final String collectorName, final Map<String, String> collectorParams, final String systemName, final String[] systemLocation, final List<String> excludedPackages, final List<String> includedPackages, final List<AnalyticaSpyHookPoint> hookPoints, final Map<String, String> localVariables, final List<String> methodBefore, final List<String> methodAfter, final Map<String, List<String>> methodCatchs, final List<String> methodFinally) {
this.collectorName = collectorName;
this.collectorParams = collectorParams;
this.systemName = systemName;
this.systemLocation = systemLocation;
fastExcludedPackages = excludedPackages;
fastIncludedPackages = includedPackages;
this.hookPoints = hookPoints;
this.localVariables = localVariables;
this.methodBefore = methodBefore;
this.methodAfter = methodAfter;
this.methodCatchs = methodCatchs;
this.methodFinally = methodFinally;
}
/**
* Check config file syntax.
* @throws IllegalArgumentException error if config file is incorrect
*/
public void checkConfig() throws IllegalArgumentException {
if ("FileLog".equals(collectorName)) {
checkMandatoryConnectorParams("FileLog", "fileName");
} else if ("RemoteHTTP".equals(collectorName)) {
checkMandatoryConnectorParams("RemoteHTTP", "serverUrl");
checkMandatoryIntConnectorParams("RemoteHTTP", "sendPaquetSize", "sendPaquetFrequencySeconds");
} else {
throw new IllegalArgumentException("Unknown Connector : " + collectorName + " fallback to DummyCollector (use one of : FileLog, RemoteHTTP, Dummy)");
}
//checkMandatoryParams(systemName, systemLocation, fastExcludedPackages, fastIncludedPackages, )
}
// private void checkMandatoryParams(final String... paramNames) {
// for (final String paramName : paramNames) {
// if (collectorParams.get(paramName) == null) {
// throw new IllegalArgumentException(paramName + " params is mandatory");
// }
// }
// }
private void checkMandatoryConnectorParams(final String connector, final String... paramNames) {
for (final String paramName : paramNames) {
if (collectorParams.get(paramName) == null) {
throw new IllegalArgumentException(paramName + " params is mandatory for " + connector + " Connector");
}
}
}
private void checkMandatoryIntConnectorParams(final String connector, final String... paramNames) {
for (final String paramName : paramNames) {
final String value = collectorParams.get(paramName);
if (value == null) {
throw new IllegalArgumentException(paramName + " params is mandatory for " + connector + " Connector");
}
try {
Integer.parseInt(value);
} catch (final NumberFormatException e) {
throw new IllegalArgumentException(paramName + " params must be a integer for " + connector + " Connector", e);
}
}
}
/**
* @return Nom du collector
*/
public String getCollectorName() {
return collectorName;
}
/**
* @return Parametre du collector
*/
public Map<String, String> getCollectorParams() {
return collectorParams;
}
/**
* @return System Name
*/
public String getSystemName() {
return systemName;
}
/**
* @return System Location
*/
public String[] getSystemLocation() {
return systemLocation;
}
/**
* @return Code ins�r� en before
*/
public List<String> getMethodBefore() {
return methodBefore;
}
/**
* @return Code ins�r� en after
*/
public List<String> getMethodAfter() {
return methodAfter;
}
/**
* @return Liste des catchs (ExceptionClass => code)
*/
public Map<String, List<String>> getMethodCatchs() {
return methodCatchs;
}
/**
* Attention : ne voit pas les variables locales.
* @return Code ins�r� en finally
*/
public List<String> getMethodFinally() {
return methodFinally;
}
/**
* @return Liste de variables locales (Nom => Class)
*/
public Map<String, String> getLocalVariables() {
return localVariables;
}
/**
* @return Pattern de package exclus, si vide pas d'exclusion
*/
public List<String> getFastExcludedPackages() {
return fastExcludedPackages;
}
/**
* @return Pattern de package inclus, tout est inclus
*/
public List<String> getFastIncludedPackages() {
return fastIncludedPackages;
}
/**
* @return Patterns de lecture du log
*/
public List<AnalyticaSpyHookPoint> getHookPoints() {
return hookPoints;
}
/**
* @return Conf au format Json.
*/
public String toJson() {
return new Gson().toJson(this);
}
}