private boolean logPropertyDifferences( String message, SortedMap<String, Class> prevMap, SortedMap<String, Class> newMap) { boolean foundDifference = false; for (String prevKey : prevMap.keySet()) { if (nonVersionSpecificAttributes.contains(prevKey)) continue; Class prevClass = prevMap.get(prevKey); Class newClass = newMap.get(prevKey); if (prevClass != null && prevClass != newClass) { if (newClass == null) { if (!foundDifference) { log.info(message); foundDifference = true; } log.info( "\tnew event missing field in prev event: %s = %s", prevKey, prevClass.getSimpleName()); } else { if (!foundDifference) { log.info(message); foundDifference = true; } // should fail in subsequent esper update anyway log.warn( "\tnew event has new type for %s, prev: %s, new: %s", prevKey, prevClass.getSimpleName(), newClass.getSimpleName()); } } } for (String newKey : newMap.keySet()) { if (nonVersionSpecificAttributes.contains(newKey)) continue; Class newClass = newMap.get(newKey); Class prevClass = prevMap.get(newKey); if (newClass != null && prevClass != newClass) { if (prevClass == null) { if (!foundDifference) { log.info(message); foundDifference = true; } log.info("\tnew event has new field: %s = %s", newKey, newClass.getSimpleName()); } } } return foundDifference; }
public List<Config> getCurrentConfigList() throws ConfigException { ConfigReader configReader = null; switch (agentConfig.getConfigInitTypeParam()) { case CONFIG_BY_EXPLICIT_PARAMS: configReader = getConfigViaExplicitParams(); break; case CONFIG_BY_CORE_TYPE_VIA_GALAXY_OUTPUT: configReader = getConfigViaGalaxyAndCoreTypeConfig(); break; case CONFIG_BY_DISCOVERY_VIA_GALAXY_OUTPUT: configReader = getConfigViaGalaxyAndDiscovery(); break; } List<Config> configList = null; if (configReader != null) { configList = configReader.getConfigurations(); } if (configList != null && configList.size() > 0) { return configList; } else { log.info("No monitoring configurations initialized"); return null; } }
private void updateEventStream(EventDefinition def) { log.info("removing registration for event type %s", def.getEventType()); notifyEventUnRegistered(def); log.info("updating event type stream %s", def.getEventType()); for (String ns : namespaces) { EPAdministrator admin = EsperProvider.getProvider(ns).getEPAdministrator(); HashMap<String, Object> m = new HashMap<String, Object>(); for (Map.Entry<String, Class> entry : def.getProperties().entrySet()) { m.put(entry.getKey(), entry.getValue()); } admin.getConfiguration().updateMapEventType(def.getEventType(), m); inputEventRegistrationsValid.add(def.getEventType()); } notifyEventRegistered(def); }
private ConfigReader getConfigViaExplicitParams() throws ConfigException { // This mode is primarily for testing // // Get config params from lists of local monitoring config filenames, host names, and config // paths... // if the number of entries in one of the lists is less than the others, the last entry in the // shorter list will // be replicated for each remaining config set. // Thus if there is only one config file name, but 10 hostnames, then the same config file will // be applied to all 10 hosts, etc. // (Note it's a bit inefficient therefore, as it will repeatedly open and close the same input // file)... // if (agentConfig.getExplicitConfigFiles().isEmpty() || agentConfig.getExplicitTypes().isEmpty() || agentConfig.getExplicitPaths().isEmpty()) { log.debug( "Could not configure via explicit params, must have non-null params for hostList, typeList and pathList"); return null; } Iterator<String> configFileIter = agentConfig.getExplicitConfigFiles().iterator(); Iterator<String> hostIter = agentConfig.getExplicitHosts().iterator(); Iterator<String> pathIter = agentConfig.getExplicitPaths().iterator(); Iterator<String> typeIter = agentConfig.getExplicitTypes().iterator(); String configFile = null; String host = null; String path = null; String type = null; CompoundConfigReader configReader = new CompoundConfigReader(); while (hostIter.hasNext() || typeIter.hasNext() || pathIter.hasNext()) { if (configFileIter.hasNext()) { configFile = configFileIter.next(); } if (hostIter.hasNext()) { host = hostIter.next(); } if (pathIter.hasNext()) { path = pathIter.next(); } if (typeIter.hasNext()) { type = typeIter.next(); } try { if (configFile != null) { log.info( "Adding initial configuration with config file '" + configFile + "', host '" + host + "', path '" + path + "', type '" + type); Reader configFileReader = new FileReader(configFile); configReader.addConfigReader( new ConfigStreamReader( configFileReader, host, path, type, guiceDefaultsForDataSources)); } else { log.info( "Adding initial configuration with host '" + host + "', path '" + path + "', type '" + type); List<InputStream> configResourceStreams = configFileUtils.getMonitoringTypeConfigStreamList(type, path, false); for (InputStream configResourceStream : configResourceStreams) { InputStreamReader configStreamReader = new InputStreamReader(configResourceStream); configReader.addConfigReader( new ConfigStreamReader( configStreamReader, host, path, type, guiceDefaultsForDataSources)); } } if (guiceDefaultsForDataSources.isJMXMonitoringProfilePollingEnabled()) { configReader.addConfigReader( new JMXMonitoringProfilePoller(host, path, type, guiceDefaultsForDataSources)); } } catch (FileNotFoundException fnfEx) { log.warn("Could not open file %s: %s", configFile, fnfEx); throw new ConfigException("Could not open file " + configFile, fnfEx); } } return configReader; }
// use this method if you only have the input event private String registerEventOrDefinition( Event event, Map<String, Object> attributes, EventDefinition inputDef) { boolean gotInputDef = (inputDef != null); String escapedEventType; SortedMap<String, Class> map; if (gotInputDef) { map = inputDef.getProperties(); escapedEventType = EsperNamingUtils.checkWordIsLegalEsperName(inputDef.getEventType()); } else if (event == null || attributes == null) { log.warn("Got null input event or attributes in registerEventOrDefinition"); return null; } else { // create map from attributes, throw out nulls map = new TreeMap<String, Class>(); for (String name : attributes.keySet()) { Object attr = attributes.get(name); if (attr == null) continue; Class propertyClass = attr.getClass(); map.put(name, propertyClass); } escapedEventType = EsperNamingUtils.checkWordIsLegalEsperName(event.getEventType()); } // prepare event signature String eventSignature = getInputEventSignature(map); // see if we've seen this event before at all if (!inputEvents.containsKey(escapedEventType)) { log.info("registering new event definition: %s", escapedEventType); addInputEventSignature(escapedEventType, eventSignature); // first see if we have a pre-existing outputEvent, and if so, we need to merge properties // in case our new upper level event is narrower than previously registered base event // TODO: this is just a guard for the case where we have prevOutputDef one level down // TODO: (it won't help in case for multi-level distance, need to replace this with plugin // specific handling, // TODO: to possibly find an ancestor prev def to use) EventDefinition prevOutputDef = this.getOutputEventDefinition(escapedEventType); EventDefinition newDef = null; if (prevOutputDef != null) { String msg = String.format( "detected differences with previously registered outputEvent: %s", escapedEventType); if (logPropertyDifferences(msg, prevOutputDef.getProperties(), map)) { if (gotInputDef) { // make a copy of def props map = new TreeMap<String, Class>(); map.putAll(inputDef.getProperties()); updateMapWithPrevOutputProperties(map, prevOutputDef.getProperties()); newDef = new EventDefinition( inputDef.getSourceEventClass(), escapedEventType, inputDef.getEvtClass(), map); } else { updateMapWithPrevOutputProperties(map, prevOutputDef.getProperties()); newDef = new EventDefinition(event, escapedEventType, event.getClass(), map); } String updatedEventSignature = getInputEventSignature(map); addInputEventSignature(escapedEventType, updatedEventSignature); } } if (newDef == null) { if (!gotInputDef) newDef = new EventDefinition(event, escapedEventType, event.getClass(), map); else newDef = inputDef; } inputEvents.put(escapedEventType, newDef); registerEventStream(newDef); } else if (eventSignature != null && !checkInputEventSignatureRegistered(escapedEventType, eventSignature)) { log.info("got new signature for event type: %s", escapedEventType); // see if we have a new variant signature for a previously registered event if (gotInputDef) { // make a copy of def props map = new TreeMap<String, Class>(); map.putAll(inputDef.getProperties()); } String combinedEventSignature = null; EventDefinition prevDef = inputEvents.get(escapedEventType); String msg = String.format("detected updated event definition: %s", escapedEventType); if (logPropertyDifferences(msg, prevDef.getProperties(), map)) { map.putAll(prevDef.getProperties()); combinedEventSignature = getInputEventSignature(map); } else { combinedEventSignature = eventSignature; } if (!checkInputEventSignatureRegistered(escapedEventType, combinedEventSignature)) { log.info("updating event definition registration: %s", escapedEventType); addInputEventSignature(escapedEventType, combinedEventSignature); EventDefinition combinedDef; if (gotInputDef) { combinedDef = new EventDefinition( inputDef.getSourceEventClass(), escapedEventType, inputDef.getEvtClass(), map); } else { combinedDef = new EventDefinition(event, escapedEventType, event.getClass(), map); } inputEvents.put(escapedEventType, combinedDef); updateEventStream(combinedDef); } addInputEventSignature(escapedEventType, eventSignature); } else if (!inputEventRegistrationsValid.contains(escapedEventType)) { // this is a previously registered stream, but no currently valid EPL statements log.info("revalidating event type: %s", escapedEventType); inputEventRegistrationsValid.add(escapedEventType); notifyEventRegistered(inputEvents.get(escapedEventType)); } return escapedEventType; }