/** * Given a class, this method returns a map of names of all the instance (non static) fields -> type. * if the class has any super class it also includes those fields. * @param clazz , not null * @return */ public static Map<String, Class> getFieldNamesToTypes(Class clazz) { Field[] declaredFields = clazz.getDeclaredFields(); Map<String, Class> instanceVariableNamesToTypes = new HashMap<>(); for(Field field : declaredFields) { if(!Modifier.isStatic(field.getModifiers())) { LOG.trace("clazz {} has field {} with type {}", clazz.getName(), field.getName(), field.getType().getName()); instanceVariableNamesToTypes.put(field.getName(), field.getType()); } else { LOG.trace("clazz {} has field {} with type {}, which is static so ignoring", clazz.getName(), field.getName(), field.getType().getName()); } } if(!clazz.getSuperclass().equals(Object.class)) { instanceVariableNamesToTypes.putAll(getFieldNamesToTypes(clazz.getSuperclass())); } return instanceVariableNamesToTypes; }
private <T extends Comparable<T>> int compare(Storable s1, Storable s2, String fieldName, Boolean desc) { try { Comparable<T> field1 = ReflectionHelper.<T>invokeGetter(fieldName, s1); T field2 = ReflectionHelper.invokeGetter(fieldName, s2); int res; if (field1 instanceof String && field2 instanceof String) { res = ((String) field1).compareToIgnoreCase((String) field2); } else { res = field1.compareTo(field2); } return (desc != null && desc) ? -res : res; } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException ex) { LOG.error("Got exception trying to get value for " + fieldName, ex); throw new RuntimeException(ex); } }
public void validate () throws Exception { String[] componentKeys = { TopologyLayoutConstants.JSON_KEY_DATA_SOURCES, TopologyLayoutConstants.JSON_KEY_DATA_SINKS, TopologyLayoutConstants.JSON_KEY_PROCESSORS, TopologyLayoutConstants.JSON_KEY_LINKS }; for (String componentKey: componentKeys) { List<Map> components = (List<Map>) this.topologyConfig.get(componentKey); for (Map component: components) { String transformationClass = (String) component.get(TopologyLayoutConstants.JSON_KEY_TRANSFORMATION_CLASS); Map<String, Object> config = (Map<String, Object>) component.get(TopologyLayoutConstants.JSON_KEY_CONFIG); FluxComponent fluxComponent = ReflectionHelper.newInstance(transformationClass); fluxComponent.withConfig(config); fluxComponent.withCatalogRootUrl(catalogRootUrl); fluxComponent.validateConfig(); } } validateParserProcessorLinks(); // Uncomment this with https://hwxiot.atlassian.net/browse/IOT-126 //validateRuleProcessorLinks(); validateCustomProcessorLinks(); }
private String addUnderlyingBoltComponent() { StreamlineProcessor underlyingProcessor = testRunProcessor.getUnderlyingProcessor(); String transformationClass = underlyingProcessor.getTransformationClass(); Map<String, Object> underlyingComponent; try { AbstractFluxComponent transformation = ReflectionHelper.newInstance(transformationClass); Map<String, Object> props = new LinkedHashMap<>(); props.putAll(underlyingProcessor.getConfig().getProperties()); props.put(StormTopologyLayoutConstants.STREAMLINE_COMPONENT_CONF_KEY, testRunProcessor.getUnderlyingProcessor()); // should get rid of below things which is only supported to spout and bolt in flux props.remove("parallelism"); transformation.withConfig(props); underlyingComponent = transformation.getComponent(); for (Map<String, Object> dependentComponents : transformation.getReferencedComponents()) { addToComponents(dependentComponents); } addToComponents(underlyingComponent); return (String) underlyingComponent.get(StormTopologyLayoutConstants.YAML_KEY_ID); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { log.error("Error creating underlying transformation instance", e); throw new RuntimeException(e); } } }
private String addUnderlyingBoltComponent() { StreamlineProcessor underlyingProcessor = testRunRulesProcessor.getUnderlyingProcessor(); String transformationClass = underlyingProcessor.getTransformationClass(); Map<String, Object> underlyingComponent; try { AbstractFluxComponent transformation = ReflectionHelper.newInstance(transformationClass); Map<String, Object> props = new LinkedHashMap<>(); props.putAll(underlyingProcessor.getConfig().getProperties()); props.put(StormTopologyLayoutConstants.STREAMLINE_COMPONENT_CONF_KEY, testRunRulesProcessor.getUnderlyingProcessor()); // should get rid of below things which is only supported to spout and bolt in flux props.remove("parallelism"); transformation.withConfig(props); underlyingComponent = transformation.getComponent(); for (Map<String, Object> dependentComponents : transformation.getReferencedComponents()) { addToComponents(dependentComponents); } addToComponents(underlyingComponent); return (String) underlyingComponent.get(StormTopologyLayoutConstants.YAML_KEY_ID); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { log.error("Error creating underlying transformation instance", e); throw new RuntimeException(e); } } }
private FileStorage getJarStorage (StreamlineConfiguration configuration, StorageManager storageManager) { FileStorage fileStorage = null; try { fileStorage = ReflectionHelper.newInstance(configuration.getFileStorageConfiguration().getClassName()); fileStorage.init(configuration.getFileStorageConfiguration().getProperties()); if (fileStorage instanceof StorageManagerAware) { ((StorageManagerAware) fileStorage).setStorageManager(storageManager); } } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { throw new RuntimeException(e); } return fileStorage; }