public static Query dummyQuery() { return Query.builder() .setObj("myQuery:key=val") .build(); }
MBeanAttributeInfo[] attrs = info.getAttributes(); Query.Builder queryBuilder = Query.builder() .setObj(name.getCanonicalName()); ResultCapture resultCapture = new ResultCapture(); query.runOutputWritersForQuery(server, results); } catch (AttributeNotFoundException anfe) { log.error("Error", anfe); output.put(result.getTypeName(), query.getAttr().toString());
public void runOutputWritersForQuery(Server server, Iterable<Result> results) throws Exception { for (OutputWriter writer : getOutputWriterInstances()) { writer.doWrite(server, this, results); } logger.debug("Finished running outputWriters for query: {}", this); }
private TypeNameValuesStringBuilder makeTypeNameValuesStringBuilder() { String separator = isAllowDottedKeys() ? "." : TypeNameValuesStringBuilder.DEFAULT_SEPARATOR; Set<String> typeNames = getTypeNames(); if (isUseAllTypeNames()) { return new UseAllTypeNameValuesStringBuilder(separator); } else if (typeNames != null && !typeNames.isEmpty()) { return new PrependingTypeNameValuesStringBuilder(separator, new ArrayList<>(typeNames)); } else { return new TypeNameValuesStringBuilder(separator); } }
public Iterable<Result> execute(Query query) throws Exception { JMXConnection jmxConnection = null; try { jmxConnection = pool.borrowObject(this); ImmutableList.Builder<Result> results = ImmutableList.builder(); MBeanServerConnection connection = jmxConnection.getMBeanServerConnection(); for (ObjectName queryName : query.queryNames(connection)) { results.addAll(query.fetchResults(connection, queryName)); } return results.build(); } catch (Exception e) { if (jmxConnection != null) { pool.invalidateObject(this, jmxConnection); jmxConnection = null; } throw e; } finally { if (jmxConnection != null) { pool.returnObject(this, jmxConnection); } } }
public void walkTree(MBeanServerConnection connection, Server server) throws Exception { // key here is null, null returns everything! Set<ObjectName> mbeans = connection.queryNames(null, null); for (ObjectName name : mbeans) { MBeanInfo info = connection.getMBeanInfo(name); MBeanAttributeInfo[] attrs = info.getAttributes(); Query.Builder queryBuilder = Query.builder() .setObj(name.getCanonicalName()) .addOutputWriterFactory(new StdOutWriter(ImmutableList.<String>of(), false, false, null, Collections.<String, Object>emptyMap())); for (MBeanAttributeInfo attrInfo : attrs) { queryBuilder.addAttr(attrInfo.getName()); } Query query = queryBuilder.build(); try { Iterable<Result> results = server.execute(query); query.runOutputWritersForQuery(server, results); } catch (AttributeNotFoundException anfe) { log.error("Error", anfe); } } } }
ObjectName oName = new ObjectName(query.getObj()); ObjectInstance oi = mbeanServer.getObjectInstance(queryName); List<String> queryAttributes = query.getAttr(); if ((queryAttributes == null) || (queryAttributes.size() == 0)) { MBeanAttributeInfo[] attrs = info.getAttributes(); for (MBeanAttributeInfo attrInfo : attrs) { query.addAttr(attrInfo.getName()); if ((query.getAttr() != null) && (query.getAttr().size() > 0)) { if (log.isDebugEnabled()) { log.debug("Executing queryName: " + queryName.getCanonicalName() + " from query: " + query); AttributeList al = mbeanServer.getAttributes(queryName, query.getAttr().toArray(new String[query.getAttr().size()])); for (Attribute attribute : al.asList()) { getResult(resList, info, oi, attribute, query); query.setResults(resList);
private void addQuery(@Nonnull Query query) { if (!queries.containsKey(query)) queries.put(query, new HashSet<OutputWriterFactory>()); Set<OutputWriterFactory> outputWritersForThisQuery = queries.get(query); for (OutputWriterFactory outputWriter : query.getOutputWriters()) { outputWritersForThisQuery.add(singleton(outputWriter)); } }
List<OutputWriter> writers = query.getOutputWriters(); if (writers == null) { writers = new ArrayList<OutputWriter>(); query.setOutputWriters(writers);
public void process() throws LifecycleException, ValidationException, SchedulerException, ParseException { for (Server server : this.masterServersList) { if (server.isLocal()) { server.setLocalMBeanServer(mbeanServer); server.setAlias(fabricService.getCurrentContainerName()); } // need to inject the poolMap for (Query query : server.getQueries()) { query.setServer(server); for (OutputWriter writer : query.getOutputWriters()) { writer.setObjectPoolMap(getObjectPoolMap()); writer.start(); } } // Now validate the setup of each of the OutputWriter's per query. validateSetup(server.getQueries()); // Now schedule the jobs for execution. scheduleJob(server); } }
/** * Given a typeName string, get the first match from the typeNames setting. * In other words, suppose you have: * * typeName=name=PS Eden Space,type=MemoryPool * * If you addTypeName("name"), then it'll retrieve 'PS Eden Space' from the * string */ public static String getConcatedTypeNameValues(Query query, List<String> typeNames, String typeName) { Set<String> queryTypeNames = query.getTypeNames(); if (queryTypeNames != null && queryTypeNames.size() > 0) { List<String> allNames = new ArrayList<String>(queryTypeNames); for (String name : typeNames) { if (!allNames.contains(name)) { allNames.add(name); } } return getConcatedTypeNameValues(allNames, typeName); } else { return getConcatedTypeNameValues(typeNames, typeName); } }
public Query build() { if (!outputWriterFactories.isEmpty()) { return new Query( this.obj, this.keys, this.attr, this.typeNames, this.resultAlias, this.useObjDomainAsKey, this.allowDottedKeys, this.useAllTypeNames, this.outputWriterFactories ); } return new Query( this.obj, this.keys, this.attr, this.typeNames, this.resultAlias, this.useObjDomainAsKey, this.allowDottedKeys, this.useAllTypeNames, copyOf(this.outputWriters) ); }
/** * Add results from a value of type composite data. * This is a recursive function. */ private void add(String attributeName, ImmutableList.Builder<String> valuePath, CompositeData cds) { CompositeType t = cds.getCompositeType(); Set<String> keys = t.keySet(); for (String key : keys) { if (!query.getKeys().isEmpty() && !query.getKeys().contains(key)) { continue; } Object value = cds.get(key); add(attributeName, newValuePath(valuePath, key), value); } }
private TypeNameValuesStringBuilder makeTypeNameValuesStringBuilder() { String separator = isAllowDottedKeys() ? "." : TypeNameValuesStringBuilder.DEFAULT_SEPARATOR; Set<String> typeNames = getTypeNames(); if (isUseAllTypeNames()) { return new UseAllTypeNameValuesStringBuilder(separator); } else if (typeNames != null && !typeNames.isEmpty()) { return new PrependingTypeNameValuesStringBuilder(separator, new ArrayList<>(typeNames)); } else { return new TypeNameValuesStringBuilder(separator); } }
private void addQuery(@Nonnull Query query) { if (!queries.containsKey(query)) queries.put(query, new HashSet<OutputWriterFactory>()); Set<OutputWriterFactory> outputWritersForThisQuery = queries.get(query); for (OutputWriterFactory outputWriter : query.getOutputWriters()) { outputWritersForThisQuery.add(singleton(outputWriter)); } }
public Iterable<Result> execute(Query query) throws Exception { JMXConnection jmxConnection = null; try { jmxConnection = pool.borrowObject(this); ImmutableList.Builder<Result> results = ImmutableList.builder(); MBeanServerConnection connection = jmxConnection.getMBeanServerConnection(); for (ObjectName queryName : query.queryNames(connection)) { results.addAll(query.fetchResults(connection, queryName)); } return results.build(); } catch (Exception e) { if (jmxConnection != null) { pool.invalidateObject(this, jmxConnection); jmxConnection = null; } throw e; } finally { if (jmxConnection != null) { pool.returnObject(this, jmxConnection); } } }
public Query build() { if (!outputWriterFactories.isEmpty()) { return new Query( this.obj, this.keys, this.attr, this.typeNames, this.resultAlias, this.useObjDomainAsKey, this.allowDottedKeys, this.useAllTypeNames, this.outputWriterFactories ); } return new Query( this.obj, this.keys, this.attr, this.typeNames, this.resultAlias, this.useObjDomainAsKey, this.allowDottedKeys, this.useAllTypeNames, copyOf(this.outputWriters) ); }
public static Query queryWithAllTypeNames() { return Query.builder() .setObj("myQuery:key=val") .setUseAllTypeNames(true) .build(); }
private void validateSetup(Server server, Query query) throws ValidationException { for (OutputWriter w : query.getOutputWriterInstances()) { injector.injectMembers(w); w.validateSetup(server, query); } }
/** */ private static void runOutputWritersForQuery(Query query) throws Exception { List<OutputWriter> writers = query.getOutputWriters(); if (writers != null) { for (OutputWriter writer : writers) { writer.doWrite(query); } } }