use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.
the class MBeanWrapper method getObjectName.
/**
* Gets the names of MBeans controlled by the MBean server
*
* @param name MBean name
* @return MBean object name
*/
ObjectName getObjectName(String name) {
Set<ObjectName> mBeanNames;
try {
mBeanNames = connection.queryNames(new ObjectName(name), null);
} catch (Exception e) {
final String errorMsg = "Error getting the names of MBeans on the monitored JVM application. Searched patter is " + name;
log.error(errorMsg, e);
throw new MonitorConfigurationException(errorMsg, e);
}
if (mBeanNames.size() != 1) {
final String errorMsg = "Error getting the names of MBeans on the monitored JVM application. Searched patter is " + name + ". We expected to find 1, but found " + mBeanNames + " MBean names.";
log.error(errorMsg);
throw new MonitorConfigurationException(errorMsg);
}
Iterator<ObjectName> it = mBeanNames.iterator();
return it.next();
}
use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.
the class MBeanWrapper method getMBeanAttribute.
/**
* Gets the value of a specific attribute of a named MBean
*
* @param objectName the object name
* @param attributeName the attribute name
* @return the attribute value
*/
Object getMBeanAttribute(ObjectName objectName, String attributeName) {
try {
for (MBeanAttributeInfo attInfo : connection.getMBeanInfo(objectName).getAttributes()) {
String attName = attInfo.getName();
if (attName.equals(attributeName)) {
return connection.getAttribute(objectName, attributeName);
}
}
} catch (Exception e) {
final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "'";
log.error(errorMsg, e);
throw new MonitorConfigurationException(errorMsg, e);
}
final String errorMsg = "Error getting the value of the '" + attributeName + "' attribute of MBean with name '" + objectName + "': The attribute is not found!";
log.error(errorMsg);
throw new MonitorConfigurationException(errorMsg);
}
use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.
the class ReadingsRepository method readFileFromJar.
private InputStream readFileFromJar(String jarFile) throws MonitorConfigurationException {
// extract the file path in the jar
String configurationFile = jarFile.substring(jarFile.lastIndexOf('!') + 2, jarFile.length());
log.info("Loading monitoring service configuration file '" + configurationFile + "' from " + jarFile);
try {
return IoUtils.readFileFromJar(jarFile, configurationFile);
} catch (IOException e) {
throw new MonitorConfigurationException("Error loading monitoring service configuration file '" + configurationFile + "' from " + jarFile);
}
}
use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.
the class ReadingsRepository method loadConfigurations.
/**
* Loads the user provided configuration files which ends up in updating the repository with supported readings.
* URLs could be direct files, in-JAR-files, tmp/work dir extracted files like in WildFly VFS
*
* @param configurationFileUrls - list of URLs of configuration files
* @throws MonitorConfigurationException
*/
public void loadConfigurations(List<URL> configurationFileUrls) throws MonitorConfigurationException {
try {
// empty the repository with readings definitions
cleanRepository();
// clear previously loaded monitors
this.alreadyLoadedMonitors.clear();
for (URL configurationFileUrl : configurationFileUrls) {
InputStream configurationFileStream = null;
try {
configurationFileStream = configurationFileUrl.openStream();
} catch (IOException e) {
throw new MonitorConfigurationException("Error reading performance configuration data from '" + configurationFileUrl + "'", e);
}
// fill the repository with readings definitions
readConfiguration(configurationFileUrl, configurationFileStream);
}
} catch (MonitorConfigurationException e) {
// on error empty the repository with readings definitions, so we know it is all clean
cleanRepository();
// on error clear previously loaded monitors
this.alreadyLoadedMonitors.clear();
throw e;
}
}
use of com.axway.ats.core.monitoring.MonitorConfigurationException in project ats-framework by Axway.
the class ReadingsRepository method readConfiguration.
void readConfiguration(URL configurationFileNameURL, InputStream configurationFileStream) throws MonitorConfigurationException {
this.readingParseState.rememberConfigurationFileName(configurationFileNameURL.toString());
Document xmlDocument;
try {
xmlDocument = XmlUtils.loadXMLFile(configurationFileStream);
} catch (IOException e) {
throw new MonitorConfigurationException("Error reading monitoring service configuration file from '" + configurationFileNameURL + "'", e);
} catch (SAXException e) {
throw new MonitorConfigurationException("Error parsing monitoring service configuration file from '" + configurationFileNameURL + "'", e);
}
Element rootElement = xmlDocument.getDocumentElement();
// iterate over all children, all of them being monitors
NodeList monitorLevelElements = rootElement.getChildNodes();
for (int i = 0; i < monitorLevelElements.getLength(); i++) {
Node monitorLevelElement = monitorLevelElements.item(i);
if (monitorLevelElement.getNodeType() == Node.ELEMENT_NODE && monitorLevelElement.getNodeName().equals(MONITOR_NODE)) {
extractMonitor((Element) monitorLevelElement);
}
}
this.readingParseState.forgetConfigurationFileName();
}
Aggregations