private static String createTableValue(IndexerConf conf) { if (conf.tableNameIsRegex()) { return String.format("regex:%s", conf.getTable()); } else { return conf.getTable(); } }
public IndexerConf build() { checkNotNull(table, "table name"); IndexerConf conf = new IndexerConf(table); conf.setMappingType(mappingType != null ? mappingType : IndexerConf.DEFAULT_MAPPING_TYPE); conf.setRowReadMode(rowReadMode != null ? rowReadMode : IndexerConf.DEFAULT_ROW_READ_MODE); conf.setUniqueKeyField(uniqueKeyField != null ? uniqueKeyField : IndexerConf.DEFAULT_UNIQUE_KEY_FIELD); conf.setRowField(rowField); conf.setColumnFamilyField(columnFamilyField); conf.setTableNameField(tableNameField); conf.setMapperClass(mapperClass); conf.setUniqueKeyFormatterClass(uniqueKeyFormatterClass != null ? uniqueKeyFormatterClass : IndexerConf.DEFAULT_UNIQUE_KEY_FORMATTER); conf.setFieldDefinitions(fieldDefinitions); conf.setDocumentExtractDefinitions(documentExtractDefinitions); conf.setGlobalParams(globalParams); return conf; } }
private String fetchIndexerTableName(String indexerName) throws Exception{ // best effort since this could be a pattern ... IndexerDefinition indexerDefinition = get(indexerName); IndexerComponentFactory factory = IndexerComponentFactoryUtil.getComponentFactory(indexerDefinition.getIndexerComponentFactory(), new ByteArrayInputStream(indexerDefinition.getConfiguration()), indexerDefinition.getConnectionParams()); String tableName = factory.createIndexerConf().getTable(); // TODO we should fail if the table does not exist return tableName; }
public static IndexerComponentFactory getComponentFactory(String factoryClass, InputStream configuration, Map<String, String> connectionParams) { IndexerComponentFactory factory; if (factoryClass == null) { factory = new DefaultIndexerComponentFactory(); } else { try { factory = (IndexerComponentFactory)Class.forName(factoryClass).newInstance(); } catch (InstantiationException e) { throw new AssertionError(e); } catch (IllegalAccessException e) { throw new AssertionError(e); } catch (ClassNotFoundException e) { throw new AssertionError(e); } } factory.configure(configuration, connectionParams); return factory; }
private Map<String, String> buildParams(Element parentElement) { Map<String, String> params = Maps.newHashMap(); for (Element paramElement : evalXPathAsElementList("param", parentElement)) { String key = getAttribute(paramElement, "name", true); String value = getAttribute(paramElement, "value", true); params.put(key, value); } return params; }
public static String getAttribute(Element element, String name, boolean required) { if (!element.hasAttribute(name)) { if (required) throw new IndexerConfException("Missing attribute " + name + " on element " + element.getLocalName()); else return null; } return element.getAttribute(name); }
public IndexerConfBuilder addFieldDefinition(String name, String valueExpression, ValueSource valueSource, String typeName, Map<String, String> params) { fieldDefinitions.add(new FieldDefinition(name, valueExpression, valueSource == null ? IndexerConf.DEFAULT_VALUE_SOURCE : valueSource, typeName == null ? IndexerConf.DEFAULT_FIELD_TYPE : typeName, params)); return this; }
public IndexerConfBuilder addDocumentExtractDefinition(String prefix, String valueExpression, ValueSource valueSource, String type, Map<String, String> params) { documentExtractDefinitions.add(new DocumentExtractDefinition(prefix, valueExpression, valueSource == null ? IndexerConf.DEFAULT_VALUE_SOURCE : valueSource, type == null ? IndexerConf.DEFAULT_EXTRACT_TYPE : type, params)); return this; }
private String fetchIndexerTableName(String indexerName) throws Exception{ // best effort since this could be a pattern ... IndexerDefinition indexerDefinition = get(indexerName); IndexerComponentFactory factory = IndexerComponentFactoryUtil.getComponentFactory(indexerDefinition.getIndexerComponentFactory(), new ByteArrayInputStream(indexerDefinition.getConfiguration()), indexerDefinition.getConnectionParams()); String tableName = factory.createIndexerConf().getTable(); // TODO we should fail if the table does not exist return tableName; }
private static String createTableValue(IndexerConf conf) { if (conf.tableNameIsRegex()) { return String.format("regex:%s", conf.getTable()); } else { return conf.getTable(); } }
public static IndexerComponentFactory getComponentFactory(String factoryClass, InputStream configuration, Map<String, String> connectionParams) { IndexerComponentFactory factory; if (factoryClass == null) { factory = new DefaultIndexerComponentFactory(); } else { try { factory = (IndexerComponentFactory)Class.forName(factoryClass).newInstance(); } catch (InstantiationException e) { throw new AssertionError(e); } catch (IllegalAccessException e) { throw new AssertionError(e); } catch (ClassNotFoundException e) { throw new AssertionError(e); } } factory.configure(configuration, connectionParams); return factory; }
private Map<String, String> buildParams(Element parentElement) { Map<String, String> params = Maps.newHashMap(); for (Element paramElement : evalXPathAsElementList("param", parentElement)) { String key = getAttribute(paramElement, "name", true); String value = getAttribute(paramElement, "value", true); params.put(key, value); } return params; }
public static String getAttribute(Element element, String name, boolean required) { if (!element.hasAttribute(name)) { if (required) throw new IndexerConfException("Missing attribute " + name + " on element " + element.getLocalName()); else return null; } return element.getAttribute(name); }
public IndexerConfBuilder addFieldDefinition(String name, String valueExpression, ValueSource valueSource, String typeName, Map<String, String> params) { fieldDefinitions.add(new FieldDefinition(name, valueExpression, valueSource == null ? IndexerConf.DEFAULT_VALUE_SOURCE : valueSource, typeName == null ? IndexerConf.DEFAULT_FIELD_TYPE : typeName, params)); return this; }
public IndexerConfBuilder addDocumentExtractDefinition(String prefix, String valueExpression, ValueSource valueSource, String type, Map<String, String> params) { documentExtractDefinitions.add(new DocumentExtractDefinition(prefix, valueExpression, valueSource == null ? IndexerConf.DEFAULT_VALUE_SOURCE : valueSource, type == null ? IndexerConf.DEFAULT_EXTRACT_TYPE : type, params)); return this; }
private static Document parse(InputStream is) throws IndexerConfException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); try { return factory.newDocumentBuilder().parse(is); } catch (ParserConfigurationException e) { throw new IndexerConfException("Failed to parse configuration", e); } catch (IOException e) { throw new IndexerConfException("Failed to parse configuration", e); } catch (SAXException e) { throw new IndexerConfException("Failed to parse configuration", e); } }