Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

/** * Internal class used by REST API to provide plugin information and the macros used in the plugin. */ class PluginInfo { Plugin plugin; MacroInfo macroInfo; }
Code Block
GET: /v3/namespaces/{namespace-id}/apps/{app-id}/plugins/{plugin-id}
 
{plugin-id} is unique in the
app.
this will return JSONlist of PluginInfoPlugin object's correspondingused toby the plugin-idapp. 
Code Block

 

 

Code Block
// No changes to existing Plugin class in CDAP-API.
public final class Plugin {
  private final ArtifactId artifactId;
  private final PluginClass pluginClass;
  private final PluginProperties properties;
   Plugin(ArtifactId artifactId, PluginClass pluginClass, PluginProperties) {
	...
  }
  ...
}
Code Block
/**
 * Plugin instance properties.
 */
@Beta
internalpublic class classPluginProperties implements MacroInfoSerializable {

  private static final long serialVersionUID = -7396484717511717753L;

  /* macro properties used at this plugin// Currently only support String->String map.
  private final Map<String, String> properties;
  private final Set<String> macros;

  public * Examples :static Builder builder() {
    *return for the field value ${hostname}:${port}/${path}, the set would be[hostname, port, path]
   * for the field value ${key1:${key2}}, the set would be [key2, key1:${key2}]new Builder();
  }

  private PluginProperties(Map<String, String> properties) {
    this.properties = properties;
    this.macros = new HashSet<String>();
  }
  
  /**
   * return the set of macros used by the plugin
   */  
  public Set<String> getMacros() {
   return macros;
  }
  
  /**
   * internal method used by platform to add macros used in properties. its not advisable for users to use this. 
   */  
  public void addMacro(String macro) {
    macros.add(macro);
  }
 
  // no changes to existing methods or Builder
  public Map<String, String> getProperties() {
    return properties;
  }

  /**
   * forA thebuilder fieldto valuecreate \${u-name}, the set would be empty as macro is escaped  {@link PluginProperties} instance.
   */
  public static final class Builder {

    private final Map<String, String> properties;

    private Builder() {
      this.properties = new HashMap<>();
    }

    /**
     * Adds multiple properties.
     *
     * @param properties map of properties to add.
     * @return this builder
     * for the field value ${key1\${key2}}, the set would be [key1\${key2}] so the user understands key2 is not a macro and will provide value for         the key, "key1${key2}"
   */
	Set<String> properties; 
	Set<MacroFunction> functions;
}


class MacroFunction {
	String functionName;
	List<String> arguments;
}

 

Notes:

MacroInfo object can be constructed by looking into plugin properties and for the fields which are macro enabled, we can use the parser to get the macros used in those fields.

...

/
    public Builder addAll(Map<String, String> properties) {
      this.properties.putAll(properties);
      return this;
    }

    /**
     * Adds a property
     * @param key the name of the property
     * @param value the value of the property
     * @return this builder
     */
    public Builder add(String key, String value) {
      this.properties.put(key, value);
      return this;
    }

    /**
     * Creates a new instance of {@link PluginProperties} with the properties added to this builder prior to this call.
     */
    public PluginProperties build() {
      return new PluginProperties(Collections.unmodifiableMap(new HashMap<>(properties)));
    }
  }
}