Search in sources :

Example 1 with OptionDescription

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();
    }
}
Also used : OptionDescription(org.apache.drill.exec.server.options.OptionValidator.OptionDescription) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) OptionValue(org.apache.drill.exec.server.options.OptionValue) ArrayList(java.util.ArrayList) File(java.io.File) OptionManager(org.apache.drill.exec.server.options.OptionManager) OptionList(org.apache.drill.exec.server.options.OptionList) BufferedWriter(java.io.BufferedWriter)

Example 2 with OptionDescription

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;
}
Also used : OptionDescription(org.apache.drill.exec.server.options.OptionValidator.OptionDescription)

Aggregations

OptionDescription (org.apache.drill.exec.server.options.OptionValidator.OptionDescription)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 OptionList (org.apache.drill.exec.server.options.OptionList)1 OptionManager (org.apache.drill.exec.server.options.OptionManager)1 OptionValue (org.apache.drill.exec.server.options.OptionValue)1