use of org.apache.drill.exec.server.options.OptionValidator.OptionDescription in project drill by apache.
the class WebServer method generateOptionsDescriptionJSFile.
/**
* Generate Options Description JavaScript to serve http://drillhost/options ACE library search features
* @throws IOException when unable to generate functions JS file
*/
private void generateOptionsDescriptionJSFile() throws IOException {
// Obtain list of Options & their descriptions
OptionManager optionManager = this.drillbit.getContext().getOptionManager();
OptionList publicOptions = optionManager.getPublicOptionList();
List<OptionValue> options = new ArrayList<>(publicOptions);
// Add internal options
OptionList internalOptions = optionManager.getInternalOptionList();
options.addAll(internalOptions);
Collections.sort(options);
int numLeftToWrite = options.size();
// Template source Javascript file
InputStream optionsDescribeTemplateStream = Resource.newClassPathResource(OPTIONS_DESCRIBE_TEMPLATE_JS).getInputStream();
// Generated file
File optionsDescriptionFile = new File(getOrCreateTmpJavaScriptDir(), OPTIONS_DESCRIBE_JS);
final String file_content_footer = "};";
// Create a copy of a template and write with that!
java.nio.file.Files.copy(optionsDescribeTemplateStream, optionsDescriptionFile.toPath());
logger.info("Will write {} descriptions to {}", numLeftToWrite, optionsDescriptionFile.getAbsolutePath());
try (BufferedWriter writer = new BufferedWriter(new FileWriter(optionsDescriptionFile, true))) {
// Iterate through options
for (OptionValue option : options) {
numLeftToWrite--;
String optionName = option.getName();
OptionDescription optionDescription = optionManager.getOptionDefinition(optionName).getValidator().getOptionDescription();
if (optionDescription != null) {
// Note: We don't need to worry about short descriptions for WebUI, since they will never be explicitly accessed from the map
writer.append(" \"").append(optionName).append("\" : \"").append(StringEscapeUtils.escapeEcmaScript(optionDescription.getDescription())).append(numLeftToWrite > 0 ? "\"," : "\"");
writer.newLine();
}
}
writer.append(file_content_footer);
writer.newLine();
writer.flush();
}
}
use of org.apache.drill.exec.server.options.OptionValidator.OptionDescription in project drill by apache.
the class ExtendedOptionIterator method getShortDescription.
// Extract a limited length from the original description if not available
private String getShortDescription(String name) {
OptionDescription optionDescription = fragmentOptions.getOptionDefinition(name).getValidator().getOptionDescription();
if (optionDescription == null) {
return "";
}
String description;
if (optionDescription.hasShortDescription()) {
description = optionDescription.getShortDescription();
} else {
description = optionDescription.getDescription();
if (description.length() > SHORT_DESCRIP_MAX_SIZE) {
// Append ellipsis (trailing dots)
return description.substring(0, SHORT_DESCRIP_MAX_SIZE - 3).concat("...");
}
}
return description;
}
Aggregations