List of usage examples for org.apache.hadoop.conf Configuration getBoolean
public boolean getBoolean(String name, boolean defaultValue)
name
property as a boolean
. From source file:com.marklogic.contentpump.Command.java
License:Apache License
protected static boolean isStreaming(CommandLine cmdline, Configuration conf) { if (conf.get(MarkLogicConstants.OUTPUT_STREAMING) != null) { return conf.getBoolean(MarkLogicConstants.OUTPUT_STREAMING, false); }/*from w ww . j av a 2s . co m*/ String arg = null; if (cmdline.hasOption(STREAMING)) { arg = cmdline.getOptionValue(STREAMING); if (arg == null || arg.equalsIgnoreCase("true")) { InputType inputType = getInputType(cmdline); if (inputType != InputType.DOCUMENTS) { LOG.warn("Streaming option is not applicable to input " + "type " + inputType); conf.setBoolean(MarkLogicConstants.OUTPUT_STREAMING, false); return false; } else { conf.setBoolean(MarkLogicConstants.OUTPUT_STREAMING, true); return true; } } } conf.setBoolean(MarkLogicConstants.OUTPUT_STREAMING, false); return false; }
From source file:com.marklogic.contentpump.Command.java
License:Apache License
static void applyModuleConfigOptions(Configuration conf, CommandLine cmdline) { if (cmdline.hasOption(TRANSFORM_MODULE)) { applyBatchTxn(conf, cmdline, 1); if (conf.getBoolean(MarkLogicConstants.OUTPUT_STREAMING, false) == true) { throw new UnsupportedOperationException("Server-side transformation can't work with streaming"); }/*from w w w . j a v a 2s . c o m*/ String arg = cmdline.getOptionValue(TRANSFORM_MODULE); conf.set(CONF_TRANSFORM_MODULE, arg); if (cmdline.hasOption(TRANSFORM_NAMESPACE)) { arg = cmdline.getOptionValue(TRANSFORM_NAMESPACE); conf.set(CONF_TRANSFORM_NAMESPACE, arg); } if (cmdline.hasOption(TRANSFORM_FUNCTION)) { arg = cmdline.getOptionValue(TRANSFORM_FUNCTION); conf.set(CONF_TRANSFORM_FUNCTION, arg); } if (cmdline.hasOption(TRANSFORM_PARAM)) { arg = cmdline.getOptionValue(TRANSFORM_PARAM); conf.set(CONF_TRANSFORM_PARAM, arg); } } else { applyBatchTxn(conf, cmdline, MAX_BATCH_SIZE); } }
From source file:com.marklogic.contentpump.CompressedDocumentInputFormat.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from www . java2s . c o m*/ public RecordReader<DocumentURIWithSourceInfo, VALUE> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException { Configuration conf = context.getConfiguration(); boolean streaming = conf.getBoolean(MarkLogicConstants.OUTPUT_STREAMING, false); if (streaming) { return (RecordReader<DocumentURIWithSourceInfo, VALUE>) new CompressedStreamingReader(); } else { return new CompressedDocumentReader<VALUE>(); } }
From source file:com.marklogic.contentpump.DatabaseContentReader.java
License:Apache License
public DatabaseContentReader(Configuration conf) { super(conf);/*from ww w .j a va 2 s.com*/ copyCollection = conf.getBoolean(ConfigConstants.CONF_COPY_COLLECTIONS, false); copyPermission = conf.getBoolean(ConfigConstants.CONF_COPY_PERMISSIONS, false); copyProperties = conf.getBoolean(ConfigConstants.CONF_COPY_PROPERTIES, false); copyQuality = conf.getBoolean(ConfigConstants.CONF_COPY_QUALITY, false); currentKey = new DocumentURI(); metadataMap = new HashMap<String, DocumentMetadata>(); }
From source file:com.marklogic.contentpump.DatabaseContentWriter.java
License:Apache License
public DatabaseContentWriter(Configuration conf, Map<String, ContentSource> forestSourceMap, boolean fastLoad, AssignmentManager am) {// w ww . j a v a2 s . com super(conf, forestSourceMap, fastLoad, am); if (countBased) { metadatas = new URIMetadata[1][batchSize]; } else { metadatas = new URIMetadata[forestIds.length][batchSize]; } isCopyProps = conf.getBoolean(ConfigConstants.CONF_COPY_PROPERTIES, true); isCopyPerms = conf.getBoolean(ConfigConstants.CONF_COPY_PERMISSIONS, true); isCopyColls = conf.getBoolean(ConfigConstants.CONF_COPY_COLLECTIONS, true); isCopyQuality = conf.getBoolean(ConfigConstants.CONF_COPY_QUALITY, true); }
From source file:com.marklogic.contentpump.DelimitedTextInputFormat.java
License:Apache License
private boolean isSplitInput(Configuration conf) { return conf.getBoolean(ConfigConstants.CONF_SPLIT_INPUT, false); }
From source file:com.marklogic.contentpump.FileAndDirectoryInputFormat.java
License:Apache License
@Override protected boolean isSplitable(JobContext context, Path filename) { Configuration conf = context.getConfiguration(); return conf.getBoolean(ConfigConstants.CONF_SPLIT_INPUT, false) && !conf.getBoolean(ConfigConstants.INPUT_COMPRESSED, false); }
From source file:com.marklogic.contentpump.ImportRecordReader.java
License:Apache License
@SuppressWarnings("unchecked") protected void configFileNameAsCollection(Configuration conf, Path file) { if (file == null) { return;//from w w w.jav a 2 s .c o m } if (conf.getBoolean(CONF_OUTPUT_FILENAME_AS_COLLECTION, false)) { if (value instanceof ContentWithFileNameWritable) { ((ContentWithFileNameWritable<VALUEIN>) value).setFileName(file.getName()); } else { Writable cvalue = new ContentWithFileNameWritable<VALUEIN>((VALUEIN) value, file.getName()); value = (VALUEIN) cvalue; } } }
From source file:com.marklogic.contentpump.utilities.AuditUtil.java
License:Apache License
/** * @param job//from ww w .java2 s .com * @param counters * @throws IOException */ public static void auditMlcpFinish(Configuration conf, String jobName, Counters counters) throws IOException { if (!conf.getBoolean(ConfigConstants.CONF_AUDIT_MLCPFINISH_ENABLED, false)) { return; } StringBuilder auditBuf = new StringBuilder(); auditBuf.append("job="); auditBuf.append(jobName); auditBuf.append(";"); Iterator<CounterGroup> groupIt = counters.iterator(); int groupCounter = 0; while (groupIt.hasNext()) { CounterGroup group = groupIt.next(); if (groupCounter != 0) { auditBuf.append("; "); } else { auditBuf.append(" "); } auditBuf.append('('); auditBuf.append(group.getDisplayName()); auditBuf.append(") "); Iterator<Counter> counterIt = group.iterator(); int counterCount = 0; while (counterIt.hasNext()) { if (counterCount != 0) { auditBuf.append(", "); } Counter counter = counterIt.next(); auditBuf.append(counter.getDisplayName()); auditBuf.append('='); auditBuf.append(counter.getValue()); counterCount++; } groupCounter++; } String ruleCounter = conf.get(ConfigConstants.CONF_AUDIT_MLCPFINISH_MESSAGE); if (ruleCounter != null) { auditBuf.append("; "); auditBuf.append(ruleCounter); } String auditMessage = auditBuf.toString(); auditBuf = new StringBuilder(); auditBuf.append("xquery version \"1.0-ml\";\n"); auditBuf.append("xdmp:audit(\"mlcpfinish\",\""); auditBuf.append(auditMessage); auditBuf.append("\", xdmp:get-current-user())"); String auditQueryStr = auditBuf.toString(); Session auditSession = null; ContentSource auditCs = null; try { auditCs = InternalUtilities.getInputContentSource(conf); auditSession = auditCs.newSession(); RequestOptions options = new RequestOptions(); options.setCacheResult(false); AdhocQuery auditQuery = auditSession.newAdhocQuery(auditQueryStr); auditQuery.setOptions(options); auditSession.submitRequest(auditQuery); } catch (XccConfigException e) { LOG.error(e); throw new IOException(e); } catch (URISyntaxException e) { LOG.error(e); throw new IOException(e); } catch (RequestException e) { LOG.error(e); LOG.error("Query: " + auditQueryStr); throw new IOException(e); } }
From source file:com.marklogic.mapreduce.ContentOutputFormat.java
License:Apache License
@Override public void checkOutputSpecs(Configuration conf, ContentSource cs) throws IOException { Session session = null;/*w w w . ja v a2s . c o m*/ ResultSequence result = null; try { session = cs.newSession(); RequestOptions options = new RequestOptions(); options.setDefaultXQueryVersion("1.0-ml"); session.setDefaultRequestOptions(options); // clear output dir if specified String outputDir = conf.get(OUTPUT_DIRECTORY); if (outputDir != null) { outputDir = outputDir.endsWith("/") ? outputDir : outputDir + "/"; if (conf.getBoolean(OUTPUT_CLEAN_DIR, false)) { // delete directory if exists String queryText = DELETE_DIRECTORY_TEMPLATE.replace(DIRECTORY_TEMPLATE, outputDir); AdhocQuery query = session.newAdhocQuery(queryText); result = session.submitRequest(query); } else { // ensure nothing exists under output dir String queryText = CHECK_DIRECTORY_EXIST_TEMPLATE.replace(DIRECTORY_TEMPLATE, outputDir); AdhocQuery query = session.newAdhocQuery(queryText); result = session.submitRequest(query); if (result.hasNext()) { ResultItem item = result.next(); if (((XSBoolean) (item.getItem())).asBoolean()) { throw new IllegalStateException("Directory " + outputDir + " already exists"); } } else { throw new IllegalStateException("Failed to query directory content."); } } } // initialize server host name and assignment policy initialize(session); // ensure manual directory creation if (fastLoad) { LOG.info("Running in fast load mode"); // store forest-info map into config system DefaultStringifier.store(conf, queryForestInfo(cs), OUTPUT_FOREST_HOST); AdhocQuery query = session.newAdhocQuery(DIRECTORY_CREATE_QUERY); result = session.submitRequest(query); if (result.hasNext()) { ResultItem item = result.next(); String dirMode = item.asString(); if (!dirMode.equals(MANUAL_DIRECTORY_MODE)) { throw new IllegalStateException("Manual directory creation mode is required. " + "The current creation mode is " + dirMode + "."); } } else { throw new IllegalStateException("Failed to query directory creation mode."); } } else { TextArrayWritable hostArray; // 23798: replace hostname in forest config with // user-specified output host String outputHost = conf.get(OUTPUT_HOST); if (MODE_LOCAL.equals(conf.get(EXECUTION_MODE))) { hostArray = queryHosts(cs, initHostName, outputHost); } else { hostArray = queryHosts(cs); } DefaultStringifier.store(conf, hostArray, OUTPUT_FOREST_HOST); } // validate capabilities String[] perms = conf.getStrings(OUTPUT_PERMISSION); if (perms != null && perms.length > 0) { if (perms.length % 2 != 0) { throw new IllegalStateException("Permissions are expected to be in <role, capability> pairs."); } int i = 0; while (i + 1 < perms.length) { String roleName = perms[i++]; if (roleName == null || roleName.isEmpty()) { throw new IllegalStateException("Illegal role name: " + roleName); } String perm = perms[i].trim(); if (!perm.equalsIgnoreCase(ContentCapability.READ.toString()) && !perm.equalsIgnoreCase(ContentCapability.EXECUTE.toString()) && !perm.equalsIgnoreCase(ContentCapability.INSERT.toString()) && !perm.equalsIgnoreCase(ContentCapability.UPDATE.toString())) { throw new IllegalStateException("Illegal capability: " + perm); } i++; } } } catch (RequestException ex) { throw new IOException(ex); } finally { if (session != null) { session.close(); } if (result != null) { result.close(); } } }